Skip to content

Commit bfdf6ee

Browse files
XiaoHeitusendya
authored andcommitted
fix(server): 换一种方案
1 parent 2fa98de commit bfdf6ee

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

commitlint.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ module.exports = {
1818
'type-enum': [
1919
2,
2020
'always',
21-
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert'],
21+
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert']
2222
],
2323
'subject-full-stop': [0, 'never'],
24-
'subject-case': [0, 'never'],
25-
},
26-
};
24+
'subject-case': [0, 'never']
25+
}
26+
}

src/permission.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import notification from 'ant-design-vue/es/notification'
77
import { setDocumentTitle, domTitle } from '@/utils/domUtil'
88
import { ACCESS_TOKEN } from '@/store/mutation-types'
99
import { i18nRender } from '@/locales'
10+
import { generatorDynamicRouter } from '@/router/generator-routers'
1011

1112
NProgress.configure({ showSpinner: false }) // NProgress Configuration
1213

@@ -18,7 +19,8 @@ router.beforeEach((to, from, next) => {
1819
NProgress.start() // start progress bar
1920
to.meta && typeof to.meta.title !== 'undefined' && setDocumentTitle(`${i18nRender(to.meta.title)} - ${domTitle}`)
2021
/* has token */
21-
if (storage.get(ACCESS_TOKEN)) {
22+
const token = storage.get(ACCESS_TOKEN)
23+
if (token) {
2224
if (to.path === loginRoutePath) {
2325
next({ path: defaultRoutePath })
2426
NProgress.done()
@@ -29,9 +31,10 @@ router.beforeEach((to, from, next) => {
2931
store
3032
.dispatch('GetInfo')
3133
.then(res => {
32-
const roles = res.result && res.result.role
3334
// generate dynamic router
34-
store.dispatch('GenerateRoutes', { roles }).then(() => {
35+
generatorDynamicRouter(token).then(routers => {
36+
store.commit('SET_ROUTERS', routers)
37+
3538
// 根据roles权限生成可访问的路由表
3639
// 动态添加可访问路由表
3740
// [email protected]+ New API

src/store/modules/async-router.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* 向后端请求用户的菜单,动态生成路由
33
*/
44
import { constantRouterMap } from '@/config/router.config'
5-
import { generatorDynamicRouter } from '@/router/generator-routers'
65

76
const permission = {
87
state: {
@@ -14,18 +13,19 @@ const permission = {
1413
state.addRouters = routers
1514
state.routers = constantRouterMap.concat(routers)
1615
}
17-
},
18-
actions: {
19-
GenerateRoutes ({ commit }, data) {
20-
return new Promise(resolve => {
21-
const { token } = data
22-
generatorDynamicRouter(token).then(routers => {
23-
commit('SET_ROUTERS', routers)
24-
resolve()
25-
})
26-
})
27-
}
2816
}
17+
// ,
18+
// actions: {
19+
// GenerateRoutes({ commit }, data) {
20+
// return new Promise(resolve => {
21+
// const { token } = data
22+
// generatorDynamicRouter(token).then(routers => {
23+
// commit('SET_ROUTERS', routers)
24+
// resolve()
25+
// })
26+
// })
27+
// }
28+
// }
2929
}
3030

3131
export default permission

src/utils/request.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios from 'axios'
2+
import store from '@/store'
23
import storage from 'store'
34
import notification from 'ant-design-vue/es/notification'
45
import { VueAxios } from './axios'
@@ -29,7 +30,7 @@ const errorHandler = (error) => {
2930
description: 'Authorization verification failed'
3031
})
3132
if (token) {
32-
this.$store.dispatch('Logout').then(() => {
33+
store.dispatch('Logout').then(() => {
3334
setTimeout(() => {
3435
window.location.reload()
3536
}, 1500)

0 commit comments

Comments
 (0)