@mpxjs/core 2.7.52 → 2.8.0-beta.2
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/@types/index.d.ts +342 -27
- package/package.json +10 -5
- package/src/convertor/convertor.js +2 -2
- package/src/convertor/mergeLifecycle.js +4 -4
- package/src/convertor/wxToAli.js +3 -4
- package/src/convertor/wxToSwan.js +2 -2
- package/src/convertor/wxToTt.js +1 -10
- package/src/convertor/wxToWeb.js +14 -7
- package/src/core/implement.js +2 -2
- package/src/core/injectMixins.js +1 -1
- package/src/core/innerLifecycle.js +15 -2
- package/src/core/mergeOptions.js +11 -5
- package/src/core/proxy.js +343 -229
- package/src/core/transferOptions.js +5 -2
- package/src/helper/const.js +10 -0
- package/src/index.js +73 -147
- package/src/observer/array.js +12 -17
- package/src/observer/computed.js +27 -56
- package/src/observer/dep.js +1 -1
- package/src/observer/effect.js +113 -0
- package/src/observer/effectScope.js +109 -0
- package/src/observer/{index.js → reactive.js} +74 -70
- package/src/observer/ref.js +97 -0
- package/src/observer/scheduler.js +171 -56
- package/src/observer/watch.js +163 -39
- package/src/platform/builtInMixins/i18nMixin.js +238 -31
- package/src/platform/builtInMixins/pageScrollMixin.web.js +4 -5
- package/src/platform/builtInMixins/pageStatusMixin.js +76 -54
- package/src/platform/builtInMixins/pageStatusMixin.web.js +35 -22
- package/src/platform/builtInMixins/proxyEventMixin.js +40 -22
- package/src/platform/builtInMixins/proxyEventMixin.web.js +16 -24
- package/src/platform/builtInMixins/refsMixin.js +82 -73
- package/src/platform/builtInMixins/refsMixin.web.js +0 -47
- package/src/platform/builtInMixins/relationsMixin.js +10 -9
- package/src/platform/builtInMixins/renderHelperMixin.js +1 -1
- package/src/platform/builtInMixins/showMixin.js +1 -1
- package/src/platform/createApp.js +5 -5
- package/src/platform/export/api.js +23 -0
- package/src/platform/export/api.web.js +26 -0
- package/src/platform/export/index.js +45 -0
- package/src/platform/export/index.web.js +36 -0
- package/src/platform/index.js +1 -5
- package/src/platform/patch/ali/getDefaultOptions.js +33 -31
- package/src/platform/patch/ali/lifecycle.js +21 -13
- package/src/platform/patch/builtInKeysMap.js +2 -1
- package/src/platform/patch/index.js +4 -9
- package/src/platform/patch/swan/getDefaultOptions.js +3 -3
- package/src/platform/patch/swan/lifecycle.js +17 -14
- package/src/platform/patch/web/getDefaultOptions.js +40 -16
- package/src/platform/patch/web/lifecycle.js +6 -3
- package/src/platform/patch/wx/getDefaultOptions.js +38 -31
- package/src/platform/patch/wx/lifecycle.js +18 -11
- package/src/runtime/createFactory.js +6 -2
- package/src/vue.web.js +3 -0
- package/src/vuePlugin.js +31 -0
- package/src/core/createStore.js +0 -241
- package/src/core/mapStore.js +0 -94
- package/src/helper/env.js +0 -20
- package/src/helper/getByPath.js +0 -127
- package/src/helper/log.js +0 -31
- package/src/helper/utils.js +0 -652
- package/src/observer/watcher.js +0 -244
package/src/observer/watch.js
CHANGED
|
@@ -1,53 +1,177 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ReactiveEffect } from './effect'
|
|
2
|
+
import { isRef } from './ref'
|
|
3
|
+
import { isReactive } from './reactive'
|
|
4
|
+
import { queuePreFlushCb, queuePostFlushCb } from './scheduler'
|
|
5
|
+
import { currentInstance } from '../core/proxy'
|
|
6
|
+
import {
|
|
7
|
+
noop,
|
|
8
|
+
isFunction,
|
|
9
|
+
isObject,
|
|
10
|
+
isPlainObject,
|
|
11
|
+
warn,
|
|
12
|
+
isArray,
|
|
13
|
+
remove,
|
|
14
|
+
callWithErrorHandling
|
|
15
|
+
} from '@mpxjs/utils'
|
|
16
|
+
|
|
17
|
+
export function watchEffect (effect, options) {
|
|
18
|
+
return watch(effect, null, options)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function watchPostEffect (effect, options) {
|
|
22
|
+
return watch(effect, null, { ...options, flush: 'post' })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function watchSyncEffect (effect, options) {
|
|
26
|
+
return watch(effect, null, { ...options, flush: 'sync' })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const warnInvalidSource = (s) => {
|
|
30
|
+
warn(`Invalid watch source: ${s}\nA watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const shouldTrigger = (value, oldValue) => !Object.is(value, oldValue) || isObject(value)
|
|
34
|
+
|
|
35
|
+
const processWatchOptionsCompat = (options) => {
|
|
36
|
+
const newOptions = { ...options }
|
|
37
|
+
if (options.sync) {
|
|
38
|
+
newOptions.flush = 'sync'
|
|
39
|
+
}
|
|
40
|
+
return newOptions
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function watch (source, cb, options = {}) {
|
|
44
|
+
let { immediate, deep, flush, immediateAsync } = processWatchOptionsCompat(options)
|
|
45
|
+
const instance = currentInstance
|
|
46
|
+
let getter
|
|
47
|
+
let isMultiSource = false
|
|
48
|
+
if (isRef(source)) {
|
|
49
|
+
getter = () => source.value
|
|
50
|
+
} else if (isReactive(source)) {
|
|
51
|
+
getter = () => source
|
|
52
|
+
deep = true
|
|
53
|
+
} else if (isArray(source)) {
|
|
54
|
+
isMultiSource = true
|
|
55
|
+
getter = () =>
|
|
56
|
+
source.map(s => {
|
|
57
|
+
if (isRef(s)) {
|
|
58
|
+
return s.value
|
|
59
|
+
} else if (isReactive(s)) {
|
|
60
|
+
return traverse(s)
|
|
61
|
+
} else if (isFunction(s)) {
|
|
62
|
+
return callWithErrorHandling(s, instance, 'watch getter')
|
|
63
|
+
} else {
|
|
64
|
+
warnInvalidSource(s)
|
|
65
|
+
return s
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
} else if (isFunction(source)) {
|
|
69
|
+
if (cb) {
|
|
70
|
+
// getter with cb
|
|
71
|
+
getter = () => callWithErrorHandling(source, instance, 'watch getter')
|
|
14
72
|
} else {
|
|
15
|
-
cb
|
|
73
|
+
// no cb -> simple effect
|
|
74
|
+
getter = () => {
|
|
75
|
+
if (instance && instance.isUnmounted()) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
if (cleanup) {
|
|
79
|
+
cleanup()
|
|
80
|
+
}
|
|
81
|
+
return callWithErrorHandling(source, instance, 'watch callback', [onCleanup])
|
|
82
|
+
}
|
|
16
83
|
}
|
|
84
|
+
} else {
|
|
85
|
+
getter = noop
|
|
86
|
+
warnInvalidSource(source)
|
|
17
87
|
}
|
|
18
88
|
|
|
19
|
-
cb
|
|
89
|
+
if (cb && deep) {
|
|
90
|
+
const baseGetter = getter
|
|
91
|
+
getter = () => traverse(baseGetter())
|
|
92
|
+
}
|
|
20
93
|
|
|
21
|
-
|
|
22
|
-
|
|
94
|
+
let cleanup
|
|
95
|
+
const onCleanup = (fn) => {
|
|
96
|
+
cleanup = effect.onStop = () => callWithErrorHandling(fn, instance, 'watch cleanup')
|
|
97
|
+
}
|
|
23
98
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
99
|
+
let oldValue = isMultiSource ? [] : undefined
|
|
100
|
+
const job = () => {
|
|
101
|
+
if (!effect.active) return
|
|
102
|
+
if (cb) {
|
|
103
|
+
const newValue = effect.run()
|
|
104
|
+
if (
|
|
105
|
+
deep ||
|
|
106
|
+
(isMultiSource
|
|
107
|
+
? newValue.some((v, i) => shouldTrigger(v, oldValue[i]))
|
|
108
|
+
: shouldTrigger(newValue, oldValue))
|
|
109
|
+
) {
|
|
110
|
+
// cleanup before running cb again
|
|
111
|
+
if (cleanup) {
|
|
112
|
+
cleanup()
|
|
113
|
+
}
|
|
114
|
+
callWithErrorHandling(cb, instance, 'watch callback', [newValue, oldValue, onCleanup])
|
|
115
|
+
oldValue = newValue
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
// watchEffect
|
|
119
|
+
effect.run()
|
|
33
120
|
}
|
|
34
121
|
}
|
|
35
122
|
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
123
|
+
let scheduler
|
|
124
|
+
if (flush === 'sync') {
|
|
125
|
+
// the scheduler function gets called directly
|
|
126
|
+
scheduler = job
|
|
127
|
+
} else if (flush === 'post') {
|
|
128
|
+
scheduler = () => queuePostFlushCb(job)
|
|
129
|
+
} else {
|
|
130
|
+
// default: 'pre'
|
|
131
|
+
scheduler = () => queuePreFlushCb(job)
|
|
42
132
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
133
|
+
|
|
134
|
+
job.allowRecurse = !!cb
|
|
135
|
+
|
|
136
|
+
const effect = new ReactiveEffect(getter, scheduler)
|
|
137
|
+
|
|
138
|
+
if (cb) {
|
|
139
|
+
if (immediate) {
|
|
140
|
+
job()
|
|
141
|
+
} else if (immediateAsync) {
|
|
142
|
+
queuePreFlushCb(job)
|
|
143
|
+
} else {
|
|
144
|
+
oldValue = effect.run()
|
|
145
|
+
}
|
|
146
|
+
} else if (flush === 'post') {
|
|
147
|
+
queuePostFlushCb(effect.run.bind(effect))
|
|
148
|
+
} else {
|
|
149
|
+
effect.run()
|
|
48
150
|
}
|
|
49
151
|
|
|
50
|
-
return
|
|
51
|
-
|
|
152
|
+
return () => {
|
|
153
|
+
effect.stop()
|
|
154
|
+
if (instance && instance.scope) {
|
|
155
|
+
remove(instance.scope.effects, effect)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function traverse (value, seen) {
|
|
161
|
+
if (!isObject(value)) return value
|
|
162
|
+
seen = seen || new Set()
|
|
163
|
+
if (seen.has(value)) return value
|
|
164
|
+
seen.add(value)
|
|
165
|
+
if (isRef(value)) {
|
|
166
|
+
traverse(value.value, seen)
|
|
167
|
+
} else if (isArray(value)) {
|
|
168
|
+
for (let i = 0; i < value.length; i++) {
|
|
169
|
+
traverse(value[i], seen)
|
|
170
|
+
}
|
|
171
|
+
} else if (isPlainObject(value)) {
|
|
172
|
+
for (const key in value) {
|
|
173
|
+
traverse(value[key], seen)
|
|
174
|
+
}
|
|
52
175
|
}
|
|
176
|
+
return value
|
|
53
177
|
}
|
|
@@ -1,42 +1,249 @@
|
|
|
1
1
|
import { BEFORECREATE } from '../../core/innerLifecycle'
|
|
2
|
-
import {
|
|
2
|
+
import { DefaultLocale } from '../../helper/const'
|
|
3
|
+
import { ref, shallowRef, triggerRef } from '../../observer/ref'
|
|
4
|
+
import { watch } from '../../observer/watch'
|
|
5
|
+
import { effectScope } from '../../observer/effectScope'
|
|
6
|
+
import { getCurrentInstance, onUnmounted } from '../../core/proxy'
|
|
7
|
+
import {
|
|
8
|
+
error,
|
|
9
|
+
isPlainObject,
|
|
10
|
+
isNumber,
|
|
11
|
+
mergeObj,
|
|
12
|
+
isEmptyObject
|
|
13
|
+
} from '@mpxjs/utils'
|
|
14
|
+
|
|
15
|
+
let i18n = null
|
|
16
|
+
|
|
17
|
+
let i18nMethods = null
|
|
18
|
+
|
|
19
|
+
export function createI18n (options) {
|
|
20
|
+
if (!options) {
|
|
21
|
+
error('CreateI18n() can not be called with null or undefined.')
|
|
22
|
+
}
|
|
23
|
+
i18nMethods = options.methods
|
|
24
|
+
const [globalScope, _global] = createGlobal(options)
|
|
25
|
+
const __instances = new WeakMap()
|
|
26
|
+
i18n = {
|
|
27
|
+
get global () {
|
|
28
|
+
return _global
|
|
29
|
+
},
|
|
30
|
+
get locale () {
|
|
31
|
+
return _global.locale.value || DefaultLocale
|
|
32
|
+
},
|
|
33
|
+
set locale (val) {
|
|
34
|
+
_global.locale.value = val
|
|
35
|
+
},
|
|
36
|
+
get fallbackLocale () {
|
|
37
|
+
return _global.fallbackLocale.value || DefaultLocale
|
|
38
|
+
},
|
|
39
|
+
set fallbackLocale (val) {
|
|
40
|
+
_global.fallbackLocale.value = val
|
|
41
|
+
},
|
|
42
|
+
get t () {
|
|
43
|
+
return _global.t
|
|
44
|
+
},
|
|
45
|
+
get tc () {
|
|
46
|
+
return _global.t
|
|
47
|
+
},
|
|
48
|
+
get te () {
|
|
49
|
+
return _global.te
|
|
50
|
+
},
|
|
51
|
+
get tm () {
|
|
52
|
+
return _global.tm
|
|
53
|
+
},
|
|
54
|
+
dispose () {
|
|
55
|
+
globalScope.stop()
|
|
56
|
+
},
|
|
57
|
+
__instances,
|
|
58
|
+
__getInstance (instance) {
|
|
59
|
+
return __instances.get(instance)
|
|
60
|
+
},
|
|
61
|
+
__setInstance (instance, composer) {
|
|
62
|
+
__instances.set(instance, composer)
|
|
63
|
+
},
|
|
64
|
+
__deleteInstance (instance) {
|
|
65
|
+
__instances.delete(instance)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return i18n
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function createGlobal (options) {
|
|
72
|
+
const scope = effectScope()
|
|
73
|
+
const obj = scope.run(() => createComposer(options))
|
|
74
|
+
return [scope, obj]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let id = 0
|
|
78
|
+
|
|
79
|
+
function createComposer (options) {
|
|
80
|
+
if (i18nMethods == null) {
|
|
81
|
+
error('CreateI18n() should be called before useI18n() calling.')
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
let { __root, inheritLocale = true, fallbackRoot = true } = options
|
|
85
|
+
|
|
86
|
+
const locale = ref(
|
|
87
|
+
__root && inheritLocale
|
|
88
|
+
? __root.locale.value
|
|
89
|
+
: (options.locale || DefaultLocale)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
const fallbackLocale = ref(
|
|
93
|
+
__root && inheritLocale
|
|
94
|
+
? __root.fallbackLocale.value
|
|
95
|
+
: (options.fallbackLocale || DefaultLocale)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
const messages = shallowRef(
|
|
99
|
+
isPlainObject(options.messages)
|
|
100
|
+
? options.messages
|
|
101
|
+
: { [locale]: {} }
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
// t && tc
|
|
105
|
+
const t = (...args) => {
|
|
106
|
+
let ret
|
|
107
|
+
if (isNumber(args[1])) {
|
|
108
|
+
// Pluralization
|
|
109
|
+
ret = i18nMethods.tc(messages.value, locale.value, fallbackLocale.value, ...args)
|
|
110
|
+
} else {
|
|
111
|
+
ret = i18nMethods.t(messages.value, locale.value, fallbackLocale.value, ...args)
|
|
112
|
+
}
|
|
113
|
+
if (ret === args[0] && fallbackRoot && __root) {
|
|
114
|
+
ret = __root.t(...args)
|
|
115
|
+
}
|
|
116
|
+
return ret
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// te
|
|
120
|
+
const te = (...args) => i18nMethods.te(messages.value, locale.value, fallbackLocale.value, ...args)
|
|
121
|
+
|
|
122
|
+
// tm
|
|
123
|
+
const tm = (...args) => i18nMethods.tm(messages.value, locale.value, fallbackLocale.value, ...args)
|
|
124
|
+
|
|
125
|
+
const getLocaleMessage = (locale) => messages.value[locale]
|
|
126
|
+
|
|
127
|
+
const setLocaleMessage = (locale, message) => {
|
|
128
|
+
messages.value[locale] = message
|
|
129
|
+
triggerRef(messages)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const mergeLocaleMessage = (locale, message) => {
|
|
133
|
+
messages.value[locale] = mergeObj(messages.value[locale] || {}, message)
|
|
134
|
+
triggerRef(messages)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (__root) {
|
|
138
|
+
watch([__root.locale, __root.fallbackLocale], ([l, fl]) => {
|
|
139
|
+
if (inheritLocale) {
|
|
140
|
+
locale.value = l
|
|
141
|
+
fallbackLocale.value = fl
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
id: id++,
|
|
148
|
+
locale,
|
|
149
|
+
fallbackLocale,
|
|
150
|
+
get messages () {
|
|
151
|
+
return messages
|
|
152
|
+
},
|
|
153
|
+
get isGlobal () {
|
|
154
|
+
return __root === undefined
|
|
155
|
+
},
|
|
156
|
+
get inheritLocale () {
|
|
157
|
+
return inheritLocale
|
|
158
|
+
},
|
|
159
|
+
set inheritLocale (val) {
|
|
160
|
+
inheritLocale = val
|
|
161
|
+
if (val && __root) {
|
|
162
|
+
locale.value = __root.locale.value
|
|
163
|
+
fallbackLocale.value = __root.fallbackLocale.value
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
get fallbackRoot () {
|
|
167
|
+
return fallbackRoot
|
|
168
|
+
},
|
|
169
|
+
set fallbackRoot (val) {
|
|
170
|
+
fallbackRoot = val
|
|
171
|
+
},
|
|
172
|
+
t,
|
|
173
|
+
te,
|
|
174
|
+
tm,
|
|
175
|
+
getLocaleMessage,
|
|
176
|
+
setLocaleMessage,
|
|
177
|
+
mergeLocaleMessage
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function getScope (options) {
|
|
182
|
+
return isEmptyObject(options) ? 'global' : 'local'
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function setupLifeCycle (instance) {
|
|
186
|
+
onUnmounted(() => {
|
|
187
|
+
i18n.__deleteInstance(instance)
|
|
188
|
+
}, instance)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function useI18n (options) {
|
|
192
|
+
const instance = getCurrentInstance()
|
|
193
|
+
if (instance == null) {
|
|
194
|
+
error('UseI18n() must be called in setup top.')
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
const scope = getScope(options)
|
|
198
|
+
const global = i18n.global
|
|
199
|
+
if (scope === 'global') return global
|
|
200
|
+
|
|
201
|
+
let composer = i18n.__getInstance(instance)
|
|
202
|
+
if (composer == null) {
|
|
203
|
+
const composerOptions = Object.assign({}, options)
|
|
204
|
+
if (global) composerOptions.__root = global
|
|
205
|
+
composer = createComposer(composerOptions)
|
|
206
|
+
setupLifeCycle(instance)
|
|
207
|
+
i18n.__setInstance(instance, composer)
|
|
208
|
+
}
|
|
209
|
+
return composer
|
|
210
|
+
}
|
|
3
211
|
|
|
4
212
|
export default function i18nMixin () {
|
|
5
|
-
if (
|
|
213
|
+
if (i18n) {
|
|
6
214
|
return {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
215
|
+
computed: {
|
|
216
|
+
_l () {
|
|
217
|
+
return i18n.global.locale.value || DefaultLocale
|
|
218
|
+
},
|
|
219
|
+
_fl () {
|
|
220
|
+
return i18n.global.fallbackLocale.value || DefaultLocale
|
|
221
|
+
}
|
|
10
222
|
},
|
|
11
223
|
[BEFORECREATE] () {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
224
|
+
// 挂载$i18n
|
|
225
|
+
this.$i18n = {
|
|
226
|
+
get locale () {
|
|
227
|
+
return i18n.global.locale.value || DefaultLocale
|
|
228
|
+
},
|
|
229
|
+
set locale (val) {
|
|
230
|
+
i18n.global.locale.value = val
|
|
231
|
+
},
|
|
232
|
+
get fallbackLocale () {
|
|
233
|
+
return i18n.global.fallbackLocale.value || DefaultLocale
|
|
234
|
+
},
|
|
235
|
+
set fallbackLocale (val) {
|
|
236
|
+
i18n.global.fallbackLocale.value = val
|
|
237
|
+
}
|
|
238
|
+
}
|
|
21
239
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
240
|
+
// 挂载翻译方法,$t等注入方法只能使用global scope
|
|
241
|
+
Object.keys(i18nMethods).forEach((methodName) => {
|
|
242
|
+
this['$' + methodName] = (...args) => {
|
|
243
|
+
if (methodName === 'tc') methodName = 't'
|
|
244
|
+
return i18n.global[methodName](...args)
|
|
245
|
+
}
|
|
28
246
|
})
|
|
29
|
-
// 挂载翻译方法
|
|
30
|
-
if (global.i18nMethods) {
|
|
31
|
-
Object.keys(global.i18nMethods).forEach((methodName) => {
|
|
32
|
-
if (/^__/.test(methodName)) return
|
|
33
|
-
this['$' + methodName] = (...args) => {
|
|
34
|
-
// tap i18n.version
|
|
35
|
-
args.unshift((global.i18n.version, this.mpxLocale))
|
|
36
|
-
return global.i18nMethods[methodName].apply(this, args)
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
247
|
}
|
|
41
248
|
}
|
|
42
249
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { error } from '
|
|
1
|
+
import { error } from '@mpxjs/utils'
|
|
2
2
|
import MpxScroll from '../../helper/MpxScroll'
|
|
3
3
|
import { getScrollTop } from '../../helper/MpxScroll/dom'
|
|
4
4
|
|
|
5
5
|
let ms
|
|
6
6
|
|
|
7
|
-
function refreshMs (
|
|
7
|
+
function refreshMs () {
|
|
8
8
|
if (ms) ms.destroy()
|
|
9
9
|
try {
|
|
10
10
|
global.__ms = ms = new MpxScroll()
|
|
11
11
|
return true
|
|
12
12
|
} catch (e) {
|
|
13
|
-
|
|
14
|
-
error(`MpxScroll init error, please check.`, location, e)
|
|
13
|
+
error('MpxScroll init error, please check.', undefined, e)
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -44,7 +43,7 @@ export default function pageScrollMixin (mixinType) {
|
|
|
44
43
|
this.__lastScrollY = 0
|
|
45
44
|
},
|
|
46
45
|
activated () {
|
|
47
|
-
if (!refreshMs(
|
|
46
|
+
if (!refreshMs()) {
|
|
48
47
|
return
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -1,79 +1,101 @@
|
|
|
1
|
-
import { CREATED } from '../../core/innerLifecycle'
|
|
1
|
+
import { CREATED, ONLOAD, ONSHOW, ONHIDE, ONRESIZE } from '../../core/innerLifecycle'
|
|
2
2
|
|
|
3
3
|
export default function pageStatusMixin (mixinType) {
|
|
4
|
-
// 只有tt和ali没有pageLifeTimes支持,需要框架实现,其余平台一律使用原生pageLifeTimes
|
|
5
|
-
// 由于业务上大量使用了pageShow进行初始化。。。下个版本再移除非必要的pageShow/Hide实现。。。
|
|
6
4
|
if (mixinType === 'page') {
|
|
7
5
|
const pageMixin = {
|
|
8
|
-
data: {
|
|
9
|
-
mpxPageStatus: 'show'
|
|
10
|
-
},
|
|
11
6
|
onShow () {
|
|
12
|
-
this.
|
|
7
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
13
8
|
},
|
|
14
9
|
onHide () {
|
|
15
|
-
this.
|
|
10
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
11
|
+
},
|
|
12
|
+
onResize (e) {
|
|
13
|
+
this.__mpxProxy.callHook(ONRESIZE, [e])
|
|
14
|
+
},
|
|
15
|
+
onLoad (query) {
|
|
16
|
+
this.__mpxProxy.callHook(ONLOAD, [query])
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
if (__mpx_mode__ === 'ali') {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
let count = 0
|
|
21
|
+
const resolvedPromise = Promise.resolve()
|
|
22
|
+
Object.assign(pageMixin, {
|
|
23
|
+
data: {
|
|
24
|
+
mpxPageStatus: null
|
|
25
|
+
},
|
|
26
|
+
onShow () {
|
|
27
|
+
// 支付宝首次延时触发,确保同步组件的onShow能够执行
|
|
28
|
+
if (this.mpxPageStatus === null) {
|
|
29
|
+
resolvedPromise.then(() => {
|
|
30
|
+
this.mpxPageStatus = 'show'
|
|
31
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
32
|
+
})
|
|
33
|
+
} else {
|
|
34
|
+
this.mpxPageStatus = 'show'
|
|
35
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
onHide () {
|
|
39
|
+
this.mpxPageStatus = 'hide'
|
|
40
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
41
|
+
},
|
|
42
|
+
events: {
|
|
43
|
+
onResize (e) {
|
|
44
|
+
this.__resizeEvent = e
|
|
45
|
+
this.mpxPageStatus = `resize${count++}`
|
|
46
|
+
this.__mpxProxy.callHook(ONRESIZE, [e])
|
|
47
|
+
}
|
|
23
48
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (__mpx_mode__ === 'tt') {
|
|
27
|
-
pageMixin.onResize = function (e) {
|
|
28
|
-
this.__resizeEvent = e
|
|
29
|
-
this.mpxPageStatus = 'resize'
|
|
30
|
-
}
|
|
49
|
+
})
|
|
50
|
+
delete pageMixin.onResize
|
|
31
51
|
}
|
|
32
52
|
return pageMixin
|
|
33
53
|
} else {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (__mpx_mode__ === 'ali') {
|
|
43
|
-
currentPage = this.$page
|
|
44
|
-
} else {
|
|
45
|
-
const pages = getCurrentPages()
|
|
46
|
-
if (typeof this.getPageId === 'function') {
|
|
47
|
-
const currentPageId = this.getPageId()
|
|
48
|
-
for (let page of pages) {
|
|
49
|
-
if (typeof page.getPageId === 'function' && currentPageId === page.getPageId()) {
|
|
50
|
-
currentPage = page
|
|
51
|
-
break
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
currentPage = currentPage || pages[pages.length - 1]
|
|
56
|
-
}
|
|
54
|
+
if (__mpx_mode__ === 'ali') {
|
|
55
|
+
return {
|
|
56
|
+
[CREATED] () {
|
|
57
|
+
const options = this.__mpxProxy.options
|
|
58
|
+
const hasHook = this.__mpxProxy.hasHook.bind(this.__mpxProxy)
|
|
59
|
+
const hasHooks = hasHook(ONSHOW) || hasHook(ONHIDE) || hasHook(ONRESIZE)
|
|
60
|
+
const pageLifetimes = options.pageLifetimes
|
|
61
|
+
const currentPage = this.$page
|
|
57
62
|
|
|
58
|
-
if (currentPage) {
|
|
63
|
+
if ((hasHooks || pageLifetimes) && currentPage) {
|
|
59
64
|
this.$watch(() => currentPage.mpxPageStatus, (val) => {
|
|
60
|
-
if (val)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
if (!val) return
|
|
66
|
+
if (val === 'show') {
|
|
67
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
68
|
+
return pageLifetimes?.show?.call(this)
|
|
69
|
+
}
|
|
70
|
+
if (val === 'hide') {
|
|
71
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
72
|
+
return pageLifetimes?.hide?.call(this)
|
|
73
|
+
}
|
|
74
|
+
if (/^resize/.test(val)) {
|
|
75
|
+
const e = currentPage.__resizeEvent
|
|
76
|
+
this.__mpxProxy.callHook(ONRESIZE, [e])
|
|
77
|
+
return pageLifetimes?.resize?.call(this, e)
|
|
69
78
|
}
|
|
70
79
|
}, {
|
|
71
|
-
sync: true
|
|
72
|
-
immediate: true
|
|
80
|
+
sync: true
|
|
73
81
|
})
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
}
|
|
85
|
+
} else {
|
|
86
|
+
return {
|
|
87
|
+
pageLifetimes: {
|
|
88
|
+
show () {
|
|
89
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
90
|
+
},
|
|
91
|
+
hide () {
|
|
92
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
93
|
+
},
|
|
94
|
+
resize (e) {
|
|
95
|
+
this.__mpxProxy.callHook(ONRESIZE, [e])
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
77
99
|
}
|
|
78
100
|
}
|
|
79
101
|
}
|