增加测试平台功能,系统设置,支持多个角色,分配菜单
This commit is contained in:
26
src/App.vue
26
src/App.vue
@@ -5,16 +5,30 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { userGetAdvance } from '@/api/Userapi'
|
||||
import { getRoleList } from '@/api/rbacApi'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
mounted() {
|
||||
const userinfo = JSON.parse(localStorage.getItem('userinfo'))
|
||||
if (userinfo) {
|
||||
userGetAdvance({ userId: userinfo.userId }).then(data => {
|
||||
this.$store.commit('SetRole', data.data.userStatus)
|
||||
})
|
||||
const authUser = JSON.parse(localStorage.getItem('authUser') || 'null')
|
||||
const userMenus = JSON.parse(localStorage.getItem('userMenus') || '[]')
|
||||
if (authUser) {
|
||||
this.$store.commit('SetCurrentUser', authUser)
|
||||
this.$store.commit('SetRole', authUser.roleIds || [])
|
||||
this.$store.commit('SetUserMenus', userMenus)
|
||||
this.loadUserMenus(authUser)
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadUserMenus(authUser) {
|
||||
const roleId = authUser && authUser.roleIds && authUser.roleIds.length ? authUser.roleIds[0] : undefined
|
||||
if (!roleId) {
|
||||
return
|
||||
}
|
||||
getRoleList({ roleId }).then(res => {
|
||||
const menus = res && Array.isArray(res.data) ? res.data : []
|
||||
this.$store.commit('SetUserMenus', menus)
|
||||
}).catch(() => {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user