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

fix(h5): getLaunchOptionsSync、getEnterOptionsSync 实现

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