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

feat: app lifecycle

上级 6f15a5a1
import { isArray, isFunction, isPlainObject } from '@vue/shared'
import { isArray, isFunction, isPlainObject, remove } from '@vue/shared'
import {
HOOKS,
......@@ -38,12 +38,11 @@ function removeInterceptorHook(
if (!interceptors || !interceptor) {
return
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook as HOOKS])) {
removeHook(
interceptors[hook as HOOKS],
interceptor[hook as HOOKS] as Function
)
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name as HOOKS]
const hook = interceptor[name as HOOKS]
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook)
}
})
}
......@@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) {
return res
}
function removeHook(hooks: Function[] | undefined, hook: Function) {
if (!hooks) {
return
}
const index = hooks.indexOf(hook)
if (index !== -1) {
hooks.splice(index, 1)
}
}
export const addInterceptor = defineSyncApi(
API_ADD_INTERCEPTOR,
(method: string | Interceptor, interceptor: Interceptor | undefined) => {
......
import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform'
import { ON_HIDE, ON_SHOW } from '@dcloudio/uni-shared'
import { defineSyncApi } from '../../helpers/api'
import {
ON_ERROR,
ON_HIDE,
ON_PAGE_NOT_FOUND,
ON_SHOW,
ON_UNHANDLE_REJECTION,
} from '@dcloudio/uni-shared'
import { ComponentInternalInstance, injectHook } from 'vue'
import { removeHook } from '@dcloudio/uni-core'
import { remove } from '@vue/shared'
import { defineSyncApi } from '../../helpers/api'
type AppShowHook = (options: UniApp.LaunchOptionsApp) => void
type AppHideHook = () => void
interface AppHooks {
onUnhandledRejection: UniApp.OnUnhandledRejectionCallback[]
onPageNotFound: UniApp.OnPageNotFoundCallback[]
onError: UniApp.OnAppErrorCallback[]
onShow: AppShowHook[]
onHide: AppHideHook[]
}
const appHooks: AppHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [],
[ON_HIDE]: [],
}
......@@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) {
appHooks[type].push(hook)
}
export function injectAppHooks(appInstance: ComponentInternalInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type as keyof AppHooks].forEach((hook) => {
injectHook(type, hook, appInstance)
})
})
}
function offAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) {
const app = getApp({ allowDefault: true })
if (app && app.$vm) {
return removeHook(app.$vm, type, hook)
}
remove(appHooks[type] as Function[], hook)
}
export function onUnhandledRejection(
hook: UniApp.OnUnhandledRejectionCallback
) {
onAppHook(ON_UNHANDLE_REJECTION, hook)
}
export function offUnhandledRejection(
hook: UniApp.OnUnhandledRejectionCallback
) {
offAppHook(ON_UNHANDLE_REJECTION, hook)
}
export function onPageNotFound(hook: UniApp.OnPageNotFoundCallback) {
onAppHook(ON_PAGE_NOT_FOUND, hook)
}
export function offPageNotFound(hook: UniApp.OnPageNotFoundCallback) {
offAppHook(ON_PAGE_NOT_FOUND, hook)
}
export function onError(hook: UniApp.OnAppErrorCallback) {
onAppHook(ON_ERROR, hook)
}
export function offError(hook: UniApp.OnAppErrorCallback) {
offAppHook(ON_ERROR, hook)
}
export function onAppShow(hook: AppShowHook) {
onAppHook(ON_SHOW, hook)
}
export function offAppShow(hook: AppShowHook) {
offAppHook(ON_SHOW, hook)
}
export function onAppHide(hook: AppHideHook) {
onAppHook(ON_HIDE, hook)
}
export function injectAppHooks(
type: keyof AppHooks,
appInstance: ComponentInternalInstance
) {
appHooks[type].forEach((hook) => {
injectHook(type, hook, appInstance)
})
export function offAppHide(hook: AppHideHook) {
offAppHook(ON_HIDE, hook)
}
type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync
......
......@@ -106,6 +106,12 @@ var serviceContext = (function (vue) {
: {};
(process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
const extend = Object.assign;
const remove = (arr, el) => {
const i = arr.indexOf(el);
if (i > -1) {
arr.splice(i, 1);
}
};
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
const hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key);
const isArray$1 = Array.isArray;
......@@ -2172,6 +2178,13 @@ var serviceContext = (function (vue) {
};
}
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray$1(hooks)) {
return;
}
remove(hooks, hook);
}
function invokeHook(vm, name, args) {
if (isString(vm)) {
args = name;
......@@ -9863,9 +9876,11 @@ var serviceContext = (function (vue) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray$1(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -9888,15 +9903,6 @@ var serviceContext = (function (vue) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......@@ -11652,6 +11658,64 @@ var serviceContext = (function (vue) {
});
});
const appHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [],
[ON_HIDE]: [],
};
function onAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return vue.injectHook(type, hook, app.$vm.$);
}
appHooks[type].push(hook);
}
function injectAppHooks(appInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type].forEach((hook) => {
vue.injectHook(type, hook, appInstance);
});
});
}
function offAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return removeHook(app.$vm, type, hook);
}
remove(appHooks[type], hook);
}
function onUnhandledRejection(hook) {
onAppHook(ON_UNHANDLE_REJECTION, hook);
}
function offUnhandledRejection(hook) {
offAppHook(ON_UNHANDLE_REJECTION, hook);
}
function onPageNotFound(hook) {
onAppHook(ON_PAGE_NOT_FOUND, hook);
}
function offPageNotFound(hook) {
offAppHook(ON_PAGE_NOT_FOUND, hook);
}
function onError(hook) {
onAppHook(ON_ERROR, hook);
}
function offError(hook) {
offAppHook(ON_ERROR, hook);
}
function onAppShow(hook) {
onAppHook(ON_SHOW, hook);
}
function offAppShow(hook) {
offAppHook(ON_SHOW, hook);
}
function onAppHide(hook) {
onAppHook(ON_HIDE, hook);
}
function offAppHide(hook) {
offAppHook(ON_HIDE, hook);
}
const API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync';
const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions();
......@@ -17527,6 +17591,7 @@ var serviceContext = (function (vue) {
// }
function initAppLaunch(appVm) {
injectAppHooks(appVm.$);
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig;
const args = initLaunchOptions({
path: entryPagePath,
......@@ -19958,6 +20023,16 @@ var serviceContext = (function (vue) {
getPushCid: getPushCid,
onPushMessage: onPushMessage,
offPushMessage: offPushMessage,
onAppHide: onAppHide,
onAppShow: onAppShow,
onError: onError,
onPageNotFound: onPageNotFound,
onUnhandledRejection: onUnhandledRejection,
offAppHide: offAppHide,
offAppShow: offAppShow,
offError: offError,
offPageNotFound: offPageNotFound,
offUnhandledRejection: offUnhandledRejection,
invokePushCallback: invokePushCallback,
setStorageSync: setStorageSync,
setStorage: setStorage,
......
......@@ -118,6 +118,16 @@ export {
getPushCid,
onPushMessage,
offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用
invokePushCallback,
} from '@dcloudio/uni-api'
import { invokeHook } from '@dcloudio/uni-core'
import { injectAppHooks } from '@dcloudio/uni-api'
import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue'
import { initLaunchOptions } from './utils'
export function initAppLaunch(appVm: ComponentPublicInstance) {
injectAppHooks(appVm.$)
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig
const args = initLaunchOptions({
path: entryPagePath,
......
import { ComponentPublicInstance } from 'vue'
import { isString } from '@vue/shared'
import { isString, isArray, remove } from '@vue/shared'
import { invokeArrayFns } from '@dcloudio/uni-shared'
import { getCurrentPageVm } from './page'
export function removeHook(
vm: ComponentPublicInstance,
name: string,
hook: Function
) {
const hooks = (vm.$ as unknown as { [name: string]: Function[] })[
name as string
]
if (!isArray(hooks)) {
return
}
remove(hooks, hook)
}
export function invokeHook(name: string, args?: unknown): unknown
export function invokeHook(id: number, name: string, args?: unknown): unknown
export function invokeHook(
......
......@@ -75,22 +75,32 @@
"navigateBack",
"navigateTo",
"offAccelerometerChange",
"offAppHide",
"offAppShow",
"offCompassChange",
"offError",
"offNetworkStatusChange",
"offPageNotFound",
"offPushMessage",
"offUnhandledRejection",
"offWindowResize",
"onAccelerometerChange",
"onAppHide",
"onAppShow",
"onCompassChange",
"onError",
"onGyroscopeChange",
"onLocaleChange",
"onMemoryWarning",
"onNetworkStatusChange",
"onPageNotFound",
"onPushMessage",
"onSocketClose",
"onSocketError",
"onSocketMessage",
"onSocketOpen",
"onTabBarMidButtonTap",
"onUnhandledRejection",
"onUserCaptureScreen",
"onWindowResize",
"openDocument",
......
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, injectHook, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
import { withModifiers, createVNode, getCurrentInstance, ref, defineComponent, openBlock, createElementBlock, provide, computed, watch, onUnmounted, inject, onBeforeUnmount, mergeProps, injectHook, reactive, onActivated, onMounted, nextTick, onBeforeMount, withDirectives, vShow, shallowRef, watchEffect, isVNode, Fragment, markRaw, Comment, createTextVNode, onBeforeActivate, onBeforeDeactivate, createBlock, renderList, onDeactivated, createApp, Transition, effectScope, withCtx, KeepAlive, resolveDynamicComponent, createElementVNode, normalizeStyle, renderSlot } from "vue";
import { isString, extend, isArray, remove, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared";
import { once, UNI_STORAGE_LOCALE, I18N_JSON_DELIMITERS, Emitter, passive, initCustomDatasetOnce, resolveComponentInstance, addLeadingSlash, invokeArrayFns, resolveOwnerVm, resolveOwnerEl, ON_WXS_INVOKE_CALL_METHOD, normalizeTarget, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, EventChannel, SCHEME_RE, DATA_RE, getCustomDataset, LINEFEED, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, debounce, ON_LOAD, UniLifecycleHooks, invokeCreateVueAppHook, NAVBAR_HEIGHT, parseQuery, ON_UNLOAD, ON_REACH_BOTTOM_DISTANCE, decodedQuery, WEB_INVOKE_APPSERVICE, ON_WEB_INVOKE_APP_SERVICE, updateElementStyle, ON_BACK_PRESS, parseUrl, addFont, scrollTo, RESPONSIVE_MIN_WIDTH, onCreateVueApp, formatDateTime, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_PULL_DOWN_REFRESH } from "@dcloudio/uni-shared";
export { onCreateVueApp } from "@dcloudio/uni-shared";
import { initVueI18n, isI18nStr, LOCALE_EN, LOCALE_ES, LOCALE_FR, LOCALE_ZH_HANS, LOCALE_ZH_HANT } from "@dcloudio/uni-i18n";
import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
......@@ -887,6 +887,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel)
statusBarStyle: meta.navigationBar.titleColor === "#000000" ? "dark" : "light"
};
}
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray(hooks)) {
return;
}
remove(hooks, hook);
}
function invokeHook(vm, name, args) {
if (isString(vm)) {
args = name;
......@@ -2843,9 +2850,11 @@ function removeInterceptorHook(interceptors2, interceptor) {
if (!interceptors2 || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors2[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors2[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -2862,15 +2871,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index2 = hooks.indexOf(hook);
if (index2 !== -1) {
hooks.splice(index2, 1);
}
}
const addInterceptor = /* @__PURE__ */ defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === "string" && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......@@ -4473,6 +4473,64 @@ const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_T
}
});
});
const appHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [],
[ON_HIDE]: []
};
function onAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return injectHook(type, hook, app.$vm.$);
}
appHooks[type].push(hook);
}
function injectAppHooks(appInstance) {
Object.keys(appHooks).forEach((type) => {
appHooks[type].forEach((hook) => {
injectHook(type, hook, appInstance);
});
});
}
function offAppHook(type, hook) {
const app = getApp({ allowDefault: true });
if (app && app.$vm) {
return removeHook(app.$vm, type, hook);
}
remove(appHooks[type], hook);
}
function onUnhandledRejection(hook) {
onAppHook(ON_UNHANDLE_REJECTION, hook);
}
function offUnhandledRejection(hook) {
offAppHook(ON_UNHANDLE_REJECTION, hook);
}
function onPageNotFound(hook) {
onAppHook(ON_PAGE_NOT_FOUND, hook);
}
function offPageNotFound(hook) {
offAppHook(ON_PAGE_NOT_FOUND, hook);
}
function onError(hook) {
onAppHook(ON_ERROR, hook);
}
function offError(hook) {
offAppHook(ON_ERROR, hook);
}
function onAppShow(hook) {
onAppHook(ON_SHOW, hook);
}
function offAppShow(hook) {
offAppHook(ON_SHOW, hook);
}
function onAppHide(hook) {
onAppHook(ON_HIDE, hook);
}
function offAppHide(hook) {
offAppHook(ON_HIDE, hook);
}
const API_GET_ENTER_OPTIONS_SYNC = "getEnterOptionsSync";
const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions();
......@@ -14130,7 +14188,8 @@ function setupApp(comp) {
setup(instance2) {
const route = usePageRoute();
const onLaunch = () => {
const { onLaunch: onLaunch2, onShow, onPageNotFound } = instance2;
injectAppHooks(instance2);
const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2 } = instance2;
const path = route.path.slice(1);
const launchOptions2 = initLaunchOptions({
path: path || __uniRoutes[0].meta.route,
......@@ -14147,7 +14206,7 @@ function setupApp(comp) {
query: {},
scene: 1001
};
onPageNotFound && invokeArrayFns$1(onPageNotFound, pageNotFoundOptions);
onPageNotFound2 && invokeArrayFns$1(onPageNotFound2, pageNotFoundOptions);
}
}
};
......@@ -19842,6 +19901,16 @@ var api = {
getPushCid,
onPushMessage,
offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
invokePushCallback,
cssVar,
cssEnv,
......@@ -22004,4 +22073,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, closePreviewImage, 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, getPushCid, 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, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offPushMessage, offWindowResize, onAccelerometerChange, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPushMessage, 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, closePreviewImage, 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, getPushCid, 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, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offAppHide, offAppShow, offCompassChange, offError, offNetworkStatusChange, offPageNotFound, offPushMessage, offUnhandledRejection, offWindowResize, onAccelerometerChange, onAppHide, onAppShow, onCompassChange, onError, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPageNotFound, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUnhandledRejection, 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 };
......@@ -22,6 +22,7 @@ import {
ON_WEB_INVOKE_APP_SERVICE,
WEB_INVOKE_APPSERVICE,
} from '@dcloudio/uni-shared'
import { injectAppHooks } from '@dcloudio/uni-api'
import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core'
import { LayoutComponent } from '../..'
import { initApp } from './app'
......@@ -139,6 +140,7 @@ export function setupApp(comp: any) {
return route.query
}
const onLaunch = () => {
injectAppHooks(instance)
const { onLaunch, onShow, onPageNotFound } = instance
const path = route.path.slice(1)
const launchOptions = initLaunchOptions({
......
......@@ -100,6 +100,16 @@ export {
getPushCid,
onPushMessage,
offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用
invokePushCallback,
} from '@dcloudio/uni-api'
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -488,15 +490,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, remove, extend } from '@vue/shared';
let vueApp;
const createVueAppHooks = [];
......@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) {
return;
}
Object.keys(interceptor).forEach((hook) => {
if (isFunction(interceptor[hook])) {
removeHook(interceptors[hook], interceptor[hook]);
Object.keys(interceptor).forEach((name) => {
const hooks = interceptors[name];
const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
}
});
}
......@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
}
return res;
}
function removeHook(hooks, hook) {
if (!hooks) {
return;
}
const index = hooks.indexOf(hook);
if (index !== -1) {
hooks.splice(index, 1);
}
}
const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册