From 3a9d8d126def0f8016054005c18a05b91095398e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Mon, 1 Nov 2021 11:43:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E9=A1=B6=E9=83=A8=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/cpd.js | 9 ++ src/components/NoticeMsgBar/index.vue | 124 ++++++++++++++++++++++++ src/store/getters.js | 3 +- src/store/index.js | 4 +- src/store/modules/noticeMsg.js | 41 ++++++++ src/store/modules/permission.js | 102 ++++++++++++++++++-- src/views/layout/components/Navbar.vue | 128 ++++++++++++++----------- 7 files changed, 346 insertions(+), 65 deletions(-) create mode 100644 src/api/cpd.js create mode 100644 src/components/NoticeMsgBar/index.vue create mode 100644 src/store/modules/noticeMsg.js diff --git a/src/api/cpd.js b/src/api/cpd.js new file mode 100644 index 00000000..3a273794 --- /dev/null +++ b/src/api/cpd.js @@ -0,0 +1,9 @@ +import axios from '@/utils/request' + +import config from '@/common/config' + +let base = config.getMallmBasePath(); + + +export const getNoticeMsg = params => { return axios.get(`${base}/mallm/cpd/index/toHandleOrdersCount`, { params: params }); }; + \ No newline at end of file diff --git a/src/components/NoticeMsgBar/index.vue b/src/components/NoticeMsgBar/index.vue new file mode 100644 index 00000000..c6688740 --- /dev/null +++ b/src/components/NoticeMsgBar/index.vue @@ -0,0 +1,124 @@ + + + + + + + diff --git a/src/store/getters.js b/src/store/getters.js index 0bb6f96d..871d6606 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -20,6 +20,7 @@ const getters = { addRouters: state => state.permission.addRouters, errorLogs: state => state.errorLog.logs, added: state => state.permission.added, - isLoadOk:state=>state.user.isLoadOk + isLoadOk:state=>state.user.isLoadOk, + noticeMsg:state=>state.noticeMsg.noticeMsg } export default getters diff --git a/src/store/index.js b/src/store/index.js index 24778fad..c58e58b1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -5,6 +5,7 @@ import errorLog from './modules/errorLog' import permission from './modules/permission' import tagsView from './modules/tagsView' import user from './modules/user' +import noticeMsg from './modules/noticeMsg' import getters from './getters' Vue.use(Vuex) @@ -15,7 +16,8 @@ const store = new Vuex.Store({ errorLog, permission, tagsView, - user + user, + noticeMsg, }, getters }) diff --git a/src/store/modules/noticeMsg.js b/src/store/modules/noticeMsg.js new file mode 100644 index 00000000..17ec7d7e --- /dev/null +++ b/src/store/modules/noticeMsg.js @@ -0,0 +1,41 @@ +const noticeMsg = { + state: { + noticeMsg:{ + toPayNum:0, + toSendNum:0, + toReceNum:0, + toApprovaNum:0, + hadApprovaNum:0, + hadFinishNum:0, + hadCloseNum:0, + hadCancelNum:0, + totalNum:0, + }, + + }, + + mutations: { + + SET_NOTICE_MSG:(state,noticeMsg)=>{ + state.noticeMsg = noticeMsg + }, + + }, + + actions: { + setNoticeMsg({ commit }, noticeMsg){ + return new Promise((resolve, reject) => { + commit("SET_NOTICE_MSG",noticeMsg) + localStorage.setItem("noticeMsg",JSON.stringify(noticeMsg)); + resolve(noticeMsg) + }) + } + + } +} +var noticeMsgLocal=localStorage.getItem("noticeMsg"); +if(noticeMsgLocal){ + + noticeMsg.state.noticeMsg=Object.assign( noticeMsg.state.noticeMsg,JSON.parse(noticeMsgLocal)) +} +export default noticeMsg \ No newline at end of file diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js index 724c8618..0b3be358 100644 --- a/src/store/modules/permission.js +++ b/src/store/modules/permission.js @@ -7,7 +7,7 @@ import { asyncRouterMap, constantRouterMap } from '@/router' * @param menus 我拥有的菜单 * @param route */ -function hasPermission( roles,menus ,route) { +function hasPermission( roles,menus ,route) { if(route==null || route=='undefined'){ return false; } @@ -17,8 +17,11 @@ function hasPermission( roles,menus ,route) { if(route.children && route.children.length){ return true; }else{ + if(!route.meta||!route.meta.menu){ + return true + } if( route.meta && route.meta.menu && menus && menus.length ){ - return menus.some(menu => menu.rpath==null?false:menu.rpath.indexOf(route.path) >= 0); + return menus.some(menu => menu.rpath==null?false:menu.rpath.indexOf(route.fullPath) >= 0); }else if( !route.meta || !route.meta.menu ){ return true; }else{ @@ -28,17 +31,68 @@ function hasPermission( roles,menus ,route) { return false } } - +function findRouteInner(routers,fullPath){ + return findRouteByFullPath({children:routers},fullPath) +} +function findRouteByFullPath(router,fullPath){ + if(router==null){ + return null; + }else{ + if(router.children && router.children.length>0){ + var routerFind=null; + router.children.forEach(i=>{ + var r= findRouteByFullPath(i,fullPath) + if(r){ + routerFind=r; + return routerFind; + } + }) + return routerFind; + }else{ + if(router.fullPath==fullPath){ + return router; + } + } + } +} /** * 递归过滤异步路由表,返回符合用户角色权限的路由表 * @param asyncRouterMap * @param roles */ -function filterAsyncRouter(asyncRouterMap, roles,menus ) { - const accessedRouters = asyncRouterMap.filter(route => { +function filterAsyncRouter(asyncRouterMap, roles,menus) { + const accessedRouters = asyncRouterMap.filter(route => { + if(!route.fullPath){ + route.fullPath=route.path; + }else{ + route.fullPath=route.fullPath+"/"+route.path + } + route.fullPath=route.fullPath.replace("//","/") if (hasPermission(roles,menus, route)) { if (route.children && route.children.length) { - route.children = filterAsyncRouter(route.children, roles,menus ) + route.children = filterAsyncRouterWithParentRoute(route, roles,menus ) + if(route.children==null || route.children.length==0){ + return false + } + } + return true + } + return false + }) + return accessedRouters +} +function filterAsyncRouterWithParentRoute(proute, roles,menus) { + + var accessedRouters = proute.children.filter(route => { + + if(!route.fullPath){ + route.fullPath=proute.fullPath+"/"+route.path; + route.fullPath=route.fullPath.replace("//","/") + } + + if (hasPermission(roles,menus, route)) { + if (route.children && route.children.length) { + route.children = filterAsyncRouterWithParentRoute(route, roles,menus ) if(route.children==null || route.children.length==0){ return false } @@ -50,6 +104,28 @@ function filterAsyncRouter(asyncRouterMap, roles,menus ) { return accessedRouters } +function initRouter(proute) { + if(proute==null){ + return; + }else{ + if(!proute.fullPath){ + if(proute.path){ + proute.fullPath=proute.path + }else{ + proute.fullPath="" + } + } + if(proute.children && proute.children.length>0){ + proute.children.forEach(i=>{ + if(!i.fullPath){ + i.fullPath=proute.fullPath+"/"+i.path + i.fullPath=i.fullPath.replace("//","/") + } + initRouter(i) + }) + } + } +} const permission = { state: { routers: constantRouterMap, @@ -68,18 +144,26 @@ const permission = { actions: { GenerateRoutes({ commit }, {roles,menus}) { return new Promise(resolve => { + debugger + initRouter({children:asyncRouterMap}) let accessedRouters - if (roles.some(role => role.roleid==='superAdmin')) { + if (roles.some(role => role.roleid==='superAdmin'||role.roleid==='platformAdmin')) { accessedRouters = asyncRouterMap - } else { + } else { accessedRouters = filterAsyncRouter(asyncRouterMap, roles,menus) } commit('SET_ROUTERS', accessedRouters) commit('SET_ADDED', true) resolve() }) + }, + FindRouter({ commit ,state}, fullPath){ + return new Promise(resolve => { + resolve(findRouteInner(state.routers,fullPath)) + }) } - } + }, + } export default permission diff --git a/src/views/layout/components/Navbar.vue b/src/views/layout/components/Navbar.vue index 44db8095..e5b0fbb6 100644 --- a/src/views/layout/components/Navbar.vue +++ b/src/views/layout/components/Navbar.vue @@ -17,50 +17,47 @@ 切换商户 --> - - - - - + + + + + + - + - - + +
- -
- - - - {{$t('navbar.dashboard')}} - - - - 用户名:{{userInfo.username}} + {{userInfo.username}} + + + +
用户名:{{userInfo.username}} 账户设置
公司:{{userInfo.branchName}} - - -
- 部门及岗位: - -
+ + +
+ + 部门:{{item.deptName}} +
+ 岗位: + +
- {{post.postName}} + {{post.postName}}
- - - +
- -
+ +
商户及门店: @@ -74,23 +71,28 @@
- +
- 我拥有的角色: - - - {{role.rolename}} - - - -
-
- - - {{$t('navbar.logOut')}} + 我拥有的角色: + + {{role.rolename}} + +
- + + + + + + + 首页 + + + + 退出 + +
@@ -104,6 +106,7 @@ import ErrorLog from '@/components/ErrorLog' import Screenfull from '@/components/Screenfull' import LangSelect from '@/components/LangSelect' import ThemePicker from '@/components/ThemePicker'; +import NoticeMsgBar from '@/components/NoticeMsgBar' //import selectShopLocationBySysDept from '@/views/mdp/app/selectShopLocationBySysDept/selectShopLocationBySysDept'; export default { @@ -114,7 +117,8 @@ export default { Screenfull, LangSelect, ThemePicker, - TopModules + TopModules, + NoticeMsgBar, }, data:function(){ return { @@ -235,7 +239,7 @@ export default {