提交 54e4d1d8 编写于 作者: D DCloud_LXH 提交者: d-u-a

fix(h5): getLaunchOptionsSync、getEnterOptionsSync 实现

上级 f74ce7d3
......@@ -9,6 +9,8 @@ import {
import onWebInvokeAppService from 'uni-platform/service/on-web-invoke-app-service'
import { initEnterOptions, getEnterOptions } from '../plugins/app'
export default function initOn (on, {
getApp,
getCurrentPages
......@@ -53,7 +55,8 @@ export default function initOn (on, {
}
function onAppEnterForeground (enterOptions) {
callAppHook(getApp(), 'onShow', enterOptions)
initEnterOptions(enterOptions)
callAppHook(getApp(), 'onShow', getEnterOptions())
const pages = getCurrentPages()
if (pages.length === 0) {
return
......@@ -99,4 +102,4 @@ export default function initOn (on, {
on('onNavigationBarSearchInputFocusChanged', createCallCurrentPageHook('onNavigationBarSearchInputFocusChanged'))
on('onWebInvokeAppService', onWebInvokeAppService)
}
}
......@@ -10,29 +10,57 @@ export {
}
from './create-app'
export let createLaunchOptions = function () {
const scene = 1001
const referrerInfo = {
appId: '',
extraData: {}
}
try {
return {
path: this.$route.meta && this.$route.meta.pagePath,
query: this.$route.query,
scene,
referrerInfo
}
} catch (error) {
return {
path: '',
query: {},
scene,
referrerInfo
const extend = Object.assign
function createLaunchOptions () {
return {
path: '',
query: {},
scene: 1001,
referrerInfo: {
appId: '',
extraData: {}
}
}
}
const enterOptions = createLaunchOptions()
const launchOptions = createLaunchOptions()
export function getLaunchOptions () {
return launchOptions
}
export function getEnterOptions () {
return enterOptions
}
export function initEnterOptions ({
path,
query,
referrerInfo
}) {
extend(enterOptions, {
path,
query: query || {},
referrerInfo: referrerInfo || {}
})
}
export function initLaunchOptions ({
path,
query,
referrerInfo
}) {
extend(launchOptions, {
path,
query: query || {},
referrerInfo: referrerInfo || {}
})
extend(enterOptions, launchOptions)
return launchOptions
}
export function createAppMixin (Vue, routes, entryRoute) {
return {
created: function AppCreated () {
......@@ -54,10 +82,12 @@ export function createAppMixin (Vue, routes, entryRoute) {
},
mounted: function appMounted () {
// 稍微靠后点,让 App 有机会在 mounted 事件前注册一些全局事件监听,如 UI 显示(showModal)
createLaunchOptions = createLaunchOptions.bind(this)
const args = createLaunchOptions()
callAppHook(this, 'onLaunch', args)
callAppHook(this, 'onShow', args)
initLaunchOptions({
path: this.$route.meta && this.$route.meta.pagePath,
query: this.$route.query
})
callAppHook(this, 'onLaunch', launchOptions)
callAppHook(this, 'onShow', enterOptions)
}
}
}
import {
createLaunchOptions
getLaunchOptions,
getEnterOptions
} from 'uni-core/service/plugins/app'
export function getLaunchOptionsSync () {
return createLaunchOptions()
return getLaunchOptions()
}
export function getEnterOptionsSync () {
return createLaunchOptions()
return getEnterOptions()
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册