menu.js 5.5 KB

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