Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
菜鸟程序猿_c
uni-app
提交
ba98c592
U
uni-app
项目概览
菜鸟程序猿_c
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ba98c592
编写于
8月 27, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(App-nvue): createLivePusherContext、createVideoContext、createMapContext
上级
51111f73
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
350 addition
and
0 deletion
+350
-0
packages/uni-api/src/protocols/context/context.ts
packages/uni-api/src/protocols/context/context.ts
+10
-0
packages/uni-app-plus/src/service/api/context/createLivePusherContext.ts
...p-plus/src/service/api/context/createLivePusherContext.ts
+98
-0
packages/uni-app-plus/src/service/api/context/operateMap.ts
packages/uni-app-plus/src/service/api/context/operateMap.ts
+64
-0
packages/uni-app-plus/src/service/api/context/operateVideoPlayer.ts
...ni-app-plus/src/service/api/context/operateVideoPlayer.ts
+47
-0
packages/uni-app-plus/src/service/api/index.ts
packages/uni-app-plus/src/service/api/index.ts
+1
-0
packages/uni-app-plus/src/service/api/util.ts
packages/uni-app-plus/src/service/api/util.ts
+127
-0
packages/uni-app-plus/src/view/components/video/index.tsx
packages/uni-app-plus/src/view/components/video/index.tsx
+3
-0
未找到文件。
packages/uni-api/src/protocols/context/context.ts
浏览文件 @
ba98c592
...
...
@@ -34,3 +34,13 @@ export const CreateCanvasContextProtocol: ProtocolOptions<String | Object>[] = [
export
const
API_CREATE_INNER_AUDIO_CONTEXT
=
'
createInnerAudioContext
'
export
type
API_TYPE_CREATEE_INNER_AUDIO_CONTEXT
=
typeof
uni
.
createInnerAudioContext
export
const
API_CREATE_LIVE_PUSHER_CONTEXT
=
'
createLivePusherContext
'
export
type
API_TYPE_CREATE_LIVE_PUSHER_CONTEXT
=
(
id
:
string
,
componentInstance
:
any
)
=>
ReturnType
<
typeof
uni
.
createLivePusherContext
>
|
void
export
const
CreateLivePusherContextProtocol
=
validator
.
concat
({
name
:
'
componentInstance
'
,
type
:
Object
,
})
packages/uni-app-plus/src/service/api/context/createLivePusherContext.ts
0 → 100644
浏览文件 @
ba98c592
import
{
API_CREATE_LIVE_PUSHER_CONTEXT
,
API_TYPE_CREATE_LIVE_PUSHER_CONTEXT
,
CreateLivePusherContextProtocol
,
defineSyncApi
,
}
from
'
@dcloudio/uni-api
'
import
{
findElmById
,
invokeVmMethod
,
invokeVmMethodWithoutArgs
,
CallBacks
as
cb
,
}
from
'
../util
'
type
CallBacks
=
Partial
<
cb
>
class
LivePusherContext
implements
UniApp
.
LivePusherContext
{
id
:
string
ctx
:
any
constructor
(
id
:
string
,
ctx
:
any
)
{
this
.
id
=
id
this
.
ctx
=
ctx
}
start
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
start
'
,
option
)
}
stop
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
stop
'
,
option
)
}
pause
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
pause
'
,
option
)
}
resume
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
resume
'
,
option
)
}
switchCamera
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
switchCamera
'
,
option
)
}
snapshot
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
snapshot
'
,
option
)
}
toggleTorch
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
toggleTorch
'
,
option
)
}
playBGM
(
option
?:
CallBacks
)
{
return
invokeVmMethod
(
this
.
ctx
,
'
playBGM
'
,
option
)
}
stopBGM
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
stopBGM
'
,
option
)
}
pauseBGM
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
pauseBGM
'
,
option
)
}
resumeBGM
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
resumeBGM
'
,
option
)
}
setBGMVolume
(
option
?:
CallBacks
)
{
return
invokeVmMethod
(
this
.
ctx
,
'
setBGMVolume
'
,
option
)
}
startPreview
(
option
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
startPreview
'
,
option
)
}
stopPreview
(
args
?:
CallBacks
)
{
return
invokeVmMethodWithoutArgs
(
this
.
ctx
,
'
stopPreview
'
,
args
)
}
'
setMICVolume
'
:
()
=>
{}
}
export
const
createLivePusherContext
=
defineSyncApi
<
API_TYPE_CREATE_LIVE_PUSHER_CONTEXT
>
(
API_CREATE_LIVE_PUSHER_CONTEXT
,
(
id
,
vm
)
=>
{
if
(
!
vm
)
{
return
console
.
warn
(
'
uni.createLivePusherContext: 2 arguments required, but only 1 present
'
)
}
const
elm
=
findElmById
(
id
,
vm
)
if
(
!
elm
)
{
return
console
.
warn
(
'
Can not find `
'
+
id
+
'
`
'
)
}
return
new
LivePusherContext
(
id
,
elm
)
},
CreateLivePusherContextProtocol
)
packages/uni-app-plus/src/service/api/context/operateMap.ts
浏览文件 @
ba98c592
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
findElmById
,
invokeVmMethod
,
invokeVmMethodWithoutArgs
}
from
'
../util
'
type
Methords
=
Record
<
string
,
(
ctx
:
any
,
args
:
any
)
=>
void
>
const
METHODS
:
Methords
=
{
getCenterLocation
(
ctx
,
cbs
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
getCenterLocation
'
,
cbs
)
},
moveToLocation
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
moveToLocation
'
,
args
)
},
translateMarker
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
translateMarker
'
,
args
,
[
'
animationEnd
'
])
},
includePoints
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
includePoints
'
,
args
)
},
getRegion
(
ctx
,
cbs
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
getRegion
'
,
cbs
)
},
getScale
(
ctx
,
cbs
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
getScale
'
,
cbs
)
},
addCustomLayer
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
addCustomLayer
'
,
args
)
},
removeCustomLayer
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
removeCustomLayer
'
,
args
)
},
addGroundOverlay
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
addGroundOverlay
'
,
args
)
},
removeGroundOverlay
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
removeGroundOverlay
'
,
args
)
},
updateGroundOverlay
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
updateGroundOverlay
'
,
args
)
},
initMarkerCluster
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
initMarkerCluster
'
,
args
)
},
addMarkers
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
addMarkers
'
,
args
)
},
removeMarkers
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
removeMarkers
'
,
args
)
},
moveAlong
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
moveAlong
'
,
args
)
},
openMapApp
(
ctx
,
args
)
{
return
invokeVmMethod
(
ctx
,
'
openMapApp
'
,
args
)
},
}
export
function
operateMap
(
id
:
string
,
pageId
:
number
,
...
...
@@ -5,6 +61,14 @@ export function operateMap(
data
?:
unknown
,
operateMapCallback
?:
(
res
:
any
)
=>
void
)
{
const
page
=
getCurrentPages
().
find
((
page
)
=>
page
.
$page
.
id
===
pageId
)
if
(
page
?.
$page
.
meta
.
isNVue
)
{
const
pageVm
=
(
page
as
any
).
$vm
as
ComponentPublicInstance
return
METHODS
[
type
as
keyof
typeof
METHODS
](
findElmById
(
id
,
pageVm
),
data
as
any
)
}
UniServiceJSBridge
.
invokeViewMethod
(
'
map.
'
+
id
,
{
...
...
packages/uni-app-plus/src/service/api/context/operateVideoPlayer.ts
浏览文件 @
ba98c592
import
{
ComponentPublicInstance
}
from
'
vue
'
import
{
findElmById
,
invokeVmMethod
,
invokeVmMethodWithoutArgs
}
from
'
../util
'
const
METHODS
=
{
play
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
play
'
)
},
pause
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
pause
'
)
},
seek
(
ctx
:
any
,
args
:
{
position
:
number
})
{
return
invokeVmMethod
(
ctx
,
'
seek
'
,
args
.
position
)
},
stop
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
stop
'
)
},
sendDanmu
(
ctx
:
any
,
args
:
WechatMiniprogram
.
Danmu
)
{
return
invokeVmMethod
(
ctx
,
'
sendDanmu
'
,
args
)
},
playbackRate
(
ctx
:
any
,
args
:
{
rate
:
number
})
{
return
invokeVmMethod
(
ctx
,
'
playbackRate
'
,
args
.
rate
)
},
requestFullScreen
(
ctx
:
any
,
args
:
WechatMiniprogram
.
VideoContextRequestFullScreenOption
=
{}
)
{
return
invokeVmMethod
(
ctx
,
'
requestFullScreen
'
,
args
)
},
exitFullScreen
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
exitFullScreen
'
)
},
showStatusBar
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
showStatusBar
'
)
},
hideStatusBar
(
ctx
:
any
)
{
return
invokeVmMethodWithoutArgs
(
ctx
,
'
hideStatusBar
'
)
},
}
export
function
operateVideoPlayer
(
videoId
:
string
,
pageId
:
number
,
type
:
string
,
data
?:
unknown
)
{
const
page
=
getCurrentPages
().
find
((
page
)
=>
page
.
$page
.
id
===
pageId
)
if
(
page
?.
$page
.
meta
.
isNVue
)
{
const
pageVm
=
(
page
as
any
).
$vm
as
ComponentPublicInstance
return
METHODS
[
type
as
keyof
typeof
METHODS
](
findElmById
(
videoId
,
pageVm
),
data
as
any
)
}
UniServiceJSBridge
.
invokeViewMethod
(
'
video.
'
+
videoId
,
{
...
...
packages/uni-app-plus/src/service/api/index.ts
浏览文件 @
ba98c592
...
...
@@ -38,6 +38,7 @@ export * from './network/uploadFile'
export
*
from
'
./context/createInnerAudioContext
'
export
*
from
'
./context/getBackgroundAudioManager
'
export
*
from
'
./context/createLivePusherContext
'
export
*
from
'
./location/getLocation
'
export
*
from
'
./location/chooseLocation
'
...
...
packages/uni-app-plus/src/service/api/util.ts
0 → 100644
浏览文件 @
ba98c592
import
{
isFunction
}
from
'
@vue/shared
'
import
{
ComponentPublicInstance
}
from
'
vue
'
const
SUCCESS
=
'
success
'
const
FAIL
=
'
fail
'
const
COMPLETE
=
'
complete
'
const
CALLBACKS
:
CallBackName
[]
=
[
SUCCESS
,
FAIL
,
COMPLETE
]
type
CallBackName
=
typeof
SUCCESS
|
typeof
FAIL
|
typeof
COMPLETE
export
type
CallBacks
=
Record
<
CallBackName
,
Function
>
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
export
function
invokeVmMethodWithoutArgs
(
vm
:
any
,
method
:
string
,
args
?:
any
,
extras
?:
[
any
]
)
{
if
(
!
vm
)
{
return
}
if
(
typeof
args
===
'
undefined
'
)
{
return
vm
[
method
]()
}
const
[,
callbacks
]
=
normalizeArgs
(
args
,
extras
)
if
(
!
Object
.
keys
(
callbacks
).
length
)
{
return
vm
[
method
]()
}
return
vm
[
method
](
normalizeCallback
(
method
,
callbacks
))
}
/**
* 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
export
function
invokeVmMethod
(
vm
:
any
,
method
:
string
,
args
:
any
,
extras
?:
[
any
]
)
{
if
(
!
vm
)
{
return
}
const
[
pureArgs
,
callbacks
]
=
normalizeArgs
(
args
,
extras
)
if
(
!
Object
.
keys
(
callbacks
).
length
)
{
return
vm
[
method
](
pureArgs
)
}
return
vm
[
method
](
pureArgs
,
normalizeCallback
(
method
,
callbacks
))
}
export
function
findElmById
(
id
:
string
,
vm
:
ComponentPublicInstance
)
{
const
elm
=
findRefByElm
(
id
,
vm
.
$el
)
if
(
!
elm
)
{
return
console
.
error
(
'
Can not find `
'
+
id
+
'
`
'
)
}
return
elm
}
function
findRefByElm
(
id
:
string
,
elm
:
any
):
any
{
if
(
!
id
||
!
elm
)
{
return
}
if
(
elm
.
attr
&&
elm
.
attr
.
id
===
id
)
{
return
elm
}
const
children
=
elm
.
children
if
(
!
children
)
{
return
}
for
(
let
i
=
0
,
len
=
children
.
length
;
i
<
len
;
i
++
)
{
const
elm
=
findRefByElm
(
id
,
children
[
i
])
if
(
elm
)
{
return
elm
}
}
}
function
normalizeArgs
(
args
:
any
=
{},
extras
?:
[
any
])
{
const
callbacks
=
Object
.
create
(
null
)
const
iterator
=
function
iterator
(
name
:
string
)
{
const
callback
=
args
[
name
]
if
(
isFunction
(
callback
))
{
callbacks
[
name
]
=
callback
delete
args
[
name
]
}
}
CALLBACKS
.
forEach
(
iterator
)
extras
&&
extras
.
forEach
(
iterator
)
return
[
args
,
callbacks
]
}
function
normalizeCallback
(
method
:
string
,
callbacks
:
CallBacks
)
{
return
function
weexCallback
(
ret
:
any
)
{
const
type
=
ret
.
type
as
CallBackName
delete
ret
.
type
const
callback
=
callbacks
[
type
]
if
(
type
===
SUCCESS
)
{
ret
.
errMsg
=
`
${
method
}
:ok`
}
else
if
(
type
===
FAIL
)
{
ret
.
errMsg
=
method
+
'
:fail
'
+
(
ret
.
msg
?
'
'
+
ret
.
msg
:
''
)
}
delete
ret
.
code
delete
ret
.
msg
isFunction
(
callback
)
&&
callback
(
ret
)
if
(
type
===
SUCCESS
||
type
===
FAIL
)
{
const
complete
=
callbacks
.
complete
isFunction
(
complete
)
&&
complete
(
ret
)
}
}
}
packages/uni-app-plus/src/view/components/video/index.tsx
浏览文件 @
ba98c592
...
...
@@ -233,6 +233,9 @@ export default /*#__PURE__*/ defineBuiltInComponent({
case
'
playbackRate
'
:
options
=
data
.
rate
break
case
'
requestFullScreen
'
:
options
=
data
.
direction
break
}
if
(
video
)
{
video
[
type
as
Method
](
options
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录