@mpxjs/core 2.10.17 → 2.10.18-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.
@@ -1,5 +1,5 @@
1
1
  // declaration for mpx mode
2
- declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony'
2
+ declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'web' | 'dd' | 'qa' | 'jd' | 'android' | 'ios' | 'harmony' | 'ks'
3
3
 
4
4
  // declaration for mpx env
5
5
  declare let __mpx_env__: string
package/@types/index.d.ts CHANGED
@@ -115,7 +115,7 @@ interface Context {
115
115
  refs: ObjectOf<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>
116
116
  asyncRefs: ObjectOf<Promise<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>>
117
117
 
118
- forceUpdate (params?: object, options?: object | (() => void), callback?: () => void): void
118
+ forceUpdate (data?: object): void
119
119
 
120
120
  selectComponent: ReplaceWxComponentIns['selectComponent']
121
121
  selectAllComponents: ReplaceWxComponentIns['selectAllComponents']
@@ -204,7 +204,7 @@ export interface MpxComponentIns {
204
204
 
205
205
  $watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
206
206
 
207
- $forceUpdate (params?: object, options?: object | (() => void), callback?: () => void): void
207
+ $forceUpdate (data?: object): void
208
208
 
209
209
  $nextTick (fn: () => void): void
210
210
 
@@ -412,7 +412,7 @@ interface MpxConfig {
412
412
  rnConfig: RnConfig,
413
413
  }
414
414
 
415
- type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
415
+ type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'| 'ks' | 'jd' | 'dd'
416
416
 
417
417
  interface ImplementOptions {
418
418
  modes?: Array<SupportedMode>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.17",
3
+ "version": "2.10.18-beta.2",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.10.17",
22
+ "@mpxjs/utils": "^2.10.18",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
@@ -113,5 +113,5 @@
113
113
  "url": "https://github.com/didi/mpx/issues"
114
114
  },
115
115
  "sideEffects": false,
116
- "gitHead": "33fbd0bb8d4b83555239a8931fabb23022af0866"
116
+ "gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
117
117
  }
@@ -9,6 +9,7 @@ import wxToTtRule from './wxToTt'
9
9
  import wxToDdRule from './wxToDd'
10
10
  import wxToJdRule from './wxToJd'
11
11
  import wxToReactRule from './wxToReact'
12
+ import wxToKsRule from './wxToKs'
12
13
 
13
14
  /**
14
15
  * 转换规则包含四点
@@ -38,7 +39,8 @@ const rulesMap = {
38
39
  wxToJd: extend({}, defaultConvertRule, wxToJdRule),
39
40
  wxToIos: extend({}, defaultConvertRule, wxToReactRule),
40
41
  wxToAndroid: extend({}, defaultConvertRule, wxToReactRule),
41
- wxToHarmony: extend({}, defaultConvertRule, wxToReactRule)
42
+ wxToHarmony: extend({}, defaultConvertRule, wxToReactRule),
43
+ wxToKs: extend({}, defaultConvertRule, wxToKsRule)
42
44
  }
43
45
 
44
46
  export function getConvertRule (convertMode) {
@@ -8,7 +8,8 @@ const convertModes = {
8
8
  'wx-dd': 'wxToDd',
9
9
  'wx-ios': 'wxToIos',
10
10
  'wx-android': 'wxToAndroid',
11
- 'wx-harmony': 'wxToHarmony'
11
+ 'wx-harmony': 'wxToHarmony',
12
+ 'wx-ks': 'wxToKs'
12
13
  }
13
14
 
14
15
  export function getConvertMode (srcMode) {
@@ -0,0 +1,21 @@
1
+ import { error } from '@mpxjs/utils'
2
+
3
+ const BEHAVIORS_MAP = [
4
+ 'wx://form-field',
5
+ 'wx://form-field-group',
6
+ 'wx://form-field-button',
7
+ 'wx://component-export'
8
+ ]
9
+
10
+ export default {
11
+ convert (options) {
12
+ if (options.behaviors) {
13
+ options.behaviors.forEach((behavior, idx) => {
14
+ if (BEHAVIORS_MAP.includes(behavior)) {
15
+ error(`Built-in behavior "${behavior}" is not supported in ks environment!`, global.currentResource || global.currentModuleId)
16
+ options.behaviors.splice(idx, 1)
17
+ }
18
+ })
19
+ }
20
+ }
21
+ }
@@ -6,7 +6,8 @@ import {
6
6
  diffAndCloneA,
7
7
  error,
8
8
  hasOwn,
9
- isDev
9
+ isDev,
10
+ getDefaultValueByType
10
11
  } from '@mpxjs/utils'
11
12
  import { implemented } from '../core/implement'
12
13
 
@@ -56,6 +57,12 @@ export default {
56
57
  return diffAndCloneA(prop.value).clone
57
58
  }
58
59
  : prop.value
60
+ } else {
61
+ // 没有显式设置value时,根据type自动添加默认值,与微信小程序原生行为保持一致
62
+ const defaultValue = getDefaultValueByType(prop.type, 'web')
63
+ if (defaultValue !== undefined) {
64
+ newProp.default = defaultValue
65
+ }
59
66
  }
60
67
  props[key] = newProp
61
68
  } else {
package/src/core/proxy.js CHANGED
@@ -31,8 +31,10 @@ import {
31
31
  wrapMethodsWithErrorHandling,
32
32
  warn,
33
33
  error,
34
- getEnvObj
34
+ getEnvObj,
35
+ def
35
36
  } from '@mpxjs/utils'
37
+ import { renderHelperDefs } from '../platform/builtInMixins/renderHelperMixin'
36
38
  import {
37
39
  BEFORECREATE,
38
40
  CREATED,
@@ -164,6 +166,7 @@ export default class MpxProxy {
164
166
  }
165
167
 
166
168
  created () {
169
+ console.log('[mpx] create proxy instance')
167
170
  if (__mpx_dynamic_runtime__) {
168
171
  // 缓存上下文,在 destoryed 阶段删除
169
172
  contextMap.set(this.uid, this.target)
@@ -190,6 +193,7 @@ export default class MpxProxy {
190
193
  this.callHook(CREATED)
191
194
 
192
195
  if (!isWeb && !isReact) {
196
+ this.initRenderHelpers()
193
197
  this.initRender()
194
198
  }
195
199
 
@@ -335,7 +339,7 @@ export default class MpxProxy {
335
339
  createSelectorQuery: this.target.createSelectorQuery ? this.target.createSelectorQuery.bind(this.target) : envObj.createSelectorQuery.bind(envObj),
336
340
  createIntersectionObserver: this.target.createIntersectionObserver ? this.target.createIntersectionObserver.bind(this.target) : envObj.createIntersectionObserver.bind(envObj),
337
341
  getPageId: this.target.getPageId.bind(this.target),
338
- getOpenerEventChannel: this.target.getOpenerEventChannel.bind(this.target)
342
+ getOpenerEventChannel: this.target.getOpenerEventChannel ? this.target.getOpenerEventChannel.bind(this.target) : noop
339
343
  }
340
344
  ])
341
345
  if (!isObject(setupResult)) {
@@ -728,6 +732,15 @@ export default class MpxProxy {
728
732
  this.toggleRecurse(true)
729
733
  }
730
734
 
735
+ initRenderHelpers () {
736
+ if (this.options.__nativeRender__ || __mpx_mode__ !== 'ks') return
737
+ Object.keys(renderHelperDefs).forEach((key) => {
738
+ if (!hasOwn(this.target, key)) {
739
+ def(this.target, key, renderHelperDefs[key])
740
+ }
741
+ })
742
+ }
743
+
731
744
  initRender () {
732
745
  if (this.options.__nativeRender__) return this.doRender()
733
746
 
@@ -740,6 +753,13 @@ export default class MpxProxy {
740
753
  const moduleId = this.target.__moduleId
741
754
  const dynamicTarget = this.target.__dynamic
742
755
 
756
+ const debugConfig = typeof global.__getMpxRenderEffectDebugRules === 'function'
757
+ ? global.__getMpxRenderEffectDebugRules(this.options?.mpxFileResource)
758
+ : {
759
+ debug: 1,
760
+ name: `MpxRenderEffect-${this.options?.mpxFileResource || 'unknown'}`
761
+ }
762
+
743
763
  const effect = this.effect = new ReactiveEffect(() => {
744
764
  // pre render for props update
745
765
  if (this.propsUpdatedFlag) {
@@ -769,8 +789,9 @@ export default class MpxProxy {
769
789
  } else {
770
790
  this.render()
771
791
  }
772
- }, () => queueJob(update), this.scope)
792
+ }, () => queueJob(update), this.scope, this.scope, debugConfig.debug, debugConfig.name)
773
793
 
794
+ console.log(`[mpx] ${this.options?.mpxFileResource} will initRender`)
774
795
  const update = this.update = effect.run.bind(effect)
775
796
  update.id = this.uid
776
797
  // render effect允许自触发
@@ -57,8 +57,8 @@ export default class MpxScroll {
57
57
  const isIntersecting = change.isIntersecting
58
58
  this.isIntersecting = isIntersecting
59
59
  if (!isIntersecting) {
60
- // 非 inter section 状态下及时清除 transtorm,以免影响正常滚动时元素的 fixed 定位
61
- this.el.style.cssText = ''
60
+ // 非 inter section 状态下及时清除 transform,以免影响正常滚动时元素的 fixed 定位
61
+ this.el.style.transform = ''
62
62
  this.pullDownEventRegister && this.pullDownEventRegister.destroy()
63
63
  } else {
64
64
  this.pullDownEventRegister = new EventRegister(this.el, [
@@ -103,7 +103,12 @@ export default class MpxScroll {
103
103
 
104
104
  transformPage (distance) {
105
105
  this.translateY = distance
106
- this.el.style.cssText = `transform: translateY(${distance}px)`
106
+ if (distance === 0) {
107
+ // 距离为 0 时移除 transform,避免影响页面 fixed 定位
108
+ this.el.style.transform = ''
109
+ } else {
110
+ this.el.style.transform = `translateY(${distance}px)`
111
+ }
107
112
  }
108
113
 
109
114
  onTouchEnd (e) {
@@ -219,8 +224,15 @@ export default class MpxScroll {
219
224
  }
220
225
 
221
226
  onReachBottom (onReachBottomDistance, callback) {
222
- const { bottom } = this.el.getBoundingClientRect()
223
- const mark = bottom - window.innerHeight <= onReachBottomDistance
227
+ const scrollTop = getScrollTop()
228
+ const scrollHeight = document.documentElement.scrollHeight
229
+ const clientHeight = window.innerHeight
230
+
231
+ // 使用 scrollHeight 判断实际内容高度是否超过视口,只有可滚动时才计算触底
232
+ const scrollable = scrollHeight > clientHeight
233
+ // 距离底部的距离 = 内容总高度 - (当前滚动位置 + 视口高度)
234
+ const distanceToBottom = scrollHeight - (scrollTop + clientHeight)
235
+ const mark = scrollable && (distanceToBottom <= onReachBottomDistance)
224
236
 
225
237
  if (!this.bottomReached && mark) {
226
238
  this.bottomReached = true
@@ -32,7 +32,7 @@ export const arrayMethods = Object.create(arrayProto)
32
32
  }
33
33
  if (inserted) ob.observeArray(inserted)
34
34
  // notify change
35
- ob.dep.notify()
35
+ ob.dep.notify(method, '[Array Method]', '[Array Method]', new Error('此时被通知变更').stack)
36
36
  }
37
37
  return result
38
38
  })
@@ -3,7 +3,7 @@ import Dep from './dep'
3
3
  import { createRef } from './ref'
4
4
  import { ReactiveEffect } from './effect'
5
5
 
6
- export function computed (getterOrOptions) {
6
+ export function computed (getterOrOptions, options = {}) {
7
7
  let getter, setter
8
8
  if (isFunction(getterOrOptions)) {
9
9
  getter = getterOrOptions
@@ -17,7 +17,7 @@ export function computed (getterOrOptions) {
17
17
  let value
18
18
  const effect = new ReactiveEffect(getter, () => {
19
19
  dirty = true
20
- })
20
+ }, undefined, options.debug || 0, options.name || 'anonymous computed')
21
21
 
22
22
  return createRef({
23
23
  get: () => {
@@ -7,30 +7,50 @@ let uid = 0
7
7
  * directives subscribing to it.
8
8
  */
9
9
  export default class Dep {
10
- constructor () {
10
+ constructor (key) {
11
11
  this.id = uid++
12
12
  this.subs = []
13
+ this.addSubStacks = new Map()
14
+ this.key = key
13
15
  }
14
16
 
15
17
  addSub (sub) {
18
+ const addSubStack = new Error('此时被添加到订阅者列表').stack
19
+ this.addSubStacks.set(sub, addSubStack)
16
20
  this.subs.push(sub)
17
21
  }
18
22
 
19
23
  removeSub (sub) {
20
24
  remove(this.subs, sub)
25
+ this.addSubStacks.delete(sub)
21
26
  }
22
27
 
23
- depend () {
28
+ depend (key, value) {
24
29
  if (Dep.target) {
25
- Dep.target.addDep(this)
30
+ // if (this.key === 'link_params' || key === 'link_params') console.log(new Error('此时被依赖').stack)
31
+ Dep.target.addDep(this, key, value)
26
32
  }
27
33
  }
28
34
 
29
- notify () {
35
+ notify (key, value, oldvalue, stack) {
30
36
  // stabilize the subscriber list first
31
37
  const subs = this.subs.slice()
38
+ try {
39
+ console.log('[Mpx Dep] notify ' +
40
+ this.subs.length +
41
+ ' subs, from ' +
42
+ key +
43
+ ': ' +
44
+ (typeof oldvalue === 'object' ? JSON.stringify(oldvalue) : oldvalue) +
45
+ ' -> ' +
46
+ (typeof value === 'object' ? JSON.stringify(value) : value) +
47
+ ', subs: ' +
48
+ subs.map(s => `id:${s.id} name:${s.name}`).join(', '))
49
+ } catch (e) {
50
+ // do nothing
51
+ }
32
52
  for (let i = 0, l = subs.length; i < l; i++) {
33
- subs[i].update()
53
+ subs[i].update(key, value, oldvalue, stack, this.addSubStacks.get(subs[i]))
34
54
  }
35
55
  }
36
56
  }
@@ -17,6 +17,8 @@ export function resetTracking () {
17
17
  shouldTrack = last === undefined ? true : last
18
18
  }
19
19
 
20
+ global.__setMpxReactiveEffect = (value) => {}
21
+
20
22
  export class ReactiveEffect {
21
23
  active = true
22
24
  deps = []
@@ -24,15 +26,45 @@ export class ReactiveEffect {
24
26
  depIds = new Set()
25
27
  newDepIds = new Set()
26
28
  allowRecurse = false
29
+ debug = 0
30
+ name = 'no-name'
27
31
 
28
32
  constructor (
29
33
  fn,
30
34
  scheduler,
31
- scope
35
+ scope,
36
+ debug,
37
+ name
32
38
  ) {
39
+ this.debug = debug || 0
40
+ this.name = name || 'no-name'
33
41
  this.id = ++uid
34
- this.fn = fn
35
- this.scheduler = scheduler
42
+ this.fn = (...args) => {
43
+ this.debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will run`)
44
+ this.debug > 1 && console.log(new Error('此时触发了run').stack)
45
+ const t = global.__setMpxReactiveEffect
46
+ global.__setMpxReactiveEffect = (option) => {
47
+ Object.entries(option).forEach(([key, value]) => {
48
+ this[key] = value
49
+ })
50
+ }
51
+ const result = fn(...args)
52
+ global.__setMpxReactiveEffect = t
53
+ return result
54
+ }
55
+ this.scheduler = (...args) => {
56
+ this.debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will scheduled`)
57
+ this.debug > 1 && console.log(new Error('此时触发scheduler').stack)
58
+ const t = global.__setMpxReactiveEffect
59
+ global.__setMpxReactiveEffect = (option) => {
60
+ Object.entries(option).forEach(([key, value]) => {
61
+ this[key] = value
62
+ })
63
+ }
64
+ const result = scheduler(...args)
65
+ global.__setMpxReactiveEffect = t
66
+ return result
67
+ }
36
68
  this.pausedState = PausedState.resumed
37
69
  recordEffectScope(this, scope)
38
70
  }
@@ -53,14 +85,14 @@ export class ReactiveEffect {
53
85
  }
54
86
 
55
87
  // add dependency to this
56
- addDep (dep) {
88
+ addDep (dep, key, value) {
57
89
  if (!shouldTrack) return
58
90
  const id = dep.id
59
91
  if (!this.newDepIds.has(id)) {
60
92
  this.newDepIds.add(id)
61
93
  this.newDeps.push(dep)
62
94
  if (!this.depIds.has(id)) {
63
- dep.addSub(this)
95
+ dep.addSub(this, key, value)
64
96
  }
65
97
  }
66
98
  }
@@ -85,12 +117,20 @@ export class ReactiveEffect {
85
117
  }
86
118
 
87
119
  // same as trigger
88
- update () {
120
+ update (key, value, oldvalue, stack, fromAddSubStack) {
121
+ const debugOptions = global.__getMpxReactiveEffectDebugRules?.(key, value)
122
+ const debug = debugOptions ? debugOptions.debug : this.debug
89
123
  // avoid dead cycle
90
124
  if (Dep.target !== this || this.allowRecurse) {
91
125
  if (this.pausedState !== PausedState.resumed) {
126
+ debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} pausedState will set to dirty with, from ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`)
127
+ debug > 1 && console.log(stack)
128
+ debug > 2 && console.log(fromAddSubStack)
92
129
  this.pausedState = PausedState.dirty
93
130
  } else {
131
+ debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will updated, from ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`)
132
+ debug > 1 && console.log(stack)
133
+ debug > 2 && console.log(fromAddSubStack)
94
134
  this.scheduler ? this.scheduler() : this.run()
95
135
  }
96
136
  }
@@ -110,7 +110,7 @@ function observe (value, shallow) {
110
110
  * Define a reactive property on an Object.
111
111
  */
112
112
  export function defineReactive (obj, key, val, shallow) {
113
- const dep = new Dep()
113
+ const dep = new Dep(key)
114
114
 
115
115
  const property = Object.getOwnPropertyDescriptor(obj, key)
116
116
  if (property && property.configurable === false) {
@@ -121,6 +121,8 @@ export function defineReactive (obj, key, val, shallow) {
121
121
  const getter = property && property.get
122
122
  const setter = property && property.set
123
123
 
124
+ const stack = new Error().stack
125
+
124
126
  let childOb = shallow ? getObserver(val) : observe(val)
125
127
  Object.defineProperty(obj, key, {
126
128
  enumerable: true,
@@ -128,9 +130,9 @@ export function defineReactive (obj, key, val, shallow) {
128
130
  get: function reactiveGetter () {
129
131
  const value = getter ? getter.call(obj) : val
130
132
  if (Dep.target) {
131
- dep.depend()
133
+ dep.depend(key, value)
132
134
  if (childOb) {
133
- childOb.dep.depend()
135
+ childOb.dep.depend(key, value)
134
136
  if (Array.isArray(value)) {
135
137
  dependArray(value)
136
138
  }
@@ -140,10 +142,12 @@ export function defineReactive (obj, key, val, shallow) {
140
142
  },
141
143
  set: function reactiveSetter (newVal) {
142
144
  const value = getter ? getter.call(obj) : val
145
+ let oldVal = value
143
146
  if (!(shallow && isForceTrigger) && !hasChanged(newVal, value)) {
144
147
  return
145
148
  }
146
149
  if (!shallow && isRef(value) && !isRef(newVal)) {
150
+ oldVal = value.value
147
151
  value.value = newVal
148
152
  } else if (setter) {
149
153
  setter.call(obj, newVal)
@@ -151,7 +155,7 @@ export function defineReactive (obj, key, val, shallow) {
151
155
  val = newVal
152
156
  }
153
157
  childOb = shallow ? getObserver(newVal) : observe(newVal)
154
- dep.notify()
158
+ dep.notify(key, newVal, oldVal, stack)
155
159
  }
156
160
  })
157
161
  }
@@ -176,8 +180,9 @@ export function set (target, key, val) {
176
180
  target[key] = val
177
181
  return val
178
182
  }
183
+ const oldVal = target[key]
179
184
  defineReactive(ob.value, key, val, ob.shallow)
180
- ob.dep.notify()
185
+ ob.dep.notify(key, val, oldVal, new Error('此时被通知变更').stack)
181
186
  return val
182
187
  }
183
188
 
@@ -193,11 +198,12 @@ export function del (target, key) {
193
198
  if (!hasOwn(target, key)) {
194
199
  return
195
200
  }
201
+ const oldVal = target[key]
196
202
  delete target[key]
197
203
  if (!ob) {
198
204
  return
199
205
  }
200
- ob.dep.notify()
206
+ ob.dep.notify(key, undefined, oldVal, new Error('此时被通知变更').stack)
201
207
  }
202
208
 
203
209
  /**
@@ -208,7 +214,7 @@ function dependArray (arr) {
208
214
  for (let i = 0, l = arr.length; i < l; i++) {
209
215
  const item = arr[i]
210
216
  const ob = getObserver(item)
211
- ob && ob.dep.depend()
217
+ ob && ob.dep.depend(i, item)
212
218
  if (Array.isArray(item)) {
213
219
  dependArray(item)
214
220
  }
@@ -137,7 +137,7 @@ export function watch (source, cb, options = {}) {
137
137
 
138
138
  job.allowRecurse = !!cb
139
139
 
140
- const effect = new ReactiveEffect(getter, scheduler)
140
+ const effect = new ReactiveEffect(getter, scheduler, undefined, options.debug || 0, options.name || 'anonymous watch')
141
141
 
142
142
  if (cb) {
143
143
  if (immediate) {
@@ -57,14 +57,18 @@ export default function getBuiltInMixins ({ type, rawOptions = {} }) {
57
57
  }
58
58
  // 此为纯增强类mixins,原生模式下不需要注入
59
59
  if (!rawOptions.__nativeRender__) {
60
- bulitInMixins = bulitInMixins.concat([
61
- renderHelperMixin(),
60
+ const enhancedMixins = [
62
61
  showMixin(type),
63
62
  i18nMixin(),
64
63
  dynamicRenderHelperMixin(),
65
64
  dynamicSlotMixin(),
66
65
  dynamicRefsMixin()
67
- ])
66
+ ]
67
+ if (__mpx_mode__ !== 'ks') {
68
+ // ks methods 不支持 _ 或者 $ 开头的方法名,所以 ks 不走 methods mixin
69
+ enhancedMixins.unshift(renderHelperMixin())
70
+ }
71
+ bulitInMixins = bulitInMixins.concat(enhancedMixins)
68
72
  }
69
73
  }
70
74
  return bulitInMixins.filter(item => item)
@@ -1,4 +1,5 @@
1
1
  import { CREATED, ONLOAD, ONSHOW, ONHIDE, ONRESIZE } from '../../core/innerLifecycle'
2
+ import { isObject } from '@mpxjs/utils'
2
3
 
3
4
  export default function pageStatusMixin (mixinType) {
4
5
  if (mixinType === 'page') {
@@ -12,8 +13,19 @@ export default function pageStatusMixin (mixinType) {
12
13
  onResize (e) {
13
14
  this.__mpxProxy.callHook(ONRESIZE, [e])
14
15
  },
15
- onLoad (query) {
16
- this.__mpxProxy.callHook(ONLOAD, [query])
16
+ onLoad (rawQuery) {
17
+ if (__mpx_mode__ === 'wx' || __mpx_mode__ === 'qq' || __mpx_mode__ === 'tt') {
18
+ const decodedQuery = {}
19
+ // 处理以上平台直接透传encode的结果,给到onload第二个参数供开发者使用
20
+ if (isObject(rawQuery)) {
21
+ for (const key in rawQuery) {
22
+ decodedQuery[key] = decodeURIComponent(rawQuery[key])
23
+ }
24
+ }
25
+ this.__mpxProxy.callHook(ONLOAD, [rawQuery, decodedQuery])
26
+ } else {
27
+ this.__mpxProxy.callHook(ONLOAD, [rawQuery, rawQuery])
28
+ }
17
29
  }
18
30
  }
19
31
  if (__mpx_mode__ === 'ali') {