From e47fc12db6d0a2098e96ae6cabf574470b24654d Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 29 Jun 2022 16:12:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(h5):=20getLaunchOptionsSync=E3=80=81getEnt?= =?UTF-8?q?erOptionsSync?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/service/plugins/app/index.js | 32 +++++++++++++++---- .../api/plugin/get-launch-options-sync.js | 10 ++++++ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 src/platforms/h5/service/api/plugin/get-launch-options-sync.js diff --git a/src/core/service/plugins/app/index.js b/src/core/service/plugins/app/index.js index c34ef0502..c5c3e6e4a 100644 --- a/src/core/service/plugins/app/index.js +++ b/src/core/service/plugins/app/index.js @@ -10,6 +10,29 @@ 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 + } + } +} + export function createAppMixin (Vue, routes, entryRoute) { return { created: function AppCreated () { @@ -31,13 +54,10 @@ export function createAppMixin (Vue, routes, entryRoute) { }, mounted: function appMounted () { // 稍微靠后点,让 App 有机会在 mounted 事件前注册一些全局事件监听,如 UI 显示(showModal) - const args = { - path: this.$route.meta && this.$route.meta.pagePath, - query: this.$route.query, - scene: 1001 - } + createLaunchOptions = createLaunchOptions.bind(this) + const args = createLaunchOptions() callAppHook(this, 'onLaunch', args) callAppHook(this, 'onShow', args) } } -} +} diff --git a/src/platforms/h5/service/api/plugin/get-launch-options-sync.js b/src/platforms/h5/service/api/plugin/get-launch-options-sync.js new file mode 100644 index 000000000..dba99a144 --- /dev/null +++ b/src/platforms/h5/service/api/plugin/get-launch-options-sync.js @@ -0,0 +1,10 @@ +import { + createLaunchOptions +} from 'uni-core/service/plugins/app' + +export function getLaunchOptionsSync () { + return createLaunchOptions() +} +export function getEnterOptionsSync () { + return createLaunchOptions() +} -- GitLab