调整router版本
This commit is contained in:
32
node_modules/uni-simple-router/src/H5/patch.ts
generated
vendored
32
node_modules/uni-simple-router/src/H5/patch.ts
generated
vendored
@@ -1,32 +0,0 @@
|
||||
import { removeSimpleValue } from '../helpers/utils';
|
||||
import { Router} from '../options/base';
|
||||
|
||||
let [dynamicCacheName, __id__] = ['', ''];
|
||||
|
||||
export const addKeepAliveInclude = function(
|
||||
router:Router
|
||||
):void{
|
||||
// 【Fixe】 https://github.com/SilurianYang/uni-simple-router/issues/316 2021年12月10日14:30:13
|
||||
const app = getApp();
|
||||
const keepAliveInclude:Array<string> = app.keepAliveInclude;
|
||||
if (router.runId === 0 && keepAliveInclude.length === 0) {
|
||||
__id__ = app.$route.params.__id__;
|
||||
dynamicCacheName = app.$route.meta.name;
|
||||
const cacheId = dynamicCacheName + '-' + __id__;
|
||||
app.keepAliveInclude.push(cacheId)
|
||||
} else {
|
||||
if (dynamicCacheName !== '') {
|
||||
const arrayCacheId = app.keepAliveInclude;
|
||||
for (let i = 0; i < arrayCacheId.length; i++) {
|
||||
const cacheId:string = arrayCacheId[i];
|
||||
const cacheIdReg = new RegExp(`${dynamicCacheName}-(\\d+)$`);
|
||||
const firstCacheId = `${dynamicCacheName}-${__id__}`;
|
||||
if (cacheIdReg.test(cacheId) && cacheId !== firstCacheId) {
|
||||
removeSimpleValue(arrayCacheId, firstCacheId);
|
||||
dynamicCacheName = '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
node_modules/uni-simple-router/src/app/appPatch.ts
generated
vendored
27
node_modules/uni-simple-router/src/app/appPatch.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import { navtoRule, objectAny, Router, totalNextRoute } from '../options/base';
|
||||
import { objectAny, Router, totalNextRoute } from '../options/base';
|
||||
import { AppConfig } from '../options/config';
|
||||
|
||||
let quitBefore:number|null = null;
|
||||
@@ -7,7 +7,7 @@ let TABBAR:objectAny|null = null;
|
||||
export function registerLoddingPage(
|
||||
router:Router,
|
||||
):void{
|
||||
if (router.options.APP?.registerLoadingPage) {
|
||||
if (router.options.registerLoadingPage) {
|
||||
const { loadingPageHook, loadingPageStyle } = router.options.APP as AppConfig; // 获取app所有配置
|
||||
const view = new plus.nativeObj.View('router-loadding', {
|
||||
top: '0px',
|
||||
@@ -40,29 +40,6 @@ export function runtimeQuit(
|
||||
}
|
||||
}
|
||||
|
||||
export function HomeNvueSwitchTab(
|
||||
router:Router,
|
||||
to:navtoRule,
|
||||
oldMethod:Function
|
||||
):Promise<Boolean> {
|
||||
return new Promise((
|
||||
resolve:(value:boolean)=>void
|
||||
) => {
|
||||
if (router.runId !== 0) {
|
||||
return resolve(false)
|
||||
}
|
||||
if (!(__uniConfig.tabBar && Array.isArray(__uniConfig.tabBar.list))) {
|
||||
return resolve(false)
|
||||
}
|
||||
// Fixe https://github.com/SilurianYang/uni-simple-router/issues/373 2022-4-3 19:40:59
|
||||
oldMethod({
|
||||
url: __uniConfig.entryPagePath,
|
||||
animationDuration:0,
|
||||
complete: () => resolve(true)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export function tabIndexSelect(
|
||||
to:totalNextRoute,
|
||||
from:totalNextRoute
|
||||
|
||||
24
node_modules/uni-simple-router/src/component/link.vue
generated
vendored
24
node_modules/uni-simple-router/src/component/link.vue
generated
vendored
@@ -36,23 +36,17 @@ export default {
|
||||
methods: {
|
||||
formatNav(text) {
|
||||
if (text != null && text.constructor === String) {
|
||||
const keyArray = [];
|
||||
text = text.replace(/((\w+)|('\s*(\w+)\s*')|("\s*(\w+)\s*"))\s*(?=:)/g, function (val) {
|
||||
const key = `"${val.trim().replace(/"|'/g, '')}"`;
|
||||
keyArray.push(key);
|
||||
return key
|
||||
text = text.replace(/\'/g, '');
|
||||
text = text.replace(/(\w+)(?=:)/g, function (val) {
|
||||
return `"${val}"`;
|
||||
});
|
||||
text = text.replace(/:\s*([^,{}\s"]+)/g, function (val) {
|
||||
const arr = val.split(':');
|
||||
return `:"${arr[1].trim()}"`;
|
||||
});
|
||||
const removeReg=/('|")/g;
|
||||
for (let i = 0; i < keyArray.length; i++) {
|
||||
const key = keyArray[i];
|
||||
text=text.replace(new RegExp(`${key}\\s*:\\s*('[^']+')`, 'g'),(...args)=>{
|
||||
const $1=args[1];
|
||||
return `${key}:"${$1.replace(removeReg,'')}"`
|
||||
})
|
||||
}
|
||||
try {
|
||||
text=JSON.parse(text);
|
||||
} catch (error) {}
|
||||
text = JSON.parse(text);
|
||||
} catch (e) {}
|
||||
}
|
||||
if (this.append) {
|
||||
let pathArr = this.$Route.path.split('/');
|
||||
|
||||
4
node_modules/uni-simple-router/src/global.d.ts
generated
vendored
4
node_modules/uni-simple-router/src/global.d.ts
generated
vendored
@@ -4,6 +4,4 @@ declare var __uniConfig:any;
|
||||
declare var __uniRoutes:any;
|
||||
declare function getCurrentPages(isAll:boolean|undefined=false):any;
|
||||
declare function getApp(args?:{allowDefault: true}):any;
|
||||
declare var $npm_package_name:string;
|
||||
declare var $npm_package_version:string;
|
||||
declare var $npm_package_last_version:string;
|
||||
declare var $npm_package_name:string;
|
||||
6
node_modules/uni-simple-router/src/helpers/config.ts
generated
vendored
6
node_modules/uni-simple-router/src/helpers/config.ts
generated
vendored
@@ -1,7 +1,6 @@
|
||||
import {err} from './warn'
|
||||
import { InstantiateConfig, LifeCycleConfig} from '../options/config'
|
||||
import { vueHookNameRule, proxyDepsRule } from '../options/base';
|
||||
import { parseQuery } from '../public/query';
|
||||
|
||||
export const mpPlatformReg = '(^mp-weixin$)|(^mp-baidu$)|(^mp-alipay$)|(^mp-toutiao$)|(^mp-qq$)|(^mp-360$)' // 小程序下不能直接导出正则 需要重新组装成正则 不然bug一推 诡异
|
||||
|
||||
@@ -27,11 +26,6 @@ export const baseConfig:InstantiateConfig = {
|
||||
applet: {
|
||||
animationDuration: 300
|
||||
},
|
||||
beforeProxyHooks: {
|
||||
onLoad: ([options], next, router) => {
|
||||
next([parseQuery({query: options}, router)])
|
||||
}
|
||||
},
|
||||
platform: 'h5',
|
||||
keepUniOriginNav: false,
|
||||
debugger: false,
|
||||
|
||||
5
node_modules/uni-simple-router/src/helpers/mixins.ts
generated
vendored
5
node_modules/uni-simple-router/src/helpers/mixins.ts
generated
vendored
@@ -8,7 +8,6 @@ import { forceGuardEach } from '../public/methods';
|
||||
import { assertParentChild, voidFun } from './utils';
|
||||
import { getEnterPath } from '../applets/appletPatch';
|
||||
import { mpPlatformReg } from './config';
|
||||
import {beforeProxyHook} from '../public/beforeProxyHook'
|
||||
|
||||
let registerRouter:boolean = false;
|
||||
let onloadProxyOk:boolean = false;
|
||||
@@ -35,7 +34,6 @@ export function getMixins(Vue:any, router: Router):{
|
||||
const toggleHooks = {
|
||||
h5: {
|
||||
beforeCreate(this: any): void {
|
||||
beforeProxyHook(this, router);
|
||||
if (this.$options.router) {
|
||||
router.$route = this.$options.router; // 挂载vue-router到路由对象下
|
||||
let vueRouteMap:RoutesRule[]|RoutesRule = [];
|
||||
@@ -53,7 +51,6 @@ export function getMixins(Vue:any, router: Router):{
|
||||
},
|
||||
'app-plus': {
|
||||
beforeCreate(this: any): void {
|
||||
beforeProxyHook(this, router);
|
||||
if (!registerRouter) {
|
||||
registerRouter = true;
|
||||
proxyPageHook(this, router, 'app');
|
||||
@@ -63,8 +60,6 @@ export function getMixins(Vue:any, router: Router):{
|
||||
},
|
||||
'app-lets': {
|
||||
beforeCreate(this: any): void {
|
||||
beforeProxyHook(this, router);
|
||||
|
||||
// 保证这个函数不会被重写
|
||||
const pluginMark = $npm_package_name;
|
||||
voidFun(pluginMark);
|
||||
|
||||
16
node_modules/uni-simple-router/src/helpers/utils.ts
generated
vendored
16
node_modules/uni-simple-router/src/helpers/utils.ts
generated
vendored
@@ -204,20 +204,6 @@ export function copyData<T>(object:T): T {
|
||||
return JSON.parse(JSON.stringify(object))
|
||||
}
|
||||
|
||||
export function removeSimpleValue(
|
||||
array:Array<string|number>,
|
||||
value:string
|
||||
):Boolean {
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
const it = array[i];
|
||||
if (it === value) {
|
||||
array.splice(i, 1);
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export function getUniCachePage<T extends objectAny>(pageIndex?:number):T|[] {
|
||||
const pages:T = getCurrentPages();
|
||||
if (pageIndex == null) {
|
||||
@@ -421,7 +407,7 @@ export function resolveAbsolutePath(
|
||||
}
|
||||
const query:string = paramsArray[2] || '';
|
||||
if (/^\.\/[^\.]+/.test(trimPath)) { // 当前路径下
|
||||
const navPath:string = (router as unknown as {currentRoute:{path:string}}).currentRoute.path + path;
|
||||
const navPath:string = router.currentRoute.path + path;
|
||||
return navPath.replace(/[^\/]+\.\//, '');
|
||||
}
|
||||
const relative = paramsArray[1].replace(/\//g, `\\/`).replace(/\.\./g, `[^\\/]+`).replace(/\./g, '\\.');
|
||||
|
||||
6
node_modules/uni-simple-router/src/index.ts
generated
vendored
6
node_modules/uni-simple-router/src/index.ts
generated
vendored
@@ -1,6 +1,5 @@
|
||||
export * from './options/base'
|
||||
export * from './options/config'
|
||||
export * from './helpers/utils'
|
||||
|
||||
export {
|
||||
runtimeQuit
|
||||
@@ -10,8 +9,3 @@ export {
|
||||
RouterMount,
|
||||
createRouter
|
||||
} from './public/router'
|
||||
|
||||
const version = $npm_package_version;
|
||||
if (/[A-Z]/g.test(version)) {
|
||||
console.warn(`【${$npm_package_name.toLocaleLowerCase()} 提示】:当前版本 ${version.toLocaleLowerCase()} 此版本为测试版。有BUG请退回正式版,线上正式版本:${$npm_package_last_version}`)
|
||||
}
|
||||
|
||||
2
node_modules/uni-simple-router/src/options/base.ts
generated
vendored
2
node_modules/uni-simple-router/src/options/base.ts
generated
vendored
@@ -208,12 +208,12 @@ export interface RoutesRule {
|
||||
}
|
||||
|
||||
export interface Router {
|
||||
[key:string]:any;
|
||||
readonly lifeCycle: LifeCycleConfig;
|
||||
readonly options: InstantiateConfig;
|
||||
$lockStatus:boolean;
|
||||
$route: object | null;
|
||||
enterPath:string;
|
||||
runId:number;
|
||||
Vue:any;
|
||||
appMain:{
|
||||
NAVTYPE:reNavMethodRule|reNotNavMethodRule,
|
||||
|
||||
20
node_modules/uni-simple-router/src/options/config.ts
generated
vendored
20
node_modules/uni-simple-router/src/options/config.ts
generated
vendored
@@ -25,25 +25,6 @@ export interface appletConfig {
|
||||
animationDuration?:number; // 页面切换时间,有助于路由锁精准解锁
|
||||
}
|
||||
|
||||
type hookRule=(args:Array<any>, next:(args:Array<any>)=>void, router:Router)=>void;
|
||||
export interface proxyHooksConfig{
|
||||
onLaunch?:hookRule;
|
||||
onShow?:hookRule;
|
||||
onHide?:hookRule;
|
||||
onError?:hookRule;
|
||||
onInit?:hookRule;
|
||||
onLoad?:hookRule;
|
||||
onReady?:hookRule;
|
||||
onUnload?:hookRule;
|
||||
onResize?:hookRule;
|
||||
destroyed?:hookRule;
|
||||
created?:hookRule;
|
||||
beforeCreate?:hookRule;
|
||||
beforeMount?:hookRule;
|
||||
mounted?:hookRule;
|
||||
beforeDestroy?:hookRule;
|
||||
}
|
||||
|
||||
export interface debuggerArrayConfig{
|
||||
error?:boolean;
|
||||
warn?:boolean;
|
||||
@@ -57,7 +38,6 @@ export interface InstantiateConfig {
|
||||
h5?: H5Config;
|
||||
APP?: AppConfig;
|
||||
applet?:appletConfig;
|
||||
beforeProxyHooks?:proxyHooksConfig;
|
||||
debugger?: debuggerConfig; // 是否处于开发阶段 设置为true则打印日志
|
||||
routerBeforeEach?: (to:navtoRule, from:navtoRule, next:(rule?: navtoRule|false)=>void) => void; // router 前置路由函数 每次触发跳转前先会触发此函数
|
||||
routerAfterEach?: (to:navtoRule, from:navtoRule, next?: Function) => void; // router 后置路由函数 每次触发跳转后会触发此函数
|
||||
|
||||
46
node_modules/uni-simple-router/src/public/beforeProxyHook.ts
generated
vendored
46
node_modules/uni-simple-router/src/public/beforeProxyHook.ts
generated
vendored
@@ -1,46 +0,0 @@
|
||||
import { voidFun } from '../helpers/utils';
|
||||
import { warn } from '../helpers/warn';
|
||||
import { Router, vueHookNameRule } from '../options/base';
|
||||
|
||||
export function beforeProxyHook(
|
||||
Vim:any,
|
||||
router:Router
|
||||
):boolean {
|
||||
const hookOptions = Vim.$options;
|
||||
const {beforeProxyHooks} = router.options;
|
||||
if (hookOptions == null) {
|
||||
return false;
|
||||
}
|
||||
if (beforeProxyHooks == null) {
|
||||
return false;
|
||||
}
|
||||
const keyArray = Object.keys(beforeProxyHooks) as Array<vueHookNameRule>;
|
||||
for (let i = 0; i < keyArray.length; i++) {
|
||||
const key = keyArray[i];
|
||||
const hooksArray:Array<Function>|null = hookOptions[key];
|
||||
if (hooksArray) {
|
||||
const beforeProxyFun = beforeProxyHooks[key];
|
||||
for (let j = 0; j < hooksArray.length; j++) {
|
||||
const hookFun = hooksArray[j];
|
||||
if (hookFun.toString().includes($npm_package_name)) {
|
||||
continue
|
||||
}
|
||||
const [oldHook] = hooksArray.splice(j, 1, function myReplace(this: any, ...args:Array<any>) {
|
||||
const pluginMarkId = $npm_package_name;
|
||||
voidFun(pluginMarkId);
|
||||
|
||||
if (beforeProxyFun) {
|
||||
beforeProxyFun.call(this, args, (options) => {
|
||||
oldHook.apply(this, options)
|
||||
}, router);
|
||||
} else {
|
||||
oldHook.apply(this, args)
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
warn(`beforeProxyHooks ===> 当前组件不适合${key},或者 hook: ${key} 不存在,已为你规避处理,可以忽略。`, router)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
4
node_modules/uni-simple-router/src/public/hooks.ts
generated
vendored
4
node_modules/uni-simple-router/src/public/hooks.ts
generated
vendored
@@ -18,7 +18,6 @@ import {
|
||||
} from '../helpers/utils'
|
||||
import { navjump } from './methods';
|
||||
import { proxyH5Mount } from '../H5/proxyHook';
|
||||
import { addKeepAliveInclude } from '../H5/patch';
|
||||
import { tabIndexSelect } from '../app/appPatch';
|
||||
|
||||
export const ERRORHOOK:Array<(error:navErrorRule, router:Router)=>void> = [
|
||||
@@ -34,10 +33,7 @@ export const HOOKLIST: hookListRule = [
|
||||
router.$lockStatus = false;
|
||||
if (router.options.platform === 'h5') {
|
||||
proxyH5Mount(router);
|
||||
// 【Fixe】 https://github.com/SilurianYang/uni-simple-router/issues/316 2021年12月10日14:30:13
|
||||
addKeepAliveInclude(router);
|
||||
}
|
||||
router.runId++;
|
||||
return callHook(router.lifeCycle.routerAfterHooks[0], to, from, router, next, false)
|
||||
}
|
||||
];
|
||||
|
||||
5
node_modules/uni-simple-router/src/public/methods.ts
generated
vendored
5
node_modules/uni-simple-router/src/public/methods.ts
generated
vendored
@@ -64,11 +64,6 @@ export function navjump(
|
||||
level = +to;
|
||||
} else {
|
||||
level = to.delta || 1;
|
||||
// 主要剥离事件函数
|
||||
animation = {
|
||||
...animation || {},
|
||||
...(to as uniBackApiRule)
|
||||
}
|
||||
}
|
||||
if (router.options.platform === 'h5') {
|
||||
(router.$route as any).go(-level);
|
||||
|
||||
35
node_modules/uni-simple-router/src/public/rewrite.ts
generated
vendored
35
node_modules/uni-simple-router/src/public/rewrite.ts
generated
vendored
@@ -27,7 +27,6 @@ import {
|
||||
} from '../helpers/warn'
|
||||
|
||||
import {uniOriginJump} from './uniOrigin'
|
||||
import { HomeNvueSwitchTab } from '../app/appPatch';
|
||||
|
||||
const rewrite: Array<reNavMethodRule|reNotNavMethodRule> = [
|
||||
'navigateTo',
|
||||
@@ -36,19 +35,6 @@ const rewrite: Array<reNavMethodRule|reNotNavMethodRule> = [
|
||||
'switchTab',
|
||||
'navigateBack'
|
||||
];
|
||||
const cacheOldMethod:{
|
||||
navigateTo:Function;
|
||||
redirectTo:Function;
|
||||
reLaunch:Function;
|
||||
switchTab:Function;
|
||||
navigateBack:Function;
|
||||
} = {
|
||||
navigateTo: () => {},
|
||||
redirectTo: () => {},
|
||||
reLaunch: () => {},
|
||||
switchTab: () => {},
|
||||
navigateBack: () => {}
|
||||
}
|
||||
|
||||
export function rewriteMethod(
|
||||
router:Router
|
||||
@@ -56,20 +42,14 @@ export function rewriteMethod(
|
||||
if (router.options.keepUniOriginNav === false) {
|
||||
rewrite.forEach(name => {
|
||||
const oldMethod: Function = uni[name];
|
||||
cacheOldMethod[name] = oldMethod;
|
||||
uni[name] = async function(
|
||||
uni[name] = function(
|
||||
params:originMixins|{from:string}|navtoRule,
|
||||
originCall:boolean = false,
|
||||
callOkCb?:Function,
|
||||
forceNav?:boolean
|
||||
):Promise<void> {
|
||||
|
||||
):void {
|
||||
if (originCall) {
|
||||
if (router.options.platform === 'app-plus') {
|
||||
await HomeNvueSwitchTab(router, (params as navtoRule), cacheOldMethod['reLaunch']);
|
||||
}
|
||||
uniOriginJump(router, oldMethod, name, params as originMixins, callOkCb, forceNav)
|
||||
|
||||
} else {
|
||||
if (router.options.platform === 'app-plus') {
|
||||
if (Object.keys(router.appMain).length === 0) {
|
||||
@@ -81,8 +61,6 @@ export function rewriteMethod(
|
||||
}
|
||||
callRouterMethod(params as uniNavApiRule, name, router);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
})
|
||||
}
|
||||
@@ -104,7 +82,8 @@ function callRouterMethod(
|
||||
if (funName === 'reLaunch' && JSON.stringify(option) === '{"url":"/"}') {
|
||||
warn(
|
||||
`uni-app 原生方法:reLaunch({url:'/'}) 默认被重写啦!你可以使用 this.$Router.replaceAll() 或者 uni.reLaunch({url:'/?xxx=xxx'})`,
|
||||
router
|
||||
router,
|
||||
true
|
||||
);
|
||||
funName = 'navigateBack';
|
||||
option = {
|
||||
@@ -134,13 +113,15 @@ function callRouterMethod(
|
||||
if (getDataType<string | string[]>(finallyPath) === '[object Array]') {
|
||||
warn(
|
||||
`uni-app 原生方法跳转路径为:${path}。此路为是tab页面时,不允许设置 alias 为数组的情况,并且不能为动态路由!当然你可以通过通配符*解决!`,
|
||||
router
|
||||
router,
|
||||
true
|
||||
);
|
||||
}
|
||||
if ((finallyPath as string) === '*') {
|
||||
warn(
|
||||
`uni-app 原生方法跳转路径为:${path}。在路由表中找不到相关路由表!当然你可以通过通配符*解决!`,
|
||||
router
|
||||
router,
|
||||
true
|
||||
);
|
||||
}
|
||||
// Fixe h5 端无法触发 onTabItemTap hook 2021年6月3日17:26:47
|
||||
|
||||
11
node_modules/uni-simple-router/src/public/router.ts
generated
vendored
11
node_modules/uni-simple-router/src/public/router.ts
generated
vendored
@@ -10,14 +10,11 @@ import {rewriteMethod} from '../public/rewrite'
|
||||
let AppReadyResolve:PromiseResolve = () => {};
|
||||
const AppReady:Promise<void> = new Promise(resolve => (AppReadyResolve = resolve));
|
||||
|
||||
function createRouter(
|
||||
params: InstantiateConfig
|
||||
):Router {
|
||||
function createRouter(params: InstantiateConfig):Router {
|
||||
const options = assertNewOptions<InstantiateConfig>(params);
|
||||
const router:Router = {
|
||||
options,
|
||||
mount: [],
|
||||
runId: 0,
|
||||
Vue: null,
|
||||
proxyHookDeps: proxyHookDeps,
|
||||
appMain: {},
|
||||
@@ -109,11 +106,7 @@ function createRouter(
|
||||
return router;
|
||||
}
|
||||
|
||||
function RouterMount(
|
||||
Vim:any,
|
||||
router:Router,
|
||||
el:string | undefined = '#app'
|
||||
) :void|never {
|
||||
function RouterMount(Vim:any, router:Router, el:string | undefined = '#app') :void|never {
|
||||
if (getDataType<Array<any>>(router.mount) === '[object Array]') {
|
||||
router.mount.push({
|
||||
app: Vim,
|
||||
|
||||
Reference in New Issue
Block a user