From 1526db3d46ab162a4d634ce2832600b9c172f7ed Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Sat, 12 Dec 2020 21:04:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2.6)?= =?UTF-8?q?=EF=BC=9Afix=20bug=20close=20https://github.com/elunez/eladmin/?= =?UTF-8?q?issues/504?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Permission/permission.js | 21 ++++++++--------- src/main.js | 2 ++ src/mixins/crud.js | 2 -- src/utils/permission.js | 30 ++++++++++++++----------- src/views/mnt/app/index.vue | 2 +- src/views/mnt/database/index.vue | 2 +- src/views/mnt/deploy/index.vue | 2 +- src/views/mnt/deployHistory/index.vue | 2 +- src/views/mnt/server/index.vue | 2 +- src/views/system/dept/index.vue | 2 +- src/views/system/dict/dictDetail.vue | 2 +- src/views/system/dict/index.vue | 2 +- src/views/system/job/index.vue | 3 +-- src/views/system/menu/index.vue | 2 +- src/views/system/role/index.vue | 2 +- src/views/system/timing/index.vue | 2 +- src/views/system/user/index.vue | 2 +- 17 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/components/Permission/permission.js b/src/components/Permission/permission.js index e731ebf..9aa9f67 100644 --- a/src/components/Permission/permission.js +++ b/src/components/Permission/permission.js @@ -1,18 +1,19 @@ import store from '@/store' export default { - inserted(el, binding, vnode) { + inserted(el, binding) { + console.log(el, binding) const { value } = binding const roles = store.getters && store.getters.roles - if (value && value instanceof Array && value.length > 0) { - const permissionRoles = value - - const hasPermission = roles.some(role => { - return permissionRoles.includes(role) - }) - - if (!hasPermission) { - el.parentNode && el.parentNode.removeChild(el) + if (value && value instanceof Array) { + if (value.length > 0) { + const permissionRoles = value + const hasPermission = roles.some(role => { + return permissionRoles.includes(role) + }) + if (!hasPermission) { + el.parentNode && el.parentNode.removeChild(el) + } } } else { throw new Error(`使用方式: v-permission="['admin','editor']"`) diff --git a/src/main.js b/src/main.js index a5c0b49..f4c6290 100644 --- a/src/main.js +++ b/src/main.js @@ -13,6 +13,7 @@ import 'mavon-editor/dist/css/index.css' import dict from './components/Dict' // 权限指令 +import checkPer from '@/utils/permission' import permission from './components/Permission' import './assets/styles/element-variables.scss' // global css @@ -30,6 +31,7 @@ import './assets/icons' // icon import './router/index' // permission control import 'echarts-gl' +Vue.use(checkPer) Vue.use(VueHighlightJS) Vue.use(mavonEditor) Vue.use(permission) diff --git a/src/mixins/crud.js b/src/mixins/crud.js index 0ccbde2..bb90342 100644 --- a/src/mixins/crud.js +++ b/src/mixins/crud.js @@ -6,7 +6,6 @@ import { parseTime, downloadFile } from '@/utils/index' -import checkPermission from '@/utils/permission' export default { data() { @@ -51,7 +50,6 @@ export default { methods: { parseTime, downloadFile, - checkPermission, async init() { if (!await this.beforeInit()) { return diff --git a/src/utils/permission.js b/src/utils/permission.js index 221d384..be3fe4e 100644 --- a/src/utils/permission.js +++ b/src/utils/permission.js @@ -5,21 +5,25 @@ import store from '@/store' * @returns {Boolean} * @example see @/views/permission/directive.vue */ -export default function checkPermission(value) { - if (value && value instanceof Array && value.length > 0) { - const roles = store.getters && store.getters.roles - const permissionRoles = value +export default { + install(Vue) { + Vue.prototype.checkPer = (value) => { + if (value && value instanceof Array && value.length > 0) { + const roles = store.getters && store.getters.roles + const permissionRoles = value - const hasPermission = roles.some(role => { - return permissionRoles.includes(role) - }) + const hasPermission = roles.some(role => { + return permissionRoles.includes(role) + }) - if (!hasPermission) { - return false + if (!hasPermission) { + 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 } } diff --git a/src/views/mnt/app/index.vue b/src/views/mnt/app/index.vue index f3b8105..976c26a 100644 --- a/src/views/mnt/app/index.vue +++ b/src/views/mnt/app/index.vue @@ -64,7 +64,7 @@ {{ parseTime(scope.row.createTime) }} - + - + - + - + - + - +