Skip to content

Commit 99b0bcd

Browse files
committed
update
1 parent 400957b commit 99b0bcd

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/mock/index2.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ mockList.forEach((b) => {
2929
let { state, url, method, result } = b[key]
3030
if (state) {
3131
// 将 result 包装为统一的响应格式
32-
Mock.mock(RegExp(url + '??.*'), method, {
33-
data: result(),
34-
})
32+
Mock.mock(RegExp(url + '??.*'), method, result)
3533
}
3634
}
3735
})
3836

37+
export { responseFormat }
3938
export default Mock

src/mock/modules/login.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// import Mock from 'mockjs'
2+
import { responseFormat } from '@/mock/index2'
23
import { userMap } from './user'
34

45
export default {
@@ -8,15 +9,15 @@ export default {
89
method: 'post',
910
result: (userInfo) => {
1011
let { username } = JSON.parse(userInfo.body)
11-
return userMap[username]
12+
return responseFormat(userMap[username])
1213
},
1314
},
1415
logout: {
1516
state: true,
1617
url: '/login/logout',
1718
method: 'post',
1819
result: () => {
19-
return 'success'
20+
return responseFormat()
2021
},
2122
},
2223
}

src/permission.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ router.beforeEach(async (to, from, next) => {
3333
// if is logged in, redirect to the home page // 有token访问login页面,就跳到首页
3434
next({ path: '/', replace: true })
3535
} else {
36-
// 如果动态路由存在,则直接next
37-
if (store.getters.roles.length > 0) {
38-
next()
36+
// 如果动态路由不存在
37+
if (store.getters.addRoutes.length === 0) {
38+
// 再次尝试加载动态路由
39+
// next()
3940
} else {
4041
// 否则,再次尝试动态生成路由
4142
if (loadFromSession('userRoutes', []).length < 1) {

src/store/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const modules = modulesFiles.keys().reduce((modules, modulePath) => {
1919
/**
2020
* 这里getters是单独拿出来的,全局统一用一个,用做取值的便捷手段。【也是官方推荐的】
2121
* 你也可以直接使用 this.$store.state.[moduleName].[paramName] 来取值
22-
* (PS:至于state,mutations,actions就由每个modules文件夹里面的文件,自己实现
22+
* (PS:至于state,mutations,actions就由每个modules文件夹里面的文件,自己去管理和实现
2323
*/
2424
const getters = {
2525
// tabsview
@@ -32,9 +32,9 @@ const getters = {
3232
avatar: (state) => state.user.userInfo.avatar,
3333
// 语言
3434
language: (state) => state.language.language,
35-
// add_routes 是动态遍历出来,添加上去的路由
35+
// addRoutes 是动态遍历出来的,和系统内置的静态路由,组成用户的完整录音
3636
addRoutes: (state) => state.permission.addRoutes,
37-
// 用户的原始permissions数据
37+
// 用户的原始permissions数据(包含:)
3838
permissions: (state) => state.user.permissions,
3939
// 用户的路由菜单权限(完整的)
4040
routers: (state) => state.permission.routes,

0 commit comments

Comments
 (0)