Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改在刷新webview页面后message未被销毁的问题 #1500

Merged
merged 11 commits into from
Jun 19, 2024

Conversation

wangxiaokou
Copy link
Collaborator

No description provided.

@@ -138,7 +138,16 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
...webRouteConfig,
routes: routes
})
global.__mpxRouter.stack = []
const sessionStorage = window.sessionStorage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加ssr判断

@@ -252,6 +261,14 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
global.__mpxRouter.needCache = insertItem
}
}
if (sessionStorage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ssr

@@ -113,8 +113,9 @@
}, window.sdkUrlMap);
var env = null;
var callbackId = 0;
var clientUid;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过query传递获取吧

@@ -55,6 +55,9 @@
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
this.mpxIframe = this.$refs.mpxIframe
this.mpxIframe.addEventListener('load', (event) => {
this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成url query传递

mpxStackPath = []
}
}
global.__mpxRouter.stack = mpxStackPath || []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要||[]

mpxStackPath = JSON.parse(sessionStorage.getItem('_mpx_stack_path_'))
}
} catch (e) {
mpxStackPath = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要

const srcQueryIndex = this.src.indexOf('?')
// webview与被打开页面通过_uid确定关联关系
if (srcQueryIndex > -1) {
src = `${this.src.substring(0, srcQueryIndex + 1)}_mpx_webview_id=${this._uid}&${this.src.substring(srcQueryIndex + 1)}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉都有mpx前缀了就不用_开头了

@@ -62,11 +62,25 @@ const SDK_URL_MAP = {
},
...window.sdkUrlMap
};

function getQueryObj () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成正则匹配获取id把

let env = null;
let callbackId = 0;
let clientUid = +getQueryObj()._mpx_webview_id || undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

|| undefined 不需要

@@ -108,6 +122,7 @@ function postMessage (type, data = {}) {
window.parent.postMessage && window.parent.postMessage({
type,
callbackId,
clientUid,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断一下没有clientUid的情况这里也不用发送了

let env = null
let callbackId = 0
let clientUid = +getQueryObj()._mpx_webview_id || undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该不需要精确类型以及添加||undefined,可以在接受的时候处理

@@ -52,17 +67,6 @@
width: sizeStr,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch有意义么


function getMpxWebViewId () {
const href = location.href
const reg = /(?<=mpx_webview_id=)\d*/g
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个正则匹配有点非主流。。。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/mpx_webview_id=(\d+)/ match[1]

type,
callbackId,
payload: filterData(data)
}, '*')
}
if (typeof clientUid !== 'undefined') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dist没重新构建,以及比较undefined不需要typeof,直接判断clientUid!==undefined就行了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面也有类似的判断,一起改一下

@hiyuki hiyuki merged commit e4cbac3 into master Jun 19, 2024
4 checks passed
@hiyuki hiyuki deleted the fix-web-view-refresh branch June 19, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants