提交 22345850 编写于 作者: D DCloud_LXH

feat: web-view bridge

上级 2efcf38d
import { ComponentPublicInstance } from '@vue/runtime-core'
import { getCurrentPage, invokeHook } from './page'
import { onWebInvokeAppService } from '@dcloudio/uni-platform'
export function initOn() {
UniServiceJSBridge.on('onAppEnterForeground', onAppEnterForeground)
UniServiceJSBridge.on('onAppEnterBackground', onAppEnterBackground)
UniServiceJSBridge.on('onWebInvokeAppService', onWebInvokeAppService)
}
function onAppEnterForeground() {
......
此差异已折叠。
此差异已折叠。
import { invokeArrayFns } from '@vue/shared'
import { invokeArrayFns, isPlainObject } from '@vue/shared'
import {
ComponentInternalInstance,
ComponentPublicInstance,
......@@ -127,6 +127,23 @@ export function setupApp(comp: any) {
onBeforeMount(onLaunch)
}
onMounted(() => {
window.addEventListener(
'message',
function (evt: {
data?: { type: string; data: any; pageId: number }
}) {
if (
isPlainObject(evt.data) &&
evt.data.type === 'WEB_INVOKE_APPSERVICE'
) {
UniServiceJSBridge.emit(
'onWebInvokeAppService',
evt.data.data,
evt.data.pageId
)
}
}
)
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') {
UniServiceJSBridge.emit('onAppEnterForeground')
......
......@@ -14,3 +14,4 @@ export {
export * from './saveImage'
export * from './constants'
export { getSameOriginUrl } from '../helpers/file'
export { onWebInvokeAppService } from '../service/onWebInvokeAppService'
type Name =
| 'navigateTo'
| 'navigateBack'
| 'switchTab'
| 'reLaunch'
| 'redirectTo'
| 'postMessage'
export function onWebInvokeAppService(
{ name, arg }: { name: Name; arg: any },
pageId: number
) {
if (name === 'postMessage') {
// TODO 小程序后退、组件销毁、分享时通知
} else {
uni[name](arg)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册