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

add web-view onWebInvokeAppService

上级 2deea6b5
...@@ -46,6 +46,17 @@ function onAppEnterForeground () { ...@@ -46,6 +46,17 @@ function onAppEnterForeground () {
callCurrentPageHook('onShow') callCurrentPageHook('onShow')
} }
function onWebInvokeAppService ({
name,
arg
}, pageId) {
if (name === 'postMessage') {
// TODO 小程序后退、组件销毁、分享时通知
} else {
uni[name](arg)
}
}
export default function initOn (on) { export default function initOn (on) {
on('onError', onError) on('onError', onError)
on('onPageNotFound', onPageNotFound) on('onPageNotFound', onPageNotFound)
...@@ -57,4 +68,6 @@ export default function initOn (on) { ...@@ -57,4 +68,6 @@ export default function initOn (on) {
on('onTabItemTap', createCallCurrentPageHook('onTabItemTap')) on('onTabItemTap', createCallCurrentPageHook('onTabItemTap'))
on('onNavigationBarButtonTap', createCallCurrentPageHook('onNavigationBarButtonTap')) on('onNavigationBarButtonTap', createCallCurrentPageHook('onNavigationBarButtonTap'))
on('onWebInvokeAppService', onWebInvokeAppService)
} }
...@@ -6,25 +6,29 @@ ...@@ -6,25 +6,29 @@
<router-view :key="key" /> <router-view :key="key" />
</keep-alive> </keep-alive>
<!-- </transition> --> <!-- </transition> -->
<tab-bar <tab-bar
v-if="hasTabBar" v-if="hasTabBar"
v-show="showTabBar" v-show="showTabBar"
v-bind="tabBar" /> v-bind="tabBar" />
<toast <toast
v-bind="showToast" v-bind="showToast"
@close="_onModalClose" /> @close="_onModalClose" />
<action-sheet <action-sheet
v-bind="showActionSheet" v-bind="showActionSheet"
@close="_onActionSheetClose" /> @close="_onActionSheetClose" />
<modal <modal
v-bind="showModal" v-bind="showModal"
@close="_onModalClose" /> @close="_onModalClose" />
<picker <picker
v-bind="showPicker" v-bind="showPicker"
@close="_onPickerClose" /> @close="_onPickerClose" />
</uni-app> </uni-app>
</template> </template>
<script> <script>
import {
isPlainObject
} from 'uni-shared'
import { import {
TABBAR_HEIGHT TABBAR_HEIGHT
} from 'uni-helpers/constants' } from 'uni-helpers/constants'
...@@ -68,24 +72,25 @@ export default { ...@@ -68,24 +72,25 @@ export default {
UniServiceJSBridge.emit('onHidePopup') UniServiceJSBridge.emit('onHidePopup')
}, },
hideTabBar (newVal, oldVal) { hideTabBar (newVal, oldVal) {
if (__PLATFORM__ === 'h5') { // TODO 不支持 css 变量时
// TODO 不支持 css 变量时 if (uni.canIUse('css.var')) {
if (uni.canIUse('css.var')) { const windowBottom = !newVal ? (TABBAR_HEIGHT + 'px') : '0px'
const windowBottom = !newVal ? (TABBAR_HEIGHT + 'px') : '0px' document.documentElement.style.setProperty('--window-bottom', windowBottom)
document.documentElement.style.setProperty('--window-bottom', windowBottom) console.debug(`uni.${windowBottom ? 'showTabBar' : 'hideTabBar'}:--window-bottom=${windowBottom}`)
console.debug(`uni.${windowBottom ? 'showTabBar' : 'hideTabBar'}:--window-bottom=${windowBottom}`)
}
} }
} }
}, },
created () { created () {
if (__PLATFORM__ === 'h5') { if (uni.canIUse('css.var')) {
if (uni.canIUse('css.var')) { document.documentElement.style.setProperty('--status-bar-height', '0px')
document.documentElement.style.setProperty('--status-bar-height', '0px')
}
} }
}, },
mounted () { 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 () { document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible') { if (document.visibilityState === 'visible') {
UniServiceJSBridge.emit('onAppEnterForeground') UniServiceJSBridge.emit('onAppEnterForeground')
...@@ -106,4 +111,4 @@ export default { ...@@ -106,4 +111,4 @@ export default {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册