提交 f1c80512 编写于 作者: L liuxiaohang

fix(app): 修复当页面存在多个weiview,返回时子webview取值有误

上级 7f2e5230
...@@ -20,3 +20,4 @@ export const INVOKE_API = 'invokeApi' ...@@ -20,3 +20,4 @@ export const INVOKE_API = 'invokeApi'
export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE' export const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
export const WEBVIEW_INSERTED = 'webviewInserted' export const WEBVIEW_INSERTED = 'webviewInserted'
export const WEBVIEW_REMOVED = 'webviewRemoved' export const WEBVIEW_REMOVED = 'webviewRemoved'
export const WEBVIEW_ID_PREFIX = 'webviewId'
...@@ -3,6 +3,10 @@ import { ...@@ -3,6 +3,10 @@ import {
ANI_DURATION ANI_DURATION
} from '../../constants' } from '../../constants'
import {
WEBVIEW_ID_PREFIX
} from '../../../constants'
import { import {
setStatusBarStyle setStatusBarStyle
} from '../../bridge' } from '../../bridge'
...@@ -30,7 +34,10 @@ function backWebview (webview, callback) { ...@@ -30,7 +34,10 @@ function backWebview (webview, callback) {
if (!children || !children.length) { // 有子 webview if (!children || !children.length) { // 有子 webview
return callback() return callback()
} }
const childWebview = children[0]
// 如果页面有subNvues,切使用了webview组件,则返回时子webview会取错,因此需要做id匹配
const childWebview = children.find(webview => webview.id.indexOf(WEBVIEW_ID_PREFIX) === 0) || children[0]
console.log('backWebview -> childWebview', childWebview)
childWebview.canBack(({ childWebview.canBack(({
canBack canBack
}) => { }) => {
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
<script> <script>
import { import {
WEBVIEW_INSERTED, WEBVIEW_INSERTED,
WEBVIEW_REMOVED WEBVIEW_REMOVED,
WEBVIEW_ID_PREFIX
} from '../../../constants' } from '../../../constants'
import { NAVBAR_HEIGHT } from 'uni-helpers/constants' import { NAVBAR_HEIGHT } from 'uni-helpers/constants'
...@@ -92,7 +93,7 @@ export default { ...@@ -92,7 +93,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.htmlId = 'webviewId' + this.$page.id this.htmlId = WEBVIEW_ID_PREFIX + this.$page.id
insertHTMLWebView({ insertHTMLWebView({
htmlId: this.htmlId htmlId: this.htmlId
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册