Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:dcloudio/uni-app into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Jun 17, 2019
2 parents bc958ad + 9c0091f commit d71b094
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ function handleLink (event) {
vueOptions.parent = parentVm;
}

const mocks$1 = ['nodeId'];
const mocks$1 = ['nodeId', 'componentName'];

function isPage$1 () {
return !this.ownerId
Expand Down
2 changes: 1 addition & 1 deletion packages/uni-mp-baidu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.844",
"version": "0.0.845",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion src/core/service/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
createPageMixin
} from './page'

import {
lifecycleMixin
} from './lifecycle'

import {
getTabBarScrollPosition
} from './app/router-guard'
Expand Down Expand Up @@ -55,7 +59,9 @@ function getLocation (base = '/') {
export default {
install (Vue, {
routes
} = {}) {
} = {}) {
lifecycleMixin(Vue)

const minId = getMinId(routes)
const router = new VueRouter({
id: minId,
Expand Down
57 changes: 57 additions & 0 deletions src/core/service/plugins/lifecycle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* @flow */

const LIFECYCLE_HOOKS = [
// App
'onLaunch',
'onShow',
'onHide',
'onUniNViewMessage',
'onError',
// Page
'onLoad',
// 'onShow',
'onReady',
// 'onHide',
'onUnload',
'onPullDownRefresh',
'onReachBottom',
'onTabItemTap',
'onShareAppMessage',
'onResize',
'onPageScroll',
'onNavigationBarButtonTap',
'onBackPress',
'onNavigationBarSearchInputChanged',
'onNavigationBarSearchInputConfirmed',
'onNavigationBarSearchInputClicked',
// Component
// 'onReady', // 兼容旧版本,应该移除该事件
'onPageShow',
'onPageHide',
'onPageResize'
]
export function lifecycleMixin (Vue) {
// fixed vue-class-component
const oldExtend = Vue.extend
Vue.extend = function (extendOptions) {
extendOptions = extendOptions || {}

const methods = extendOptions.methods
if (methods) {
Object.keys(methods).forEach(methodName => {
if (LIFECYCLE_HOOKS.indexOf(methodName) !== -1) {
extendOptions[methodName] = methods[methodName]
delete methods[methodName]
}
})
}

return oldExtend.call(this, extendOptions)
}

const strategies = Vue.config.optionMergeStrategies
const mergeHook = strategies.created
LIFECYCLE_HOOKS.forEach(hook => {
strategies[hook] = mergeHook
})
}
20 changes: 8 additions & 12 deletions src/core/service/plugins/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
isFn
} from 'uni-shared'

function callHook (vm, hook, params) {
return isFn(vm.$options[hook]) && vm.$options[hook].apply(vm, params)
return vm.__call_hook(hook, params)
}

export function callAppHook (vm, hook, ...params) {
Expand All @@ -20,12 +16,12 @@ export function callPageHook (vm, hook, ...params) {
vm.$mp.query = params[0]
UniServiceJSBridge.publishHandler('onPageLoad', vm, vm.$page.id)
}
if (hook === 'onShow') {
if (
vm.$route.meta.isTabBar &&
vm.$route.params.detail
) {
UniServiceJSBridge.emit('onTabItemTap', vm.$route.params.detail)
if (hook === 'onShow') {
if (
vm.$route.meta.isTabBar &&
vm.$route.params.detail
) {
UniServiceJSBridge.emit('onTabItemTap', vm.$route.params.detail)
}
UniServiceJSBridge.publishHandler('onPageShow', vm, vm.$page.id)
}
Expand All @@ -34,4 +30,4 @@ export function callPageHook (vm, hook, ...params) {
console.debug(`${vm.$page.route}[${vm.$page.id}]:${hook} have been invoked`)
}
return callHook(vm, hook, params)
}
}
2 changes: 1 addition & 1 deletion src/platforms/mp-baidu/runtime/wrapper/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const mocks = ['nodeId']
export const mocks = ['nodeId', 'componentName']

export function isPage () {
return !this.ownerId
Expand Down

0 comments on commit d71b094

Please sign in to comment.