Skip to content

Commit bbfc8a4

Browse files
committed
修复没有token的时候
1 parent 88ee79b commit bbfc8a4

File tree

5 files changed

+61
-9
lines changed

5 files changed

+61
-9
lines changed

menu-data.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = [
2+
{
3+
id: 0,
4+
icon: 'el-icon-s-order',
5+
index: 'table',
6+
title: '基础表格',
7+
pid: -1,
8+
},
9+
{
10+
id: 1,
11+
icon: 'el-icon-s-marketing',
12+
index: 'tab',
13+
title: 'tab选项卡',
14+
pid: -1,
15+
},
16+
{
17+
id: 2,
18+
icon: 'el-icon-folder-opened',
19+
index: 'form',
20+
title: '表单相关',
21+
pid: -1,
22+
},
23+
{
24+
id: 3,
25+
index: 'base_form',
26+
title: '基本表单',
27+
icon: 'el-icon-s-data',
28+
pid: 2,
29+
},
30+
{
31+
id: 4,
32+
index: 'upload',
33+
title: '文件上传',
34+
pid: 2,
35+
}
36+
];

src/router/router.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,21 @@ const auth = (to, from, next) => {
5656
* @param {type}
5757
* @return:
5858
*/
59+
const whiteList = ['login'];
5960
const authRoutes = async (to, from, next) => {
60-
const routes = await store.dispatch('getMenuListApi');
61-
const routesUrlList = routes.map(item => item.index);
62-
if (routesUrlList.includes(to.name)) {
63-
next({ ...to, replace: true });
61+
if (storage.getItem(authToken)) {
62+
const routes = await store.dispatch('getMenuListApi');
63+
const routesUrlList = routes.map(item => item.index);
64+
if (routesUrlList.includes(to.name) || whiteList.includes(to.name)) {
65+
next({ ...to, replace: true });
66+
return
67+
} else {
68+
next({ name: 'home', replace: true });
69+
}
6470
} else {
65-
next({ name: 'home', replace: true });
71+
// next({name: '/login'});
6672
}
73+
6774
}
6875
/********************************路由拦截配置 start********************************/
6976
router.beforeEach((to, from, next) => {

src/services/menu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import axios from 'axios';
33
class MenuService {
44
// 获取菜单的接口
55
async getMenuList () {
6-
return await axios.get('http://localhost:3000/category');
6+
return await axios.get('http://localhost:9000/api/category');
77
}
88
}
99

src/store/modules/menus.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export default {
1212
actions: {
1313
// 获取菜单的api
1414
async getMenuListApi ({ commit }) {
15-
const { menuList } = await MenuService.getMenuList();
16-
commit('setAuthMenuList', menuList);
17-
return menuList;
15+
const { data } = await MenuService.getMenuList();
16+
commit('setAuthMenuList', data);
17+
return data;
1818
},
1919
}
2020
}

vue.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const path = require("path");
2+
const menus = require('./menu-data');
23

34
module.exports = {
45
configureWebpack: {
@@ -13,5 +14,13 @@ module.exports = {
1314
port: 9000,
1415
open: false,
1516
disableHostCheck: true,
17+
before(app) {
18+
app.get('/api/category', (req, res) => {
19+
res.json({
20+
code: 0,
21+
data: menus,
22+
})
23+
})
24+
}
1625
},
1726
}

0 commit comments

Comments
 (0)