提交 1e0a8c6d 编写于 作者: fxy060608's avatar fxy060608

feat(v3): add getSubNVueById

上级 73efe94d
......@@ -192,7 +192,9 @@ const third = [
'offPush',
'requireNativePlugin',
'upx2px',
'restoreGlobal'
'restoreGlobal',
'getSubNVueById',
'getCurrentSubNVue'
]
const apis = [
......
......@@ -67,4 +67,8 @@ export function getSubNVueById (id) {
wrapper(webview)
}
return webview
}
export function getCurrentSubNVue () {
return getSubNVueById(plus.webview.currentWebview().id)
}
......@@ -44,7 +44,8 @@ export * from './plugin/payment'
export * from './plugin/push'
export * from './plugin/require-native-plugin'
export * from './plugin/share'
export * from './plugin/restore-global'
export * from './plugin/restore-global'
export * from './plugin/sub-nvue'
export * from './route/navigate-back'
export * from './route/navigate-to'
......
import {
requireNativePlugin
} from './require-native-plugin'
function wrapper (webview) {
webview.$processed = true
webview.postMessage = function (data) {
plus.webview.postMessageToUniNView({
type: 'UniAppSubNVue',
data
}, webview.id)
}
let callbacks = []
webview.onMessage = function (callback) {
callbacks.push(callback)
}
webview.$consumeMessage = function (e) {
callbacks.forEach(callback => callback(e))
}
if (!webview.__uniapp_mask_id) {
return
}
const maskColor = webview.__uniapp_mask
let maskWebview = webview.__uniapp_mask_id === '0' ? {
setStyle ({
mask
}) {
requireNativePlugin('uni-tabview').setMask({
color: mask
})
}
} : plus.webview.getWebviewById(webview.__uniapp_mask_id)
const oldShow = webview.show
const oldHide = webview.hide
const oldClose = webview.close
const showMask = function () {
maskWebview.setStyle({
mask: maskColor
})
}
const closeMask = function () {
maskWebview.setStyle({
mask: 'none'
})
}
webview.show = function (...args) {
showMask()
return oldShow.apply(webview, args)
}
webview.hide = function (...args) {
closeMask()
return oldHide.apply(webview, args)
}
webview.close = function (...args) {
closeMask()
callbacks = []
return oldClose.apply(webview, args)
}
}
export function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id)
if (webview && !webview.$processed) {
wrapper(webview)
}
return webview
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册