修改pages.json

This commit is contained in:
Jason 2022-09-09 10:45:16 +08:00
parent c9bf4ed561
commit 6c7e918c52
8 changed files with 91 additions and 122 deletions

92
app/package-lock.json generated
View File

@ -22,7 +22,6 @@
"@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3050520220824001",
"lodash-es": "^4.17.21",
"pinia": "^2.0.20",
"uni-crazy-router": "^1.1.1",
"vconsole": "^3.14.6",
"vue": "^3.2.37",
"vue-i18n": "^9.2.2",
@ -36,7 +35,7 @@
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3050520220824001",
"@rushstack/eslint-patch": "^1.1.4",
"@types/lodash-es": "^4.17.6",
"@types/node": "^18.7.13",
"@types/node": "^18.7.16",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"autoprefixer": "^10.4.8",
@ -1345,9 +1344,9 @@
}
},
"node_modules/@types/node": {
"version": "18.7.13",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-18.7.13.tgz",
"integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==",
"version": "18.7.16",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-18.7.16.tgz",
"integrity": "sha512-EQHhixfu+mkqHMZl1R2Ovuvn47PUw18azMJOTwSZr9/fhzHNGXAJ0ma0dayRVchprpCj0Kc1K1xKoWaATWF1qg==",
"dev": true
},
"node_modules/@typescript-eslint/eslint-plugin": {
@ -4232,16 +4231,6 @@
"node": ">=0.6"
}
},
"node_modules/querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmmirror.com/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==",
"deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.",
"peer": true,
"engines": {
"node": ">=0.4.x"
}
},
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz",
@ -4299,12 +4288,6 @@
"node": ">=8.10.0"
}
},
"node_modules/regenerator-runtime": {
"version": "0.12.1",
"resolved": "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==",
"peer": true
},
"node_modules/regexpp": {
"version": "3.2.0",
"resolved": "https://registry.npmmirror.com/regexpp/-/regexpp-3.2.0.tgz",
@ -4808,15 +4791,6 @@
"node": ">=4.2.0"
}
},
"node_modules/uni-crazy-router": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/uni-crazy-router/-/uni-crazy-router-1.1.1.tgz",
"integrity": "sha512-vxGq9AgSx85Ed6lkg1R5tQ1umTqluUhNDyMXE0lmdIVgCGRVblE/iaHoPKQmPgwvZTObVvVaHKQk0et5O44UWQ==",
"peerDependencies": {
"regenerator-runtime": "0.12.1",
"url": "^0.11.0"
}
},
"node_modules/universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz",
@ -4863,22 +4837,6 @@
"punycode": "^2.1.0"
}
},
"node_modules/url": {
"version": "0.11.0",
"resolved": "https://registry.npmmirror.com/url/-/url-0.11.0.tgz",
"integrity": "sha512-kbailJa29QrtXnxgq+DdCEGlbTeYM2eJUxsz6vjZavrCYPMIFHMKQmSKYAIuUK2i7hgPm28a8piX5NTUtM/LKQ==",
"peer": true,
"dependencies": {
"punycode": "1.3.2",
"querystring": "0.2.0"
}
},
"node_modules/url/node_modules/punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmmirror.com/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==",
"peer": true
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz",
@ -6380,9 +6338,9 @@
}
},
"@types/node": {
"version": "18.7.13",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-18.7.13.tgz",
"integrity": "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw==",
"version": "18.7.16",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-18.7.16.tgz",
"integrity": "sha512-EQHhixfu+mkqHMZl1R2Ovuvn47PUw18azMJOTwSZr9/fhzHNGXAJ0ma0dayRVchprpCj0Kc1K1xKoWaATWF1qg==",
"dev": true
},
"@typescript-eslint/eslint-plugin": {
@ -8588,12 +8546,6 @@
"side-channel": "^1.0.4"
}
},
"querystring": {
"version": "0.2.0",
"resolved": "https://registry.npmmirror.com/querystring/-/querystring-0.2.0.tgz",
"integrity": "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g==",
"peer": true
},
"queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz",
@ -8639,12 +8591,6 @@
"picomatch": "^2.2.1"
}
},
"regenerator-runtime": {
"version": "0.12.1",
"resolved": "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz",
"integrity": "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==",
"peer": true
},
"regexpp": {
"version": "3.2.0",
"resolved": "https://registry.npmmirror.com/regexpp/-/regexpp-3.2.0.tgz",
@ -9028,12 +8974,6 @@
"integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==",
"devOptional": true
},
"uni-crazy-router": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/uni-crazy-router/-/uni-crazy-router-1.1.1.tgz",
"integrity": "sha512-vxGq9AgSx85Ed6lkg1R5tQ1umTqluUhNDyMXE0lmdIVgCGRVblE/iaHoPKQmPgwvZTObVvVaHKQk0et5O44UWQ==",
"requires": {}
},
"universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz",
@ -9068,24 +9008,6 @@
"punycode": "^2.1.0"
}
},
"url": {
"version": "0.11.0",
"resolved": "https://registry.npmmirror.com/url/-/url-0.11.0.tgz",
"integrity": "sha512-kbailJa29QrtXnxgq+DdCEGlbTeYM2eJUxsz6vjZavrCYPMIFHMKQmSKYAIuUK2i7hgPm28a8piX5NTUtM/LKQ==",
"peer": true,
"requires": {
"punycode": "1.3.2",
"querystring": "0.2.0"
},
"dependencies": {
"punycode": {
"version": "1.3.2",
"resolved": "https://registry.npmmirror.com/punycode/-/punycode-1.3.2.tgz",
"integrity": "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw==",
"peer": true
}
}
},
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz",

View File

@ -60,7 +60,7 @@
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3050520220824001",
"@rushstack/eslint-patch": "^1.1.4",
"@types/lodash-es": "^4.17.6",
"@types/node": "^18.7.13",
"@types/node": "^18.7.16",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"autoprefixer": "^10.4.8",

View File

@ -1,6 +1,7 @@
import { createSSRApp } from 'vue'
import App from './App.vue'
import plugins from './plugins'
import './router'
import './styles/index.scss'
export function createApp() {
const app = createSSRApp(App)

View File

@ -52,7 +52,8 @@
"path": "pages/collection/collection",
"style": {
"navigationBarTitleText": "我的收藏"
}
},
"auth": true
},
{
"path": "pages/search/search",

View File

@ -0,0 +1,31 @@
import { getToken } from '@/utils/auth'
import { generateRoutes } from './transformPages'
const routes = generateRoutes()
export default async function () {
const list = ['navigateTo', 'redirectTo', 'reLaunch', 'switchTab']
list.forEach((item) => {
uni.addInterceptor(item, {
invoke(e) {
// 获取要跳转的页面路径url去掉"?"和"?"后的参数)
const url = e.url.split('?')[0]
const currentRoute = routes.find((item) => {
return url === item.path
})
// 需要登录并且没有token
if (currentRoute?.isAuth && !getToken()) {
uni.navigateTo({
url: '/pages/login/login'
})
return false
}
return e
},
fail(err) {
// 失败回调拦截
console.log(err)
}
})
})
}

View File

@ -0,0 +1,45 @@
import PagesJSON from '../pages.json'
const CONFIG = {
includes: ['path', 'aliasPath', 'name', 'auth']
}
function getPagesRoutes(pages: any[], rootPath = null) {
const routes: any[] = []
for (let i = 0; i < pages.length; i++) {
const item = pages[i]
const route: any = {}
for (let j = 0; j < CONFIG.includes.length; j++) {
const key = CONFIG.includes[j]
let value = item[key]
if (key === 'path') {
value = rootPath ? `/${rootPath}/${value}` : `/${value}`
}
if (key === 'aliasPath' && i == 0 && rootPath == null) {
route[key] = route[key] || '/'
} else if (value !== undefined) {
route[key] = value
}
}
routes.push(route)
}
return routes
}
function getSubPackagesRoutes(pagesJson: any) {
const { subPackages } = pagesJson
let routes: any[] = []
if (subPackages == null || subPackages.length == 0) {
return []
}
for (let i = 0; i < subPackages.length; i++) {
const subPages = subPackages[i].pages
const root = subPackages[i].root
const subRoutes = getPagesRoutes(subPages, root)
routes = routes.concat(subRoutes)
}
return routes
}
export function generateRoutes() {
return getPagesRoutes(PagesJSON.pages).concat(getSubPackagesRoutes(PagesJSON))
}

View File

@ -54,9 +54,6 @@ const requestHooks: RequestHooks = {
case RequestCodeEnum.TOKEN_INVALID:
case RequestCodeEnum.TOKEN_EMPTY:
logout()
uni.navigateTo({
url: '/pages/login/login'
})
return Promise.reject()
default:

View File

@ -943,10 +943,10 @@
"resolved" "https://registry.npmmirror.com/@types/lodash/-/lodash-4.14.184.tgz"
"version" "4.14.184"
"@types/node@^18.7.13":
"integrity" "sha512-46yIhxSe5xEaJZXWdIBP7GU4HDTG8/eo0qd9atdiL+lFpA03y8KS+lkTN834TWJj5767GbWv4n/P6efyTFt1Dw=="
"resolved" "https://registry.npmmirror.com/@types/node/-/node-18.7.13.tgz"
"version" "18.7.13"
"@types/node@^18.7.16":
"integrity" "sha512-EQHhixfu+mkqHMZl1R2Ovuvn47PUw18azMJOTwSZr9/fhzHNGXAJ0ma0dayRVchprpCj0Kc1K1xKoWaATWF1qg=="
"resolved" "https://registry.npmmirror.com/@types/node/-/node-18.7.16.tgz"
"version" "18.7.16"
"@typescript-eslint/eslint-plugin@^5.0.0":
"integrity" "sha512-RBZZXZlI4XCY4Wzgy64vB+0slT9+yAPQRjj/HSaRwUot33xbDjF1oN9BLwOLTewoOI0jothIltZRe9uJCHf8gg=="
@ -2856,11 +2856,6 @@
"resolved" "https://registry.npmmirror.com/punycode/-/punycode-2.1.1.tgz"
"version" "2.1.1"
"punycode@1.3.2":
"integrity" "sha512-RofWgt/7fL5wP1Y7fxE7/EmTLzQVnB0ycyibJ0OOHIlJqTNzglYFxVwETOcIoJqJmpDXJ9xImDv+Fq34F/d4Dw=="
"resolved" "https://registry.npmmirror.com/punycode/-/punycode-1.3.2.tgz"
"version" "1.3.2"
"qrcode-reader@^1.0.4":
"integrity" "sha512-rRjALGNh9zVqvweg1j5OKIQKNsw3bLC+7qwlnead5K/9cb1cEIAGkwikt/09U0K+2IDWGD9CC6SP7tHAjUeqvQ=="
"resolved" "https://registry.npmmirror.com/qrcode-reader/-/qrcode-reader-1.0.4.tgz"
@ -2878,11 +2873,6 @@
dependencies:
"side-channel" "^1.0.4"
"querystring@0.2.0":
"integrity" "sha512-X/xY82scca2tau62i9mDyU9K+I+djTMUsvwf7xnUX5GLvVzgJybOJf4Y6o9Zx3oJK/LSXg5tTZBjwzqVPaPO2g=="
"resolved" "https://registry.npmmirror.com/querystring/-/querystring-0.2.0.tgz"
"version" "0.2.0"
"queue-microtask@^1.2.2":
"integrity" "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A=="
"resolved" "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz"
@ -2932,11 +2922,6 @@
"resolved" "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz"
"version" "0.13.9"
"regenerator-runtime@0.12.1":
"integrity" "sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg=="
"resolved" "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz"
"version" "0.12.1"
"regexpp@^3.2.0":
"integrity" "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg=="
"resolved" "https://registry.npmmirror.com/regexpp/-/regexpp-3.2.0.tgz"
@ -3251,11 +3236,6 @@
"resolved" "https://registry.npmmirror.com/typescript/-/typescript-4.7.4.tgz"
"version" "4.7.4"
"uni-crazy-router@^1.1.1":
"integrity" "sha512-vxGq9AgSx85Ed6lkg1R5tQ1umTqluUhNDyMXE0lmdIVgCGRVblE/iaHoPKQmPgwvZTObVvVaHKQk0et5O44UWQ=="
"resolved" "https://registry.npmmirror.com/uni-crazy-router/-/uni-crazy-router-1.1.1.tgz"
"version" "1.1.1"
"universalify@^2.0.0":
"integrity" "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
"resolved" "https://registry.npmmirror.com/universalify/-/universalify-2.0.0.tgz"
@ -3286,14 +3266,6 @@
dependencies:
"punycode" "^2.1.0"
"url@^0.11.0":
"integrity" "sha512-kbailJa29QrtXnxgq+DdCEGlbTeYM2eJUxsz6vjZavrCYPMIFHMKQmSKYAIuUK2i7hgPm28a8piX5NTUtM/LKQ=="
"resolved" "https://registry.npmmirror.com/url/-/url-0.11.0.tgz"
"version" "0.11.0"
dependencies:
"punycode" "1.3.2"
"querystring" "0.2.0"
"util-deprecate@^1.0.2":
"integrity" "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw=="
"resolved" "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz"