提交 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)
}
......@@ -6,25 +6,29 @@
<router-view :key="key" />
</keep-alive>
<!-- </transition> -->
<tab-bar
v-if="hasTabBar"
v-show="showTabBar"
<tab-bar
v-if="hasTabBar"
v-show="showTabBar"
v-bind="tabBar" />
<toast
v-bind="showToast"
<toast
v-bind="showToast"
@close="_onModalClose" />
<action-sheet
v-bind="showActionSheet"
<action-sheet
v-bind="showActionSheet"
@close="_onActionSheetClose" />
<modal
v-bind="showModal"
<modal
v-bind="showModal"
@close="_onModalClose" />
<picker
v-bind="showPicker"
<picker
v-bind="showPicker"
@close="_onPickerClose" />
</uni-app>
</template>
<script>
import {
isPlainObject
} from 'uni-shared'
import {
TABBAR_HEIGHT
} from 'uni-helpers/constants'
......@@ -68,24 +72,25 @@ 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'
document.documentElement.style.setProperty('--window-bottom', windowBottom)
console.debug(`uni.${windowBottom ? 'showTabBar' : 'hideTabBar'}:--window-bottom=${windowBottom}`)
}
// TODO 不支持 css 变量时
if (uni.canIUse('css.var')) {
const windowBottom = !newVal ? (TABBAR_HEIGHT + 'px') : '0px'
document.documentElement.style.setProperty('--window-bottom', windowBottom)
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')
}
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')
......@@ -106,4 +111,4 @@ export default {
width: 100%;
height: 100%;
}
</style>
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册