From 1eb2f79229729086bd959bf336c3d4e6972c9688 Mon Sep 17 00:00:00 2001 From: hyt <958868763@qq.com> Date: Thu, 16 May 2024 16:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E6=95=B0=E6=8D=AEv3=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=8C=96=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=8A=A8=E6=80=81=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E6=9D=83=E9=99=90=E6=9B=B4=E6=96=B0=EF=BC=8C=E9=9B=86?= =?UTF-8?q?=E6=88=90=E4=BB=BB=E5=8A=A1=E6=97=A5=E5=BF=97=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/base/baseLayout/index.vue | 2 +- src/directive/index.js | 3 +- src/directive/permission/btnPermission.js | 17 + src/directive/permission/index.js | 11 + src/main.js | 2 + src/permission.js | 138 +++-- src/store/getters.js | 1 + src/store/index.js | 4 +- src/store/modules/perButton.js | 23 + .../compoments/baseTable.vue | 2 + src/views/integrationOptionV2/index.vue | 481 ++++++++++-------- .../taskLogdetailData/configData.js | 28 +- .../taskLogdetailData/index.vue | 93 ++-- .../masterDataOptions/distribute/index.vue | 325 ++++++------ 14 files changed, 649 insertions(+), 481 deletions(-) create mode 100644 src/directive/permission/btnPermission.js create mode 100644 src/directive/permission/index.js create mode 100644 src/store/modules/perButton.js diff --git a/src/components/base/baseLayout/index.vue b/src/components/base/baseLayout/index.vue index 78b16bb..ff30de7 100644 --- a/src/components/base/baseLayout/index.vue +++ b/src/components/base/baseLayout/index.vue @@ -545,7 +545,7 @@ export default { }, refresh() { this.ruleForm = Object.assign({}, ""); - this.$emit("onQuery", this.mergeParam(true)); + this.$emit("onQuery", this.mergeParam(true),this.ruleForm); }, testEnter() { if (this.enterClickType) { diff --git a/src/directive/index.js b/src/directive/index.js index b2901d7..138f2cd 100644 --- a/src/directive/index.js +++ b/src/directive/index.js @@ -4,7 +4,7 @@ import dialogDrag from './dialog/drag' import dialogDragWidth from './dialog/dragWidth' import dialogDragHeight from './dialog/dragHeight' import clipboard from './module/clipboard' - +import btnPermission from "@/directive/permission/btnPermission"; const install = function(Vue) { Vue.directive('hasRole', hasRole) Vue.directive('hasPermi', hasPermi) @@ -12,6 +12,7 @@ const install = function(Vue) { Vue.directive('dialogDrag', dialogDrag) Vue.directive('dialogDragWidth', dialogDragWidth) Vue.directive('dialogDragHeight', dialogDragHeight) + Vue.directive("btnPermission", btnPermission); } if (window.Vue) { diff --git a/src/directive/permission/btnPermission.js b/src/directive/permission/btnPermission.js new file mode 100644 index 0000000..2080c17 --- /dev/null +++ b/src/directive/permission/btnPermission.js @@ -0,0 +1,17 @@ +import store from "@/store"; + +export default { + inserted(el, bindling) { + let perVal = bindling.value.btnID; + let routeId = bindling.value.routeId; + if (perVal && routeId) { + let perObj = store.getters.getButtonPre; + if (Object.keys(perObj).length) { + let hasPer = perObj[routeId] && perObj[routeId].includes(perVal); + if (!hasPer) { + el.parentNode.removeChild(el); + } + } + } + }, +}; diff --git a/src/directive/permission/index.js b/src/directive/permission/index.js new file mode 100644 index 0000000..d798b91 --- /dev/null +++ b/src/directive/permission/index.js @@ -0,0 +1,11 @@ +import btnPermission from "@/directive/permission/btnPermission"; +const directives = { + btnPermission, +}; +export default { + install(Vue) { + Object.keys(directives).forEach((key) => { + Vue.directive(key, directives[key]); + }); + }, +}; diff --git a/src/main.js b/src/main.js index 1536b80..dde5e4f 100644 --- a/src/main.js +++ b/src/main.js @@ -66,6 +66,8 @@ Vue.directive('enterNumber', { }) } }) +import Directives from "@/directive/permission/index"; +Vue.use(Directives); import { download } from '@/utils/request' import { openLoading, closeLoading } from '@/utils/loading' diff --git a/src/permission.js b/src/permission.js index 5817219..836e116 100644 --- a/src/permission.js +++ b/src/permission.js @@ -1,77 +1,129 @@ -import router from "./router"; -import store from "./store"; -import { Message } from "element-ui"; -import NProgress from "nprogress"; -import "nprogress/nprogress.css"; -import { getToken, getCompanyId } from "@/utils/auth"; -import { isRelogin, getButtonLish } from "@/utils/request"; +import router from './router' +import store from './store' +import { Message } from 'element-ui' +import NProgress from 'nprogress' +import 'nprogress/nprogress.css' +import { getToken, getCompanyId } from '@/utils/auth' +import { isRelogin, getButtonLish } from '@/utils/request' +import { authApi } from '@/api/apis/auth' +import { getInfo } from '@/utils/auth' NProgress.configure({ - showSpinner: false, -}); + showSpinner: false +}) const whiteList = [ - "/login", - "/test", - "/auth-redirect", - "/bind", - "/contractAssistant", - "/register", - "/systemInit", - "/databaseLogin", - "/apiLogs", -]; + '/login', + '/test', + '/auth-redirect', + '/bind', + '/contractAssistant', + '/register', + '/systemInit', + '/databaseLogin', + '/apiLogs' +] router.beforeEach((to, from, next) => { - NProgress.start(); + NProgress.start() if (getToken()) { - to.meta.title && store.dispatch("settings/setTitle", to.meta.title); + to.meta.title && store.dispatch('settings/setTitle', to.meta.title) /* has token*/ - if (to.path === "/login") { + if (to.path === '/login') { next({ - path: "/", - }); - NProgress.done(); + path: '/' + }) + NProgress.done() } else { - let routeList = localStorage.getItem("routeList") - ? localStorage.getItem("routeList") - : null; + let routeList = localStorage.getItem('routeList') + ? localStorage.getItem('routeList') + : null // store.dispatch("GenerateRoutes").then((accessRoutes) => { // next() // }) if (store.getters.permission_routes.length == 0) { - store.dispatch("GenerateRoutes").then((accessRoutes) => { + store.dispatch('GenerateRoutes').then((accessRoutes) => { // 根据roles权限生成可访问的路由表 // for (let i = 0, length = accessRoutes.length; i < length; i += 1) { // const element = accessRoutes[i]; // // router.addRoutes(accessRoutes); // 动态添加可访问路由表 // } - router.addRoutes(accessRoutes); // 动态添加可访问路由表 + router.addRoutes(accessRoutes) // 动态添加可访问路由表 // router.addRoutes(accessRoutes) // 动态添加可访问路由表 - localStorage.setItem("routeList", JSON.stringify(accessRoutes)); - next({ - ...to, - replace: true, - }); // hack方法 确保addRoutes已完成 - }); + localStorage.setItem('routeList', JSON.stringify(accessRoutes)) + //获取当前已获取的权限按钮 + let perObj = store.getters.getButtonPre + //获取当前权限按钮 + if (to.meta.id && !perObj[to.meta.id]) { + let userId = JSON.parse(getInfo()).id + authApi('sysButtonConfigService', '', 'getUserButton', '', { + menuId: to.meta.id, + userId: userId + }).then((res) => { + // 处理接口 格式为:{路由id:[按钮id,按钮id],....} + let tempObj = {} + let tempArr = [] + res.attribute.forEach((item) => { + tempArr.push(item.nameEn) + }) + tempObj.id = to.meta.id + tempObj.value = tempArr + store.commit('perButton/SET_BUTTONOBJ', tempObj) + next({ + ...to, + replace: true + }) + }) + } else { + next({ + ...to, + replace: true + }) + } + // next({ + // ...to, + // replace: true + // }) // hack方法 确保addRoutes已完成 + }) } else { - next(); + //获取当前已获取的权限按钮 + let perObj = store.getters.getButtonPre + if (to.meta.id && !perObj[to.meta.id]) { + let userId = JSON.parse(getInfo()).id + authApi('sysButtonConfigService', '', 'getUserButton', '', { + menuId: to.meta.id, + userId: userId + }).then((res) => { + // 处理接口 格式为:{路由id:[按钮id,按钮id],....} + let tempObj = {} + let tempArr = [] + res.attribute.forEach((item) => { + tempArr.push(item.nameEn) + }) + tempObj.id = to.meta.id + tempObj.value = tempArr + store.commit('perButton/SET_BUTTONOBJ', tempObj) + next() + }) + } else { + next() + } } } } else { // 没有token if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入 - next(); + next() } else { - next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页 - NProgress.done(); + next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页 + NProgress.done() } } -}); +}) router.afterEach(() => { - NProgress.done(); -}); + NProgress.done() +}) diff --git a/src/store/getters.js b/src/store/getters.js index 6bc15e4..64b63b6 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -36,5 +36,6 @@ const getters = { copyerConfig: state => state.flowPath.copyerConfig, conditionDrawer: state => state.flowPath.conditionDrawer, conditionsConfig: state => state.flowPath.conditionsConfig, + getButtonPre: (state) => state.perButton.buttonObj, } export default getters diff --git a/src/store/index.js b/src/store/index.js index 5dc6223..eee7147 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -9,6 +9,7 @@ import settings from './modules/settings' import getters from './getters' import approval from './modules/approval' import flowPath from "./modules/flowPath" +import perButton from "@/store/modules/perButton"; Vue.use(Vuex) @@ -21,7 +22,8 @@ const store = new Vuex.Store({ permission, settings, approval, - flowPath + flowPath, + perButton }, getters }) diff --git a/src/store/modules/perButton.js b/src/store/modules/perButton.js new file mode 100644 index 0000000..d932f30 --- /dev/null +++ b/src/store/modules/perButton.js @@ -0,0 +1,23 @@ +const state = { + buttonObj: {}, +}; +const mutations = { + //保存按钮 + SET_BUTTONOBJ(state, data) { + if (!data.id) return; + state.buttonObj[data.id] = data.value; + }, + //清空按钮 + CLEAN_BUTTONOBJ(state, data) { + state.buttonObj = {}; + }, +}; + +const actions = {}; + +export default { + namespaced: true, + state, + mutations, + actions, +}; diff --git a/src/views/integrationOptionV2/compoments/baseTable.vue b/src/views/integrationOptionV2/compoments/baseTable.vue index 4488dc6..25a7a53 100644 --- a/src/views/integrationOptionV2/compoments/baseTable.vue +++ b/src/views/integrationOptionV2/compoments/baseTable.vue @@ -176,8 +176,10 @@ class="btnText" :style="{ background: item.color ? item.color : '#5a9cf8' }" style="padding: 3px 10px; border-radius: 20px" + v-btnPermission="{ btnID: item.type, routeId: $route.meta.id }" > {{ item.text }}