From 1efc57b866b4ec2eb0f491afd8895b435fd65632 Mon Sep 17 00:00:00 2001 From: lyt-Top <1105290566@qq.com> Date: Fri, 26 Feb 2021 00:48:10 +0800 Subject: [PATCH] =?UTF-8?q?'admin-21.02.26:=E5=A4=84=E7=90=86=E5=90=8E?= =?UTF-8?q?=E7=AB=AF=E6=8E=A7=E5=88=B6=E8=B7=AF=E7=94=B1=E3=80=81=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E6=9C=80=E6=96=B0=E4=BE=9D=E8=B5=96=E7=AD=89'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- package.json | 4 +- src/api/menu/index.ts | 3 +- src/api/menu/testMenu.json | 309 ------------------------------------- src/router/index.ts | 20 +-- src/utils/themeConfig.ts | 2 +- 6 files changed, 16 insertions(+), 324 deletions(-) delete mode 100644 src/api/menu/testMenu.json diff --git a/.env b/.env index b56a0c1..b17df70 100644 --- a/.env +++ b/.env @@ -4,5 +4,5 @@ VITE_PORT = 10000 # open 运行 npm run dev 时自动打开浏览器 VITE_OPEN = false -# public path 配置线上环境路径 +# public path 配置线上环境路径(打包) VITE_PUBLIC_PATH = /vue-admin-wonderful-next-preview/ \ No newline at end of file diff --git a/package.json b/package.json index a2b7da1..5d77881 100644 --- a/package.json +++ b/package.json @@ -26,11 +26,11 @@ "@types/nprogress": "^0.2.0", "@types/sortablejs": "^1.10.6", "@vitejs/plugin-vue": "^1.1.4", - "@vue/compiler-sfc": "^3.0.5", + "@vue/compiler-sfc": "^3.0.6", "dotenv": "^8.2.0", "sass": "^1.32.8", "sass-loader": "^11.0.1", "typescript": "^4.2.2", - "vite": "^2.0.2" + "vite": "^2.0.3" } } \ No newline at end of file diff --git a/src/api/menu/index.ts b/src/api/menu/index.ts index e41f70c..3a6dc48 100644 --- a/src/api/menu/index.ts +++ b/src/api/menu/index.ts @@ -16,8 +16,7 @@ export function getMenuAdmin(params?: object) { // 获取后端动态路由菜单(test) export function getMenuTest(params?: object) { return request({ - // url: '/gitee/lyt-top/vue-admin-wonderful-images/raw/master/next/menu/testMenu.json', - url: '/src/api/menu/testMenu.json', + url: '/gitee/lyt-top/vue-admin-wonderful-images/raw/master/next/menu/testMenu.json', method: 'get', params, }); diff --git a/src/api/menu/testMenu.json b/src/api/menu/testMenu.json deleted file mode 100644 index 3a461ef..0000000 --- a/src/api/menu/testMenu.json +++ /dev/null @@ -1,309 +0,0 @@ -{ - "code": 0, - "type": "testMenu", - "data": [ - { - "path": "/home", - "name": "home", - "component": "home/index", - "meta": { - "title": "首页", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": true, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-shouye" - } - }, - { - "path": "/limits", - "name": "limits", - "component": "layout/routerView/parent", - "redirect": "/limits/frontEnd", - "meta": { - "title": "权限管理", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-quanxian" - }, - "children": [ - { - "path": "/limits/backEnd", - "name": "limitsBackEnd", - "component": "layout/routerView/parent", - "meta": { - "title": "后端控制", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ] - }, - "children": [ - { - "path": "/limits/backEnd/page", - "name": "limitsBackEndEndPage", - "component": "limits/backEnd/page/index", - "meta": { - "title": "页面权限", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ] - } - } - ] - } - ] - }, - { - "path": "/menu", - "name": "menu", - "component": "layout/routerView/parent", - "redirect": "/menu/menu1", - "meta": { - "title": "菜单嵌套", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - }, - "children": [ - { - "path": "/menu/menu1", - "name": "menu1", - "component": "layout/routerView/parent", - "redirect": "/menu/menu1/menu11", - "meta": { - "title": "菜单1", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - }, - "children": [ - { - "path": "/menu/menu1/menu11", - "name": "menu11", - "component": "menu/menu1/menu11/index", - "meta": { - "title": "菜单11", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - } - }, - { - "path": "/menu/menu1/menu12", - "name": "menu12", - "component": "layout/routerView/parent", - "redirect": "/menu/menu1/menu12/menu121", - "meta": { - "title": "菜单12", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - }, - "children": [ - { - "path": "/menu/menu1/menu12/menu121", - "name": "menu121", - "component": "menu/menu1/menu12/menu121/index", - "meta": { - "title": "菜单121", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - } - }, - { - "path": "/menu/menu1/menu12/menu122", - "name": "menu122", - "component": "menu/menu1/menu12/menu122/index", - "meta": { - "title": "菜单122", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - } - } - ] - }, - { - "path": "/menu/menu1/menu13", - "name": "menu13", - "component": "menu/menu1/menu13/index", - "meta": { - "title": "菜单13", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - } - } - ] - }, - { - "path": "/menu/menu2", - "name": "menu2", - "component": "menu/menu2/index", - "meta": { - "title": "菜单2", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-caidan" - } - } - ] - }, - { - "path": "/fun", - "name": "funIndex", - "component": "layout/routerView/parent", - "redirect": "/fun/tagsView", - "meta": { - "title": "功能", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-crew_feature" - }, - "children": [ - { - "path": "/fun/tagsView", - "name": "funTagsView", - "component": "fun/tagsView/index", - "meta": { - "title": "tagsView操作", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "el-icon-thumb" - } - } - ] - }, - { - "path": "/pages", - "name": "pagesIndex", - "component": "pages/index", - "meta": { - "title": "页面", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-fuzhiyemian" - } - }, - { - "path": "/chart", - "name": "chartIndex", - "component": "chart/index", - "meta": { - "title": "大数据图表", - "isLink": "", - "isHide": false, - "isKeepAlive": true, - "isAffix": false, - "isIframe": false, - "auth": [ - "admin", - "test" - ], - "icon": "iconfonticon-ico_shuju" - } - } - ] -} \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index a0d520b..6d22db7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -476,7 +476,7 @@ export function getBackEndControlRoutes() { if (!token) return false store.dispatch('setUserInfos') const auth = store.state.userInfos.authPageList[0] // 模拟 admin 与 test - if (auth !== 'admin') { + if (auth === 'admin') { return new Promise((resolve, reject) => { getMenuAdmin().then((res: any) => { setBackEndControlRoutesFun(res) @@ -486,11 +486,13 @@ export function getBackEndControlRoutes() { }) } else { return new Promise((resolve, reject) => { - getMenuTest().then((res: any) => { - setBackEndControlRoutesFun(res) - if (res.data) resolve(res) - else reject('请求错误') - }) + setTimeout(() => { + getMenuTest().then((res: any) => { + setBackEndControlRoutesFun(res) + if (res.data) resolve(res) + else reject('请求错误') + }) + }, 1000) }) } } @@ -500,12 +502,12 @@ export function setBackEndControlRoutesFun(res: any) { const oldRoutes = JSON.parse(JSON.stringify(res.data)) store.dispatch('setBackEndControlRoutes', oldRoutes) dynamicRoutes[0].children = backEndRouter(res.data) + resetRoute() // 删除/重置路由 router.addRoute(pathMatch) // 添加404界面 setAddRoute() // 添加动态路由 setFilterMenu() // 过滤权限菜单 setCacheTagsViewRoutes() // 添加 keepAlive 缓存 - console.log(dynamicRoutes) - console.log(router.getRoutes()) + window.location.href = window.location.href } // 后端控制路由,后端路由 component 转换 @@ -659,7 +661,7 @@ if (store.state.themeConfig.isRequestRoutes) getBackEndControlRoutes() router.beforeEach((to, from, next) => { document.title = `${to.meta.title} - vue-admin-wonderful-next` || `vue-admin-wonderful-next` NProgress.configure({ showSpinner: false }) - NProgress.start() + if (to.meta.title) NProgress.start() const token = getSession('token') if (to.path === '/login' && !token) { next() diff --git a/src/utils/themeConfig.ts b/src/utils/themeConfig.ts index 8ece3e4..1493029 100644 --- a/src/utils/themeConfig.ts +++ b/src/utils/themeConfig.ts @@ -39,5 +39,5 @@ export default { animation: 'slideRight', columnsAsideStyle: 'columnsRound', layout: 'defaults', - isRequestRoutes: true + isRequestRoutes: false } \ No newline at end of file