feat: 路由管理
This commit is contained in:
+36
-6
@@ -74,14 +74,17 @@ export const getUrlObj = (url: string) => {
|
||||
}
|
||||
/**
|
||||
* 得到所有的需要登录的pages,包括主包和分包的
|
||||
* 这里设计得通用一点,可以传递key作为判断依据,默认是 needLogin, 与 route-block 配对使用
|
||||
* 这里设计得通用一点,可以传递key作为判断依据,默认是 notNeedLogin, 与 route-block 配对使用
|
||||
* 如果没有传 key,则表示所有的pages,如果传递了 key, 则表示通过 key 过滤
|
||||
*/
|
||||
export const getAllPages = (key = 'needLogin') => {
|
||||
export const getAllPages = (key = 'notNeedLogin') => {
|
||||
// 这里处理主包
|
||||
const mainPages = [
|
||||
...pages
|
||||
.filter((page) => !key || page[key])
|
||||
.filter((page) => {
|
||||
if (!key) return false
|
||||
return page[key] === false
|
||||
})
|
||||
.map((page) => ({
|
||||
...page,
|
||||
path: `/${page.path}`,
|
||||
@@ -103,7 +106,6 @@ export const getAllPages = (key = 'needLogin') => {
|
||||
})
|
||||
})
|
||||
const result = [...mainPages, ...subPages]
|
||||
console.log(subPackages)
|
||||
// console.log(`getAllPages by ${key} result: `, result)
|
||||
return result
|
||||
}
|
||||
@@ -112,13 +114,14 @@ export const getAllPages = (key = 'needLogin') => {
|
||||
* 得到所有的需要登录的pages,包括主包和分包的
|
||||
* 只得到 path 数组
|
||||
*/
|
||||
export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((page) => page.path)
|
||||
export const getNotNeedLoginPages = (): string[] =>
|
||||
getAllPages('notNeedLogin').map((page) => page.path)
|
||||
|
||||
/**
|
||||
* 得到所有的需要登录的pages,包括主包和分包的
|
||||
* 只得到 path 数组
|
||||
*/
|
||||
export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path)
|
||||
export const notNeedLoginPages: string[] = getAllPages('notNeedLogin').map((page) => page.path)
|
||||
|
||||
/**
|
||||
* 根据微信小程序当前环境,判断应该获取的BaseUrl
|
||||
@@ -177,3 +180,30 @@ export const getEnvBaseUploadUrl = () => {
|
||||
|
||||
return baseUploadUrl
|
||||
}
|
||||
|
||||
export function mergeStep(wrapped: (...rest: any[]) => Promise<any>) {
|
||||
let _mergeStepRequestInstance: any = null
|
||||
return async function (...args) {
|
||||
if (this?._mergeStepRequestInstance ?? _mergeStepRequestInstance)
|
||||
return this?._mergeStepRequestInstance ?? _mergeStepRequestInstance
|
||||
if (this) {
|
||||
this._mergeStepRequestInstance = wrapped.apply(this, args)
|
||||
} else {
|
||||
_mergeStepRequestInstance = wrapped(...args)
|
||||
}
|
||||
if (
|
||||
Object.prototype.toString.call(
|
||||
this?._mergeStepRequestInstance ?? _mergeStepRequestInstance,
|
||||
) === '[object Promise]'
|
||||
) {
|
||||
;(this?._mergeStepRequestInstance ?? _mergeStepRequestInstance).finally(() => {
|
||||
if (this?._mergeStepRequestInstance) {
|
||||
this._mergeStepRequestInstance = null
|
||||
} else {
|
||||
_mergeStepRequestInstance = null
|
||||
}
|
||||
})
|
||||
}
|
||||
return _mergeStepRequestInstance
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user