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

chore: merge

import { isArray, isFunction, isPlainObject } from '@vue/shared' import { isArray, isFunction, isPlainObject, remove } from '@vue/shared'
import { import {
HOOKS, HOOKS,
...@@ -38,12 +38,11 @@ function removeInterceptorHook( ...@@ -38,12 +38,11 @@ function removeInterceptorHook(
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return return
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook as HOOKS])) { const hooks = interceptors[name as HOOKS]
removeHook( const hook = interceptor[name as HOOKS]
interceptors[hook as HOOKS], if (isArray(hooks) && isFunction(hook)) {
interceptor[hook as HOOKS] as Function remove(hooks, hook)
)
} }
}) })
} }
...@@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) { ...@@ -72,16 +71,6 @@ function dedupeHooks(hooks: Function[]) {
return res 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( export const addInterceptor = defineSyncApi(
API_ADD_INTERCEPTOR, API_ADD_INTERCEPTOR,
(method: string | Interceptor, interceptor: Interceptor | undefined) => { (method: string | Interceptor, interceptor: Interceptor | undefined) => {
......
import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform' import { getEnterOptions, getLaunchOptions } from '@dcloudio/uni-platform'
import { ON_HIDE, ON_SHOW } from '@dcloudio/uni-shared' import {
import { defineSyncApi } from '../../helpers/api' ON_ERROR,
ON_HIDE,
ON_PAGE_NOT_FOUND,
ON_SHOW,
ON_UNHANDLE_REJECTION,
} from '@dcloudio/uni-shared'
import { ComponentInternalInstance, injectHook } from 'vue' 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 AppShowHook = (options: UniApp.LaunchOptionsApp) => void
type AppHideHook = () => void type AppHideHook = () => void
interface AppHooks { interface AppHooks {
onUnhandledRejection: UniApp.OnUnhandledRejectionCallback[]
onPageNotFound: UniApp.OnPageNotFoundCallback[]
onError: UniApp.OnAppErrorCallback[]
onShow: AppShowHook[] onShow: AppShowHook[]
onHide: AppHideHook[] onHide: AppHideHook[]
} }
const appHooks: AppHooks = { const appHooks: AppHooks = {
[ON_UNHANDLE_REJECTION]: [],
[ON_PAGE_NOT_FOUND]: [],
[ON_ERROR]: [],
[ON_SHOW]: [], [ON_SHOW]: [],
[ON_HIDE]: [], [ON_HIDE]: [],
} }
...@@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) { ...@@ -24,21 +38,64 @@ function onAppHook(type: keyof AppHooks, hook: (...args: any[]) => void) {
appHooks[type].push(hook) 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) { export function onAppShow(hook: AppShowHook) {
onAppHook(ON_SHOW, hook) onAppHook(ON_SHOW, hook)
} }
export function offAppShow(hook: AppShowHook) {
offAppHook(ON_SHOW, hook)
}
export function onAppHide(hook: AppHideHook) { export function onAppHide(hook: AppHideHook) {
onAppHook(ON_HIDE, hook) onAppHook(ON_HIDE, hook)
} }
export function injectAppHooks( export function offAppHide(hook: AppHideHook) {
type: keyof AppHooks, offAppHook(ON_HIDE, hook)
appInstance: ComponentInternalInstance
) {
appHooks[type].forEach((hook) => {
injectHook(type, hook, appInstance)
})
} }
type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync type API_TYPE_GET_ENTER_OPTIONS_SYNC = typeof uni.getLaunchOptionsSync
......
import { isArray as isArray$1, hasOwn as hasOwn$1, isString, isPlainObject, isObject as isObject$1, toRawType, capitalize, makeMap, isFunction, isPromise, extend, toTypeString } from '@vue/shared'; import { isArray as isArray$1, hasOwn as hasOwn$1, isString, isPlainObject, isObject as isObject$1, toRawType, capitalize, makeMap, isFunction, isPromise, extend, remove, toTypeString } from '@vue/shared';
import { LINEFEED, once, I18N_JSON_DELIMITERS, Emitter, addLeadingSlash, resolveComponentInstance, invokeArrayFns, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, SCHEME_RE, DATA_RE, cacheStringFunction, parseQuery, ON_ERROR, callOptions, PRIMARY_COLOR, removeLeadingSlash, getLen, formatLog, TABBAR_HEIGHT, NAVBAR_HEIGHT, ON_THEME_CHANGE, ON_KEYBOARD_HEIGHT_CHANGE, BACKGROUND_COLOR, ON_NAVIGATION_BAR_BUTTON_TAP, stringifyQuery as stringifyQuery$1, debounce, ON_PULL_DOWN_REFRESH, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_BACK_PRESS, UniNode, NODE_TYPE_PAGE, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_INSERT, ACTION_TYPE_CREATE, ACTION_TYPE_REMOVE, ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ON_READY, ON_UNLOAD, EventChannel, ON_REACH_BOTTOM_DISTANCE, parseUrl, onCreateVueApp, ON_TAB_ITEM_TAP, ON_LAUNCH, ACTION_TYPE_EVENT, createUniEvent, ON_WXS_INVOKE_CALL_METHOD, WEB_INVOKE_APPSERVICE } from '@dcloudio/uni-shared'; import { LINEFEED, once, I18N_JSON_DELIMITERS, Emitter, addLeadingSlash, resolveComponentInstance, invokeArrayFns, ON_RESIZE, ON_APP_ENTER_FOREGROUND, ON_APP_ENTER_BACKGROUND, ON_SHOW, ON_HIDE, ON_PAGE_SCROLL, ON_REACH_BOTTOM, SCHEME_RE, DATA_RE, cacheStringFunction, parseQuery, ON_ERROR, callOptions, ON_UNHANDLE_REJECTION, ON_PAGE_NOT_FOUND, PRIMARY_COLOR, removeLeadingSlash, getLen, formatLog, TABBAR_HEIGHT, NAVBAR_HEIGHT, ON_THEME_CHANGE, ON_KEYBOARD_HEIGHT_CHANGE, BACKGROUND_COLOR, ON_NAVIGATION_BAR_BUTTON_TAP, stringifyQuery as stringifyQuery$1, debounce, ON_PULL_DOWN_REFRESH, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_BACK_PRESS, UniNode, NODE_TYPE_PAGE, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_INSERT, ACTION_TYPE_CREATE, ACTION_TYPE_REMOVE, ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ON_READY, ON_UNLOAD, EventChannel, ON_REACH_BOTTOM_DISTANCE, parseUrl, onCreateVueApp, ON_TAB_ITEM_TAP, ON_LAUNCH, ACTION_TYPE_EVENT, createUniEvent, ON_WXS_INVOKE_CALL_METHOD, WEB_INVOKE_APPSERVICE } from '@dcloudio/uni-shared';
import { ref, createVNode, render, queuePostFlushCb, getCurrentInstance, onMounted, nextTick, onBeforeUnmount } from 'vue'; import { ref, injectHook, createVNode, render, queuePostFlushCb, getCurrentInstance, onMounted, nextTick, onBeforeUnmount } from 'vue';
/* /*
* base64-arraybuffer * base64-arraybuffer
...@@ -1484,6 +1484,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel) ...@@ -1484,6 +1484,13 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel)
}; };
} }
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray$1(hooks)) {
return;
}
remove(hooks, hook);
}
function invokeHook(vm, name, args) { function invokeHook(vm, name, args) {
if (isString(vm)) { if (isString(vm)) {
args = name; args = name;
...@@ -9123,9 +9130,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -9123,9 +9130,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray$1(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -9148,15 +9157,6 @@ function dedupeHooks(hooks) { ...@@ -9148,15 +9157,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
...@@ -10912,6 +10912,64 @@ const getSelectedTextRange = defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { r ...@@ -10912,6 +10912,64 @@ const getSelectedTextRange = defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { r
}); });
}); });
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 API_GET_ENTER_OPTIONS_SYNC = 'getEnterOptionsSync';
const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { const getEnterOptionsSync = defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions(); return getEnterOptions();
...@@ -18585,6 +18643,16 @@ var uni$1 = { ...@@ -18585,6 +18643,16 @@ var uni$1 = {
getPushCid: getPushCid, getPushCid: getPushCid,
onPushMessage: onPushMessage, onPushMessage: onPushMessage,
offPushMessage: offPushMessage, offPushMessage: offPushMessage,
onAppHide: onAppHide,
onAppShow: onAppShow,
onError: onError,
onPageNotFound: onPageNotFound,
onUnhandledRejection: onUnhandledRejection,
offAppHide: offAppHide,
offAppShow: offAppShow,
offError: offError,
offPageNotFound: offPageNotFound,
offUnhandledRejection: offUnhandledRejection,
invokePushCallback: invokePushCallback, invokePushCallback: invokePushCallback,
setStorageSync: setStorageSync, setStorageSync: setStorageSync,
setStorage: setStorage, setStorage: setStorage,
...@@ -18853,6 +18921,7 @@ function onPlusMessage(type, callback, once = false) { ...@@ -18853,6 +18921,7 @@ function onPlusMessage(type, callback, once = false) {
// } // }
function initAppLaunch(appVm) { function initAppLaunch(appVm) {
injectAppHooks(appVm.$);
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig; const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig;
const args = initLaunchOptions({ const args = initLaunchOptions({
path: entryPagePath, path: entryPagePath,
......
...@@ -117,6 +117,16 @@ export { ...@@ -117,6 +117,16 @@ export {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用 // 内部使用
invokePushCallback, invokePushCallback,
} from '@dcloudio/uni-api' } from '@dcloudio/uni-api'
import { invokeHook } from '@dcloudio/uni-core' import { invokeHook } from '@dcloudio/uni-core'
import { injectAppHooks } from '@dcloudio/uni-api'
import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared' import { ON_LAUNCH, ON_SHOW, ON_HIDE } from '@dcloudio/uni-shared'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
import { initLaunchOptions } from './utils' import { initLaunchOptions } from './utils'
export function initAppLaunch(appVm: ComponentPublicInstance) { export function initAppLaunch(appVm: ComponentPublicInstance) {
injectAppHooks(appVm.$)
const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig const { entryPagePath, entryPageQuery, referrerInfo } = __uniConfig
const args = initLaunchOptions({ const args = initLaunchOptions({
path: entryPagePath, path: entryPagePath,
......
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
import { isString } from '@vue/shared' import { isString, isArray, remove } from '@vue/shared'
import { invokeArrayFns } from '@dcloudio/uni-shared' import { invokeArrayFns } from '@dcloudio/uni-shared'
import { getCurrentPageVm } from './page' 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(name: string, args?: unknown): unknown
export function invokeHook(id: number, name: string, args?: unknown): unknown export function invokeHook(id: number, name: string, args?: unknown): unknown
export function invokeHook( export function invokeHook(
......
...@@ -75,22 +75,32 @@ ...@@ -75,22 +75,32 @@
"navigateBack", "navigateBack",
"navigateTo", "navigateTo",
"offAccelerometerChange", "offAccelerometerChange",
"offAppHide",
"offAppShow",
"offCompassChange", "offCompassChange",
"offError",
"offNetworkStatusChange", "offNetworkStatusChange",
"offPageNotFound",
"offPushMessage", "offPushMessage",
"offUnhandledRejection",
"offWindowResize", "offWindowResize",
"onAccelerometerChange", "onAccelerometerChange",
"onAppHide",
"onAppShow",
"onCompassChange", "onCompassChange",
"onError",
"onGyroscopeChange", "onGyroscopeChange",
"onLocaleChange", "onLocaleChange",
"onMemoryWarning", "onMemoryWarning",
"onNetworkStatusChange", "onNetworkStatusChange",
"onPageNotFound",
"onPushMessage", "onPushMessage",
"onSocketClose", "onSocketClose",
"onSocketError", "onSocketError",
"onSocketMessage", "onSocketMessage",
"onSocketOpen", "onSocketOpen",
"onTabBarMidButtonTap", "onTabBarMidButtonTap",
"onUnhandledRejection",
"onUserCaptureScreen", "onUserCaptureScreen",
"onWindowResize", "onWindowResize",
"openDocument", "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 { 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, stringifyStyle, parseStringStyle, isPlainObject, isFunction, capitalize, camelize, isArray, hasOwn, isObject, toRawType, makeMap as makeMap$1, isPromise, hyphenate, invokeArrayFns as invokeArrayFns$1 } from "@vue/shared"; 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, 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 { 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"; 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 { 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"; import { useRoute, createRouter, createWebHistory, createWebHashHistory, useRouter, isNavigationFailure, RouterView } from "vue-router";
...@@ -887,6 +887,15 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel) ...@@ -887,6 +887,15 @@ function initPageInternalInstance(openType, url, pageQuery, meta, eventChannel)
statusBarStyle: meta.navigationBar.titleColor === "#000000" ? "dark" : "light" statusBarStyle: meta.navigationBar.titleColor === "#000000" ? "dark" : "light"
}; };
} }
function removeHook(vm, name, hook) {
const hooks = vm.$[name];
if (!isArray(hooks)) {
return;
}
if (hook.__weh) {
remove(hooks, hook.__weh)
}
}
function invokeHook(vm, name, args) { function invokeHook(vm, name, args) {
if (isString(vm)) { if (isString(vm)) {
args = name; args = name;
...@@ -2843,9 +2852,11 @@ function removeInterceptorHook(interceptors2, interceptor) { ...@@ -2843,9 +2852,11 @@ function removeInterceptorHook(interceptors2, interceptor) {
if (!interceptors2 || !interceptor) { if (!interceptors2 || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors2[name];
removeHook(interceptors2[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -2862,15 +2873,6 @@ function dedupeHooks(hooks) { ...@@ -2862,15 +2873,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = /* @__PURE__ */ defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === "string" && isPlainObject(interceptor)) { if (typeof method === "string" && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
...@@ -4473,6 +4475,64 @@ const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_T ...@@ -4473,6 +4475,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 API_GET_ENTER_OPTIONS_SYNC = "getEnterOptionsSync";
const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => { const getEnterOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_ENTER_OPTIONS_SYNC, () => {
return getEnterOptions(); return getEnterOptions();
...@@ -14130,7 +14190,8 @@ function setupApp(comp) { ...@@ -14130,7 +14190,8 @@ function setupApp(comp) {
setup(instance2) { setup(instance2) {
const route = usePageRoute(); const route = usePageRoute();
const onLaunch = () => { const onLaunch = () => {
const { onLaunch: onLaunch2, onShow, onPageNotFound } = instance2; injectAppHooks(instance2);
const { onLaunch: onLaunch2, onShow, onPageNotFound: onPageNotFound2 } = instance2;
const path = route.path.slice(1); const path = route.path.slice(1);
const launchOptions2 = initLaunchOptions({ const launchOptions2 = initLaunchOptions({
path: path || __uniRoutes[0].meta.route, path: path || __uniRoutes[0].meta.route,
...@@ -14147,7 +14208,7 @@ function setupApp(comp) { ...@@ -14147,7 +14208,7 @@ function setupApp(comp) {
query: {}, query: {},
scene: 1001 scene: 1001
}; };
onPageNotFound && invokeArrayFns$1(onPageNotFound, pageNotFoundOptions); onPageNotFound2 && invokeArrayFns$1(onPageNotFound2, pageNotFoundOptions);
} }
} }
}; };
...@@ -19842,6 +19903,16 @@ var api = { ...@@ -19842,6 +19903,16 @@ var api = {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
invokePushCallback, invokePushCallback,
cssVar, cssVar,
cssEnv, cssEnv,
...@@ -22004,4 +22075,4 @@ var index = /* @__PURE__ */ defineSystemComponent({ ...@@ -22004,4 +22075,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]); 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 { ...@@ -22,6 +22,7 @@ import {
ON_WEB_INVOKE_APP_SERVICE, ON_WEB_INVOKE_APP_SERVICE,
WEB_INVOKE_APPSERVICE, WEB_INVOKE_APPSERVICE,
} from '@dcloudio/uni-shared' } from '@dcloudio/uni-shared'
import { injectAppHooks } from '@dcloudio/uni-api'
import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core' import { subscribeViewMethod, unsubscribeViewMethod } from '@dcloudio/uni-core'
import { LayoutComponent } from '../..' import { LayoutComponent } from '../..'
import { initApp } from './app' import { initApp } from './app'
...@@ -139,6 +140,7 @@ export function setupApp(comp: any) { ...@@ -139,6 +140,7 @@ export function setupApp(comp: any) {
return route.query return route.query
} }
const onLaunch = () => { const onLaunch = () => {
injectAppHooks(instance)
const { onLaunch, onShow, onPageNotFound } = instance const { onLaunch, onShow, onPageNotFound } = instance
const path = route.path.slice(1) const path = route.path.slice(1)
const launchOptions = initLaunchOptions({ const launchOptions = initLaunchOptions({
......
...@@ -100,6 +100,16 @@ export { ...@@ -100,6 +100,16 @@ export {
getPushCid, getPushCid,
onPushMessage, onPushMessage,
offPushMessage, offPushMessage,
onAppHide,
onAppShow,
onError,
onPageNotFound,
onUnhandledRejection,
offAppHide,
offAppShow,
offError,
offPageNotFound,
offUnhandledRejection,
// 内部使用 // 内部使用
invokePushCallback, invokePushCallback,
} from '@dcloudio/uni-api' } 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -463,9 +463,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -488,15 +490,6 @@ function dedupeHooks(hooks) { ...@@ -488,15 +490,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), 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; let vueApp;
const createVueAppHooks = []; const createVueAppHooks = [];
...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) { ...@@ -499,9 +499,11 @@ function removeInterceptorHook(interceptors, interceptor) {
if (!interceptors || !interceptor) { if (!interceptors || !interceptor) {
return; return;
} }
Object.keys(interceptor).forEach((hook) => { Object.keys(interceptor).forEach((name) => {
if (isFunction(interceptor[hook])) { const hooks = interceptors[name];
removeHook(interceptors[hook], interceptor[hook]); const hook = interceptor[name];
if (isArray(hooks) && isFunction(hook)) {
remove(hooks, hook);
} }
}); });
} }
...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) { ...@@ -524,15 +526,6 @@ function dedupeHooks(hooks) {
} }
return res; 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) => { const addInterceptor = defineSyncApi(API_ADD_INTERCEPTOR, (method, interceptor) => {
if (typeof method === 'string' && isPlainObject(interceptor)) { if (typeof method === 'string' && isPlainObject(interceptor)) {
mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor); mergeInterceptorHook(scopedInterceptors[method] || (scopedInterceptors[method] = {}), interceptor);
......
var version = "0.0.1-nvue3.3040020220221002"; var version = "0.0.1-nvue3.3040020220221002";
const STAT_VERSION = version; const STAT_VERSION = version;
const STAT_URL = 'https://tongji.dcloud.io/uni/stat'; const STAT_URL = 'https://tongji.dcloud.io/uni/stat';
const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif'; const STAT_H5_URL = 'https://tongji.dcloud.io/uni/stat.gif';
const PAGE_PVER_TIME = 1800; const PAGE_PVER_TIME = 1800;
const APP_PVER_TIME = 300; const APP_PVER_TIME = 300;
const OPERATING_TIME = 10; const OPERATING_TIME = 10;
const DIFF_TIME = 60 * 1000 * 60 * 24; const DIFF_TIME = 60 * 1000 * 60 * 24;
const statConfig$1 = { const statConfig$1 = {
...@@ -932,16 +932,16 @@ const lifecycle = { ...@@ -932,16 +932,16 @@ const lifecycle = {
}; };
function main() { function main() {
// if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// uni.report = function (type, options) {}; uni.report = function (type, options) {};
// } else { } else {
uni.onCreateVueApp((app) => { uni.onCreateVueApp((app) => {
app.mixin(lifecycle); app.mixin(lifecycle);
uni.report = function (type, options) { uni.report = function (type, options) {
stat.sendEvent(type, options); stat.sendEvent(type, options);
}; };
}); });
// } }
} }
main(); main();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册