[代码优化](v2.6):fix bug
close https://github.com/elunez/eladmin/issues/504
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inserted(el, binding, vnode) {
|
inserted(el, binding) {
|
||||||
|
console.log(el, binding)
|
||||||
const { value } = binding
|
const { value } = binding
|
||||||
const roles = store.getters && store.getters.roles
|
const roles = store.getters && store.getters.roles
|
||||||
if (value && value instanceof Array && value.length > 0) {
|
if (value && value instanceof Array) {
|
||||||
const permissionRoles = value
|
if (value.length > 0) {
|
||||||
|
const permissionRoles = value
|
||||||
const hasPermission = roles.some(role => {
|
const hasPermission = roles.some(role => {
|
||||||
return permissionRoles.includes(role)
|
return permissionRoles.includes(role)
|
||||||
})
|
})
|
||||||
|
if (!hasPermission) {
|
||||||
if (!hasPermission) {
|
el.parentNode && el.parentNode.removeChild(el)
|
||||||
el.parentNode && el.parentNode.removeChild(el)
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`使用方式: v-permission="['admin','editor']"`)
|
throw new Error(`使用方式: v-permission="['admin','editor']"`)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'mavon-editor/dist/css/index.css'
|
|||||||
import dict from './components/Dict'
|
import dict from './components/Dict'
|
||||||
|
|
||||||
// 权限指令
|
// 权限指令
|
||||||
|
import checkPer from '@/utils/permission'
|
||||||
import permission from './components/Permission'
|
import permission from './components/Permission'
|
||||||
import './assets/styles/element-variables.scss'
|
import './assets/styles/element-variables.scss'
|
||||||
// global css
|
// global css
|
||||||
@@ -30,6 +31,7 @@ import './assets/icons' // icon
|
|||||||
import './router/index' // permission control
|
import './router/index' // permission control
|
||||||
import 'echarts-gl'
|
import 'echarts-gl'
|
||||||
|
|
||||||
|
Vue.use(checkPer)
|
||||||
Vue.use(VueHighlightJS)
|
Vue.use(VueHighlightJS)
|
||||||
Vue.use(mavonEditor)
|
Vue.use(mavonEditor)
|
||||||
Vue.use(permission)
|
Vue.use(permission)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
parseTime,
|
parseTime,
|
||||||
downloadFile
|
downloadFile
|
||||||
} from '@/utils/index'
|
} from '@/utils/index'
|
||||||
import checkPermission from '@/utils/permission'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
@@ -51,7 +50,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
parseTime,
|
parseTime,
|
||||||
downloadFile,
|
downloadFile,
|
||||||
checkPermission,
|
|
||||||
async init() {
|
async init() {
|
||||||
if (!await this.beforeInit()) {
|
if (!await this.beforeInit()) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -5,21 +5,25 @@ import store from '@/store'
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
* @example see @/views/permission/directive.vue
|
* @example see @/views/permission/directive.vue
|
||||||
*/
|
*/
|
||||||
export default function checkPermission(value) {
|
export default {
|
||||||
if (value && value instanceof Array && value.length > 0) {
|
install(Vue) {
|
||||||
const roles = store.getters && store.getters.roles
|
Vue.prototype.checkPer = (value) => {
|
||||||
const permissionRoles = value
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
|
const roles = store.getters && store.getters.roles
|
||||||
|
const permissionRoles = value
|
||||||
|
|
||||||
const hasPermission = roles.some(role => {
|
const hasPermission = roles.some(role => {
|
||||||
return permissionRoles.includes(role)
|
return permissionRoles.includes(role)
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
console.error(`need roles! Like v-permission="['admin','editor']"`)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
console.error(`need roles! Like v-permission="['admin','editor']"`)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','app:edit','app:del']" label="操作" width="150px" align="center">
|
<el-table-column v-if="checkPer['admin','app:edit','app:del']" label="操作" width="150px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','database:edit','database:del']" label="操作" width="150px" align="center">
|
<el-table-column v-if="checkPer['admin','database:edit','database:del']" label="操作" width="150px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','deploy:edit','deploy:del']" label="操作" width="150px" align="center">
|
<el-table-column v-if="checkPer['admin','deploy:edit','deploy:del']" label="操作" width="150px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<span>{{ parseTime(scope.row.deployDate) }}</span>
|
<span>{{ parseTime(scope.row.deployDate) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','deployHistory:del']" label="操作" width="100px" align="center">
|
<el-table-column v-if="checkPer['admin','deployHistory:del']" label="操作" width="100px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-popover
|
<el-popover
|
||||||
:ref="scope.row.id"
|
:ref="scope.row.id"
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','serverDeploy:edit','serverDeploy:del']" label="操作" width="150px" align="center">
|
<el-table-column v-if="checkPer['admin','serverDeploy:edit','serverDeploy:del']" label="操作" width="150px" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -84,7 +84,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','dept:edit','dept:del']" label="操作" width="130px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','dept:edit','dept:del']" label="操作" width="130px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<el-table-column prop="label" label="字典标签" />
|
<el-table-column prop="label" label="字典标签" />
|
||||||
<el-table-column prop="value" label="字典值" />
|
<el-table-column prop="value" label="字典值" />
|
||||||
<el-table-column prop="dictSort" label="排序" />
|
<el-table-column prop="dictSort" label="排序" />
|
||||||
<el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<el-table-column type="selection" width="55" />
|
<el-table-column type="selection" width="55" />
|
||||||
<el-table-column :show-overflow-tooltip="true" prop="name" label="名称" />
|
<el-table-column :show-overflow-tooltip="true" prop="name" label="名称" />
|
||||||
<el-table-column :show-overflow-tooltip="true" prop="description" label="描述" />
|
<el-table-column :show-overflow-tooltip="true" prop="description" label="描述" />
|
||||||
<el-table-column v-permission="['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','dict:edit','dict:del']" label="操作" width="130px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<!-- 编辑与删除 -->
|
<!-- 编辑与删除 -->
|
||||||
<el-table-column
|
<el-table-column
|
||||||
v-permission="['admin','job:edit','job:del']"
|
v-if="checkPer(['admin','job:edit','job:del'])"
|
||||||
label="操作"
|
label="操作"
|
||||||
width="130px"
|
width="130px"
|
||||||
align="center"
|
align="center"
|
||||||
@@ -60,7 +60,6 @@ import CRUD, { presenter } from '@crud/crud'
|
|||||||
import crudOperation from '@crud/CRUD.operation'
|
import crudOperation from '@crud/CRUD.operation'
|
||||||
import pagination from '@crud/Pagination'
|
import pagination from '@crud/Pagination'
|
||||||
import udOperation from '@crud/UD.operation'
|
import udOperation from '@crud/UD.operation'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Job',
|
name: 'Job',
|
||||||
components: { eHeader, eForm, crudOperation, pagination, udOperation },
|
components: { eHeader, eForm, crudOperation, pagination, udOperation },
|
||||||
|
|||||||
@@ -138,7 +138,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','menu:edit','menu:del']" label="操作" width="130px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','menu:edit','menu:del']" label="操作" width="130px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
:data="scope.row"
|
:data="scope.row"
|
||||||
|
|||||||
@@ -66,7 +66,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','roles:edit','roles:del']" label="操作" width="130px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','roles:edit','roles:del']" label="操作" width="130px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<udOperation
|
<udOperation
|
||||||
v-if="scope.row.level >= level"
|
v-if="scope.row.level >= level"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column v-permission="['admin','timing:edit','timing:del']" label="操作" width="170px" align="center" fixed="right">
|
<el-table-column v-if="checkPer['admin','timing:edit','timing:del']" label="操作" width="170px" align="center" fixed="right">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button v-permission="['admin','timing:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">编辑</el-button>
|
<el-button v-permission="['admin','timing:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">编辑</el-button>
|
||||||
<el-button v-permission="['admin','timing:edit']" style="margin-left: -2px" type="text" size="mini" @click="execute(scope.row.id)">执行</el-button>
|
<el-button v-permission="['admin','timing:edit']" style="margin-left: -2px" type="text" size="mini" @click="execute(scope.row.id)">执行</el-button>
|
||||||
|
|||||||
@@ -169,7 +169,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
v-permission="['admin','user:edit','user:del']"
|
v-if="checkPer['admin','user:edit','user:del']"
|
||||||
label="操作"
|
label="操作"
|
||||||
width="115"
|
width="115"
|
||||||
align="center"
|
align="center"
|
||||||
|
|||||||
Reference in New Issue
Block a user