diff --git a/PC/InterFace.Dash/public/config.js b/PC/InterFace.Dash/public/config.js index 61875c1..f80aefc 100644 --- a/PC/InterFace.Dash/public/config.js +++ b/PC/InterFace.Dash/public/config.js @@ -17,7 +17,8 @@ window.SITE_CONFIG['appClientScope'] = 'Z' window.SITE_CONFIG['browserTitle'] = '接口看板-QAD&WMS' // 隐藏的页面 window.SITE_CONFIG['menuHiddenConfig'] = [ - 'AsnDet','PoDet','ReceiptDet','ReturnDet' + 'AsnDet','PoDet','ReceiptDet','ReturnDet', + // 'AbpIdentityMarkUsers' ] // window.SITE_CONFIG['isAutoLogin'] = true diff --git a/PC/InterFace.Dash/src/components/currenButton/innerButton.vue b/PC/InterFace.Dash/src/components/currenButton/innerButton.vue index 2b32b42..198fd11 100644 --- a/PC/InterFace.Dash/src/components/currenButton/innerButton.vue +++ b/PC/InterFace.Dash/src/components/currenButton/innerButton.vue @@ -16,6 +16,7 @@ }" :class="item.class" @click="tableButtonClick(item.name,item)" + v-permission="item.permission" >{{ item.label }} diff --git a/PC/InterFace.Dash/src/components/tablePagination/index.vue b/PC/InterFace.Dash/src/components/tablePagination/index.vue index afc8d66..9e16895 100644 --- a/PC/InterFace.Dash/src/components/tablePagination/index.vue +++ b/PC/InterFace.Dash/src/components/tablePagination/index.vue @@ -97,7 +97,7 @@ export default { noUsePermissionBtn:{ type: Array, default: () => { - return ['refresh','field'] + return ['refresh','field','export','filter']//刷新,字段设置,导出,筛选 } }, rowMaxHeight:{ diff --git a/PC/InterFace.Dash/src/permission.js b/PC/InterFace.Dash/src/permission.js index b7295c5..f60ca15 100644 --- a/PC/InterFace.Dash/src/permission.js +++ b/PC/InterFace.Dash/src/permission.js @@ -38,10 +38,10 @@ const toPageInit = async (to, from, next) => { toNextHandle(to, from, next) }) .catch(()=>{ - // todo:接口恢复后更改 - // toNextHandle(to, from, next) - Message.error(noUserMsg) - pageToLogin(to, from, next) + // todo-fast:接口恢复后更改 + toNextHandle(to, from, next) + // Message.error(noUserMsg) + // pageToLogin(to, from, next) }) return } @@ -112,10 +112,10 @@ router.beforeEach(async (to, from, next) => { toPageInit(to, from, next) }) .catch(()=>{ - // todo:接口恢复后更改 - // toNextHandle(to, from, next) - Message.error(noUserMsg) - pageToLogin(to, from, next) + // todo-fast:接口恢复后更改 + toNextHandle(to, from, next) + // Message.error(noUserMsg) + // pageToLogin(to, from, next) }) }else{ console.log('没有token,不是登录页,不是自动登录,pageToLogin') diff --git a/PC/InterFace.Dash/src/router/index.js b/PC/InterFace.Dash/src/router/index.js index 0b28111..962c925 100644 --- a/PC/InterFace.Dash/src/router/index.js +++ b/PC/InterFace.Dash/src/router/index.js @@ -96,24 +96,24 @@ export let constantRoutes = [ } }] }, - { - path: '/', - component: Layout, - redirect: '/RoleManage', - hidden: true, - children: [{ - path: 'RoleManage', - component: () => import('@/views/systemManage/RoleManage'), - name: 'RoleManage', - meta: { - keepAlive : true, - title: 'RoleManage', - icon: 'svg_dashboard', - outerFirst:true - // affix: true - } - }] - }, + // { + // path: '/', + // component: Layout, + // redirect: '/RoleManage', + // hidden: true, + // children: [{ + // path: 'RoleManage', + // component: () => import('@/views/systemManage/RoleManage'), + // name: 'RoleManage', + // meta: { + // keepAlive : true, + // title: 'RoleManage', + // icon: 'svg_dashboard', + // outerFirst:true + // // affix: true + // } + // }] + // }, ] /** diff --git a/PC/InterFace.Dash/src/store/getters.js b/PC/InterFace.Dash/src/store/getters.js index 3205c47..adb0c18 100644 --- a/PC/InterFace.Dash/src/store/getters.js +++ b/PC/InterFace.Dash/src/store/getters.js @@ -7,9 +7,10 @@ const getters = { cachedViews: state => state.tagsView.cachedViews, token: state => state.user.token, introduction: state => state.user.introduction, - roles: state => state.user.roles, + roles: state => state.permission.roles,//当前用户权限 currentUserInfo: state => state.user.userInfo,//当前用户信息 - permission_routes: state => state.permission.routes,//接口获取的菜单 + permission_routes: state => state.permission.routes,//全部菜单 + addRoutes:state => state.permission.addRoutes,//非项目内固定的路由(接口获取的) tablesName:state => state.permission.tablesName,//接口获取所有的表名 errorLogs: state => state.errorLog.logs, enumList: state => state.definition.enumList,//接口获取的枚举 diff --git a/PC/InterFace.Dash/src/store/modules/permission copy.js b/PC/InterFace.Dash/src/store/modules/permission copy.js new file mode 100644 index 0000000..ca8f347 --- /dev/null +++ b/PC/InterFace.Dash/src/store/modules/permission copy.js @@ -0,0 +1,319 @@ +import { + asyncRoutes, + constantRoutes +} from '@/router' +import Layout from '@/layout' +import { getDefinitionMenu } from '@/api/wms-auth' +import store from '@/store' +import router from '@/router' + +/** + * Use meta.role to determine if the current user has permission + * @param roles + * @param route + */ +function hasPermission(roles, route) { + if (route.meta && route.meta.roles) { + if (route.meta.roles == "skip") { + return true + } else { + return roles.some(role => route.meta.roles.includes(role)) + } + } else { + return false + } +} +const filterAccessedRoutes = (items,indexVal,childrenIndex) => { + const route = JSON.parse(JSON.stringify(items)) + route.forEach((val, index) => { + // debugger; + if(val.meta && val.meta.roles == "skip"){ + if (val.children && val.children.length != 0) { + filterAccessedRoutes(items[index-indexVal].children,childrenIndex) + } + if(items[index-indexVal].children && items[index-indexVal].children.length == 0){ + items.splice(index-indexVal, 1) + indexVal++ + } + } + }) + indexVal = 0 +} +/** + * Filter asynchronous routing tables by recursion + * @param routes asyncRoutes + * @param roles + */ +export function filterAsyncRoutes(routes, roles) { + const res = [] + routes.forEach(route => { + const tmp = { + ...route + } + if (hasPermission(roles, tmp)) { + if (tmp.children) { + tmp.children = filterAsyncRoutes(tmp.children, roles) + } + res.push(tmp) + } + }) + return res +} + +const state = { + routes: [],//菜单 + // addRoutes: [], + tablesName:null,//所有的表名 + abpIdentityName:null,//所有身份配置权限 +} + +const mutations = { + SET_ROUTES: (state, routes) => { + // state.addRoutes = routes + state.routes = constantRoutes.concat(routes) + router.addRoutes(routes) + }, + SET_TABLESNAME: (state, data) => { + state.tablesName = data + }, + SET_AbpIdentity: (state, data) => { + state.abpIdentityName = data + } +} +/** + * 静态路由懒加载 + * @param view 格式必须为 xxx/xxx 开头不要加斜杠 + * @returns + */ + export const loadView = (view) => { + return (resolve) => require([`@/views/menuList/${view}`], resolve) +} + +const AbpIdentity_mark = 'AbpIdentityMark' +/** + * 把从后端查询的菜单数据拼装成路由格式的数据 + * @param routes + * @param data 后端返回的菜单数据 + */ +export function generaMenu(routes, data, first) { + // 不显示的菜单配置隐藏 + let _noShowMenus = localStorage.getItem('menuHiddenConfig').split(',') + data.forEach(item => { + let _item = { + path: '/'+item.name, + component: loadView(item.name), + hidden: _noShowMenus.indexOf(item.name) >= 0, // 状态为0的隐藏 + name: item.name, + // meta: item.meta + meta: { + title: item.title, + icon: item.icon || 'svg_default', + roles: item.permission, + outerFirst:first + }, + } + let menu = _item + if(first && item.component == '@/layout'){ + menu = { + path: '/', + component: Layout, + redirect: '/' + item.name, + children: [], + } + menu.children = [] + menu.children.push(_item) + } + // 一级菜单 二级菜单 特定属性 + // if (item.component == '@/layout' || item.component == 'index') { + // menu.alwaysShow = true + // menu.redirect = 'noRedirect' + // } + // if (item.sort < 99) { + // menu.level = 1 + // } else if (item.sort > 99 && item.sort < 9999) { + // menu.level = 2 + // } else { + // menu.level = 3 + // } + // iframe页面处理 + // if (item.permission.indexOf('Report') > -1) { + // // delete menu.component + // menu.iframeComponent = item.component === '@/layout' ? Layout : loadView(item.component) + // menu.hasOpen = false // 是否打开过,默认false + // } + if (item.children && item.children.length > 0) { + generaMenu(menu.children, item.children) + } + // if (item.permission == 'skip' && item.children.length == 0) { + // } + if(!routes)routes = [] + routes.push(menu) + }) + return routes +} + +// todo:接口返回的层级菜单,与查重后最终显示的菜单数组做查重及组合处理 +export function initTreeMenusHandle(tree, list,first) { + let _res = [] + tree.forEach(item=>{ + // 如果有身份权限的页面 + // if(state.abpIdentityName && state.abpIdentityName.length > 0){ + // // // 身份权限的页面(角色等) + // if(item.name == '系统权限管理'){ + // let _name = item.name.slice(AbpIdentity_mark.length,item.name.length) + // console.log(165,item.name,_name) + // // item.title = store.getters.columZHList[_name] || _name + // // if(first)item.component = '@/layout' + // // if (item.children && item.children.length > 0) { + // // item.children = initTreeMenusHandle(item.children,list) + // // } + // // _res.push(item) + // } + // } + //配置权限的页面 + // else{ + if(list.indexOf(item.name) >= 0){ + item.title = store.getters.columZHList[item.name] || item.name + console.log(175,item.name,first) + if(first){ + // if(item.name == AbpIdentity_mark){ + // item.title = '系统权限管理' + // } + item.component = '@/layout' + } + if (item.children && item.children.length > 0) { + item.children = initTreeMenusHandle(item.children,list) + } + console.log(186,item) + _res.push(item) + } + // } + }) + console.log(191,_res) + return _res +} +const actions = { + getApiColumnsNames({ + commit + }, userId) { + return new Promise(resolve => { + let accessedRoutes = asyncRoutes + // accessedRoutes = filterAsyncRoutes(asyncRoutes, roles) + // let indexVal = 0 + // let childrenIndex = 0 + // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) + // commit('SET_ROUTES', accessedRoutes) + // resolve(accessedRoutes) + getDefinitionMenu(true).then(res => { + let _allConfig = res.auth.grantedPolicies;//所有配置 + let _menuList = []//接口获取所有的菜单 + let _AbpIdentity = []//接口获取所有的身份配置信息数据 + for(let item in _allConfig){ + let point_number = item.split('.').length - 1 + // 只选择配置项中的数据 + if(point_number == 1 && item.substring(0,item.indexOf('.')) == localStorage.getItem('appClientScope')){ + _menuList.push(item.substring(item.indexOf('.') + 1,item.length)) + } + // 身份配置信息数据(用户、角色) + if(point_number == 1 && item.substring(0,item.indexOf('.')) == 'AbpIdentity'){ + _AbpIdentity.push(AbpIdentity_mark + item.substring(item.indexOf('.') + 1,item.length)) + } + } + // 存储所有的表名 + commit('SET_TABLESNAME', _menuList) + // 存储身份标识 + commit('SET_AbpIdentity', _AbpIdentity) + + // 数据模拟,todo-new:接口获取 + let _treeMenusAll = null//树形菜单 + _treeMenusAll = [ + {name:"aaaaaaa"}, + {name:"ExportCustomUserSetting" + // ,children:[ + // {name:'OutgoingDataHistory',children:[ + // {name:'IncomingData',children:[ + // {name:'OutgoingDataHistory'}, + // {name:'IncomingData'}, + // {name:'333333'}, + // ]}, + // {name:'eee1111-bbb',children:[ + // {name:'ExportCustomUserSetting'}, + // {name:'MessageReceive'}, + // ]}, + // ]}, + // {name:'eee222'}, + // {name:'eee333'}, + // {name:'eee444'}, + // {name:'eee555'}, + // ] + }, + {name:"OutgoingDataHistory"}, + {name:"IncomingData"}, + {name:"IncomingDataHistory"}, + {name:"MesProductL7PartsNote"}, + {name:"MessageReceive"}, + {name:"OutgoingData"}, + {name:"AsnDet"}, + {name:"AsnMstr"}, + {name:"Bom"}, + {name:"CustPart"}, + {name:"Cust"}, + {name:"Inventory"}, + {name:"Loc"}, + {name:"Part"}, + {name:"PoDet"}, + {name:"PoMstr"}, + {name:"PrhHist"}, + {name:"ProdLine"}, + {name:"ReceiptDet"}, + {name:"ReceiptMstr"}, + {name:"ReturnDet"}, + {name:"ReturnMstr"}, + {name:"SodDet"}, + {name:"VendPart"}, + {name:"Vend"}, + ] + + // 包含配置项中的业务菜单+身份权限菜单(角色用户等) + // let _menuAndAbpList = [..._menuList,...[AbpIdentity_mark],..._AbpIdentity] + let _menuAndAbpList = [..._menuList,..._AbpIdentity] + + let _initTreeMenus = [] + if(_treeMenusAll && _treeMenusAll.length > 0){ + _initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuAndAbpList,true) + }else{ + let _data = [] + if(_AbpIdentity && _AbpIdentity.length > 0){ + _data.push({name:AbpIdentity_mark,children:[]}) + } + for(let i in _menuAndAbpList){ + if(_menuAndAbpList[i].indexOf(AbpIdentity_mark) >= 0){ + _data[0].children.push({ name:_menuAndAbpList[i] }) + } + else{ + _data.push({name:_menuAndAbpList[i]}) + } + } + _initTreeMenus = initTreeMenusHandle(_data,[..._menuAndAbpList,...[AbpIdentity_mark]],true) + } + // 最后查重+层级查重后的菜单 + let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) + let accessedRoutes = _initEndMenus + // let indexVal = 0 + // let childrenIndex = 0 + // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) + commit('SET_ROUTES', accessedRoutes) + resolve(accessedRoutes) + }).catch(err => { + console.log(err) + }) + }) + }, +} + +export default { + namespaced: true, + state, + mutations, + actions +} \ No newline at end of file diff --git a/PC/InterFace.Dash/src/store/modules/permission.js b/PC/InterFace.Dash/src/store/modules/permission.js index b555874..5342f9f 100644 --- a/PC/InterFace.Dash/src/store/modules/permission.js +++ b/PC/InterFace.Dash/src/store/modules/permission.js @@ -7,61 +7,12 @@ import { getDefinitionMenu } from '@/api/wms-auth' import store from '@/store' import router from '@/router' -/** - * Use meta.role to determine if the current user has permission - * @param roles - * @param route - */ -function hasPermission(roles, route) { - if (route.meta && route.meta.roles) { - if (route.meta.roles == "skip") { - return true - } else { - return roles.some(role => route.meta.roles.includes(role)) - } - } else { - return false - } -} -const filterAccessedRoutes = (items,indexVal,childrenIndex) => { - const route = JSON.parse(JSON.stringify(items)) - route.forEach((val, index) => { - // debugger; - if(val.meta && val.meta.roles == "skip"){ - if (val.children && val.children.length != 0) { - filterAccessedRoutes(items[index-indexVal].children,childrenIndex) - } - if(items[index-indexVal].children && items[index-indexVal].children.length == 0){ - items.splice(index-indexVal, 1) - indexVal++ - } - } - }) - indexVal = 0 -} -/** - * Filter asynchronous routing tables by recursion - * @param routes asyncRoutes - * @param roles - */ -export function filterAsyncRoutes(routes, roles) { - const res = [] - routes.forEach(route => { - const tmp = { - ...route - } - if (hasPermission(roles, tmp)) { - if (tmp.children) { - tmp.children = filterAsyncRoutes(tmp.children, roles) - } - res.push(tmp) - } - }) - return res -} +// 身份权限的页面标识(角色等) +const AbpIdentity_mark = 'AbpIdentityMark' const state = { routes: [],//菜单 + roles: [],//当前用户权限 addRoutes: [], tablesName:null,//所有的表名 } @@ -72,8 +23,15 @@ const mutations = { state.routes = constantRoutes.concat(routes) router.addRoutes(routes) }, + // 设置权限(v-permission) + SET_ROLES: (state, roles) => { + state.roles = roles + }, SET_TABLESNAME: (state, data) => { state.tablesName = data + }, + SET_AbpIdentity: (state, data) => { + state.abpIdentityName = data } } /** @@ -94,28 +52,27 @@ export function generaMenu(routes, data, first) { let _noShowMenus = localStorage.getItem('menuHiddenConfig').split(',') data.forEach(item => { let _item = { - path: '/'+item.name, + path: item.path, component: loadView(item.name), hidden: _noShowMenus.indexOf(item.name) >= 0, // 状态为0的隐藏 name: item.name, - // meta: item.meta - meta: { - title: item.title, - icon: item.icon || 'svg_default', - roles: item.permission, - outerFirst:first - }, + meta: item.meta } let menu = _item - if(first && item.component == '@/layout'){ + // if(first && item.component == '@/layout'){ + if(first){ menu = { path: '/', component: Layout, redirect: '/' + item.name, - children: [], + // redirect: 'noRedirect', + } + if(item.children && item.children.length > 0){ + menu.meta=item.meta + }else{ + menu.children = [] + menu.children.push(_item) } - menu.children = [] - menu.children.push(_item) } // 一级菜单 二级菜单 特定属性 // if (item.component == '@/layout' || item.component == 'index') { @@ -136,6 +93,7 @@ export function generaMenu(routes, data, first) { // menu.hasOpen = false // 是否打开过,默认false // } if (item.children && item.children.length > 0) { + if(!menu.children)menu.children = [] generaMenu(menu.children, item.children) } // if (item.permission == 'skip' && item.children.length == 0) { @@ -149,9 +107,25 @@ export function generaMenu(routes, data, first) { export function initTreeMenusHandle(tree, list,first) { let _res = [] tree.forEach(item=>{ - if(list.indexOf(item.name) >= 0){ - item.title = store.getters.columZHList[item.name] || item.name - if(first)item.component = '@/layout' + if(list.indexOf(item.name) >= 0 || item.name.indexOf(AbpIdentity_mark) >= 0){ + if(item.name.indexOf(AbpIdentity_mark) >= 0){ + if(item.name == AbpIdentity_mark){ + item.title = '系统设置管理' + }else{ + let _name = item.name.substring(AbpIdentity_mark.length,item.name.length) + item.title = store.getters.columZHList[_name] || _name + } + }else{ + item.title = store.getters.columZHList[item.name] || item.name + } + item.path = '/'+item.name + item.meta={ + title: item.title, + icon: item.icon || 'svg_default', + // roles: item.permission, + outerFirst:first + } + // if(first)item.component = '@/layout' if (item.children && item.children.length > 0) { item.children = initTreeMenusHandle(item.children,list) } @@ -161,55 +135,66 @@ export function initTreeMenusHandle(tree, list,first) { return _res } const actions = { + // 设置权限 + setUserRoles({commit},data){ + commit('SET_ROLES', data) + }, getApiColumnsNames({ commit }, userId) { return new Promise(resolve => { - let accessedRoutes = asyncRoutes - // accessedRoutes = filterAsyncRoutes(asyncRoutes, roles) - // let indexVal = 0 - // let childrenIndex = 0 - // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) - // commit('SET_ROUTES', accessedRoutes) - // resolve(accessedRoutes) getDefinitionMenu(true).then(res => { + let roles_arr = [] + for(let r in res.auth.grantedPolicies){ + if(res.auth.grantedPolicies[r])roles_arr.push(r) + } + commit('SET_ROLES', roles_arr) + let _allConfig = res.auth.grantedPolicies;//所有配置 let _menuList = []//接口获取所有的菜单 + let _AbpIdentity = []//接口获取所有的身份配置信息数据 for(let item in _allConfig){ let point_number = item.split('.').length - 1 // 只选择配置项中的数据 if(point_number == 1 && item.substring(0,item.indexOf('.')) == localStorage.getItem('appClientScope')){ _menuList.push(item.substring(item.indexOf('.') + 1,item.length)) - } + } + // 身份配置信息数据(用户、角色) + if(point_number == 1 && item.substring(0,item.indexOf('.')) == 'AbpIdentity'){ + _AbpIdentity.push(AbpIdentity_mark + item.substring(item.indexOf('.') + 1,item.length)) + } } // 存储所有的表名 commit('SET_TABLESNAME', _menuList) + // 存储身份标识 + commit('SET_AbpIdentity', _AbpIdentity) // 数据模拟,todo-new:接口获取 let _treeMenusAll = null//树形菜单 // _treeMenusAll = [ // {name:"aaaaaaa"}, - // {name:"ExportCustomUserSetting" - // // ,children:[ - // // {name:'OutgoingDataHistory',children:[ - // // {name:'IncomingData',children:[ - // // {name:'OutgoingDataHistory'}, - // // {name:'IncomingData'}, - // // {name:'333333'}, - // // ]}, - // // {name:'eee1111-bbb',children:[ - // // {name:'ExportCustomUserSetting'}, - // // {name:'MessageReceive'}, - // // ]}, - // // ]}, - // // {name:'eee222'}, - // // {name:'eee333'}, - // // {name:'eee444'}, - // // {name:'eee555'}, - // // ] + // { + // name:"ExportCustomUserSetting1", + // children:[ + // {name:'ExportCustomUserSetting'}, + // {name:'OutgoingDataHistory' + // ,children:[ + // {name:"OutgoingDataHistory"}, + // {name:'IncomingData',children:[ + // {name:'IncomingDataHistory'}, + // {name:'IncomingData'}, + // {name:'333333'}, + // ]}, + // {name:'eee1111-bbb',children:[ + // {name:'IncomingDataHistory'}, + // {name:'MessageReceive'}, + // ]}, + // ]}, + // {name:'eee222'}, + // {name:'eee333'}, + // {name:'eee444'}, + // {name:'eee555'}, + // ] // }, - // {name:"OutgoingDataHistory"}, - // {name:"IncomingData"}, - // {name:"IncomingDataHistory"}, // {name:"MesProductL7PartsNote"}, // {name:"MessageReceive"}, // {name:"OutgoingData"}, @@ -233,23 +218,30 @@ const actions = { // {name:"VendPart"}, // {name:"Vend"}, // ] - - let _initTreeMenus = [] + + let _menuAndAbpList = [..._menuList,..._AbpIdentity]// 包含配置项中的业务菜单+身份权限菜单(角色用户等) + let _initTreeMenus = []//转义为树状结构 if(_treeMenusAll && _treeMenusAll.length > 0){ - _initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuList,true) + _initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuAndAbpList,true) }else{ let _data = [] - for(let i in _menuList){ - _data.push({name:_menuList[i]}) + // 自定义系统设置管理分级 + if(_AbpIdentity && _AbpIdentity.length > 0){ + _data.push({name:AbpIdentity_mark,children:[]}) + } + for(let i in _menuAndAbpList){ + if(_menuAndAbpList[i].indexOf(AbpIdentity_mark) >= 0){ + _data[0].children.push({ name:_menuAndAbpList[i] }) + } + else{ + _data.push({name:_menuAndAbpList[i]}) + } } - _initTreeMenus = initTreeMenusHandle(_data,_menuList,true) + _initTreeMenus = initTreeMenusHandle(_data,_menuAndAbpList,true) } // 最后查重+层级查重后的菜单 let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) let accessedRoutes = _initEndMenus - // let indexVal = 0 - // let childrenIndex = 0 - // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) commit('SET_ROUTES', accessedRoutes) resolve(accessedRoutes) }).catch(err => { diff --git a/PC/InterFace.Dash/src/store/modules/permission_old.js b/PC/InterFace.Dash/src/store/modules/permission_old.js new file mode 100644 index 0000000..b555874 --- /dev/null +++ b/PC/InterFace.Dash/src/store/modules/permission_old.js @@ -0,0 +1,267 @@ +import { + asyncRoutes, + constantRoutes +} from '@/router' +import Layout from '@/layout' +import { getDefinitionMenu } from '@/api/wms-auth' +import store from '@/store' +import router from '@/router' + +/** + * Use meta.role to determine if the current user has permission + * @param roles + * @param route + */ +function hasPermission(roles, route) { + if (route.meta && route.meta.roles) { + if (route.meta.roles == "skip") { + return true + } else { + return roles.some(role => route.meta.roles.includes(role)) + } + } else { + return false + } +} +const filterAccessedRoutes = (items,indexVal,childrenIndex) => { + const route = JSON.parse(JSON.stringify(items)) + route.forEach((val, index) => { + // debugger; + if(val.meta && val.meta.roles == "skip"){ + if (val.children && val.children.length != 0) { + filterAccessedRoutes(items[index-indexVal].children,childrenIndex) + } + if(items[index-indexVal].children && items[index-indexVal].children.length == 0){ + items.splice(index-indexVal, 1) + indexVal++ + } + } + }) + indexVal = 0 +} +/** + * Filter asynchronous routing tables by recursion + * @param routes asyncRoutes + * @param roles + */ +export function filterAsyncRoutes(routes, roles) { + const res = [] + routes.forEach(route => { + const tmp = { + ...route + } + if (hasPermission(roles, tmp)) { + if (tmp.children) { + tmp.children = filterAsyncRoutes(tmp.children, roles) + } + res.push(tmp) + } + }) + return res +} + +const state = { + routes: [],//菜单 + addRoutes: [], + tablesName:null,//所有的表名 +} + +const mutations = { + SET_ROUTES: (state, routes) => { + state.addRoutes = routes + state.routes = constantRoutes.concat(routes) + router.addRoutes(routes) + }, + SET_TABLESNAME: (state, data) => { + state.tablesName = data + } +} +/** + * 静态路由懒加载 + * @param view 格式必须为 xxx/xxx 开头不要加斜杠 + * @returns + */ + export const loadView = (view) => { + return (resolve) => require([`@/views/menuList/${view}`], resolve) +} +/** + * 把从后端查询的菜单数据拼装成路由格式的数据 + * @param routes + * @param data 后端返回的菜单数据 + */ +export function generaMenu(routes, data, first) { + // 不显示的菜单配置隐藏 + let _noShowMenus = localStorage.getItem('menuHiddenConfig').split(',') + data.forEach(item => { + let _item = { + path: '/'+item.name, + component: loadView(item.name), + hidden: _noShowMenus.indexOf(item.name) >= 0, // 状态为0的隐藏 + name: item.name, + // meta: item.meta + meta: { + title: item.title, + icon: item.icon || 'svg_default', + roles: item.permission, + outerFirst:first + }, + } + let menu = _item + if(first && item.component == '@/layout'){ + menu = { + path: '/', + component: Layout, + redirect: '/' + item.name, + children: [], + } + menu.children = [] + menu.children.push(_item) + } + // 一级菜单 二级菜单 特定属性 + // if (item.component == '@/layout' || item.component == 'index') { + // menu.alwaysShow = true + // menu.redirect = 'noRedirect' + // } + // if (item.sort < 99) { + // menu.level = 1 + // } else if (item.sort > 99 && item.sort < 9999) { + // menu.level = 2 + // } else { + // menu.level = 3 + // } + // iframe页面处理 + // if (item.permission.indexOf('Report') > -1) { + // // delete menu.component + // menu.iframeComponent = item.component === '@/layout' ? Layout : loadView(item.component) + // menu.hasOpen = false // 是否打开过,默认false + // } + if (item.children && item.children.length > 0) { + generaMenu(menu.children, item.children) + } + // if (item.permission == 'skip' && item.children.length == 0) { + // } + routes.push(menu) + }) + return routes +} + +// todo:接口返回的层级菜单,与查重后最终显示的菜单数组做查重及组合处理 +export function initTreeMenusHandle(tree, list,first) { + let _res = [] + tree.forEach(item=>{ + if(list.indexOf(item.name) >= 0){ + item.title = store.getters.columZHList[item.name] || item.name + if(first)item.component = '@/layout' + if (item.children && item.children.length > 0) { + item.children = initTreeMenusHandle(item.children,list) + } + _res.push(item) + } + }) + return _res +} +const actions = { + getApiColumnsNames({ + commit + }, userId) { + return new Promise(resolve => { + let accessedRoutes = asyncRoutes + // accessedRoutes = filterAsyncRoutes(asyncRoutes, roles) + // let indexVal = 0 + // let childrenIndex = 0 + // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) + // commit('SET_ROUTES', accessedRoutes) + // resolve(accessedRoutes) + getDefinitionMenu(true).then(res => { + let _allConfig = res.auth.grantedPolicies;//所有配置 + let _menuList = []//接口获取所有的菜单 + for(let item in _allConfig){ + let point_number = item.split('.').length - 1 + // 只选择配置项中的数据 + if(point_number == 1 && item.substring(0,item.indexOf('.')) == localStorage.getItem('appClientScope')){ + _menuList.push(item.substring(item.indexOf('.') + 1,item.length)) + } + } + // 存储所有的表名 + commit('SET_TABLESNAME', _menuList) + // 数据模拟,todo-new:接口获取 + let _treeMenusAll = null//树形菜单 + // _treeMenusAll = [ + // {name:"aaaaaaa"}, + // {name:"ExportCustomUserSetting" + // // ,children:[ + // // {name:'OutgoingDataHistory',children:[ + // // {name:'IncomingData',children:[ + // // {name:'OutgoingDataHistory'}, + // // {name:'IncomingData'}, + // // {name:'333333'}, + // // ]}, + // // {name:'eee1111-bbb',children:[ + // // {name:'ExportCustomUserSetting'}, + // // {name:'MessageReceive'}, + // // ]}, + // // ]}, + // // {name:'eee222'}, + // // {name:'eee333'}, + // // {name:'eee444'}, + // // {name:'eee555'}, + // // ] + // }, + // {name:"OutgoingDataHistory"}, + // {name:"IncomingData"}, + // {name:"IncomingDataHistory"}, + // {name:"MesProductL7PartsNote"}, + // {name:"MessageReceive"}, + // {name:"OutgoingData"}, + // {name:"AsnDet"}, + // {name:"AsnMstr"}, + // {name:"Bom"}, + // {name:"CustPart"}, + // {name:"Cust"}, + // {name:"Inventory"}, + // {name:"Loc"}, + // {name:"Part"}, + // {name:"PoDet"}, + // {name:"PoMstr"}, + // {name:"PrhHist"}, + // {name:"ProdLine"}, + // {name:"ReceiptDet"}, + // {name:"ReceiptMstr"}, + // {name:"ReturnDet"}, + // {name:"ReturnMstr"}, + // {name:"SodDet"}, + // {name:"VendPart"}, + // {name:"Vend"}, + // ] + + let _initTreeMenus = [] + if(_treeMenusAll && _treeMenusAll.length > 0){ + _initTreeMenus = initTreeMenusHandle(_treeMenusAll,_menuList,true) + }else{ + let _data = [] + for(let i in _menuList){ + _data.push({name:_menuList[i]}) + } + _initTreeMenus = initTreeMenusHandle(_data,_menuList,true) + } + // 最后查重+层级查重后的菜单 + let _initEndMenus = generaMenu(asyncRoutes, _initTreeMenus,true) + let accessedRoutes = _initEndMenus + // let indexVal = 0 + // let childrenIndex = 0 + // filterAccessedRoutes(accessedRoutes,indexVal,childrenIndex) + commit('SET_ROUTES', accessedRoutes) + resolve(accessedRoutes) + }).catch(err => { + console.log(err) + }) + }) + }, +} + +export default { + namespaced: true, + state, + mutations, + actions +} \ No newline at end of file diff --git a/PC/InterFace.Dash/src/store/modules/user.js b/PC/InterFace.Dash/src/store/modules/user.js index 183b6a5..763044e 100644 --- a/PC/InterFace.Dash/src/store/modules/user.js +++ b/PC/InterFace.Dash/src/store/modules/user.js @@ -17,7 +17,6 @@ import store from '@/store' const state = { token: getToken(), introduction: '', - roles: [], userInfo:null } @@ -28,16 +27,6 @@ const mutations = { SET_INTRODUCTION: (state, introduction) => { state.introduction = introduction }, - // 设置权限(v-permission) - SET_ROLES: (state, roles) => { - let _roles = [ - 'IncomingDataHistory.filter', - 'IncomingData.export', - 'MesProductL7PartsNote.filter', - 'MesProductL7PartsNote.export' - ] - state.roles = _roles - }, SET_USERINFO: (state, data) => { state.userInfo = data } @@ -119,9 +108,10 @@ const actions = { dispatch }) { return new Promise((resolve, reject) => { - logout().then(() => { + // todo-fast:退出登录接口好使后,打开logout + // logout().then(() => { commit('SET_TOKEN', '') - commit('SET_ROLES', []) + dispatch('permission/setUserRoles',[]) removeToken() resetRouter() // reset visited views and cached views @@ -132,9 +122,9 @@ const actions = { resolve() // 防止路由叠加 location.reload() - }).catch(error => { - reject(error) - }) + // }).catch(error => { + // reject(error) + // }) }) }, @@ -158,7 +148,6 @@ const actions = { return new Promise((resolve, reject) => { getUsersByUserName(username).then(res=>{ if(res && JSON.stringify(res).length > 0){ - // commit('SET_ROLES', res) commit('SET_USERINFO', res) resolve(res) }else{ diff --git a/PC/InterFace.Dash/src/views/dashboard/index.vue b/PC/InterFace.Dash/src/views/dashboard/index.vue index a099f66..32f46e3 100644 --- a/PC/InterFace.Dash/src/views/dashboard/index.vue +++ b/PC/InterFace.Dash/src/views/dashboard/index.vue @@ -27,24 +27,28 @@ export default { ]) }, mounted(){ - this.initData(this.permission_routes) + let _menus = JSON.parse(JSON.stringify(this.permission_routes)) + let _showList = _menus.filter(item=>{ + return !item.hidden + }) + this.navList = this.initData(_showList,true) }, methods:{ - initData(data){ + initData(data,first){ + let _list = [] data.forEach(item => { - if(!item.hidden && item.path !== '/' && item.meta) { - let _item = { - title:item.meta.title, - name:item.name, - path:item.path, - children:item.children - } - this.navList.push(_item) + // 多层数据 + if(item.meta){ + item.title = item.meta.title + _list.push(item) } - if(!item.hidden && item.children){ - this.initData(item.children) + // 默认为单层 + else{ + _list.push(item.children[0]) } - }) + if(item.children)item.children = this.initData(item.children) + }); + return _list }, goPage(item){ this.$router.push({name: item.name}) diff --git a/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkRoles.vue b/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkRoles.vue new file mode 100644 index 0000000..a5b074f --- /dev/null +++ b/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkRoles.vue @@ -0,0 +1,712 @@ + + + + diff --git a/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkUsers.vue b/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkUsers.vue new file mode 100644 index 0000000..3281d1b --- /dev/null +++ b/PC/InterFace.Dash/src/views/menuList/AbpIdentityMarkUsers.vue @@ -0,0 +1,19 @@ + +