Skip to content

Commit

Permalink
Merge pull request #692 from didi/feat-add-h5-load-options
Browse files Browse the repository at this point in the history
输出h5 onLoad 钩子执行补充options参数
  • Loading branch information
hiyuki committed Jan 13, 2021
2 parents b46c107 + 5771fa8 commit af01156
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/convertor/wxToWeb.js
Expand Up @@ -32,7 +32,7 @@ export default {
// support传递为true以将methods外层的方法函数合入methods中
support: true,
lifecycleProxyMap: {
'__created__': ['onLoad', 'created', 'attached'],
'__created__': ['created', 'attached'],
'__mounted__': ['ready', 'onReady'],
'__destroyed__': ['detached', 'onUnload'],
'__updated__': ['updated'],
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/platform/builtInMixins/index.js
Expand Up @@ -11,6 +11,7 @@ import pageResizeMixin from './pageResizeMixin'
import componentGenericsMixin from './componentGenericsMixin'
import getTabBarMixin from './getTabBarMixin'
import pageRouteMixin from './pageRouteMixin'
import pageLoadMixin from './pageLoadMixin'

export default function getBuiltInMixins (options, type) {
let bulitInMixins = []
Expand All @@ -24,7 +25,8 @@ export default function getBuiltInMixins (options, type) {
pageResizeMixin(type),
componentGenericsMixin(type),
getTabBarMixin(type),
pageRouteMixin(type)
pageRouteMixin(type),
pageLoadMixin(type)
]
} else {
// 此为差异抹平类mixins,原生模式下也需要注入也抹平平台差异
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/platform/builtInMixins/pageLoadMixin.js
@@ -0,0 +1,18 @@
/**
* 输出 H5 页面 onLoad
* @param mixinType
* @returns {{created(): void}}
*/
import { CREATED } from '../../core/innerLifecycle'
export default function onLoad (mixinType) {
if (mixinType === 'page' && __mpx_mode__ === 'web') {
return {
[CREATED] () {
if (this.onLoad) {
const current = (global.__mpxRouter && global.__mpxRouter.currentRoute) || {}
this.onLoad(current.query)
}
}
}
}
}
12 changes: 10 additions & 2 deletions packages/core/src/platform/createApp.js
Expand Up @@ -29,13 +29,21 @@ export default function createApp (option, config = {}) {
created () {
Object.assign(this, option.proto)
Object.assign(this, appData)
this.$options.onLaunch && this.$options.onLaunch.call(this, {})
const current = (global.__mpxRouter && global.__mpxRouter.currentRoute) || {}
const options = {
path: current.path && current.path.replace(/^\//, ''),
query: current.query,
scene: 0,
shareTicket: '',
referrerInfo: {}
}
this.$options.onLaunch && this.$options.onLaunch.call(this, options)
global.__mpxAppCbs = global.__mpxAppCbs || {
show: [],
hide: []
}
if (this.$options.onShow) {
this.$options.onShow.call(this, {})
this.$options.onShow.call(this, options)
global.__mpxAppCbs.show.push(this.$options.onShow.bind(this))
}
if (this.$options.onHide) {
Expand Down

0 comments on commit af01156

Please sign in to comment.