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

wip: lifecycle

上级 b87d746c
import { UniLifecycleHooks } from '@dcloudio/uni-vue/src/apiLifecycle'
import { ComponentCustomProperties, ComponentInternalInstance } from 'vue'
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
$page: Page.PageInstance['$page']
}
type LifecycleHook = Function[] | null
type UniLifecycleHookInstance = {
[name in UniLifecycleHooks]: LifecycleHook
}
interface ComponentInternalInstance extends UniLifecycleHookInstance {
__isUnload: boolean
__isVisible: boolean
}
export const callSyncHook: (
name: 'onLaunch' | 'onLoad' | 'onShow',
type: UniLifecycleHooks,
options: ComponentOptions,
instance: ComponentInternalInstance,
globalMixins: ComponentOptions[]
) => void
export const onBeforeActivate: (fn: () => void) => void
export const onBeforeDeactivate: (fn: () => void) => void
}
......@@ -275,7 +275,7 @@ function createGetter(isReadonly = false, shallow = false) {
return res;
};
}
const set = /*#__PURE__*/ createSetter();
const set$1 = /*#__PURE__*/ createSetter();
const shallowSet = /*#__PURE__*/ createSetter(true);
function createSetter(shallow = false) {
return function set(target, key, value, receiver) {
......@@ -325,7 +325,7 @@ function ownKeys(target) {
}
const mutableHandlers = {
get,
set,
set: set$1,
deleteProperty,
has,
ownKeys
......@@ -407,7 +407,7 @@ function add(value) {
}
return this;
}
function set$1(key, value) {
function set$1$1(key, value) {
value = toRaw(value);
const target = toRaw(this);
const { has, get } = getProto(target);
......@@ -527,7 +527,7 @@ const mutableInstrumentations = {
},
has: has$1,
add,
set: set$1,
set: set$1$1,
delete: deleteEntry,
clear,
forEach: createForEach(false, false)
......@@ -541,7 +541,7 @@ const shallowInstrumentations = {
},
has: has$1,
add,
set: set$1,
set: set$1$1,
delete: deleteEntry,
clear,
forEach: createForEach(false, true)
......@@ -6713,7 +6713,7 @@ function createDuplicateChecker() {
};
}
let shouldCacheAccess = true;
function applyOptions(instance, options, deferredData = [], deferredWatch = [], deferredProvide = [], asMixin = false) {
function applyOptions$1(instance, options, deferredData = [], deferredWatch = [], deferredProvide = [], asMixin = false) {
const {
// composition
mixins, extends: extendsOptions,
......@@ -6746,7 +6746,7 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
}
// extending a base component...
if (extendsOptions) {
applyOptions(instance, extendsOptions, deferredData, deferredWatch, deferredProvide, true);
applyOptions$1(instance, extendsOptions, deferredData, deferredWatch, deferredProvide, true);
}
// local mixins
if (mixins) {
......@@ -6982,6 +6982,7 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
}
}
}
// fixed by xxxxxx
function callSyncHook(name, type, options, instance, globalMixins) {
for (let i = 0; i < globalMixins.length; i++) {
callHookWithMixinAndExtends(name, type, globalMixins[i], instance);
......@@ -7005,7 +7006,7 @@ function callHookWithMixinAndExtends(name, type, options, instance) {
}
function applyMixins(instance, mixins, deferredData, deferredWatch, deferredProvide) {
for (let i = 0; i < mixins.length; i++) {
applyOptions(instance, mixins[i], deferredData, deferredWatch, deferredProvide, true);
applyOptions$1(instance, mixins[i], deferredData, deferredWatch, deferredProvide, true);
}
}
function resolveData(instance, dataFn, publicThis) {
......@@ -7606,7 +7607,7 @@ function finishComponentSetup(instance, isSSR) {
if (__VUE_OPTIONS_API__) {
currentInstance = instance;
pauseTracking();
applyOptions(instance, Component);
applyOptions$1(instance, Component);
resetTracking();
currentInstance = null;
}
......@@ -9404,18 +9405,61 @@ const compile$1 = () => {
}
};
function applyOptions(options, instance, publicThis) {
Object.keys(options).forEach((name) => {
if (name.indexOf('on') === 0) {
const hook = options[name];
if (isFunction(hook)) {
injectHook(name, hook.bind(publicThis), instance);
}
}
});
}
function set(target, key, val) {
return (target[key] = val);
}
function hasHook(name) {
const hooks = this.$[name];
if (hooks && hooks.length) {
return true;
}
return false;
}
function callHook(name, args) {
const hooks = this.$[name];
let ret;
if (hooks) {
for (let i = 0; i < hooks.length; i++) {
ret = hooks[i](args);
}
}
return ret;
}
function errorHandler(err, instance, info) {
if (!instance) {
throw err;
}
const appInstance = instance.$.appContext.$appInstance;
if (!appInstance) {
throw err;
}
appInstance.$callHook('onError', err, info);
}
// @ts-ignore
const createHook = (lifecycle) => (hook, target) =>
// post-create lifecycle registrations are noops during SSR
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
const onShow = /*#__PURE__*/ createHook("onShow" /* ON_SHOW */);
const onHide = /*#__PURE__*/ createHook("onHide" /* ON_HIDE */);
const onLaunch = /*#__PURE__*/ createHook("onLaunch" /* ON_LAUCH */);
const onLaunch = /*#__PURE__*/ createHook("onLaunch" /* ON_LAUNCH */);
const onError = /*#__PURE__*/ createHook("onError" /* ON_ERROR */);
const onThemeChange = /*#__PURE__*/ createHook("onThemeChange" /* ON_THEME_CHANGE */);
const onPageNotFound = /*#__PURE__*/ createHook("onPageNotFound" /* ON_PAGE_NOT_FOUND */);
const onUnhandledRejection = /*#__PURE__*/ createHook("onUnhandledRejection" /* ON_UNHANDLE_REJECTION */);
const onLoad = /*#__PURE__*/ createHook("onLoad" /* ON_LOAD */);
// export const onLoad = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LOAD)
const onReady = /*#__PURE__*/ createHook("onReady" /* ON_READY */);
const onUnload = /*#__PURE__*/ createHook("onUnload" /* ON_UNLOAD */);
const onResize = /*#__PURE__*/ createHook("onResize" /* ON_RESIZE */);
......@@ -9433,4 +9477,18 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook("onNavigation
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook("onNavigationBarSearchInputConfirmed" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED */);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
function initApp(app) {
const appConfig = app._context.config;
if (isFunction(app._component.onError)) {
appConfig.errorHandler = errorHandler;
}
const globalProperties = appConfig.globalProperties;
globalProperties.$hasHook = hasHook;
globalProperties.$callHook = callHook;
if (__VUE_OPTIONS_API__) {
globalProperties.$set = set;
globalProperties.$applyOptions = applyOptions;
}
}
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callSyncHook, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initApp, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
......@@ -6982,6 +6982,7 @@ function applyOptions(instance, options, deferredData = [], deferredWatch = [],
}
}
}
// fixed by xxxxxx
function callSyncHook(name, type, options, instance, globalMixins) {
for (let i = 0; i < globalMixins.length; i++) {
callHookWithMixinAndExtends(name, type, globalMixins[i], instance);
......@@ -9404,4 +9405,4 @@ const compile$1 = () => {
}
};
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callSyncHook, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createApp as createVueApp, createSSRApp as createVueSSRApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isRuntimeOnly, isVNode, markRaw, mergeProps, nextTick, onActivated, onBeforeActivate, onBeforeDeactivate, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
// @ts-ignore
export * from '../lib/vue.runtime.esm.js'
export * from '@dcloudio/uni-vue/src/apiLifecycle'
export * from '@dcloudio/uni-vue'
import {isFunction, extend, isPlainObject, isString, hasOwn as hasOwn$1, hyphenate, isArray, isObject as isObject$1, capitalize, toRawType, makeMap as makeMap$1, isPromise} from "@vue/shared";
import {injectHook, createVNode, inject, provide, reactive, computed, nextTick, openBlock, createBlock, mergeProps, toDisplayString, ref, defineComponent, resolveComponent, toHandlers, renderSlot, createCommentVNode, getCurrentInstance, onBeforeUnmount, withModifiers, withDirectives, vShow, vModelDynamic, createTextVNode, Fragment, renderList, vModelText, onMounted, watch, onBeforeMount, withCtx, KeepAlive, resolveDynamicComponent} from "vue";
import {isFunction, extend, isPlainObject, invokeArrayFns, isString, hasOwn as hasOwn$1, hyphenate, isArray, isObject as isObject$1, capitalize, toRawType, makeMap as makeMap$1, isPromise} from "@vue/shared";
import {injectHook, isInSSRComponentSetup, createVNode, inject, provide, reactive, computed, nextTick, getCurrentInstance, onBeforeMount, onMounted, onBeforeActivate, onBeforeDeactivate, openBlock, createBlock, mergeProps, toDisplayString, ref, defineComponent, resolveComponent, toHandlers, renderSlot, createCommentVNode, onBeforeUnmount, withModifiers, withDirectives, vShow, vModelDynamic, createTextVNode, Fragment, renderList, vModelText, watch, withCtx, KeepAlive, resolveDynamicComponent} from "vue";
import {passive, NAVBAR_HEIGHT, removeLeadingSlash, plusReady, debounce, PRIMARY_COLOR, getLen} from "@dcloudio/uni-shared";
import {createRouter, createWebHistory, createWebHashHistory, useRoute, isNavigationFailure, RouterView} from "vue-router";
import {useRoute, createRouter, createWebHistory, createWebHashHistory, isNavigationFailure, RouterView} from "vue-router";
function applyOptions(options, instance2, publicThis) {
Object.keys(options).forEach((name) => {
if (name.indexOf("on") === 0) {
......@@ -42,6 +42,57 @@ function errorHandler(err, instance2, info) {
}
appInstance.$callHook("onError", err, info);
}
var UniLifecycleHooks;
(function(UniLifecycleHooks2) {
UniLifecycleHooks2["ON_SHOW"] = "onShow";
UniLifecycleHooks2["ON_HIDE"] = "onHide";
UniLifecycleHooks2["ON_LAUNCH"] = "onLaunch";
UniLifecycleHooks2["ON_ERROR"] = "onError";
UniLifecycleHooks2["ON_THEME_CHANGE"] = "onThemeChange";
UniLifecycleHooks2["ON_PAGE_NOT_FOUND"] = "onPageNotFound";
UniLifecycleHooks2["ON_UNHANDLE_REJECTION"] = "onUnhandledRejection";
UniLifecycleHooks2["ON_LOAD"] = "onLoad";
UniLifecycleHooks2["ON_READY"] = "onReady";
UniLifecycleHooks2["ON_UNLOAD"] = "onUnload";
UniLifecycleHooks2["ON_RESIZE"] = "onResize";
UniLifecycleHooks2["ON_BACK_PRESS"] = "onBackPress";
UniLifecycleHooks2["ON_PAGE_SCROLL"] = "onPageScroll";
UniLifecycleHooks2["ON_TAB_ITEM_TAP"] = "onTabItemTap";
UniLifecycleHooks2["ON_REACH_BOTTOM"] = "onReachBottom";
UniLifecycleHooks2["ON_PULL_DOWN_REFRESH"] = "onPullDownRefresh";
UniLifecycleHooks2["ON_SHARE_TIMELINE"] = "onShareTimeline";
UniLifecycleHooks2["ON_ADD_TO_FAVORITES"] = "onAddToFavorites";
UniLifecycleHooks2["ON_SHARE_APP_MESSAGE"] = "onShareAppMessage";
UniLifecycleHooks2["ON_NAVIGATION_BAR_BUTTON_TAP"] = "onNavigationBarButtonTap";
UniLifecycleHooks2["ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED"] = "onNavigationBarSearchInputClicked";
UniLifecycleHooks2["ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED"] = "onNavigationBarSearchInputChanged";
UniLifecycleHooks2["ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED"] = "onNavigationBarSearchInputConfirmed";
UniLifecycleHooks2["ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED"] = "onNavigationBarSearchInputFocusChanged";
})(UniLifecycleHooks || (UniLifecycleHooks = {}));
const createHook = (lifecycle) => (hook, target) => !isInSSRComponentSetup && injectHook(lifecycle, hook, target);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_SHOW);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_HIDE);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_LAUNCH);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_ERROR);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_THEME_CHANGE);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_PAGE_NOT_FOUND);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_UNHANDLE_REJECTION);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_READY);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_UNLOAD);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_RESIZE);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_BACK_PRESS);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_PAGE_SCROLL);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_TAB_ITEM_TAP);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_REACH_BOTTOM);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_PULL_DOWN_REFRESH);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_SHARE_TIMELINE);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_ADD_TO_FAVORITES);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_SHARE_APP_MESSAGE);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_NAVIGATION_BAR_BUTTON_TAP);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED);
/* @__PURE__ */ createHook(UniLifecycleHooks.ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED);
function initApp$1(app) {
const appConfig = app._context.config;
if (isFunction(app._component.onError)) {
......@@ -1223,41 +1274,6 @@ function getRealRoute(fromRoute, toRoute) {
fromRouteArray.splice(fromRouteArray.length - i2 - 1, i2 + 1);
return "/" + fromRouteArray.concat(toRouteArray).join("/");
}
function initRouter(app) {
app.use(createAppRouter(createRouter(createRouterOptions())));
}
const scrollBehavior = (to, from, savedPosition) => {
if (savedPosition) {
return savedPosition;
}
};
function createRouterOptions() {
return {
history: initHistory(),
strict: !!__uniConfig.router.strict,
routes: __uniRoutes,
scrollBehavior
};
}
function createAppRouter(router) {
return router;
}
function initHistory() {
const history2 = __UNI_FEATURE_ROUTER_MODE__ === "history" ? createWebHistory() : createWebHashHistory();
return history2;
}
let appVm;
function getApp$1() {
return appVm;
}
function isApp(vm) {
return vm.$options.mpType === "app";
}
function initApp(vm) {
appVm = vm;
appVm.$vm = vm;
appVm.globalData = appVm.$options.globalData || {};
}
const pageMetaKey = PolySymbol(process.env.NODE_ENV !== "production" ? "UniPageMeta" : "upm");
function usePageMeta() {
return inject(pageMetaKey);
......@@ -1360,6 +1376,18 @@ function getCurrentPages$1(isAll = false) {
pruneCurrentPages();
return [...currentPagesMap.values()];
}
function removeCurrentPages(delta = -1) {
const keys = [...currentPagesMap.keys()];
const start = keys.length - 1;
const end = start - delta;
for (let i2 = start; i2 > end; i2--) {
const routeKey = keys[i2];
const pageVm = currentPagesMap.get(routeKey);
pageVm.$.__isUnload = true;
pageVm.$callHook("onUnload");
currentPagesMap.delete(routeKey);
}
}
let id = history.state && history.state.__id__ || 1;
function createPageState(type) {
return {
......@@ -1367,9 +1395,6 @@ function createPageState(type) {
__type__: type
};
}
function isPage(vm) {
return vm.$options.mpType === "page";
}
function initPublicPage(route) {
if (!route) {
const {path: path2} = __uniRoutes[0];
......@@ -1389,11 +1414,14 @@ function initPage(vm) {
const route = vm.$route;
vm.$vm = vm;
vm.$page = initPublicPage(route);
currentPagesMap.set(vm.$page.id, vm);
currentPagesMap.set(normalizeRouteKey(route.path, vm.$page.id), vm);
}
function normalizeRouteKey(path, id2) {
return path + SEP + id2;
}
function useKeepAliveRoute() {
const route = useRoute();
const routeKey = computed(() => route.fullPath + SEP + (history.state.__id__ || 1));
const routeKey = computed(() => normalizeRouteKey(route.path, history.state.__id__ || 1));
return {
routeKey,
routeCache
......@@ -1409,6 +1437,10 @@ const routeCache = {
pageCacheMap.set(key, value);
},
delete(key) {
const vnode = pageCacheMap.get(key);
if (!vnode) {
return;
}
pageCacheMap.delete(key);
},
forEach(fn) {
......@@ -1429,58 +1461,120 @@ function pruneRouteCache(key) {
}
});
}
function initMixin(app) {
app.mixin({
created() {
this.__isApp = isApp(this);
this.__isPage = !this.__isApp && isPage(this);
if (this.__isApp) {
initApp(this);
} else if (this.__isPage) {
initPage(this);
this.$callHook("onLoad", {});
this.__isVisible = true;
this.$callHook("onShow");
} else {
if (this.$parent) {
this.$page = this.$parent.$page;
}
}
},
mounted() {
if (this.__isPage) {
this.$callHook("onReady");
}
},
beforeActivate() {
if (this.__isPage && !this.__isVisible) {
this.$callHook("onShow");
}
},
beforeDeactivate() {
if (this.__isPage) {
this.__isVisible = false;
this.$callHook("onHide");
}
},
beforeUnmount() {
if (this.__isPage) {
this.$callHook("onUnload");
}
function initRouter(app) {
app.use(createAppRouter(createRouter(createRouterOptions())));
}
const scrollBehavior = (to, from, savedPosition) => {
if (savedPosition) {
return savedPosition;
}
};
function createRouterOptions() {
return {
history: initHistory(),
strict: !!__uniConfig.router.strict,
routes: __uniRoutes,
scrollBehavior
};
}
function createAppRouter(router) {
return router;
}
function initHistory() {
const history2 = __UNI_FEATURE_ROUTER_MODE__ === "history" ? createWebHistory() : createWebHashHistory();
history2.listen((_to, _from, info) => {
if (info.direction === "back") {
removeCurrentPages(Math.abs(info.delta));
}
});
return history2;
}
var index$7 = {
var index$6 = {
install(app) {
initApp$1(app);
initView(app);
initService(app);
initMixin(app);
if (__UNI_FEATURE_PAGES__) {
initRouter(app);
}
}
};
let appVm;
function getApp$1() {
return appVm;
}
function initApp(vm) {
appVm = vm;
appVm.$vm = vm;
appVm.globalData = appVm.$options.globalData || {};
}
function wrapperComponentSetup(comp, {init: init2, setup, after}) {
const oldSetup = comp.setup;
comp.setup = (props, ctx) => {
const instance2 = getCurrentInstance();
init2(instance2.proxy);
setup(instance2);
if (oldSetup) {
return oldSetup(props, ctx);
}
};
after && after(comp);
}
function setupComponent(comp, options) {
if (comp && (comp.__esModule || comp[Symbol.toStringTag] === "Module")) {
wrapperComponentSetup(comp.default, options);
} else {
wrapperComponentSetup(comp, options);
}
return comp;
}
function setupPage(comp) {
return setupComponent(comp, {
init: initPage,
setup(instance2) {
onBeforeMount(() => {
const {onLoad, onShow} = instance2;
onLoad && invokeArrayFns(onLoad);
instance2.__isVisible = true;
onShow && invokeArrayFns(onShow);
});
onMounted(() => {
const {onReady} = instance2;
onReady && invokeArrayFns(onReady);
});
onBeforeActivate(() => {
if (!instance2.__isVisible) {
instance2.__isVisible = true;
const {onShow} = instance2;
onShow && invokeArrayFns(onShow);
}
});
onBeforeDeactivate(() => {
if (instance2.__isVisible && !instance2.__isUnload) {
instance2.__isVisible = false;
const {onHide} = instance2;
onHide && invokeArrayFns(onHide);
}
});
}
});
}
function setupApp(comp) {
return setupComponent(comp, {
init: initApp,
setup(instance2) {
onBeforeMount(() => {
const {onLaunch, onShow} = instance2;
onLaunch && invokeArrayFns(onLaunch);
onShow && invokeArrayFns(onShow);
});
},
after(comp2) {
comp2.mpType = "app";
comp2.render = () => (openBlock(), createBlock(LayoutComponent));
}
});
}
function broadcast(componentName, eventName, ...params) {
const children = this.$children;
const len = children.length;
......@@ -2091,7 +2185,7 @@ function useBooleanAttr(props, keys) {
}, Object.create(null));
}
const uniFormKey = PolySymbol(process.env.NODE_ENV !== "production" ? "uniForm" : "uf");
var index$6 = defineComponent({
var index$5 = defineComponent({
name: "Form",
setup(_props, {
slots,
......@@ -2128,7 +2222,7 @@ function provideForm(emit) {
});
return fields;
}
var index$5 = defineComponent({
var index$4 = defineComponent({
name: "Button",
props: {
id: {
......@@ -3791,7 +3885,7 @@ const ICONS = {
c: GREY_COLOR
}
};
var index$4 = defineComponent({
var index$3 = defineComponent({
name: "Icon",
props: {
type: {
......@@ -3926,6 +4020,9 @@ function getRealPath(filePath) {
const ua = navigator.userAgent;
const isAndroid = /android/i.test(ua);
const isIOS$1 = /iphone|ipad|ipod/i.test(ua);
const isWindows = ua.match(/Windows NT ([\d|\d.\d]*)/i);
const isMac = /Macintosh|Mac/i.test(ua);
const isLinux = /Linux|X11/i.test(ua);
function getScreenFix() {
return /^Apple/.test(navigator.vendor) && typeof window.orientation === "number";
}
......@@ -9262,7 +9359,7 @@ function normalizeText(text2, {
}
return text2.replace(/&nbsp;/g, SPACE_UNICODE.nbsp).replace(/&ensp;/g, SPACE_UNICODE.ensp).replace(/&emsp;/g, SPACE_UNICODE.emsp).replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'");
}
var index$3 = defineComponent({
var index$2 = defineComponent({
name: "Text",
props: {
selectable: {
......@@ -9588,7 +9685,7 @@ function _sfc_render$4(_ctx, _cache, $props, $setup, $data, $options) {
], 16);
}
_sfc_main$4.render = _sfc_render$4;
var index$2 = defineComponent({
var index$1 = defineComponent({
name: "View",
props: extend({}, hoverProps),
setup(props, {
......@@ -10467,6 +10564,56 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
break;
}
}
} else if (isWindows || isMac || isLinux) {
model = "PC";
osname = "PC";
osversion = "0";
let osversionFind = ua.match(/\((.+?)\)/)[1];
if (isWindows) {
osname = "Windows";
switch (isWindows[1]) {
case "5.1":
osversion = "XP";
break;
case "6.0":
osversion = "Vista";
break;
case "6.1":
osversion = "7";
break;
case "6.2":
osversion = "8";
break;
case "6.3":
osversion = "8.1";
break;
case "10.0":
osversion = "10";
break;
}
const framework = osversionFind && osversionFind.match(/[Win|WOW]([\d]+)/);
if (framework) {
osversion += ` x${framework[1]}`;
}
} else if (isMac) {
osname = "Mac";
osversion = osversionFind && osversionFind.match(/Mac OS X (.+)/) || "";
if (osversion) {
osversion = osversion[1].replace(/_/g, ".");
if (osversion.indexOf(";") !== -1) {
osversion = osversion.split(";")[0];
}
}
} else if (isLinux) {
osname = "Linux";
osversion = osversionFind && osversionFind.match(/Linux (.*)/) || "";
if (osversion) {
osversion = osversion[1];
if (osversion.indexOf(";") !== -1) {
osversion = osversion.split(";")[0];
}
}
}
} else {
osname = "Other";
osversion = "0";
......@@ -11430,7 +11577,7 @@ function createTabBarMidButtonTsx(color, iconPath, midButton, tabBar2, index2, o
}, null, 12, ["src"])], 4), createTabBarItemBdTsx(color, iconPath, midButton, tabBar2)], 12, ["onClick"]);
}
const CSS_VARS = ["--status-bar-height", "--top-window-height", "--window-left", "--window-right", "--window-margin", "--tab-bar-height"];
var index$1 = defineComponent({
var LayoutComponent = defineComponent({
name: "Layout",
setup(props, {
emit
......@@ -12229,4 +12376,4 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
]);
}
_sfc_main.render = _sfc_render;
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$n as Audio, index$5 as Button, _sfc_main$m as Canvas, _sfc_main$l as Checkbox, _sfc_main$k as CheckboxGroup, _sfc_main$j as Editor, index$6 as Form, index$4 as Icon, _sfc_main$h as Image, _sfc_main$g as Input, _sfc_main$f as Label, index$1 as LayoutComponent, _sfc_main$e as MovableView, _sfc_main$d as Navigator, index as PageComponent, _sfc_main$c as Progress, _sfc_main$b as Radio, _sfc_main$a as RadioGroup, _sfc_main$i as ResizeSensor, _sfc_main$9 as RichText, _sfc_main$8 as ScrollView, _sfc_main$7 as Slider, _sfc_main$6 as SwiperItem, _sfc_main$5 as Switch, index$3 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as Video, index$2 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getNetworkType, getSystemInfo, getSystemInfoSync, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, makePhoneCall, navigateBack, navigateTo, offNetworkStatusChange, onNetworkStatusChange, onTabBarMidButtonTap, openDocument, index$7 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeTabBarBadge, request, setNavigationBarColor, setNavigationBarTitle, setTabBarBadge, setTabBarItem, setTabBarStyle, showNavigationBarLoading, showTabBar, showTabBarRedDot, switchTab, uni$1 as uni, uploadFile, upx2px, useSubscribe};
export {_sfc_main$1 as AsyncErrorComponent, _sfc_main as AsyncLoadingComponent, _sfc_main$n as Audio, index$4 as Button, _sfc_main$m as Canvas, _sfc_main$l as Checkbox, _sfc_main$k as CheckboxGroup, _sfc_main$j as Editor, index$5 as Form, index$3 as Icon, _sfc_main$h as Image, _sfc_main$g as Input, _sfc_main$f as Label, LayoutComponent, _sfc_main$e as MovableView, _sfc_main$d as Navigator, index as PageComponent, _sfc_main$c as Progress, _sfc_main$b as Radio, _sfc_main$a as RadioGroup, _sfc_main$i as ResizeSensor, _sfc_main$9 as RichText, _sfc_main$8 as ScrollView, _sfc_main$7 as Slider, _sfc_main$6 as SwiperItem, _sfc_main$5 as Switch, index$2 as Text, _sfc_main$4 as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, _sfc_main$3 as Video, index$1 as View, addInterceptor, arrayBufferToBase64, base64ToArrayBuffer, canIUse, createIntersectionObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getCurrentPages$1 as getCurrentPages, getImageInfo, getNetworkType, getSystemInfo, getSystemInfoSync, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, makePhoneCall, navigateBack, navigateTo, offNetworkStatusChange, onNetworkStatusChange, onTabBarMidButtonTap, openDocument, index$6 as plugin, promiseInterceptor, reLaunch, redirectTo, removeInterceptor, removeTabBarBadge, request, setNavigationBarColor, setNavigationBarTitle, setTabBarBadge, setTabBarItem, setTabBarStyle, setupApp, setupPage, showNavigationBarLoading, showTabBar, showTabBarRedDot, switchTab, uni$1 as uni, uploadFile, upx2px, useSubscribe};
......@@ -4,7 +4,7 @@ import { initApp } from '@dcloudio/uni-vue'
import { initView, initService } from '@dcloudio/uni-core'
import { initRouter } from './router'
import { initMixin } from './mixin'
// import { initMixin } from './mixin'
export default {
install(app: App) {
......@@ -12,7 +12,7 @@ export default {
initView(app)
initService(app)
initMixin(app)
// initMixin(app)
if (__UNI_FEATURE_PAGES__) {
initRouter(app)
......
import { App, ComponentPublicInstance } from 'vue'
import { isApp, initApp } from './app'
import { initPage, isPage } from './page'
export function initMixin(app: App) {
// 目前使用mixin实现,稍后应调整为不依赖options的方案
app.mixin({
created(this: ComponentPublicInstance) {
this.__isApp = isApp(this)
this.__isPage = !this.__isApp && isPage(this)
if (this.__isApp) {
initApp(this)
} else if (this.__isPage) {
initPage(this)
this.$callHook('onLoad', {})
this.__isVisible = true
this.$callHook('onShow')
} else {
// TODO 待优化
if (this.$parent) {
this.$page = this.$parent.$page
}
}
},
mounted() {
if (this.__isPage) {
this.$callHook('onReady')
}
},
beforeActivate() {
if (this.__isPage && !this.__isVisible) {
this.$callHook('onShow')
}
},
beforeDeactivate() {
if (this.__isPage) {
this.__isVisible = false
this.$callHook('onHide')
}
},
beforeUnmount() {
// TODO 目前onUnload时机不对,比前一个页面的onShow要晚
if (this.__isPage) {
this.$callHook('onUnload')
}
},
})
}
......@@ -11,7 +11,7 @@ import { usePageMeta } from './provide'
const SEP = '$$'
const currentPagesMap = new Map<number, Page.PageInstance>()
const currentPagesMap = new Map<string, Page.PageInstance>()
function pruneCurrentPages() {
currentPagesMap.forEach((page, id) => {
......@@ -26,6 +26,19 @@ export function getCurrentPages(isAll: boolean = false) {
return [...currentPagesMap.values()]
}
export function removeCurrentPages(delta: number = -1) {
const keys = [...currentPagesMap.keys()]
const start = keys.length - 1
const end = start - delta
for (let i = start; i > end; i--) {
const routeKey = keys[i]
const pageVm = currentPagesMap.get(routeKey) as ComponentPublicInstance
pageVm.$.__isUnload = true
pageVm.$callHook('onUnload')
currentPagesMap.delete(routeKey)
}
}
let id = (history.state && history.state.__id__) || 1
export function createPageState(
......@@ -62,13 +75,20 @@ export function initPage(vm: ComponentPublicInstance) {
const route = vm.$route
;(vm as any).$vm = vm
;(vm as any).$page = initPublicPage(route)
currentPagesMap.set(vm.$page.id, (vm as unknown) as Page.PageInstance)
currentPagesMap.set(
normalizeRouteKey(route.path, vm.$page.id),
(vm as unknown) as Page.PageInstance
)
}
function normalizeRouteKey(path: string, id: number) {
return path + SEP + id
}
export function useKeepAliveRoute() {
const route = useRoute()
const routeKey = computed(
() => route.fullPath + SEP + (history.state.__id__ || 1)
const routeKey = computed(() =>
normalizeRouteKey(route.path, history.state.__id__ || 1)
)
return {
routeKey,
......@@ -100,6 +120,10 @@ const routeCache: KeepAliveCache = {
pageCacheMap.set(key, value)
},
delete(key) {
const vnode = pageCacheMap.get(key)
if (!vnode) {
return
}
pageCacheMap.delete(key)
},
forEach(fn) {
......
import { App } from 'vue'
import { Router, RouterOptions, RouteRecordRaw } from 'vue-router'
import {
Router,
RouterOptions,
RouteRecordRaw,
RouterHistory,
} from 'vue-router'
import {
createRouter,
createWebHistory,
createWebHashHistory,
} from 'vue-router'
import { removeCurrentPages } from './page'
export function initRouter(app: App) {
app.use(createAppRouter(createRouter(createRouterOptions())))
......@@ -39,5 +45,10 @@ function initHistory() {
__UNI_FEATURE_ROUTER_MODE__ === 'history'
? createWebHistory()
: createWebHashHistory()
history.listen((_to, _from, info) => {
if (info.direction === 'back') {
removeCurrentPages(Math.abs(info.delta))
}
})
return history
}
import { invokeArrayFns } from '@vue/shared'
import {
ComponentInternalInstance,
ComponentPublicInstance,
createBlock,
DefineComponent,
getCurrentInstance,
onMounted,
openBlock,
onBeforeActivate,
onBeforeDeactivate,
onBeforeMount,
} from 'vue'
import { LayoutComponent } from '../..'
import { initApp } from './app'
import { initPage } from './page'
interface SetupComponentOptions {
init: (vm: ComponentPublicInstance) => void
setup: (instance: ComponentInternalInstance) => void
after?: (comp: DefineComponent) => void
}
function wrapperComponentSetup(
comp: DefineComponent,
{ init, setup, after }: SetupComponentOptions
) {
const oldSetup = comp.setup
comp.setup = (props, ctx) => {
const instance = getCurrentInstance()!
init(instance.proxy!)
setup(instance)
if (oldSetup) {
return oldSetup(props, ctx)
}
}
after && after(comp)
}
function setupComponent(comp: any, options: SetupComponentOptions) {
if (comp && (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
wrapperComponentSetup(comp.default, options)
} else {
wrapperComponentSetup(comp, options)
}
return comp
}
export function setupPage(comp: any) {
return setupComponent(comp, {
init: initPage,
setup(instance) {
onBeforeMount(() => {
const { onLoad, onShow } = instance
onLoad && invokeArrayFns(onLoad)
instance.__isVisible = true
onShow && invokeArrayFns(onShow)
})
onMounted(() => {
const { onReady } = instance
onReady && invokeArrayFns(onReady)
})
onBeforeActivate(() => {
if (!instance.__isVisible) {
instance.__isVisible = true
const { onShow } = instance
onShow && invokeArrayFns(onShow)
}
})
onBeforeDeactivate(() => {
if (instance.__isVisible && !instance.__isUnload) {
instance.__isVisible = false
const { onHide } = instance
onHide && invokeArrayFns(onHide)
}
})
},
})
}
export function setupApp(comp: any) {
return setupComponent(comp, {
init: initApp,
setup(instance) {
onBeforeMount(() => {
const { onLaunch, onShow } = instance
onLaunch && invokeArrayFns(onLaunch)
onShow && invokeArrayFns(onShow)
})
},
after(comp) {
comp.mpType = 'app'
comp.render = () => (openBlock(), createBlock(LayoutComponent))
},
})
}
declare module '@vue/runtime-core' {
interface ComponentCustomProperties {
__isApp: boolean
__isPage: boolean
__isUnload: boolean
__isVisible: boolean
$page: Page.PageInstance['$page']
}
}
export { default as plugin } from './framework/plugin'
import plugin from './framework/plugin'
export { plugin }
export * from './framework/plugin/setup'
export * from '@dcloudio/uni-components'
export * from './view/components'
......
......@@ -4082,6 +4082,35 @@ function errorHandler(err, instance, info) {
appInstance.$callHook('onError', err, info);
}
// @ts-ignore
const createHook = (lifecycle) => (hook, target) =>
// post-create lifecycle registrations are noops during SSR
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
const onShow = /*#__PURE__*/ createHook("onShow" /* ON_SHOW */);
const onHide = /*#__PURE__*/ createHook("onHide" /* ON_HIDE */);
const onLaunch = /*#__PURE__*/ createHook("onLaunch" /* ON_LAUNCH */);
const onError = /*#__PURE__*/ createHook("onError" /* ON_ERROR */);
const onThemeChange = /*#__PURE__*/ createHook("onThemeChange" /* ON_THEME_CHANGE */);
const onPageNotFound = /*#__PURE__*/ createHook("onPageNotFound" /* ON_PAGE_NOT_FOUND */);
const onUnhandledRejection = /*#__PURE__*/ createHook("onUnhandledRejection" /* ON_UNHANDLE_REJECTION */);
// export const onLoad = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LOAD)
const onReady = /*#__PURE__*/ createHook("onReady" /* ON_READY */);
const onUnload = /*#__PURE__*/ createHook("onUnload" /* ON_UNLOAD */);
const onResize = /*#__PURE__*/ createHook("onResize" /* ON_RESIZE */);
const onBackPress = /*#__PURE__*/ createHook("onBackPress" /* ON_BACK_PRESS */);
const onPageScroll = /*#__PURE__*/ createHook("onPageScroll" /* ON_PAGE_SCROLL */);
const onTabItemTap = /*#__PURE__*/ createHook("onTabItemTap" /* ON_TAB_ITEM_TAP */);
const onReachBottom = /*#__PURE__*/ createHook("onReachBottom" /* ON_REACH_BOTTOM */);
const onPullDownRefresh = /*#__PURE__*/ createHook("onPullDownRefresh" /* ON_PULL_DOWN_REFRESH */);
const onShareTimeline = /*#__PURE__*/ createHook("onShareTimeline" /* ON_SHARE_TIMELINE */);
const onAddToFavorites = /*#__PURE__*/ createHook("onAddToFavorites" /* ON_ADD_TO_FAVORITES */);
const onShareAppMessage = /*#__PURE__*/ createHook("onShareAppMessage" /* ON_SHARE_APP_MESSAGE */);
const onNavigationBarButtonTap = /*#__PURE__*/ createHook("onNavigationBarButtonTap" /* ON_NAVIGATION_BAR_BUTTON_TAP */);
const onNavigationBarSearchInputChanged = /*#__PURE__*/ createHook("onNavigationBarSearchInputChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED */);
const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook("onNavigationBarSearchInputClicked" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED */);
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook("onNavigationBarSearchInputConfirmed" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED */);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
function initApp(app) {
const appConfig = app._context.config;
if (isFunction(app._component.onError)) {
......@@ -4119,38 +4148,9 @@ var plugin = {
},
};
// @ts-ignore
const createHook = (lifecycle) => (hook, target) =>
// post-create lifecycle registrations are noops during SSR
!isInSSRComponentSetup && injectHook(lifecycle, hook, target);
const onShow = /*#__PURE__*/ createHook("onShow" /* ON_SHOW */);
const onHide = /*#__PURE__*/ createHook("onHide" /* ON_HIDE */);
const onLaunch = /*#__PURE__*/ createHook("onLaunch" /* ON_LAUCH */);
const onError = /*#__PURE__*/ createHook("onError" /* ON_ERROR */);
const onThemeChange = /*#__PURE__*/ createHook("onThemeChange" /* ON_THEME_CHANGE */);
const onPageNotFound = /*#__PURE__*/ createHook("onPageNotFound" /* ON_PAGE_NOT_FOUND */);
const onUnhandledRejection = /*#__PURE__*/ createHook("onUnhandledRejection" /* ON_UNHANDLE_REJECTION */);
const onLoad = /*#__PURE__*/ createHook("onLoad" /* ON_LOAD */);
const onReady = /*#__PURE__*/ createHook("onReady" /* ON_READY */);
const onUnload = /*#__PURE__*/ createHook("onUnload" /* ON_UNLOAD */);
const onResize = /*#__PURE__*/ createHook("onResize" /* ON_RESIZE */);
const onBackPress = /*#__PURE__*/ createHook("onBackPress" /* ON_BACK_PRESS */);
const onPageScroll = /*#__PURE__*/ createHook("onPageScroll" /* ON_PAGE_SCROLL */);
const onTabItemTap = /*#__PURE__*/ createHook("onTabItemTap" /* ON_TAB_ITEM_TAP */);
const onReachBottom = /*#__PURE__*/ createHook("onReachBottom" /* ON_REACH_BOTTOM */);
const onPullDownRefresh = /*#__PURE__*/ createHook("onPullDownRefresh" /* ON_PULL_DOWN_REFRESH */);
const onShareTimeline = /*#__PURE__*/ createHook("onShareTimeline" /* ON_SHARE_TIMELINE */);
const onAddToFavorites = /*#__PURE__*/ createHook("onAddToFavorites" /* ON_ADD_TO_FAVORITES */);
const onShareAppMessage = /*#__PURE__*/ createHook("onShareAppMessage" /* ON_SHARE_APP_MESSAGE */);
const onNavigationBarButtonTap = /*#__PURE__*/ createHook("onNavigationBarButtonTap" /* ON_NAVIGATION_BAR_BUTTON_TAP */);
const onNavigationBarSearchInputChanged = /*#__PURE__*/ createHook("onNavigationBarSearchInputChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED */);
const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook("onNavigationBarSearchInputClicked" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED */);
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook("onNavigationBarSearchInputConfirmed" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED */);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
function createApp(rootComponent, rootProps = null) {
rootComponent && (rootComponent.mpType = 'app');
return createVueApp(rootComponent, rootProps).use(plugin);
}
export { callWithAsyncErrorHandling, callWithErrorHandling, computed$1 as computed, createApp, createHook, createVueApp, customRef, defineComponent, defineEmit, defineProps, getCurrentInstance, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, provide, reactive, readonly, ref, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, version, warn, watch, watchEffect, withDirectives };
export { callWithAsyncErrorHandling, callWithErrorHandling, computed$1 as computed, createApp, createHook, createVueApp, customRef, defineComponent, defineEmit, defineProps, getCurrentInstance, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, provide, reactive, readonly, ref, resolveDirective, shallowReactive, shallowReadonly, shallowRef, toRaw, toRef, toRefs, triggerRef, unref, version, warn, watch, watchEffect, withDirectives };
......@@ -7,7 +7,7 @@ export const enum UniLifecycleHooks {
ON_SHOW = 'onShow',
ON_HIDE = 'onHide',
//App
ON_LAUCH = 'onLaunch',
ON_LAUNCH = 'onLaunch',
ON_ERROR = 'onError',
ON_THEME_CHANGE = 'onThemeChange',
ON_PAGE_NOT_FOUND = 'onPageNotFound',
......@@ -44,7 +44,7 @@ export const createHook = <T extends Function = () => any>(
export const onShow = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_SHOW)
export const onHide = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_HIDE)
export const onLaunch = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LAUCH)
export const onLaunch = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LAUNCH)
export const onError = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_ERROR)
export const onThemeChange = /*#__PURE__*/ createHook(
UniLifecycleHooks.ON_THEME_CHANGE
......@@ -56,7 +56,7 @@ export const onUnhandledRejection = /*#__PURE__*/ createHook(
UniLifecycleHooks.ON_UNHANDLE_REJECTION
)
export const onLoad = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LOAD)
// export const onLoad = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_LOAD)
export const onReady = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_READY)
export const onUnload = /*#__PURE__*/ createHook(UniLifecycleHooks.ON_UNLOAD)
......
......@@ -6,6 +6,8 @@ import { applyOptions } from './componentOptions'
import { set, hasHook, callHook } from './componentInstance'
import { errorHandler } from './appConfig'
export * from './apiLifecycle'
export function initApp(app: App) {
const appConfig = app._context.config
if (isFunction((app._component as any).onError)) {
......
......@@ -13,7 +13,7 @@ export function uniMainJsPlugin(options: VitePluginUniResolvedOptions): Plugin {
transform(code, id) {
if (id === mainJsPath || id === mainTsPath) {
return {
code: `import { openBlock, createBlock } from 'vue';import { plugin,LayoutComponent } from '@dcloudio/uni-h5';import '${pagesJsonJsPath}';function createApp(rootComponent,rootProps){rootComponent && (rootComponent.mpType = 'app',rootComponent.render = ()=>(openBlock(),createBlock(LayoutComponent)));return createVueApp(rootComponent, rootProps).use(plugin)};${code.replace(
code: `import { plugin, setupApp } from '@dcloudio/uni-h5';import '${pagesJsonJsPath}';function createApp(rootComponent,rootProps){rootComponent && setupApp(rootComponent);return createVueApp(rootComponent, rootProps).use(plugin)};${code.replace(
'createApp',
'createVueApp'
)}`,
......
......@@ -63,8 +63,9 @@ function parsePagesJson(
const cssCode = generateCssCode(config)
return `
import { extend } from '@vue/shared'
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5'
import { setupPage, PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '${manifestJsonPath}'
${cssCode}
${uniConfigCode}
......@@ -123,20 +124,23 @@ function generateCssCode(config: ResolvedConfig) {
function generatePageDefineCode(pageOptions: UniApp.PagesJsonPageOptions) {
return `const ${normalizePageIdentifier(
pageOptions.path
)} = defineAsyncComponent({
loader: () => import('./${pageOptions.path}.vue?mpType=page'),
loadingComponent: AsyncLoadingComponent,
errorComponent: AsyncErrorComponent,
delay: async.delay,
timeout: async.timeout,
suspensible: async.suspensible
})`
)} = defineAsyncComponent(extend({loader:()=>import('./${
pageOptions.path
}.vue?mpType=page').then(comp=>setupPage(comp))},AsyncComponentOptions))`
}
function generatePagesDefineCode(pagesJson: UniApp.PagesJson) {
return pagesJson.pages
.map((pageOptions) => generatePageDefineCode(pageOptions))
.join('\n')
const { pages } = pagesJson
return (
`const AsyncComponentOptions = {
loadingComponent: AsyncLoadingComponent,
errorComponent: AsyncErrorComponent,
delay: async.delay,
timeout: async.timeout,
suspensible: async.suspensible
}
` + pages.map((pageOptions) => generatePageDefineCode(pageOptions)).join('\n')
)
}
function normalizePagesRoute(pagesJson: UniApp.PagesJson): PageRouteOptions[] {
......@@ -176,11 +180,7 @@ function generatePageRoute({ name, path, meta }: PageRouteOptions) {
const alias = isEntry ? `\n alias:'/${path}',` : ''
return `{
path:'/${isEntry ? '' : path}',${alias}
component:{
render() {
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(${name})]), _: 1 /* STABLE */}))
}
},
component:{render(){return renderPage(${name})}},
meta: ${JSON.stringify(meta)}
}`
}
......@@ -190,7 +190,11 @@ function generatePagesRoute(pagesRouteOptions: PageRouteOptions[]) {
}
function generateRoutes(pagesJson: UniApp.PagesJson) {
return `window.__uniRoutes=[${[
return `
function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
}
window.__uniRoutes=[${[
...generatePagesRoute(normalizePagesRoute(pagesJson)),
].join(',')}]`
}
......
......@@ -39,6 +39,7 @@
"include": [
"packages/global.d.ts",
"packages/shims-uni-app.d.ts",
"packages/shims-vue-runtime.d.ts",
"packages/shims-vue.d.ts",
"packages/*/src",
"packages/*/__tests__",
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册