diff --git a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java index 73a3ad49e..b68bc058f 100644 --- a/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java +++ b/litemall-admin-api/src/main/java/org/linlinjava/litemall/admin/web/AdminAdController.java @@ -30,7 +30,7 @@ public class AdminAdController { @RequiresPermissions("admin:ad:list") @RequiresPermissionsDesc(menu={"推广管理" , "广告管理"}, button="查询") - @GetMapping("/list") + @RequestMapping("/list") public Object list(String name, String content, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, diff --git a/litemall-admin/src/lang/en.js b/litemall-admin/src/lang/en.js index 3f6641944..930f0ad1f 100644 --- a/litemall-admin/src/lang/en.js +++ b/litemall-admin/src/lang/en.js @@ -87,7 +87,6 @@ export default { }, permission: { roles: 'Your roles', - perms: 'Your permissions', switchRoles: 'Switch roles' }, guide: { diff --git a/litemall-admin/src/lang/zh.js b/litemall-admin/src/lang/zh.js index 6960274b1..46e96ccf5 100644 --- a/litemall-admin/src/lang/zh.js +++ b/litemall-admin/src/lang/zh.js @@ -86,9 +86,8 @@ export default { github: 'Github 地址' }, permission: { - roles: '你的角色', - perms: '你的权限', - switchRoles: '切换角色' + roles: '你的权限', + switchRoles: '切换权限' }, guide: { description: '引导页对于一些第一次进入项目的人很有用,你可以简单介绍下项目的功能。本 Demo 是基于', diff --git a/litemall-admin/src/main.js b/litemall-admin/src/main.js index 0daf46773..499409837 100644 --- a/litemall-admin/src/main.js +++ b/litemall-admin/src/main.js @@ -19,15 +19,11 @@ import './permission' // permission control import * as filters from './filters' // global filters -import permission from '@/directive/permission/index.js' // 权限判断指令 - Vue.use(Element, { size: Cookies.get('size') || 'medium', // set element-ui default size i18n: (key, value) => i18n.t(key, value) }) -Vue.directive('permission', permission) - // register global utility filters. Object.keys(filters).forEach(key => { Vue.filter(key, filters[key]) diff --git a/litemall-admin/src/permission.js b/litemall-admin/src/permission.js index 4603bbc6d..8da249569 100644 --- a/litemall-admin/src/permission.js +++ b/litemall-admin/src/permission.js @@ -8,10 +8,10 @@ import { getToken } from '@/utils/auth' // getToken from cookie NProgress.configure({ showSpinner: false })// NProgress Configuration // permission judge function -function hasPermission(perms, permissions) { - if (perms.indexOf('*') >= 0) return true // admin permission passed directly - if (!permissions) return true - return perms.some(perm => permissions.indexOf(perm) >= 0) +function hasPermission(roles, permissionRoles) { + if (roles.indexOf('admin') >= 0) return true // admin permission passed directly + if (!permissionRoles) return true + return roles.some(role => permissionRoles.indexOf(role) >= 0) } const whiteList = ['/login', '/auth-redirect']// no redirect whitelist @@ -24,10 +24,10 @@ router.beforeEach((to, from, next) => { next({ path: '/' }) NProgress.done() // if current page is dashboard will not trigger afterEach hook, so manually handle it } else { - if (store.getters.perms.length === 0) { // 判断当前用户是否已拉取完user_info信息 + if (store.getters.roles.length === 0) { // 判断当前用户是否已拉取完user_info信息 store.dispatch('GetUserInfo').then(res => { // 拉取user_info - const perms = res.data.data.perms // note: perms must be a array! such as: ['GET /aaa','POST /bbb'] - store.dispatch('GenerateRoutes', { perms }).then(() => { // 根据perms权限生成可访问的路由表 + const roles = res.data.data.roles // note: roles must be a array! such as: ['editor','develop'] + store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表 router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表 next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record }) @@ -39,7 +39,7 @@ router.beforeEach((to, from, next) => { }) } else { // 没有动态改变权限的需求可直接next() 删除下方权限判断 ↓ - if (hasPermission(store.getters.perms, to.meta.perms)) { + if (hasPermission(store.getters.roles, to.meta.roles)) { next() } else { next({ path: '/401', replace: true, query: { noGoBack: true }}) diff --git a/litemall-admin/src/router/index.js b/litemall-admin/src/router/index.js index 8930c5cf9..112e24f8e 100644 --- a/litemall-admin/src/router/index.js +++ b/litemall-admin/src/router/index.js @@ -18,7 +18,7 @@ import Layout from '@/views/layout/Layout' * redirect: noredirect if `redirect:noredirect` will no redirect in the breadcrumb * name:'router-name' the name is used by (must set!!!) * meta : { - perms: ['GET /aaa','POST /bbb'] will control the page perms (you can set multiple perms) + roles: ['admin','editor'] will control the page roles (you can set multiple roles) title: 'title' the name show in submenu and breadcrumb (recommend set) icon: 'svg-name' the icon show in the sidebar, noCache: true if true ,the page will no be cached(default is false) @@ -82,7 +82,6 @@ export const asyncRouterMap = [ path: '/user', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'userManage', meta: { title: '用户管理', @@ -93,61 +92,37 @@ export const asyncRouterMap = [ path: 'user', component: () => import('@/views/user/user'), name: 'user', - meta: { - perms: ['GET /admin/user/list', 'POST /admin/user/create', 'POST /admin/user/update'], - title: '会员管理', - noCache: true - } + meta: { title: '会员管理', noCache: true } }, { path: 'address', component: () => import('@/views/user/address'), name: 'address', - meta: { - perms: ['GET /admin/address/list'], - title: '收货地址', - noCache: true - } + meta: { title: '收货地址', noCache: true } }, { path: 'collect', component: () => import('@/views/user/collect'), name: 'collect', - meta: { - perms: ['GET /admin/collect/list'], - title: '会员收藏', - noCache: true - } + meta: { title: '会员收藏', noCache: true } }, { path: 'footprint', component: () => import('@/views/user/footprint'), name: 'footprint', - meta: { - perms: ['GET /admin/footprint/list'], - title: '会员足迹', - noCache: true - } + meta: { title: '会员足迹', noCache: true } }, { path: 'history', component: () => import('@/views/user/history'), name: 'history', - meta: { - perms: ['GET /admin/history/list'], - title: '搜索历史', - noCache: true - } + meta: { title: '搜索历史', noCache: true } }, { path: 'feedback', component: () => import('@/views/user/feedback'), name: 'feedback', - meta: { - perms: ['GET /admin/feedback/list'], - title: '意见反馈', - noCache: true - } + meta: { title: '意见反馈', noCache: true } } ] }, @@ -156,7 +131,6 @@ export const asyncRouterMap = [ path: '/mall', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'mallManage', meta: { title: '商场管理', @@ -167,60 +141,37 @@ export const asyncRouterMap = [ path: 'region', component: () => import('@/views/mall/region'), name: 'region', - meta: { - title: '行政区域', - noCache: true - } + meta: { title: '行政区域', noCache: true } }, { path: 'brand', component: () => import('@/views/mall/brand'), name: 'brand', - meta: { - perms: ['GET /admin/brand/list', 'POST /admin/brand/create', 'GET /admin/brand/read', 'POST /admin/brand/update', 'POST /admin/brand/delete'], - title: '品牌制造商', - noCache: true - } + meta: { title: '品牌制造商', noCache: true } }, { path: 'category', component: () => import('@/views/mall/category'), name: 'category', - meta: { - perms: ['GET /admin/category/list', 'POST /admin/category/create', 'GET /admin/category/read', 'POST /admin/category/update', 'POST /admin/category/delete'], - title: '商品类目', - noCache: true - } + meta: { title: '商品类目', noCache: true } }, { path: 'order', component: () => import('@/views/mall/order'), name: 'order', - meta: { - perms: ['GET /admin/order/list', 'GET /admin/order/detail', 'POST /admin/order/ordership', 'POST /admin/order/orderrefund', 'POST /admin/order/orderreply'], - title: '订单管理', - noCache: true - } + meta: { title: '订单管理', noCache: true } }, { path: 'issue', component: () => import('@/views/mall/issue'), name: 'issue', - meta: { - perms: ['GET /admin/issue/list', 'POST /admin/issue/create', 'GET /admin/issue/read', 'POST /admin/issue/update', 'POST /admin/issue/delete'], - title: '通用问题', - noCache: true - } + meta: { title: '通用问题', noCache: true } }, { path: 'keyword', component: () => import('@/views/mall/keyword'), name: 'keyword', - meta: { - perms: ['GET /admin/keyword/list', 'POST /admin/keyword/create', 'GET /admin/keyword/read', 'POST /admin/keyword/update', 'POST /admin/keyword/delete'], - title: '关键词', - noCache: true - } + meta: { title: '关键词', noCache: true } } ] }, @@ -229,7 +180,6 @@ export const asyncRouterMap = [ path: '/goods', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'goodsManage', meta: { title: '商品管理', @@ -240,42 +190,26 @@ export const asyncRouterMap = [ path: 'list', component: () => import('@/views/goods/list'), name: 'goodsList', - meta: { - perms: ['GET /admin/goods/list', 'POST /admin/goods/delete'], - title: '商品列表', - noCache: true - } + meta: { title: '商品列表', noCache: true } }, { path: 'create', component: () => import('@/views/goods/create'), name: 'goodsCreate', - meta: { - perms: ['POST /admin/goods/create'], - title: '商品上架', - noCache: true - } + meta: { title: '商品上架', noCache: true } }, { path: 'edit', component: () => import('@/views/goods/edit'), name: 'goodsEdit', - meta: { - perms: ['GET /admin/goods/detail', 'POST /admin/goods/update', 'POST /admin/goods/catAndBrand'], - title: '商品编辑', - noCache: true - }, + meta: { title: '商品编辑', noCache: true }, hidden: true }, { path: 'comment', component: () => import('@/views/goods/comment'), name: 'goodsComment', - meta: { - perms: ['GET /admin/comment/list', 'POST /admin/comment/delete'], - title: '商品评论', - noCache: true - } + meta: { title: '商品评论', noCache: true } } ] }, @@ -283,7 +217,6 @@ export const asyncRouterMap = [ path: '/promotion', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'promotionManage', meta: { title: '推广管理', @@ -294,62 +227,38 @@ export const asyncRouterMap = [ path: 'ad', component: () => import('@/views/promotion/ad'), name: 'ad', - meta: { - perms: ['GET /admin/ad/list', 'POST /admin/ad/create', 'GET /admin/ad/read', 'POST /admin/ad/update', 'POST /admin/ad/delete'], - title: '广告管理', - noCache: true - } + meta: { title: '广告管理', noCache: true } }, { path: 'coupon', component: () => import('@/views/promotion/coupon'), name: 'coupon', - meta: { - perms: ['GET /admin/coupon/list', 'POST /admin/coupon/create', 'POST /admin/coupon/update', 'POST /admin/coupon/delete'], - title: '优惠券管理', - noCache: true - } + meta: { title: '优惠券管理', noCache: true } }, { path: 'couponDetail', component: () => import('@/views/promotion/couponDetail'), name: 'couponDetail', - meta: { - perms: ['GET /admin/coupon/list', 'GET /admin/coupon/listuser'], - title: '优惠券详情', - noCache: true - }, + meta: { title: '优惠券详情', noCache: true }, hidden: true }, { path: 'topic', component: () => import('@/views/promotion/topic'), name: 'topic', - meta: { - perms: ['GET /admin/topic/list', 'POST /admin/topic/create', 'GET /admin/topic/read', 'POST /admin/topic/update', 'POST /admin/topic/delete'], - title: '专题管理', - noCache: true - } + meta: { title: '专题管理', noCache: true } }, { path: 'groupon-rule', component: () => import('@/views/promotion/grouponRule'), name: 'grouponRule', - meta: { - perms: ['GET /admin/groupon/list', 'POST /admin/groupon/create', 'POST /admin/groupon/update', 'POST /admin/groupon/delete'], - title: '团购规则', - noCache: true - } + meta: { title: '团购规则', noCache: true } }, { path: 'groupon-activity', component: () => import('@/views/promotion/grouponActivity'), name: 'grouponActivity', - meta: { - perms: ['GET /admin/groupon/listRecord'], - title: '团购活动', - noCache: true - } + meta: { title: '团购活动', noCache: true } } ] }, @@ -358,7 +267,6 @@ export const asyncRouterMap = [ path: '/sys', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'sysManage', meta: { title: '系统管理', @@ -369,31 +277,19 @@ export const asyncRouterMap = [ path: 'admin', component: () => import('@/views/sys/admin'), name: 'admin', - meta: { - perms: ['GET /admin/admin/list', 'POST /admin/admin/create', 'POST /admin/admin/update', 'POST /admin/admin/delete'], - title: '管理员', - noCache: true - } + meta: { title: '管理员', noCache: true } }, { path: 'role', component: () => import('@/views/sys/role'), name: 'role', - meta: { - perms: ['GET /admin/role/list', 'POST /admin/role/create', 'POST /admin/role/update', 'POST /admin/role/delete', 'GET /admin/role/permissions', 'POST /admin/role/permissions'], - title: '角色管理', - noCache: true - } + meta: { title: '角色管理', noCache: true } }, { path: 'os', component: () => import('@/views/sys/os'), name: 'os', - meta: { - perms: ['GET /admin/os/list', 'POST /admin/os/create', 'POST /admin/os/update', 'POST /admin/os/delete'], - title: '对象存储', - noCache: true - } + meta: { title: '对象存储', noCache: true } } ] }, @@ -402,7 +298,6 @@ export const asyncRouterMap = [ path: '/stat', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'statManage', meta: { title: '统计', @@ -413,31 +308,19 @@ export const asyncRouterMap = [ path: 'user', component: () => import('@/views/stat/user'), name: 'statUser', - meta: { - perms: ['GET /admin/stat/user'], - title: '用户统计', - noCache: true - } + meta: { title: '用户统计', noCache: true } }, { path: 'order', component: () => import('@/views/stat/order'), name: 'statOrder', - meta: { - perms: ['GET /admin/stat/order'], - title: '订单统计', - noCache: true - } + meta: { title: '订单统计', noCache: true } }, { path: 'goods', component: () => import('@/views/stat/goods'), name: 'statGoods', - meta: { - perms: ['GET /admin/stat/goods'], - title: '商品统计', - noCache: true - } + meta: { title: '商品统计', noCache: true } } ] }, @@ -445,7 +328,6 @@ export const asyncRouterMap = [ path: 'external-link', component: Layout, redirect: 'noredirect', - alwaysShow: true, name: 'externalLink', meta: { title: '外链', @@ -486,7 +368,6 @@ export const asyncRouterMap = [ path: '/profile', component: Layout, redirect: 'noredirect', - alwaysShow: true, children: [ { path: 'password', diff --git a/litemall-admin/src/store/getters.js b/litemall-admin/src/store/getters.js index 745789c73..0d05236e2 100644 --- a/litemall-admin/src/store/getters.js +++ b/litemall-admin/src/store/getters.js @@ -11,7 +11,6 @@ const getters = { introduction: state => state.user.introduction, status: state => state.user.status, roles: state => state.user.roles, - perms: state => state.user.perms, setting: state => state.user.setting, permission_routers: state => state.permission.routers, addRouters: state => state.permission.addRouters diff --git a/litemall-admin/src/store/modules/permission.js b/litemall-admin/src/store/modules/permission.js index bcdeea764..97de701e9 100644 --- a/litemall-admin/src/store/modules/permission.js +++ b/litemall-admin/src/store/modules/permission.js @@ -1,13 +1,13 @@ import { asyncRouterMap, constantRouterMap } from '@/router' /** - * 通过meta.perms判断是否与当前用户权限匹配 - * @param perms + * 通过meta.role判断是否与当前用户权限匹配 + * @param roles * @param route */ -function hasPermission(perms, route) { - if (route.meta && route.meta.perms) { - return perms.some(perm => route.meta.perms.includes(perm)) +function hasPermission(roles, route) { + if (route.meta && route.meta.roles) { + return roles.some(role => route.meta.roles.includes(role)) } else { return true } @@ -16,22 +16,18 @@ function hasPermission(perms, route) { /** * 递归过滤异步路由表,返回符合用户角色权限的路由表 * @param routes asyncRouterMap - * @param perms + * @param roles */ -function filterAsyncRouter(routes, perms) { +function filterAsyncRouter(routes, roles) { const res = [] routes.forEach(route => { const tmp = { ...route } - if (tmp.children) { - tmp.children = filterAsyncRouter(tmp.children, perms) - if (tmp.children && tmp.children.length > 0) { - res.push(tmp) - } - } else { - if (hasPermission(perms, tmp)) { - res.push(tmp) + if (hasPermission(roles, tmp)) { + if (tmp.children) { + tmp.children = filterAsyncRouter(tmp.children, roles) } + res.push(tmp) } }) @@ -52,12 +48,12 @@ const permission = { actions: { GenerateRoutes({ commit }, data) { return new Promise(resolve => { - const { perms } = data + const { roles } = data let accessedRouters - if (perms.includes('*')) { + if (roles.includes('admin')) { accessedRouters = asyncRouterMap } else { - accessedRouters = filterAsyncRouter(asyncRouterMap, perms) + accessedRouters = filterAsyncRouter(asyncRouterMap, roles) } commit('SET_ROUTERS', accessedRouters) resolve() diff --git a/litemall-admin/src/store/modules/user.js b/litemall-admin/src/store/modules/user.js index 16d0cb2c5..67c1730d1 100644 --- a/litemall-admin/src/store/modules/user.js +++ b/litemall-admin/src/store/modules/user.js @@ -11,7 +11,6 @@ const user = { avatar: '', introduction: '', roles: [], - perms: [], setting: { articlePlatform: [] } @@ -41,9 +40,6 @@ const user = { }, SET_ROLES: (state, roles) => { state.roles = roles - }, - SET_PERMS: (state, perms) => { - state.perms = perms } }, @@ -69,13 +65,12 @@ const user = { getUserInfo(state.token).then(response => { const data = response.data.data - if (data.perms && data.perms.length > 0) { // 验证返回的perms是否是一个非空数组 - commit('SET_PERMS', data.perms) + if (data.roles && data.roles.length > 0) { // 验证返回的roles是否是一个非空数组 + commit('SET_ROLES', data.roles) } else { - reject('getInfo: perms must be a non-null array !') + reject('getInfo: roles must be a non-null array !') } - commit('SET_ROLES', data.roles) commit('SET_NAME', data.name) commit('SET_AVATAR', data.avatar) commit('SET_INTRODUCTION', data.introduction) @@ -106,7 +101,6 @@ const user = { logout(state.token).then(() => { commit('SET_TOKEN', '') commit('SET_ROLES', []) - commit('SET_PERMS', []) removeToken() resolve() }).catch(error => { @@ -132,7 +126,6 @@ const user = { getUserInfo(role).then(response => { const data = response.data commit('SET_ROLES', data.roles) - commit('SET_PERMS', data.perms) commit('SET_NAME', data.name) commit('SET_AVATAR', data.avatar) commit('SET_INTRODUCTION', data.introduction) diff --git a/litemall-admin/src/views/login/index.vue b/litemall-admin/src/views/login/index.vue index fe98db980..f1388cfc9 100644 --- a/litemall-admin/src/views/login/index.vue +++ b/litemall-admin/src/views/login/index.vue @@ -22,21 +22,6 @@ 登录 - -
-
- 超级管理员用户名: admin123 - 超级管理员用户名:admin123 -
-
- 商城管理员用户名: mall123 - 商城管理员用户名:mall123 -
-
- 推广管理员用户名: promotion123 - 推广管理员用户名:promotion123 -
-
diff --git a/litemall-admin/src/views/promotion/ad.vue b/litemall-admin/src/views/promotion/ad.vue index 89a711f62..6011a0f7b 100644 --- a/litemall-admin/src/views/promotion/ad.vue +++ b/litemall-admin/src/views/promotion/ad.vue @@ -5,8 +5,8 @@
- 查找 - 添加 + 查找 + 添加 导出
@@ -37,8 +37,8 @@ diff --git a/litemall-admin/src/views/sys/role.vue b/litemall-admin/src/views/sys/role.vue index 43453343e..b36760c36 100644 --- a/litemall-admin/src/views/sys/role.vue +++ b/litemall-admin/src/views/sys/role.vue @@ -50,12 +50,7 @@ :default-checked-keys="assignedPermissions" show-checkbox node-key="id" - highlight-current> - - {{ data.label }} - {{ data.api }} - - + highlight-current/>