Skip to content

Commit

Permalink
fix:角色赋权与同步交互上的优化 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-xiaowu authored Apr 25, 2023
1 parent 32f83e4 commit d97664f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ router.beforeEach(async(to, from, next) => {
try {
// get user info
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
const { id, roles } = await store.dispatch('user/getInfo')
const userinfo = { id: id, roles: roles }
const { ID, roles } = await store.dispatch('user/getInfo')
const userinfo = { id: ID, roles: roles }
// generate accessible routes map based on roles

const accessRoutes = await store.dispatch('permission/generateRoutes', userinfo)
Expand All @@ -49,7 +49,7 @@ router.beforeEach(async(to, from, next) => {
next({ ...to, replace: true })
} catch (error) {
// remove token and go to login page to re-login

await store.dispatch('user/resetToken')
Message.error(error || 'Has Error')
next(`/login?redirect=${to.path}`)
Expand All @@ -59,7 +59,7 @@ router.beforeEach(async(to, from, next) => {
}
} else {
/* has no token*/

if (whiteList.indexOf(to.path) !== -1) {
//在免费登录白名单,直接去
next()
Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const actions = {
generateRoutes({ commit }, userinfo) {
return new Promise((resolve, reject) => {
let accessedRoutes = []
const {roles}=userinfo
const {id, roles}=userinfo
// 获取菜单树
getUserMenuTreeByUserId({id: roles[0].ID}).then(res => {
getUserMenuTreeByUserId({id: id}).then(res => {

const { data } = res
const menuTree = data
Expand Down
6 changes: 1 addition & 5 deletions src/views/personnel/group/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ export default {
this.loading = false
this.getTableData()
})
this.loading = false
},
syncWeComDepts() {
this.loading = true
Expand All @@ -477,7 +476,6 @@ export default {
this.loading = false
this.getTableData()
})
this.loading = false
},
syncFeiShuDepts() {
this.loading = true
Expand All @@ -486,7 +484,6 @@ export default {
this.loading = false
this.getTableData()
})
this.loading = false
},
syncOpenLdapDepts() {
this.loading = true
Expand All @@ -495,8 +492,7 @@ export default {
this.loading = false
this.getTableData()
})
this.loading = false
},
}
}
}
</script>
Expand Down
20 changes: 8 additions & 12 deletions src/views/personnel/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -720,38 +720,34 @@ export default {
syncDingTalkUsers() {
this.loading = true
syncDingTalkUsersApi().then(res => {
this.loading = false
this.judgeResult(res)
this.loading = false
this.getTableData()
})
this.getTableData()
this.loading = false
},
syncWeComUsers() {
this.loading = true
syncWeComUsersApi().then(res => {
this.loading = false
this.judgeResult(res)
this.loading = false
this.getTableData()
})
this.getTableData()
this.loading = false
},
syncFeiShuUsers() {
this.loading = true
syncFeiShuUsersApi().then(res => {
this.loading = false
this.judgeResult(res)
this.loading = false
this.getTableData()
})
this.getTableData()
this.loading = false
},
syncOpenLdapUsers() {
this.loading = true
syncOpenLdapUsersApi().then(res => {
this.loading = false
this.judgeResult(res)
this.loading = false
this.getTableData()
})
this.getTableData()
this.loading = false
}
}
}
Expand Down

0 comments on commit d97664f

Please sign in to comment.