From a26f711d83e762dc5e68b1c1520313c56030e779 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Fri, 28 May 2021 02:05:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A0=B9=E6=8D=AE=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E4=B8=8D=E5=90=8C=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/asyncRoutes.ts | 17 ++++++++++++----- mock/map.ts | 26 +++++++++++++------------- src/main.ts | 6 ++---- src/router/index.ts | 8 ++++++-- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/mock/asyncRoutes.ts b/mock/asyncRoutes.ts index 5d2bd9a88..acbbce17d 100644 --- a/mock/asyncRoutes.ts +++ b/mock/asyncRoutes.ts @@ -42,11 +42,18 @@ export default [ { url: "/getAsyncRoutes", method: "get", - response: () => { - return { - code: 0, - info: systemRouter, - }; + response: ({ query }) => { + if (query.name === "admin") { + return { + code: 0, + info: systemRouter, + }; + } else { + return { + code: 0, + info: [], + }; + } }, }, ] as MockMethod[]; diff --git a/mock/map.ts b/mock/map.ts index 36511fa9a..4ff83e6ca 100644 --- a/mock/map.ts +++ b/mock/map.ts @@ -1,29 +1,29 @@ -import { MockMethod } from 'vite-plugin-mock' +import { MockMethod } from "vite-plugin-mock"; // http://mockjs.com/examples.html#Object const mapList = (): any => { - const result: any[] = [] + const result: any[] = []; for (let index = 0; index < 200; index++) { result.push({ plateNumber: "豫A@natural(11111, 99999)@character('upper')", - driver: '@cname()', + driver: "@cname()", "orientation|1-360": 100, "lng|113-114.1-10": 1, - "lat|34-35.1-10": 1 - }) + "lat|34-35.1-10": 1, + }); } - return result -} + return result; +}; export default [ { - url: '/getMapInfo', - method: 'get', + url: "/getMapInfo", + method: "get", response: () => { return { code: 0, - info: mapList() - } + info: mapList(), + }; }, - } -] as MockMethod[] + }, +] as MockMethod[]; diff --git a/src/main.ts b/src/main.ts index 85719d39d..8075c7a14 100644 --- a/src/main.ts +++ b/src/main.ts @@ -50,9 +50,7 @@ export const getServerConfig = async (): Promise => { }; getServerConfig().then(async () => { - app.use(router).use(store).use(useElementPlus).use(useTable).use(usI18n); - + app.use(router); await router.isReady(); - - app.mount("#app"); + app.use(store).use(useElementPlus).use(useTable).use(usI18n).mount("#app"); }); diff --git a/src/router/index.ts b/src/router/index.ts index b12ad66f3..ef5533090 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -75,9 +75,12 @@ const whiteList = ["/login", "/register"]; router.beforeEach((to, _from, next) => { let isLogin = storageSession.getItem("info"); // _from?.name; - if (isLogin && isLogin.username === "admin") { + if (isLogin) { // 异步路由 - getAsyncRoutes().then(({ info }) => { + getAsyncRoutes({ name: isLogin.username }).then(({ info }) => { + if (info.length === 0) { + return; + } addAsyncRoutes([info]).forEach((v: any) => { // 防止重复添加路由 if ( @@ -92,6 +95,7 @@ router.beforeEach((to, _from, next) => { router.addRoute(v.name, v); }); }); + console.log(router.options.routes); } NProgress.start(); const { t } = i18n.global;