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

add web-view onWebInvokeAppService

上级 2deea6b5
......@@ -46,6 +46,17 @@ function onAppEnterForeground () {
callCurrentPageHook('onShow')
}
function onWebInvokeAppService ({
name,
arg
}, pageId) {
if (name === 'postMessage') {
// TODO 小程序后退、组件销毁、分享时通知
} else {
uni[name](arg)
}
}
export default function initOn (on) {
on('onError', onError)
on('onPageNotFound', onPageNotFound)
......@@ -57,4 +68,6 @@ export default function initOn (on) {
on('onTabItemTap', createCallCurrentPageHook('onTabItemTap'))
on('onNavigationBarButtonTap', createCallCurrentPageHook('onNavigationBarButtonTap'))
on('onWebInvokeAppService', onWebInvokeAppService)
}
......@@ -25,6 +25,10 @@
</uni-app>
</template>
<script>
import {
isPlainObject
} from 'uni-shared'
import {
TABBAR_HEIGHT
} from 'uni-helpers/constants'
......@@ -68,7 +72,6 @@ export default {
UniServiceJSBridge.emit('onHidePopup')
},
hideTabBar (newVal, oldVal) {
if (__PLATFORM__ === 'h5') {
// TODO 不支持 css 变量时
if (uni.canIUse('css.var')) {
const windowBottom = !newVal ? (TABBAR_HEIGHT + 'px') : '0px'
......@@ -76,16 +79,18 @@ export default {
console.debug(`uni.${windowBottom ? 'showTabBar' : 'hideTabBar'}:--window-bottom=${windowBottom}`)
}
}
}
},
created () {
if (__PLATFORM__ === 'h5') {
if (uni.canIUse('css.var')) {
document.documentElement.style.setProperty('--status-bar-height', '0px')
}
}
},
mounted () {
window.addEventListener('message', function (evt) {
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')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册