menu.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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: '48',
  112. // parentId: '47',
  113. // name: '文档',
  114. // type: 1,
  115. // icon: 'icon-favorfill',
  116. // orderNum: 0,
  117. // router: '/tutorial/doc',
  118. // viewPath: 'https://docs.x-admin.com/#/',
  119. // keepAlive: 1
  120. // },
  121. // 工作台
  122. // {
  123. // id: '1',
  124. // parentId: null,
  125. // name: '工作台',
  126. // type: 0,
  127. // icon: 'icongongzuotai',
  128. // orderNum: 1,
  129. // router: '/',
  130. // viewPath: null,
  131. // keepAlive: 1
  132. // },
  133. // 商家管理
  134. {
  135. id: '1',
  136. parentId: null,
  137. name: '商家管理',
  138. type: 0,
  139. icon: 'icongongzuotai',
  140. orderNum: 1,
  141. router: '/sass/shop-list',
  142. viewPath: null,
  143. keepAlive: 1
  144. },
  145. {
  146. id: '11',
  147. parentId: '1',
  148. name: '商家列表',
  149. type: 1,
  150. icon: 'icongongzuotai',
  151. orderNum: 1,
  152. router: '/sass/merchant/merchant-list',
  153. viewPath: 'sass/shop/list',
  154. keepAlive: 1
  155. },
  156. {
  157. id: '12',
  158. parentId: '1',
  159. name: '申请记录',
  160. type: 1,
  161. icon: 'icongongzuotai',
  162. orderNum: 1,
  163. router: '/sass/merchant/apply-list',
  164. viewPath: 'sass/shop/apply',
  165. keepAlive: 1
  166. },
  167. {
  168. id: '13',
  169. parentId: '1',
  170. name: '小程序',
  171. type: 1,
  172. icon: 'icongongzuotai',
  173. orderNum: 1,
  174. router: '/sass/merchant/upgrade',
  175. viewPath: 'sass/shop/upgrade',
  176. keepAlive: 1
  177. },
  178. {
  179. id: '14',
  180. parentId: '1',
  181. name: '门店管理',
  182. type: 1,
  183. icon: 'icongongzuotai',
  184. orderNum: 1,
  185. router: '/sass/merchant/shop-list',
  186. viewPath: 'sass/shop/shop',
  187. keepAlive: 1
  188. },
  189. {
  190. id: '14',
  191. parentId: '1',
  192. name: '付费订单',
  193. type: 1,
  194. icon: 'icongongzuotai',
  195. orderNum: 1,
  196. router: '/sass/merchant/buy-list',
  197. viewPath: 'sass/shop/buy',
  198. keepAlive: 1
  199. },
  200. // 订单管理
  201. {
  202. id: '2',
  203. parentId: null,
  204. name: '订单管理',
  205. type: 1,
  206. icon: 'icongongzuotai',
  207. orderNum: 1,
  208. router: '/sass/order/list',
  209. viewPath: 'sass/order/list',
  210. keepAlive: 1
  211. },
  212. // 商家客户
  213. {
  214. id: '3',
  215. parentId: null,
  216. name: '商家客户',
  217. type: 1,
  218. icon: 'icongongzuotai',
  219. orderNum: 1,
  220. router: '/sass/member/list',
  221. viewPath: 'sass/member/list',
  222. keepAlive: 1
  223. },
  224. // 平台客户
  225. {
  226. id: '4',
  227. parentId: null,
  228. name: '店长管理',
  229. type: 1,
  230. icon: 'icongongzuotai',
  231. orderNum: 1,
  232. router: '/sass/pt-member/list',
  233. viewPath: 'sass/pt-member/list',
  234. keepAlive: 1
  235. },
  236. // 商家商品
  237. {
  238. id: '5',
  239. parentId: null,
  240. name: '商家商品',
  241. type: 1,
  242. icon: 'icongongzuotai',
  243. orderNum: 1,
  244. router: '/sass/goods/list',
  245. viewPath: 'sass/goods/list',
  246. keepAlive: 1
  247. },
  248. // 节日管理
  249. {
  250. id: '6',
  251. parentId: null,
  252. name: '节日列表',
  253. type: 1,
  254. icon: 'icongongzuotai',
  255. orderNum: 1,
  256. router: '/sass/fest/list',
  257. viewPath: 'sass/fest/list',
  258. keepAlive: 1
  259. },
  260. // 套餐管理
  261. {
  262. id: '7',
  263. parentId: null,
  264. name: '套餐管理',
  265. type: 0,
  266. icon: 'icongongzuotai',
  267. orderNum: 1,
  268. router: '/sass/manage/list',
  269. viewPath: 'sass/manage/list',
  270. keepAlive: 1
  271. },
  272. {
  273. id: '701',
  274. parentId: '7',
  275. name: '套餐列表',
  276. type: 1,
  277. icon: 'icongongzuotai',
  278. orderNum: 1,
  279. router: '/sass/manage/package',
  280. viewPath: 'sass/manage/package',
  281. keepAlive: 1
  282. },
  283. {
  284. id: '701',
  285. parentId: '7',
  286. name: '权限管理',
  287. type: 1,
  288. icon: 'icongongzuotai',
  289. orderNum: 1,
  290. router: '/sass/manage/auth',
  291. viewPath: 'sass/manage/auth',
  292. keepAlive: 1
  293. }
  294. ]
  295. };