@mpxjs/webpack-plugin 2.8.39 → 2.8.40-test
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.
- package/lib/dependencies/CommonJsExtractDependency.js +51 -0
- package/lib/dependencies/ResolveDependency.js +11 -9
- package/lib/extractor.js +1 -0
- package/lib/helpers.js +9 -1
- package/lib/index.js +173 -72
- package/lib/json-compiler/helper.js +25 -9
- package/lib/json-compiler/index.js +77 -28
- package/lib/loader.js +3 -10
- package/lib/native-loader.js +21 -14
- package/lib/platform/json/wx/index.js +65 -2
- package/lib/platform/run-rules.js +2 -1
- package/lib/platform/template/normalize-component-rules.js +2 -0
- package/lib/platform/template/wx/component-config/README.md +1 -1
- package/lib/platform/template/wx/component-config/fix-html-tag.js +17 -0
- package/lib/platform/template/wx/component-config/hypen-tag-name.js +2 -6
- package/lib/platform/template/wx/component-config/index.js +4 -2
- package/lib/platform/template/wx/component-config/view.js +0 -11
- package/lib/platform/template/wx/index.js +65 -18
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/filterTag.js +9 -30
- package/lib/runtime/components/web/getInnerListeners.js +2 -14
- package/lib/runtime/components/web/mpx-keep-alive.vue +10 -17
- package/lib/runtime/components/web/mpx-movable-view.vue +105 -23
- package/lib/runtime/components/web/mpx-picker-view.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +69 -23
- package/lib/runtime/components/web/mpx-swiper.vue +152 -62
- package/lib/runtime/components/web/mpx-video.vue +123 -89
- package/lib/runtime/components/web/mpx-web-view.vue +120 -81
- package/lib/runtime/components/web/promisify.js +19 -0
- package/lib/runtime/components/wx/default-page.mpx +27 -0
- package/lib/runtime/optionProcessor.js +12 -18
- package/lib/style-compiler/index.js +5 -1
- package/lib/template-compiler/bind-this.js +280 -49
- package/lib/template-compiler/compiler.js +54 -58
- package/lib/template-compiler/index.js +35 -23
- package/lib/utils/dom-tag-config.js +115 -0
- package/lib/utils/make-map.js +12 -0
- package/lib/utils/string.js +7 -1
- package/lib/utils/ts-loader-watch-run-loader-filter.js +4 -5
- package/lib/web/processJSON.js +35 -0
- package/lib/web/processScript.js +7 -4
- package/lib/web/processTemplate.js +7 -34
- package/package.json +4 -4
- package/lib/partial-compile/index.js +0 -35
- package/lib/template-compiler/preprocessor.js +0 -29
- package/lib/wxss/compile-exports.js +0 -52
- package/lib/wxss/createResolver.js +0 -36
- package/lib/wxss/css-base.js +0 -79
- package/lib/wxss/getLocalIdent.js +0 -25
- package/lib/wxss/localsLoader.js +0 -44
- package/lib/wxss/processCss.js +0 -274
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<video
|
|
3
3
|
ref="_mpx_video_ref"
|
|
4
|
-
|
|
5
|
-
:src="src"
|
|
6
|
-
:controls="showControlsTool"
|
|
7
|
-
:autoplay="autoplay"
|
|
8
|
-
:loop="loop"
|
|
9
|
-
:muted="mutedCopy"
|
|
10
|
-
:poster="poster"
|
|
4
|
+
class="video-js"
|
|
11
5
|
v-bind="playsinlineAttr"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
<script>
|
|
6
|
+
></video>
|
|
7
|
+
</template>
|
|
8
|
+
<script>
|
|
17
9
|
import { inheritEvent } from './getInnerListeners'
|
|
10
|
+
import videojs from 'video.js'
|
|
11
|
+
import 'video.js/dist/video-js.min.css'
|
|
18
12
|
|
|
19
13
|
export default {
|
|
20
14
|
name: 'mpx-video',
|
|
@@ -54,7 +48,7 @@
|
|
|
54
48
|
type: Boolean,
|
|
55
49
|
default: false
|
|
56
50
|
},
|
|
57
|
-
initialTime: {
|
|
51
|
+
initialTime: {
|
|
58
52
|
type: Number,
|
|
59
53
|
default: 0
|
|
60
54
|
},
|
|
@@ -63,6 +57,10 @@
|
|
|
63
57
|
type: Boolean,
|
|
64
58
|
default: true
|
|
65
59
|
},
|
|
60
|
+
showBottomProgress: { // done
|
|
61
|
+
type: Boolean,
|
|
62
|
+
default: true
|
|
63
|
+
},
|
|
66
64
|
showFullscreenBtn: { // done
|
|
67
65
|
type: Boolean,
|
|
68
66
|
default: true
|
|
@@ -125,130 +123,166 @@
|
|
|
125
123
|
default: false
|
|
126
124
|
},
|
|
127
125
|
playsinline: {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
type: Boolean,
|
|
127
|
+
default: true
|
|
128
|
+
}
|
|
131
129
|
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (!this.playsinline) return {}
|
|
135
|
-
return {
|
|
136
|
-
'webkit-playsinline': true,
|
|
137
|
-
'playsinline': true,
|
|
138
|
-
'x5-playsinline': true
|
|
139
|
-
}
|
|
130
|
+
data () {
|
|
131
|
+
return {
|
|
140
132
|
}
|
|
141
133
|
},
|
|
142
|
-
|
|
134
|
+
computed: {
|
|
135
|
+
playsinlineAttr () {
|
|
136
|
+
if (!this.playsinline) return {}
|
|
143
137
|
return {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
138
|
+
'webkit-playsinline': true,
|
|
139
|
+
'playsinline': true,
|
|
140
|
+
'x5-playsinline': true,
|
|
141
|
+
'x5-video-orientation': 'landscape|portrait'
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
watch: {
|
|
146
|
+
muted: function (val) {
|
|
147
|
+
this._player?.muted(val)
|
|
148
|
+
},
|
|
149
|
+
controls: function (show) {
|
|
150
|
+
this.$emit('controlstoggle', inheritEvent('controlstoggle', {}, { show }))
|
|
147
151
|
}
|
|
148
152
|
},
|
|
149
153
|
mounted () {
|
|
154
|
+
const videoNode = this.$refs['_mpx_video_ref']
|
|
155
|
+
this._player = videojs(videoNode, {
|
|
156
|
+
controls: true,
|
|
157
|
+
sources:[
|
|
158
|
+
{
|
|
159
|
+
src: this.src
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
autoplay: this.autoplay,
|
|
163
|
+
loop: this.loop,
|
|
164
|
+
/**
|
|
165
|
+
log 若 controls 属性值为 false 则设置 poster 无效
|
|
166
|
+
*/
|
|
167
|
+
poster: this.controls ? this.poster : ''
|
|
168
|
+
}, function () {
|
|
169
|
+
})
|
|
170
|
+
this.initPlayer()
|
|
150
171
|
this.initStyle()
|
|
151
172
|
this.initEvent()
|
|
152
173
|
},
|
|
153
174
|
methods: {
|
|
154
|
-
|
|
155
|
-
|
|
175
|
+
initPlayer () {
|
|
176
|
+
this._player.muted(this.muted)
|
|
156
177
|
if (this.initialTime) {
|
|
157
|
-
|
|
178
|
+
this._player.currentTime(this.initialTime)
|
|
158
179
|
}
|
|
159
|
-
if (this.autoplay) { // log 解决autoplay无法自动播放问题
|
|
160
|
-
this.mutedCopy = true
|
|
161
|
-
}
|
|
162
|
-
if (!this.showProgress) this.classList += ' mpx-no-show_progress'
|
|
163
|
-
if (!this.showFullscreenBtn) this.classList += ' mpx-no-show_fullscreen_btn'
|
|
164
|
-
if (!this.showPlayBtn) this.classList += ' mpx-no-show_play_btn'
|
|
165
|
-
if (!this.showCenterPlayBtn) this.classList += ' mpx-no-show_center_play_btn'
|
|
166
|
-
if (!this.showMuteBtn) this.classList += ' mpx-no-show_mute_btn'
|
|
167
180
|
},
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
initStyle () {
|
|
182
|
+
if (!this.controls) this._player.el_.classList.add('mpx-no-show_controls')
|
|
183
|
+
|
|
184
|
+
if (!this.showBottomProgress) this._player.el_.classList.add('mpx-no-show_progress')
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
showProgress若不设置,宽度大于240时才会显示
|
|
188
|
+
*/
|
|
189
|
+
if (!this.showProgress || (this._player.el_.offsetWidth < 240 && this.showProgress)) this._player.el_.classList.add('mpx-no-show_progress')
|
|
190
|
+
|
|
191
|
+
if (!this.showFullscreenBtn) this._player.el_.classList.add('mpx-no-show_fullscreen_btn')
|
|
192
|
+
|
|
193
|
+
if (!this.showPlayBtn) this._player.el_.classList.add('mpx-no-show_play_btn')
|
|
194
|
+
|
|
195
|
+
if (!this.showCenterPlayBtn) this._player.el_.classList.add('mpx-no-show_center_play_btn')
|
|
170
196
|
|
|
171
|
-
|
|
197
|
+
if (!this.showMuteBtn) this._player.el_.classList.add('mpx-no-show_mute_btn')
|
|
198
|
+
},
|
|
199
|
+
initEvent () {
|
|
200
|
+
this._player.on('play', (e) => {
|
|
172
201
|
this.$emit('play', inheritEvent('play', e, {}))
|
|
173
202
|
})
|
|
174
203
|
|
|
175
|
-
|
|
204
|
+
this._player.on('pause', (e) => {
|
|
176
205
|
this.$emit('pause', inheritEvent('pause', e, {}))
|
|
177
206
|
})
|
|
178
207
|
|
|
179
|
-
|
|
208
|
+
this._player.on('ended', (e) => {
|
|
180
209
|
this.$emit('ended', inheritEvent('ended', e, {}))
|
|
181
210
|
})
|
|
182
211
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
this.$emit('timeupdate', inheritEvent('timeupdate', e, { currentTime: eNode.currentTime, duration: eNode.duration }))
|
|
212
|
+
this._player.on('timeupdate', (e) => {
|
|
213
|
+
this.$emit('timeupdate', inheritEvent('timeupdate', e, {}))
|
|
186
214
|
})
|
|
187
215
|
|
|
188
|
-
|
|
216
|
+
this._player.on('error', (e) => {
|
|
189
217
|
this.$emit('error', inheritEvent('error', e, {}))
|
|
190
218
|
})
|
|
191
219
|
|
|
192
|
-
|
|
220
|
+
this._player.on('waiting', (e) => {
|
|
193
221
|
this.$emit('waiting', inheritEvent('waiting', e, {}))
|
|
194
222
|
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const eNode = e.target
|
|
198
|
-
this.$emit('loadedmetadata', inheritEvent('loadedmetadata', e, { width: eNode.videoWidth, height: eNode.videoHeight, duration: eNode.duration }))
|
|
223
|
+
this._player.on('loadedmetadata', (e) => {
|
|
224
|
+
this.$emit('loadedmetadata', inheritEvent('loadedmetadata', e, {}))
|
|
199
225
|
})
|
|
200
226
|
|
|
201
|
-
|
|
227
|
+
this._player.on('progress', (e) => {
|
|
202
228
|
const eNode = e.target
|
|
203
229
|
const buffered = (eNode?.buffered?.end(0)) / (eNode?.duration)
|
|
204
230
|
this.$emit('progress', inheritEvent('progress', e, { buffered: buffered * 100 }))
|
|
205
231
|
})
|
|
206
232
|
|
|
207
|
-
|
|
233
|
+
this._player.on('seeked', (e) => {
|
|
208
234
|
const eNode = e.target
|
|
209
|
-
this.$emit('seekcomplete', inheritEvent('seekcomplete', e, { position: eNode.currentTime
|
|
235
|
+
this.$emit('seekcomplete', inheritEvent('seekcomplete', e, { position: eNode.currentTime }))
|
|
210
236
|
})
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: false }))
|
|
237
|
+
this._player.on('fullscreenchange', (e) => {
|
|
238
|
+
if (!this._player.paused()) {
|
|
239
|
+
// hack: 解决退出全屏自动暂停
|
|
240
|
+
setTimeout(() => {
|
|
241
|
+
this._player.play()
|
|
242
|
+
}, 500)
|
|
218
243
|
}
|
|
244
|
+
this.$emit('fullscreenchange', inheritEvent('fullscreenchange', e, { fullScreen: this._player.isFullscreen() }))
|
|
219
245
|
})
|
|
220
246
|
|
|
221
|
-
|
|
247
|
+
this._player.on('enterpictureinpicture', (e) => {
|
|
222
248
|
this.$emit('enterpictureinpicture', inheritEvent('enterpictureinpicture', e, {}))
|
|
223
249
|
})
|
|
224
250
|
|
|
225
|
-
|
|
251
|
+
this._player.on('leavepictureinpicture', (e) => {
|
|
226
252
|
this.$emit('leavepictureinpicture', inheritEvent('leavepictureinpicture', e, {}))
|
|
227
253
|
})
|
|
254
|
+
|
|
228
255
|
}
|
|
229
256
|
}
|
|
230
257
|
}
|
|
231
|
-
</script>
|
|
232
|
-
|
|
233
|
-
<style lang="stylus">
|
|
234
|
-
|
|
235
|
-
.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
258
|
+
</script>
|
|
259
|
+
|
|
260
|
+
<style lang="stylus">
|
|
261
|
+
|
|
262
|
+
.vjs-chapters-button
|
|
263
|
+
display: none !important
|
|
264
|
+
|
|
265
|
+
.mpx-no-show_controls
|
|
266
|
+
.vjs-control-bar
|
|
267
|
+
display none !important
|
|
268
|
+
|
|
269
|
+
.mpx-no-show_progress
|
|
270
|
+
.vjs-progress-control
|
|
271
|
+
display none !important
|
|
272
|
+
|
|
273
|
+
.mpx-no-show_fullscreen_btn
|
|
274
|
+
.vjs-fullscreen-control
|
|
275
|
+
display none !important
|
|
276
|
+
|
|
277
|
+
.mpx-no-show_play_btn
|
|
278
|
+
.vjs-play-control
|
|
279
|
+
display none !important
|
|
280
|
+
|
|
281
|
+
.mpx-no-show_center_play_btn
|
|
282
|
+
.vjs-big-play-button
|
|
283
|
+
display none !important
|
|
284
|
+
|
|
285
|
+
.mpx-no-show_mute_btn
|
|
286
|
+
.vjs-mute-control
|
|
287
|
+
display none !important
|
|
288
|
+
</style>
|
|
@@ -1,107 +1,78 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<iframe ref="mpxIframe" class="mpx-iframe" :src="
|
|
2
|
+
<iframe ref="mpxIframe" class="mpx-iframe" :src="currentUrl" :key="currentUrl"></iframe>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
6
|
import { getCustomEvent } from './getInnerListeners'
|
|
7
|
-
import
|
|
7
|
+
import promisify from './promisify'
|
|
8
|
+
import { redirectTo, navigateTo, navigateBack, reLaunch, switchTab } from '@mpxjs/api-proxy'
|
|
8
9
|
|
|
9
10
|
const eventLoad = 'load'
|
|
10
11
|
const eventError = 'error'
|
|
11
12
|
const eventMessage = 'message'
|
|
13
|
+
const mpx = global.__mpx
|
|
12
14
|
export default {
|
|
13
|
-
data: function () {
|
|
14
|
-
return {
|
|
15
|
-
origin: '',
|
|
16
|
-
messageList: [],
|
|
17
|
-
Loaded: false,
|
|
18
|
-
isActived: false,
|
|
19
|
-
mpxIframe: null,
|
|
20
|
-
isPostMessage: false
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
15
|
props: {
|
|
24
16
|
src: {
|
|
25
17
|
type: String
|
|
26
18
|
}
|
|
27
19
|
},
|
|
28
20
|
computed: {
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (index > -1) {
|
|
34
|
-
domain = src.substr(0, index)
|
|
35
|
-
return domain
|
|
36
|
-
}
|
|
37
|
-
domain = src.split('/')
|
|
38
|
-
if (domain[2]) {
|
|
39
|
-
domain = domain[0] + '//' + domain[2]
|
|
21
|
+
host () {
|
|
22
|
+
let host = this.src.split('/')
|
|
23
|
+
if (host[2]) {
|
|
24
|
+
host = host[0] + '//' + host[2]
|
|
40
25
|
} else {
|
|
41
|
-
|
|
26
|
+
host = ''
|
|
27
|
+
}
|
|
28
|
+
return host
|
|
29
|
+
},
|
|
30
|
+
currentUrl () {
|
|
31
|
+
if (!this.src) return ''
|
|
32
|
+
const hostValidate = this.hostValidate(this.host)
|
|
33
|
+
if (!hostValidate) {
|
|
34
|
+
console.error('访问页面域名不符合domainWhiteLists白名单配置,请确认是否正确配置该域名白名单')
|
|
35
|
+
return ''
|
|
36
|
+
}
|
|
37
|
+
return this.src
|
|
38
|
+
},
|
|
39
|
+
loadData () {
|
|
40
|
+
return {
|
|
41
|
+
src: this.host,
|
|
42
|
+
fullUrl: this.src
|
|
42
43
|
}
|
|
43
|
-
return domain
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
watch: {
|
|
47
|
+
currentUrl: {
|
|
48
|
+
handler (value) {
|
|
49
|
+
if (!value) {
|
|
50
|
+
this.$emit(eventError, getCustomEvent(eventError, {
|
|
51
|
+
...this.loadData,
|
|
52
|
+
errMsg: 'web-view load failed due to not in domain list'
|
|
53
|
+
}, this))
|
|
54
|
+
} else {
|
|
55
|
+
this.$nextTick(() => {
|
|
56
|
+
if (this.$refs.mpxIframe && this.mpxIframe != this.$refs.mpxIframe) {
|
|
57
|
+
this.mpxIframe = this.$refs.mpxIframe
|
|
58
|
+
this.mpxIframe.addEventListener('load', (event) => {
|
|
59
|
+
this.$emit(eventLoad, getCustomEvent(eventLoad, this.loadData, this))
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
})
|
|
51
63
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
this.mpxIframe = this.$refs.mpxIframe
|
|
56
|
-
this.mpxIframe.addEventListener('load', (event) => {
|
|
57
|
-
event.currentTarget.contentWindow.postMessage(this.mainDomain, '*')
|
|
58
|
-
})
|
|
59
|
-
window.addEventListener('message', (event) => {
|
|
60
|
-
const data = event.data
|
|
61
|
-
const value = data.detail && data.detail.data && data.detail.data
|
|
62
|
-
if (!this.isActived) {
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
switch (data.type) {
|
|
66
|
-
case eventMessage:
|
|
67
|
-
this.isPostMessage = true
|
|
68
|
-
this.messageList.push(value.data)
|
|
69
|
-
break
|
|
70
|
-
case 'navigateTo':
|
|
71
|
-
this.isActived = false
|
|
72
|
-
navigateTo(value)
|
|
73
|
-
break
|
|
74
|
-
case 'navigateBack':
|
|
75
|
-
this.isActived = false
|
|
76
|
-
value ? navigateBack(value) : navigateBack()
|
|
77
|
-
break
|
|
78
|
-
case 'redirectTo':
|
|
79
|
-
this.isActived = false
|
|
80
|
-
redirectTo(value)
|
|
81
|
-
break
|
|
82
|
-
case 'switchTab':
|
|
83
|
-
this.isActived = false
|
|
84
|
-
switchTab(value)
|
|
85
|
-
break
|
|
86
|
-
case 'reLaunch':
|
|
87
|
-
this.isActived = false
|
|
88
|
-
reLaunch(value)
|
|
89
|
-
break
|
|
90
|
-
case 'load':
|
|
91
|
-
this.Loaded = true
|
|
92
|
-
const loadData = {
|
|
93
|
-
src: this.src
|
|
94
|
-
}
|
|
95
|
-
this.$emit(eventLoad, getCustomEvent(eventLoad, loadData, this))
|
|
96
|
-
}
|
|
97
|
-
})
|
|
64
|
+
},
|
|
65
|
+
immediate: true
|
|
66
|
+
}
|
|
98
67
|
},
|
|
99
|
-
|
|
100
|
-
this.
|
|
101
|
-
|
|
68
|
+
beforeCreate () {
|
|
69
|
+
this.messageList = []
|
|
70
|
+
},
|
|
71
|
+
mounted () {
|
|
72
|
+
window.addEventListener('message', this.messageCallback)
|
|
102
73
|
},
|
|
103
74
|
deactivated () {
|
|
104
|
-
if (!this.
|
|
75
|
+
if (!this.messageList.length) {
|
|
105
76
|
return
|
|
106
77
|
}
|
|
107
78
|
let data = {
|
|
@@ -111,7 +82,8 @@
|
|
|
111
82
|
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
112
83
|
},
|
|
113
84
|
destroyed () {
|
|
114
|
-
|
|
85
|
+
window.removeEventListener('message', this.messageCallback)
|
|
86
|
+
if (!this.messageList.length) {
|
|
115
87
|
return
|
|
116
88
|
}
|
|
117
89
|
let data = {
|
|
@@ -119,6 +91,73 @@
|
|
|
119
91
|
data: this.messageList
|
|
120
92
|
}
|
|
121
93
|
this.$emit(eventMessage, getCustomEvent(eventMessage, data, this))
|
|
94
|
+
},
|
|
95
|
+
methods: {
|
|
96
|
+
messageCallback (event) {
|
|
97
|
+
const hostValidate = this.hostValidate(event.origin)
|
|
98
|
+
const data = event.data
|
|
99
|
+
let value = data.payload
|
|
100
|
+
if (!hostValidate) {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
let asyncCallback = null
|
|
104
|
+
switch (data.type) {
|
|
105
|
+
case 'postMessage':
|
|
106
|
+
this.messageList.push(value)
|
|
107
|
+
asyncCallback = Promise.resolve({
|
|
108
|
+
errMsg: 'invokeWebappApi:ok'
|
|
109
|
+
})
|
|
110
|
+
break
|
|
111
|
+
case 'navigateTo':
|
|
112
|
+
asyncCallback = promisify(value, navigateTo)
|
|
113
|
+
break
|
|
114
|
+
case 'navigateBack':
|
|
115
|
+
asyncCallback = promisify(value = {}, navigateBack)
|
|
116
|
+
break
|
|
117
|
+
case 'redirectTo':
|
|
118
|
+
asyncCallback = promisify(value, redirectTo)
|
|
119
|
+
break
|
|
120
|
+
case 'switchTab':
|
|
121
|
+
asyncCallback = promisify(value, switchTab)
|
|
122
|
+
break
|
|
123
|
+
case 'reLaunch':
|
|
124
|
+
asyncCallback = promisify(value, reLaunch)
|
|
125
|
+
break
|
|
126
|
+
case 'getLocation':
|
|
127
|
+
const getLocation = mpx.config.webviewConfig.apiImplementations && mpx.config.webviewConfig.apiImplementations.getLocation
|
|
128
|
+
if (getLocation) {
|
|
129
|
+
asyncCallback = getLocation()
|
|
130
|
+
} else {
|
|
131
|
+
asyncCallback = Promise.reject({
|
|
132
|
+
errMsg: '未在apiImplementations中配置getLocation方法'
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
break
|
|
136
|
+
}
|
|
137
|
+
asyncCallback && asyncCallback.then((res) => {
|
|
138
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
139
|
+
type: data.type,
|
|
140
|
+
callbackId: data.callbackId,
|
|
141
|
+
result: res
|
|
142
|
+
}, event.origin)
|
|
143
|
+
}).catch((error) => {
|
|
144
|
+
this.mpxIframe && this.mpxIframe.contentWindow && this.mpxIframe.contentWindow.postMessage && this.mpxIframe.contentWindow.postMessage({
|
|
145
|
+
type: data.type,
|
|
146
|
+
callbackId: data.callbackId,
|
|
147
|
+
error
|
|
148
|
+
}, event.origin)
|
|
149
|
+
})
|
|
150
|
+
},
|
|
151
|
+
hostValidate (host) {
|
|
152
|
+
const hostWhitelists = mpx.config.webviewConfig && mpx.config.webviewConfig.hostWhitelists || []
|
|
153
|
+
if (hostWhitelists.length) {
|
|
154
|
+
return hostWhitelists.some((item) => {
|
|
155
|
+
return host.endsWith(item)
|
|
156
|
+
})
|
|
157
|
+
} else {
|
|
158
|
+
return true
|
|
159
|
+
}
|
|
160
|
+
}
|
|
122
161
|
}
|
|
123
162
|
}
|
|
124
163
|
</script>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function promisify (obj = {}, callback) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const originSuccess = obj.success
|
|
4
|
+
const originFail = obj.fail
|
|
5
|
+
obj.success = function (res) {
|
|
6
|
+
originSuccess && originSuccess.call(this, res)
|
|
7
|
+
resolve(res)
|
|
8
|
+
}
|
|
9
|
+
obj.fail = function (e) {
|
|
10
|
+
originFail && originFail.call(this, e)
|
|
11
|
+
reject(e)
|
|
12
|
+
}
|
|
13
|
+
if (callback) {
|
|
14
|
+
callback(obj)
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default promisify
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view>局部构建兜底页面</view>
|
|
3
|
+
<view>当前路由:{{currentRoute}}</view>
|
|
4
|
+
</template>
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
import { onLoad } from '@mpxjs/core'
|
|
8
|
+
import { createPage } from '@mpxjs/core'
|
|
9
|
+
|
|
10
|
+
createPage({
|
|
11
|
+
data() {
|
|
12
|
+
return {
|
|
13
|
+
currentRoute: '',
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
onLoad() {
|
|
17
|
+
this.getPagePath()
|
|
18
|
+
},
|
|
19
|
+
methods: {
|
|
20
|
+
getPagePath() {
|
|
21
|
+
const pages = getCurrentPages() || []
|
|
22
|
+
const currPage = pages[pages.length - 1]
|
|
23
|
+
this.currentRoute = currPage && currPage.route || ''
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
</script>
|
|
@@ -57,8 +57,10 @@ export default function processOption (
|
|
|
57
57
|
routes: routes
|
|
58
58
|
})
|
|
59
59
|
global.__mpxRouter.stack = []
|
|
60
|
+
global.__mpxRouter.lastStack = null
|
|
60
61
|
global.__mpxRouter.needCache = null
|
|
61
62
|
global.__mpxRouter.needRemove = []
|
|
63
|
+
global.__mpxRouter.eventChannelMap = {}
|
|
62
64
|
// 处理reLaunch中传递的url并非首页时的replace逻辑
|
|
63
65
|
global.__mpxRouter.beforeEach(function (to, from, next) {
|
|
64
66
|
let action = global.__mpxRouter.__mpxAction
|
|
@@ -97,24 +99,15 @@ export default function processOption (
|
|
|
97
99
|
})
|
|
98
100
|
}
|
|
99
101
|
} else {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
methods = 'redirectTo'
|
|
107
|
-
break
|
|
108
|
-
case 'back':
|
|
109
|
-
methods = 'navigateBack'
|
|
110
|
-
break
|
|
111
|
-
case 'reLaunch':
|
|
112
|
-
methods = 'reLaunch'
|
|
113
|
-
break
|
|
114
|
-
default:
|
|
115
|
-
methods = 'navigateTo'
|
|
102
|
+
const typeMethodMap = {
|
|
103
|
+
to: 'navigateTo',
|
|
104
|
+
redirect: 'redirectTo',
|
|
105
|
+
back: 'navigateBack',
|
|
106
|
+
switch: 'switchTab',
|
|
107
|
+
reLaunch: 'reLaunch'
|
|
116
108
|
}
|
|
117
|
-
|
|
109
|
+
const method = typeMethodMap[action.type]
|
|
110
|
+
throw new Error(`${method}:fail page "${to.path}" is not found`)
|
|
118
111
|
}
|
|
119
112
|
}
|
|
120
113
|
|
|
@@ -126,6 +119,7 @@ export default function processOption (
|
|
|
126
119
|
case 'to':
|
|
127
120
|
stack.push(insertItem)
|
|
128
121
|
global.__mpxRouter.needCache = insertItem
|
|
122
|
+
if (action.eventChannel) global.__mpxRouter.eventChannelMap[to.path.slice(1)] = action.eventChannel
|
|
129
123
|
break
|
|
130
124
|
case 'back':
|
|
131
125
|
global.__mpxRouter.needRemove = stack.splice(stack.length - action.delta, action.delta)
|
|
@@ -166,7 +160,7 @@ export default function processOption (
|
|
|
166
160
|
return next({
|
|
167
161
|
path: action.path,
|
|
168
162
|
query: {
|
|
169
|
-
|
|
163
|
+
routeCount: action.routeCount
|
|
170
164
|
},
|
|
171
165
|
replace: true
|
|
172
166
|
})
|
|
@@ -47,6 +47,10 @@ module.exports = function (css, map) {
|
|
|
47
47
|
plugins.push(transSpecial({ id }))
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
if (mode === 'web') {
|
|
51
|
+
plugins.push(transSpecial({ id }))
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
plugins.push(pluginCondStrip({
|
|
51
55
|
defs
|
|
52
56
|
}))
|
|
@@ -85,7 +89,7 @@ module.exports = function (css, map) {
|
|
|
85
89
|
.process(css, options)
|
|
86
90
|
.then(result => {
|
|
87
91
|
// ali环境添加全局样式抹平root差异
|
|
88
|
-
if (mode === 'ali' && isApp) {
|
|
92
|
+
if ((mode === 'ali' || mode === 'web') && isApp) {
|
|
89
93
|
result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
|
|
90
94
|
}
|
|
91
95
|
|