@mpxjs/webpack-plugin 2.8.54 → 2.8.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl"></iframe>
|
|
2
|
+
<iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl" :key="currentUrl"></iframe>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
@@ -11,91 +11,115 @@
|
|
|
11
11
|
const eventMessage = 'message'
|
|
12
12
|
const mpx = global.__mpx
|
|
13
13
|
export default {
|
|
14
|
-
data: function () {
|
|
15
|
-
return {
|
|
16
|
-
origin: '',
|
|
17
|
-
messageList: [],
|
|
18
|
-
Loaded: false,
|
|
19
|
-
isActived: false,
|
|
20
|
-
mpxIframe: null,
|
|
21
|
-
isPostMessage: false,
|
|
22
|
-
currentUrl: ''
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
14
|
props: {
|
|
26
15
|
src: {
|
|
27
16
|
type: String
|
|
28
17
|
}
|
|
29
18
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
let host
|
|
33
|
-
host = value.split('/')
|
|
19
|
+
computed: {
|
|
20
|
+
host () {
|
|
21
|
+
let host = this.src.split('/')
|
|
34
22
|
if (host[2]) {
|
|
35
23
|
host = host[0] + '//' + host[2]
|
|
36
24
|
} else {
|
|
37
25
|
host = ''
|
|
38
26
|
}
|
|
39
|
-
|
|
27
|
+
return host
|
|
28
|
+
},
|
|
29
|
+
currentUrl () {
|
|
30
|
+
if (!this.src) return ''
|
|
31
|
+
const hostValidate = this.hostValidate(this.host)
|
|
40
32
|
if (!hostValidate) {
|
|
41
33
|
console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
|
|
42
|
-
return
|
|
34
|
+
return ''
|
|
43
35
|
}
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
36
|
+
return this.src
|
|
37
|
+
},
|
|
38
|
+
loadData () {
|
|
39
|
+
return {
|
|
40
|
+
src: this.host,
|
|
41
|
+
fullUrl: this.src
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
watch: {
|
|
46
|
+
currentUrl: {
|
|
47
|
+
handler (value) {
|
|
48
|
+
if (!value) {
|
|
49
|
+
this.$emit(eventError, getCustomEvent(eventError, {
|
|
50
|
+
...this.loadData,
|
|
51
|
+
errMsg: 'web-view load failed due to not in domain list'
|
|
52
|
+
}, this))
|
|
53
|
+
} else {
|
|
54
|
+
this.$nextTick(() => {
|
|
55
|
+
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
|
|
56
|
+
this.mpxIframe = this.$refs.mpxIframe
|
|
57
|
+
this.mpxIframe.addEventListener('load', (event) => {
|
|
58
|
+
this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
})
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
},
|
|
64
|
+
immediate: true
|
|
53
65
|
}
|
|
54
66
|
},
|
|
67
|
+
beforeCreate () {
|
|
68
|
+
this.messageList = []
|
|
69
|
+
},
|
|
55
70
|
mounted () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
window.addEventListener('message', this.messageCallback)
|
|
72
|
+
},
|
|
73
|
+
deactivated () {
|
|
74
|
+
if (!this.messageList.length) {
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
let data = {
|
|
78
|
+
type: 'message',
|
|
79
|
+
data: this.messageList
|
|
80
|
+
}
|
|
81
|
+
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
82
|
+
},
|
|
83
|
+
destroyed () {
|
|
84
|
+
window.removeEventListener('message', this.messageCallback)
|
|
85
|
+
if (!this.messageList.length) {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
let data = {
|
|
89
|
+
type: 'message',
|
|
90
|
+
data: this.messageList
|
|
91
|
+
}
|
|
92
|
+
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
93
|
+
},
|
|
94
|
+
methods: {
|
|
95
|
+
messageCallback (event) {
|
|
65
96
|
const hostValidate = this.hostValidate(event.origin)
|
|
66
|
-
const hasPostMessage = this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage
|
|
67
97
|
const data = event.data
|
|
68
98
|
const value = data.payload
|
|
69
|
-
if (!
|
|
99
|
+
if (!hostValidate) {
|
|
70
100
|
return
|
|
71
101
|
}
|
|
72
102
|
let asyncCallback = null
|
|
73
103
|
switch (data.type) {
|
|
74
104
|
case 'postMessage':
|
|
75
|
-
this.
|
|
76
|
-
this.messageList.push(value.data)
|
|
105
|
+
this.messageList.push(value)
|
|
77
106
|
asyncCallback = Promise.resolve({
|
|
78
107
|
errMsg: 'invokeWebappApi:ok'
|
|
79
108
|
})
|
|
80
109
|
break
|
|
81
110
|
case 'navigateTo':
|
|
82
|
-
this.isActived = false
|
|
83
111
|
asyncCallback = navigateTo(value)
|
|
84
112
|
break
|
|
85
113
|
case 'navigateBack':
|
|
86
|
-
this.isActived = false
|
|
87
114
|
asyncCallback = value ? navigateBack(value) : navigateBack()
|
|
88
115
|
break
|
|
89
116
|
case 'redirectTo':
|
|
90
|
-
this.isActived = false
|
|
91
117
|
asyncCallback = redirectTo(value)
|
|
92
118
|
break
|
|
93
119
|
case 'switchTab':
|
|
94
|
-
this.isActived = false
|
|
95
120
|
asyncCallback = switchTab(value)
|
|
96
121
|
break
|
|
97
122
|
case 'reLaunch':
|
|
98
|
-
this.isActived = false
|
|
99
123
|
asyncCallback = reLaunch(value)
|
|
100
124
|
break
|
|
101
125
|
case 'getLocation':
|
|
@@ -110,45 +134,19 @@
|
|
|
110
134
|
break
|
|
111
135
|
}
|
|
112
136
|
asyncCallback && asyncCallback.then((res) => {
|
|
113
|
-
|
|
137
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
114
138
|
type: data.type,
|
|
115
139
|
callbackId: data.callbackId,
|
|
116
140
|
result: res
|
|
117
141
|
}, event.origin)
|
|
118
142
|
}).catch((error) => {
|
|
119
|
-
|
|
143
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
120
144
|
type: data.type,
|
|
121
145
|
callbackId: data.callbackId,
|
|
122
146
|
error
|
|
123
147
|
}, event.origin)
|
|
124
148
|
})
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
activated () {
|
|
128
|
-
this.isActived = true
|
|
129
|
-
this.isPostMessage = false
|
|
130
|
-
},
|
|
131
|
-
deactivated () {
|
|
132
|
-
if (!this.isPostMessage) {
|
|
133
|
-
return
|
|
134
|
-
}
|
|
135
|
-
let data = {
|
|
136
|
-
type: 'message',
|
|
137
|
-
data: this.messageList
|
|
138
|
-
}
|
|
139
|
-
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
140
|
-
},
|
|
141
|
-
destroyed () {
|
|
142
|
-
if (!this.isPostMessage) {
|
|
143
|
-
return
|
|
144
|
-
}
|
|
145
|
-
let data = {
|
|
146
|
-
type: 'message',
|
|
147
|
-
data: this.messageList
|
|
148
|
-
}
|
|
149
|
-
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
150
|
-
},
|
|
151
|
-
methods: {
|
|
149
|
+
},
|
|
152
150
|
hostValidate (host) {
|
|
153
151
|
const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
|
|
154
152
|
if (hostWhitelists.length) {
|
|
@@ -89,7 +89,7 @@ module.exports = function (css, map) {
|
|
|
89
89
|
.process(css, options)
|
|
90
90
|
.then(result => {
|
|
91
91
|
// ali环境添加全局样式抹平root差异
|
|
92
|
-
if (mode === 'ali' && isApp) {
|
|
92
|
+
if ((mode === 'ali' || mode === 'web') && isApp) {
|
|
93
93
|
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
|
|
94
94
|
}
|
|
95
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.56",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=14.14.0"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "391feabc6246acfa17271aa632adf5da2c308a05"
|
|
85
85
|
}
|