menu.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import store from '@/utils/store';
  2. import { deepTree, revisePath, isArray } from '@/cool/utils/index';
  3. import router from '@/router/index';
  4. export default {
  5. state: {
  6. routes: store.get('viewRoutes') || [],
  7. group: store.get('menuGroup') || [],
  8. menu: [],
  9. permission: [],
  10. collapse: false,
  11. index: 0
  12. },
  13. actions: {
  14. permMenu({ commit, state }) {
  15. return new Promise((resolve, reject) => {
  16. this.$service.common
  17. .permMenu()
  18. .then(res => {
  19. if (!isArray(res.menus)) {
  20. console.warn('Invalid menus. Expected Array');
  21. res.menus = [];
  22. }
  23. if (!isArray(res.perms)) {
  24. console.warn('Invalid perms. Expected Array');
  25. res.perms = [];
  26. }
  27. const routes = res.menus
  28. .filter(e => e.type != 2)
  29. .map(e => {
  30. return {
  31. id: e.id,
  32. parentId: e.parentId,
  33. path: revisePath(e.router || e.id),
  34. viewPath: e.viewPath,
  35. type: e.type,
  36. name: e.name,
  37. icon: e.icon,
  38. orderNum: e.orderNum,
  39. meta: {
  40. keepAlive: e.keepAlive
  41. },
  42. children: []
  43. };
  44. });
  45. const menuGroup = deepTree(routes);
  46. commit('SET_PERMIESSION', res.perms);
  47. commit('SET_MENU_GROUP', menuGroup);
  48. commit(
  49. 'SET_VIEW_ROUTES',
  50. routes.filter(e => e.type == 1)
  51. );
  52. commit('SET_MENU_LIST', state.index);
  53. resolve(menuGroup);
  54. })
  55. .catch(err => {
  56. reject(err);
  57. });
  58. });
  59. }
  60. },
  61. mutations: {
  62. SET_MENU_GROUP(state, list) {
  63. state.group = list;
  64. store.set('menuGroup', list);
  65. },
  66. SET_VIEW_ROUTES(state, list) {
  67. router.$plugin.addRoutes(list);
  68. state.routes = list;
  69. store.set('viewRoutes', list);
  70. },
  71. SET_MENU_LIST(state, index) {
  72. const item = state.group[index];
  73. state.index = index;
  74. state.menu = item ? item.children : [];
  75. },
  76. SET_PERMIESSION(state, list) {
  77. state.permission = list;
  78. store.set('permission', list);
  79. },
  80. COLLAPSE_MENU(state, val = false) {
  81. state.collapse = val;
  82. }
  83. }
  84. };
  85. let menu = {
  86. perms: [
  87. 'sys:menu:add',
  88. 'sys:menu:delete',
  89. 'sys:menu:update',
  90. 'sys:menu:page',
  91. 'sys:menu:list',
  92. 'sys:menu:info',
  93. 'sys:user:add',
  94. 'sys:user:delete',
  95. 'sys:user:update',
  96. 'sys:user:page',
  97. 'sys:user:list',
  98. 'sys:user:info',
  99. 'sys:role:add',
  100. 'sys:role:delete',
  101. 'sys:role:update',
  102. 'sys:role:page',
  103. 'sys:role:list',
  104. 'sys:role:info',
  105. '1',
  106. 'sys:log:page',
  107. 'sys:log:clear'
  108. ],
  109. menus: [
  110. {
  111. id: '1',
  112. parentId: null,
  113. name: '商家管理',
  114. type: 0,
  115. icon: 'icongongzuotai',
  116. orderNum: 1,
  117. router: '/sass/shop-list',
  118. viewPath: null,
  119. keepAlive: 1
  120. },
  121. {
  122. id: '11',
  123. parentId: '1',
  124. name: '商家列表',
  125. type: 1,
  126. icon: 'icongongzuotai',
  127. orderNum: 1,
  128. router: '/sass/merchant/merchant-list',
  129. viewPath: 'sass/shop/list',
  130. keepAlive: 1
  131. },
  132. {
  133. id: '12',
  134. parentId: '1',
  135. name: '申请记录',
  136. type: 1,
  137. icon: 'icongongzuotai',
  138. orderNum: 1,
  139. router: '/sass/merchant/apply-list',
  140. viewPath: 'sass/shop/apply',
  141. keepAlive: 1
  142. },
  143. {
  144. id: '13',
  145. parentId: '1',
  146. name: '小程序',
  147. type: 1,
  148. icon: 'icongongzuotai',
  149. orderNum: 1,
  150. router: '/sass/merchant/upgrade',
  151. viewPath: 'sass/shop/upgrade',
  152. keepAlive: 1
  153. },
  154. {
  155. id: '14',
  156. parentId: '1',
  157. name: '门店管理',
  158. type: 1,
  159. icon: 'icongongzuotai',
  160. orderNum: 1,
  161. router: '/sass/merchant/shop-list',
  162. viewPath: 'sass/shop/shop',
  163. keepAlive: 1
  164. },
  165. {
  166. id: '14',
  167. parentId: '1',
  168. name: '付费订单',
  169. type: 1,
  170. icon: 'icongongzuotai',
  171. orderNum: 1,
  172. router: '/sass/merchant/buy-list',
  173. viewPath: 'sass/shop/buy',
  174. keepAlive: 1
  175. },
  176. // 订单管理
  177. {
  178. id: '2',
  179. parentId: null,
  180. name: '订单管理',
  181. type: 1,
  182. icon: 'icongongzuotai',
  183. orderNum: 1,
  184. router: '/sass/order/list',
  185. viewPath: 'sass/order/list',
  186. keepAlive: 1
  187. },
  188. // 商家客户
  189. {
  190. id: '3',
  191. parentId: null,
  192. name: '商家客户',
  193. type: 1,
  194. icon: 'icongongzuotai',
  195. orderNum: 1,
  196. router: '/sass/member/list',
  197. viewPath: 'sass/member/list',
  198. keepAlive: 1
  199. },
  200. // 平台客户
  201. {
  202. id: '4',
  203. parentId: null,
  204. name: '店长管理',
  205. type: 1,
  206. icon: 'icongongzuotai',
  207. orderNum: 1,
  208. router: '/sass/pt-member/list',
  209. viewPath: 'sass/pt-member/list',
  210. keepAlive: 1
  211. },
  212. // 商家商品
  213. {
  214. id: '5',
  215. parentId: null,
  216. name: '商家商品',
  217. type: 1,
  218. icon: 'icongongzuotai',
  219. orderNum: 1,
  220. router: '/sass/goods/list',
  221. viewPath: 'sass/goods/list',
  222. keepAlive: 1
  223. },
  224. // 节日管理
  225. {
  226. id: '6',
  227. parentId: null,
  228. name: '节日列表',
  229. type: 1,
  230. icon: 'icongongzuotai',
  231. orderNum: 1,
  232. router: '/sass/fest/list',
  233. viewPath: 'sass/fest/list',
  234. keepAlive: 1
  235. },
  236. // 套餐管理
  237. {
  238. id: '7',
  239. parentId: null,
  240. name: '套餐管理',
  241. type: 0,
  242. icon: 'icongongzuotai',
  243. orderNum: 1,
  244. router: '/sass/manage/list',
  245. viewPath: 'sass/manage/list',
  246. keepAlive: 1
  247. },
  248. {
  249. id: '701',
  250. parentId: '7',
  251. name: '套餐列表',
  252. type: 1,
  253. icon: 'icongongzuotai',
  254. orderNum: 1,
  255. router: '/sass/manage/package',
  256. viewPath: 'sass/manage/package',
  257. keepAlive: 1
  258. },
  259. {
  260. id: '701',
  261. parentId: '7',
  262. name: '权限管理',
  263. type: 1,
  264. icon: 'icongongzuotai',
  265. orderNum: 1,
  266. router: '/sass/manage/auth',
  267. viewPath: 'sass/manage/auth',
  268. keepAlive: 1
  269. }
  270. ]
  271. };