提交 1fd11424 编写于 作者: fxy060608's avatar fxy060608

feat: add getLaunchOptionsSync, getEnterOptionsSync

上级 5e07520d
......@@ -61,6 +61,10 @@ declare namespace UniApp {
qqMapKey?: string
googleMapKey?: string
// app-plus
referrerInfo?: {
appId: string
extraData: Record<string, any>
}
entryPagePath?: string
entryPageQuery?: string
realEntryPagePath?: string
......
......@@ -19,7 +19,7 @@ export * from './service/ui/setPageMeta'
export * from './service/keyboard/getSelectedTextRange'
export * from './service/hook/app'
export * from './service/lifecycle/app'
// protocols
export * from './protocols/base/canIUse'
......
import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform'
import { ON_LAUNCH } from '@dcloudio/uni-shared'
import { defineSyncApi } from '../../helpers/api'
import { ComponentInternalInstance, injectHook } from 'vue'
......@@ -17,3 +19,23 @@ export function injectAppLaunchHooks(appInstance: ComponentInternalInstance) {
injectHook(ON_LAUNCH, hook, appInstance)
})
}
type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync
const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync'
export const getEnterOptionsSync =
defineSyncApi<API_TYPE_GET_ENTER_OPTIONS_SYNC>(
API_GET_ENTER_OPTIONS_SYNC,
() => {
return getEnterOptions()
}
)
type API_TYPE_GET_LAUNCH_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync
const API_GET_LAUNCH_OPTIONS_SYNC = 'getLaunchOptionsSync'
export const getLaunchOptionsSync =
defineSyncApi<API_TYPE_GET_LAUNCH_OPTIONS_SYNC>(
API_GET_LAUNCH_OPTIONS_SYNC,
() => {
return getLaunchOptions()
}
)
......@@ -2225,17 +2225,9 @@ var serviceContext = (function (vue) {
invokeHook(getCurrentPage(), ON_RESIZE, res);
UniServiceJSBridge.invokeOnCallback('onWindowResize', res); // API
}
function onAppEnterForeground() {
function onAppEnterForeground(enterOptions) {
const page = getCurrentPage();
const showOptions = {
path: '',
query: {},
};
if (page) {
showOptions.path = page.$page.route;
showOptions.query = page.$page.options;
}
invokeHook(getApp(), ON_SHOW, showOptions);
invokeHook(getApp(), ON_SHOW, enterOptions);
invokeHook(page, ON_SHOW);
}
function onAppEnterBackground() {
......@@ -2343,6 +2335,18 @@ var serviceContext = (function (vue) {
initAppConfig(app._context.config);
}
function createLaunchOptions() {
return {
path: '',
query: {},
scene: 1001,
referrerInfo: {
appId: '',
extraData: {},
},
};
}
function getRealPath(filepath) {
// 无协议的情况补全 https
if (filepath.indexOf('//') === 0) {
......@@ -2649,6 +2653,55 @@ var serviceContext = (function (vue) {
UniServiceJSBridge.unsubscribe(getEventName(reqId));
}
const EVENT_BACKBUTTON = 'backbutton';
function backbuttonListener() {
uni.navigateBack({
from: 'backbutton',
success() { }, // 传入空方法,避免返回Promise,因为onBackPress可能导致fail
});
}
const enterOptions = createLaunchOptions();
const launchOptions = createLaunchOptions();
function getLaunchOptions() {
return launchOptions;
}
function getEnterOptions() {
return enterOptions;
}
function initEnterOptions({ path, query, referrerInfo, }) {
extend(enterOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {},
});
}
function initLaunchOptions({ path, query, referrerInfo, }) {
extend(launchOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {},
});
extend(enterOptions, launchOptions);
return launchOptions;
}
function parseRedirectInfo() {
const weexPlus = weex.requireModule('plus');
const { path, query, extraData, userAction } = weexPlus.getRedirectInfo() || {};
const referrerInfo = {
appId: '',
extraData: {},
};
if (extraData) {
referrerInfo.extraData = extraData;
}
return {
path,
query: query ? '?' + query : '',
referrerInfo,
userAction,
};
}
const TEMP_PATH$1 = '';
const API_UPX2PX = 'upx2px';
......@@ -4506,7 +4559,15 @@ var serviceContext = (function (vue) {
appLaunchHooks.forEach((hook) => {
vue.injectHook(ON_LAUNCH, hook, appInstance);
});
}
}
const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync';
const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions();
});
const API_GET_LAUNCH_OPTIONS_SYNC = 'getLaunchOptionsSync';
const getLaunchOptionsSync = defineSyncApi(API_GET_LAUNCH_OPTIONS_SYNC, () => {
return getLaunchOptions();
});
const API_GET_BACKGROUND_AUDIO_MANAGER = 'getBackgroundAudioManager';
......@@ -10179,9 +10240,10 @@ var serviceContext = (function (vue) {
let entryPageQuery;
const weexPlus = weex.requireModule('plus');
if (weexPlus.getRedirectInfo) {
const info = weexPlus.getRedirectInfo() || {};
entryPagePath = info.path;
entryPageQuery = info.query ? '?' + info.query : '';
const { path, query, referrerInfo } = parseRedirectInfo();
entryPagePath = path;
entryPageQuery = query;
__uniConfig.referrerInfo = referrerInfo;
}
else {
const argsJsonStr = plus.runtime.arguments;
......@@ -10244,14 +10306,6 @@ var serviceContext = (function (vue) {
}
}
const EVENT_BACKBUTTON = 'backbutton';
function backbuttonListener() {
uni.navigateBack({
from: 'backbutton',
success() { }, // 传入空方法,避免返回Promise,因为onBackPress可能导致fail
});
}
function initGlobalEvent() {
const plusGlobalEvent = plus.globalEvent;
const weexGlobalEvent = weex.requireModule('globalEvent');
......@@ -10268,7 +10322,11 @@ var serviceContext = (function (vue) {
emit(ON_APP_ENTER_BACKGROUND);
});
plusGlobalEvent.addEventListener('resume', () => {
emit(ON_APP_ENTER_FOREGROUND);
const info = parseRedirectInfo();
if (info.userAction) {
initEnterOptions(info);
}
emit(ON_APP_ENTER_FOREGROUND, getEnterOptions());
});
weexGlobalEvent.addEventListener('uistylechange', function (event) {
const args = {
......@@ -10303,12 +10361,15 @@ var serviceContext = (function (vue) {
}
function initAppLaunch(appVm) {
const args = {
path: __uniConfig.entryPagePath,
query: {},
scene: 1001,
app: appVm,
};
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig;
const args = extend({
// 为了让 uni-stat 在 uni.onLaunch 中可以 mixin
app: { mixin: appVm.$.appContext.app.mixin },
}, initLaunchOptions({
path: entryPagePath,
query: entryPageQuery,
referrerInfo: referrerInfo,
}));
injectAppLaunchHooks(appVm.$);
invokeHook(appVm, ON_LAUNCH, args);
invokeHook(appVm, ON_SHOW, args);
......@@ -12775,6 +12836,8 @@ var serviceContext = (function (vue) {
onAppLaunch: onAppLaunch,
onLocaleChange: onLocaleChange,
setPageMeta: setPageMeta,
getEnterOptionsSync: getEnterOptionsSync,
getLaunchOptionsSync: getLaunchOptionsSync,
setStorageSync: setStorageSync,
setStorage: setStorage,
getStorageSync: getStorageSync,
......
......@@ -24,3 +24,8 @@ export function getSameOriginUrl(url: string): Promise<string> {
return Promise.resolve(url)
}
export const TEMP_PATH = ''
export {
getEnterOptions,
getLaunchOptions,
} from '../service/framework/app/utils'
......@@ -107,4 +107,6 @@ export {
onAppLaunch,
onLocaleChange,
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
} from '@dcloudio/uni-api'
import { extend } from '@vue/shared'
import { injectAppLaunchHooks } from '@dcloudio/uni-api'
import { invokeHook } from '@dcloudio/uni-core'
import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue'
import { initLaunchOptions } from './utils'
export function initAppLaunch(appVm: ComponentPublicInstance) {
const args = {
path: __uniConfig.entryPagePath,
query: {},
scene: 1001,
app: appVm,
}
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig
const args = extend(
{
// 为了让 uni-stat 在 uni.onLaunch 中可以 mixin
app: { mixin: appVm.$.appContext.app.mixin },
},
initLaunchOptions({
path: entryPagePath,
query: entryPageQuery,
referrerInfo: referrerInfo,
})
)
injectAppLaunchHooks(appVm.$)
invokeHook(appVm, ON_LAUNCH, args)
invokeHook(appVm, ON_SHOW, args)
......
import { getRouteOptions } from '@dcloudio/uni-core'
import { parseRedirectInfo } from './utils'
let isInitEntryPage = false
......@@ -14,9 +15,10 @@ export function initEntry() {
const weexPlus = weex.requireModule('plus')
if (weexPlus.getRedirectInfo) {
const info = weexPlus.getRedirectInfo() || {}
entryPagePath = info.path
entryPageQuery = info.query ? '?' + info.query : ''
const { path, query, referrerInfo } = parseRedirectInfo()
entryPagePath = path
entryPageQuery = query
__uniConfig.referrerInfo = referrerInfo
} else {
const argsJsonStr = plus.runtime.arguments
if (!argsJsonStr) {
......
......@@ -5,7 +5,13 @@ import {
ON_THEME_CHANGE,
ON_KEYBOARD_HEIGHT_CHANGE,
} from '@dcloudio/uni-shared'
import { EVENT_BACKBUTTON, backbuttonListener } from './utils'
import {
EVENT_BACKBUTTON,
backbuttonListener,
parseRedirectInfo,
initEnterOptions,
getEnterOptions,
} from './utils'
export function initGlobalEvent() {
const plusGlobalEvent = (plus as any).globalEvent
......@@ -25,7 +31,11 @@ export function initGlobalEvent() {
})
plusGlobalEvent.addEventListener('resume', () => {
emit(ON_APP_ENTER_FOREGROUND)
const info = parseRedirectInfo()
if (info.userAction) {
initEnterOptions(info)
}
emit(ON_APP_ENTER_FOREGROUND, getEnterOptions())
})
weexGlobalEvent.addEventListener(
......
import { extend } from '@vue/shared'
import { parseQuery } from '@dcloudio/uni-shared'
import { createLaunchOptions, LaunchOptions } from '@dcloudio/uni-core'
export const EVENT_BACKBUTTON = 'backbutton'
export function backbuttonListener() {
uni.navigateBack({
from: 'backbutton',
success() {}, // 传入空方法,避免返回Promise,因为onBackPress可能导致fail
} as UniApp.NavigateBackOptions)
}
const enterOptions: LaunchOptions = createLaunchOptions()
const launchOptions: LaunchOptions = createLaunchOptions()
export function getLaunchOptions() {
return launchOptions
}
export function getEnterOptions() {
return enterOptions
}
export function initEnterOptions({
path,
query,
referrerInfo,
}: Partial<RedirectInfo>) {
extend(enterOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {},
})
}
export function initLaunchOptions({
path,
query,
referrerInfo,
}: Partial<RedirectInfo>) {
extend(launchOptions, {
path,
query: query ? parseQuery(query) : {},
referrerInfo: referrerInfo || {},
})
extend(enterOptions, launchOptions)
return launchOptions
}
interface RedirectInfo extends Omit<LaunchOptions, 'query' | 'scene'> {
query: string
userAction: boolean
}
export function parseRedirectInfo(): RedirectInfo {
const weexPlus = weex.requireModule('plus')
const { path, query, extraData, userAction } =
weexPlus.getRedirectInfo() || {}
const referrerInfo: UniApp.UniConfig['referrerInfo'] = {
appId: '',
extraData: {},
}
if (extraData) {
referrerInfo.extraData = extraData
}
return {
path,
query: query ? '?' + query : '',
referrerInfo,
userAction,
}
}
......@@ -5,3 +5,4 @@ export {
} from './bridge'
export { initService, initAppVm, initPageVm } from './init'
export { initServicePlugin } from './plugin'
export * from './utils'
......@@ -8,6 +8,7 @@ import {
import { ComponentPublicInstance } from '@vue/runtime-core'
import { invokeHook } from '../../helpers/hook'
import { getCurrentPage } from '../../helpers/page'
import { LaunchOptions } from '../utils'
export function initOn() {
const { on } = UniServiceJSBridge
......@@ -21,17 +22,10 @@ function onResize(res: UniApp.WindowResizeResult) {
UniServiceJSBridge.invokeOnCallback('onWindowResize', res) // API
}
function onAppEnterForeground() {
function onAppEnterForeground(enterOptions: LaunchOptions) {
const page = getCurrentPage()
const showOptions = {
path: '',
query: {},
}
if (page) {
showOptions.path = page.$page.route
showOptions.query = page.$page.options
}
invokeHook(getApp() as ComponentPublicInstance, ON_SHOW, showOptions)
invokeHook(getApp() as ComponentPublicInstance, ON_SHOW, enterOptions)
invokeHook(page as ComponentPublicInstance, ON_SHOW)
}
......
export interface LaunchOptions {
path: string
query: Record<string, any>
scene: number
referrerInfo: { appId: string; extraData: Record<string, any> }
}
export function createLaunchOptions() {
return {
path: '',
query: {},
scene: 1001,
referrerInfo: {
appId: '',
extraData: {},
},
}
}
......@@ -31,8 +31,10 @@
"createVideoContext",
"downloadFile",
"getClipboardData",
"getEnterOptionsSync",
"getFileInfo",
"getImageInfo",
"getLaunchOptionsSync",
"getLeftWindowStyle",
"getLocale",
"getLocation",
......
......@@ -1397,17 +1397,9 @@ function onResize$1(res) {
invokeHook(getCurrentPage(), ON_RESIZE, res);
UniServiceJSBridge.invokeOnCallback("onWindowResize", res);
}
function onAppEnterForeground() {
function onAppEnterForeground(enterOptions2) {
const page = getCurrentPage();
const showOptions = {
path: "",
query: {}
};
if (page) {
showOptions.path = page.$page.route;
showOptions.query = page.$page.options;
}
invokeHook(getApp(), ON_SHOW, showOptions);
invokeHook(getApp(), ON_SHOW, enterOptions2);
invokeHook(page, ON_SHOW);
}
function onAppEnterBackground() {
......@@ -1509,6 +1501,17 @@ function initAppConfig(appConfig) {
function initServicePlugin(app) {
initAppConfig(app._context.config);
}
function createLaunchOptions() {
return {
path: "",
query: {},
scene: 1001,
referrerInfo: {
appId: "",
extraData: {}
}
};
}
function converPx(value) {
if (/^-?\d+[ur]px$/i.test(value)) {
return value.replace(/(^-?\d+)[ur]px$/i, (text2, num) => {
......@@ -4473,6 +4476,14 @@ function injectAppLaunchHooks(appInstance) {
injectHook(ON_LAUNCH, hook, appInstance);
});
}
const API_GET_ENTER_OPTIONS_SYNC = "getEnterOptionsSync";
const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions();
});
const API_GET_LAUNCH_OPTIONS_SYNC = "getLaunchOptionsSync";
const getLaunchOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_LAUNCH_OPTIONS_SYNC, () => {
return getLaunchOptions();
});
const API_CAN_I_USE = "canIUse";
const CanIUseProtocol = [
{
......@@ -6084,6 +6095,25 @@ function revokeObjectURL(url) {
URL.revokeObjectURL(url);
delete files[url];
}
const launchOptions = createLaunchOptions();
const enterOptions = createLaunchOptions();
function getEnterOptions() {
return enterOptions;
}
function getLaunchOptions() {
return launchOptions;
}
function initLaunchOptions({
path,
query
}) {
extend(launchOptions, {
path,
query
});
extend(enterOptions, launchOptions);
return launchOptions;
}
var ResizeSensor = /* @__PURE__ */ defineBuiltInComponent({
name: "ResizeSensor",
props: {
......@@ -13976,14 +14006,14 @@ function setupApp(comp) {
const onLaunch = () => {
const { onLaunch: onLaunch2, onShow, onPageNotFound } = instance2;
const path = route.path.substr(1);
const launchOptions = {
const launchOptions2 = extend({
app: { mixin: instance2.appContext.app.mixin }
}, initLaunchOptions({
path: path || __uniRoutes[0].meta.route,
query: decodedQuery(route.query),
scene: 1001,
app: instance2.proxy
};
onLaunch2 && invokeArrayFns$1(onLaunch2, launchOptions);
onShow && invokeArrayFns$1(onShow, launchOptions);
query: decodedQuery(route.query)
}));
onLaunch2 && invokeArrayFns$1(onLaunch2, launchOptions2);
onShow && invokeArrayFns$1(onShow, launchOptions2);
if (__UNI_FEATURE_PAGES__) {
if (!route.matched.length) {
const pageNotFoundOptions = {
......@@ -14038,7 +14068,12 @@ function onMessage(evt) {
}
}
function onVisibilityChange() {
UniServiceJSBridge.emit(document.visibilityState === "visible" ? ON_APP_ENTER_FOREGROUND : ON_APP_ENTER_BACKGROUND);
const { emit: emit2 } = UniServiceJSBridge;
if (document.visibilityState === "visible") {
emit2(ON_APP_ENTER_FOREGROUND, getEnterOptions());
} else {
emit2(ON_APP_ENTER_BACKGROUND);
}
}
function formatTime(val) {
val = val > 0 && val < Infinity ? val : 0;
......@@ -19667,6 +19702,8 @@ var api = {
onAppLaunch,
onLocaleChange,
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
cssVar,
cssEnv,
cssConstant,
......@@ -21826,4 +21863,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getFileInfo, getImageInfo, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
import { invokeArrayFns, isPlainObject } from '@vue/shared'
import { extend, invokeArrayFns, isPlainObject } from '@vue/shared'
import {
nextTick,
ComponentInternalInstance,
......@@ -29,6 +29,7 @@ import { LayoutComponent } from '../..'
import { initApp } from './app'
import { initPage, onPageShow, onPageReady } from './page'
import { usePageMeta, usePageRoute } from './provide'
import { initLaunchOptions, getEnterOptions } from './utils'
interface SetupComponentOptions {
init: (vm: ComponentPublicInstance) => void
......@@ -141,12 +142,15 @@ export function setupApp(comp: any) {
const onLaunch = () => {
const { onLaunch, onShow, onPageNotFound } = instance
const path = route.path.substr(1)
const launchOptions = {
path: path || __uniRoutes[0].meta.route,
query: decodedQuery(route.query),
scene: 1001,
app: instance.proxy,
}
const launchOptions = extend(
{
app: { mixin: instance.appContext.app.mixin },
},
initLaunchOptions({
path: path || __uniRoutes[0].meta.route,
query: decodedQuery(route.query),
})
)
onLaunch && invokeArrayFns(onLaunch, launchOptions)
onShow && invokeArrayFns(onShow, launchOptions)
if (__UNI_FEATURE_PAGES__) {
......@@ -213,9 +217,10 @@ function onMessage(evt: {
}
}
function onVisibilityChange() {
UniServiceJSBridge.emit(
document.visibilityState === 'visible'
? ON_APP_ENTER_FOREGROUND
: ON_APP_ENTER_BACKGROUND
)
const { emit } = UniServiceJSBridge
if (document.visibilityState === 'visible') {
emit(ON_APP_ENTER_FOREGROUND, getEnterOptions())
} else {
emit(ON_APP_ENTER_BACKGROUND)
}
}
import { extend } from '@vue/shared'
import { createLaunchOptions, LaunchOptions } from '@dcloudio/uni-core'
const launchOptions: LaunchOptions = createLaunchOptions()
const enterOptions: LaunchOptions = createLaunchOptions()
export function getEnterOptions() {
return enterOptions
}
export function getLaunchOptions() {
return launchOptions
}
export function initLaunchOptions({
path,
query,
}: {
path: string
query: Record<string, any>
}) {
extend(launchOptions, {
path,
query,
})
extend(enterOptions, launchOptions)
return launchOptions
}
......@@ -15,3 +15,4 @@ export {
export * from './saveImage'
export * from './constants'
export { getSameOriginUrl } from '../helpers/file'
export { getEnterOptions, getLaunchOptions } from '../framework/setup/utils'
......@@ -95,5 +95,7 @@ export {
onAppLaunch,
onLocaleChange,
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
} from '@dcloudio/uni-api'
//#endif
......@@ -313,7 +313,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -372,7 +372,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -66,7 +66,13 @@ function parseApp(
injectAppLaunchHooks(internalInstance)
ctx.globalData = this.globalData
instance.$callHook(ON_LAUNCH, extend({ app: this }, options))
instance.$callHook(
ON_LAUNCH,
extend(
{ app: { mixin: internalInstance.appContext.app.mixin } },
options
)
)
},
}
......
......@@ -367,7 +367,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -366,7 +366,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -363,7 +363,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -366,7 +366,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -235,7 +235,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
......@@ -363,7 +363,7 @@ function parseApp(instance, parseAppOptions) {
});
injectAppLaunchHooks(internalInstance);
ctx.globalData = this.globalData;
instance.$callHook(ON_LAUNCH, extend({ app: this }, options));
instance.$callHook(ON_LAUNCH, extend({ app: { mixin: internalInstance.appContext.app.mixin } }, options));
},
};
initLocale(instance);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册