From c5b1f279f9b6ce64835f8c5518fedd1025b9eaa0 Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Sun, 26 Jul 2020 20:27:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=87=E4=BB=A4=EF=BC=9Av-?= =?UTF-8?q?auth=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=BD=93=E5=89=8D=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E6=9D=A5=E9=80=89=E6=8B=A9=E6=98=AF=E5=90=A6=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E9=A1=B5=E9=9D=A2=E6=9F=90=E4=BA=9B=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/directive/auth.js | 40 +++++++++++++++++++++++++++++++++++++++ web/src/main.js | 8 +++++--- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 web/src/directive/auth.js diff --git a/web/src/directive/auth.js b/web/src/directive/auth.js new file mode 100644 index 00000000..bf6fc829 --- /dev/null +++ b/web/src/directive/auth.js @@ -0,0 +1,40 @@ +// 权限按钮展示指令 +import { store } from '@/store/index' +const userInfo = store.getters['user/userInfo'] +export const auth = (Vue) => { + Vue.directive('auth', { + // 当被绑定的元素插入到 DOM 中时…… + bind: function (el, binding) { + let type = "" + switch (Object.prototype.toString.call(binding.value)) { + case "[object Array]": + type = "Array" + break; + case "[object String]": + type = "String" + break; + case "[object Number]": + type = "Number" + break; + default: + type = "" + break; + } + if (type === "") { + /* eslint-disable */ + console.error("v-auth必须是Array,Number,String属性,暂不支持其他属性") + /* eslint-enable */ + return + } + const waitUse = binding.value.toString().split(",") + + let flag = waitUse.some(item=>item==userInfo.authorityId) + if (binding.modifiers.not) { + flag = !flag + } + if(!flag){ + el.style.display = 'none' + } + } + }) +} diff --git a/web/src/main.js b/web/src/main.js index acd1c0f3..4f1dea42 100644 --- a/web/src/main.js +++ b/web/src/main.js @@ -47,6 +47,11 @@ Vue.use(APlayer, { }); +import {auth} from '@/directive/auth' +// 按钮权限指令 +auth(Vue) + + new Vue({ render: h => h(App), router, @@ -56,6 +61,3 @@ new Vue({ //引入echarts import echarts from 'echarts' Vue.prototype.$echarts = echarts; - - -