Commit f2827f07 authored by 晓彤's avatar 晓彤

权判断

parent a47950c9
import permission from './permission'
export default {
install(Vue) {
Vue.directive('permission', permission)
}
}
import { hasPermission } from '../utils/hasPermission'
export default {
inserted: function(el, binding) {
let { value, modifiers } = binding
// 通过|分割开的权限,满足任意一种即可. 此处可以自己拓展&来处理[且]的关系,
// 更复杂的 &| 的关系可以 v-if="hasPerm('a:b') & .. | .." 来实现
let keys =
value && value.trim() !== '' ? value.split('|') : Object.keys(modifiers)
if (keys && keys.length) {
let hasAuth = keys.some(key => hasPermission(key))
!hasAuth && el.parentNode.removeChild(el)
}
}
}
...@@ -12,6 +12,7 @@ import axios from 'axios' ...@@ -12,6 +12,7 @@ import axios from 'axios'
import store from './store/store' import store from './store/store'
import JsonViewer from 'vue-json-viewer' import JsonViewer from 'vue-json-viewer'
import bus from '../src/utils/bus' import bus from '../src/utils/bus'
import directives from '@/directives'
// import Sortable from 'sortablejs' // import Sortable from 'sortablejs'
import { import {
...@@ -97,6 +98,7 @@ Vue.use(Row) ...@@ -97,6 +98,7 @@ Vue.use(Row)
Vue.use(Col) Vue.use(Col)
Vue.use(JsonViewer) Vue.use(JsonViewer)
Vue.use(Tooltip) Vue.use(Tooltip)
Vue.use(directives)
// Vue.use(Sortable) // Vue.use(Sortable)
/* eslint-disable no-new */ /* eslint-disable no-new */
......
const state = { const state = {
userId: '123', userId: '',
username: '', username: '',
menuList: [], menuList: [],
roleIds: [], roleIds: [],
...@@ -7,8 +7,8 @@ const state = { ...@@ -7,8 +7,8 @@ const state = {
} }
const mutations = { const mutations = {
SET_USER: (state, userInfo) => { SET_USER(state, userInfo) {
state.userId = userInfo.id state.userId = userInfo.userId
state.username = userInfo.username state.username = userInfo.username
state.menuList = userInfo.menuList state.menuList = userInfo.menuList
state.roleIds = userInfo.roleIds state.roleIds = userInfo.roleIds
...@@ -25,12 +25,16 @@ const mutations = { ...@@ -25,12 +25,16 @@ const mutations = {
const getters = { const getters = {
UserId: state => { UserId: state => {
return state.userId return state.userId
},
PermissionList: state => {
return state.permissionCodeList
} }
} }
// 异步获取用户信息
const actions = { const actions = {
userMsg(context, userInfo) { userMsg(context, userInfo) {
console.log('用户信息', userInfo) console.log('用户信息', userInfo)
context.commit('SET_USER', userInfo) context.commit('SET_USER', userInfo.userInfo)
} }
} }
......
// import store from '../store/store'
export function hasPermission(permission) {
permission = permission.trim()
let myPermissions = this.$store.user.getters.PermissionList
console.log('111', myPermissions)
return myPermissions.indexOf(permission) > -1
}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<el-button type="primary" icon="el-icon-search" @click="searchMockList">查询</el-button> --> <el-button type="primary" icon="el-icon-search" @click="searchMockList">查询</el-button> -->
<!-- <el-button type="primary" icon="el-icon-circle-plus" @click="DialogAddVisible=true">新增</el-button> --> <!-- <el-button type="primary" icon="el-icon-circle-plus" @click="DialogAddVisible=true">新增</el-button> -->
<el-button type="primary" icon="el-icon-circle-plus" @click="DialogAddVisible=true">新增</el-button> <el-button type="primary" icon="el-icon-circle-plus" @click="DialogAddVisible=true" v-permission="'auto:project:add'">新增</el-button>
</div> </div>
<el-table :data="projectList" border style="width: 100%;margin-top:20px"> <el-table :data="projectList" border style="width: 100%;margin-top:20px">
<el-table-column type='index' width="50px"> <el-table-column type='index' width="50px">
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'
import { import {
getProjectList, getProjectList,
addProject, addProject,
...@@ -112,6 +113,12 @@ export default { ...@@ -112,6 +113,12 @@ export default {
created() { created() {
this.getProjectList() this.getProjectList()
}, },
computed: {
...mapGetters({
// 获取权限信息
getPermissionList: 'user/PermissionList'
})
},
methods: { methods: {
// 获取项目列表 // 获取项目列表
getProjectList() { getProjectList() {
......
...@@ -93,9 +93,14 @@ export default { ...@@ -93,9 +93,14 @@ export default {
// 获取用户详细信息 // 获取用户详细信息
getUserDetail() { getUserDetail() {
getUserDetail().then((resp) => { getUserDetail().then((resp) => {
this.$store.dispatch('user/userMsg', { // 异步调用action
userInfo: resp.data.data // this.$store.dispatch('user/userMsg', {
}) // userInfo: resp.data.data
// })
// 同步赋值mutations
this.$store.commit('user/SET_USER', resp.data.data)
console.log(this.getUserId) console.log(this.getUserId)
this.menuList = resp.data.data.menuList this.menuList = resp.data.data.menuList
this.getNav() this.getNav()
...@@ -109,6 +114,7 @@ export default { ...@@ -109,6 +114,7 @@ export default {
}, },
...mapGetters({ ...mapGetters({
getCollapseState: 'header/CollapseState', getCollapseState: 'header/CollapseState',
// 获取用户信息
getUserId: 'user/UserId' getUserId: 'user/UserId'
}) })
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment