index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import {autoSaveAuth} from "@/api/AdminAuth"
  4. Vue.use(Router)
  5. /* Layout */
  6. import Layout from '@/layout'
  7. /* Router Modules */
  8. // import componentsRouter from './modules/components'
  9. // import chartsRouter from './modules/charts'
  10. // import tableRouter from './modules/table'
  11. // import nestedRouter from './modules/nested'
  12. /**
  13. * Note: sub-menu only appear when route children.length >= 1
  14. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  15. *
  16. * hidden: true if set true, item will not show in the sidebar(default is false)
  17. * alwaysShow: true if set true, will always show the root menu
  18. * if not set alwaysShow, when item has more than one children route,
  19. * it will becomes nested mode, otherwise not show the root menu
  20. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  21. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  22. * meta : {
  23. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  24. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  25. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  26. noCache: true if set true, the page will no be cached(default is false)
  27. affix: true if set true, the tag will affix in the tags-view
  28. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  29. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  30. }
  31. */
  32. /**
  33. * constantRoutes
  34. * a base page that does not have permission requirements
  35. * all roles can be accessed
  36. */
  37. export const constantRoutes = [
  38. {
  39. path: '/redirect',
  40. component: Layout,
  41. hidden: true,
  42. children: [
  43. {
  44. path: '/redirect/:path(.*)',
  45. component: () => import('@/views/redirect/index')
  46. }
  47. ]
  48. },
  49. {
  50. path: '/login',
  51. component: () => import('@/views/login/index'),
  52. hidden: true
  53. },
  54. {
  55. path: '/auth-redirect',
  56. component: () => import('@/views/login/auth-redirect'),
  57. hidden: true
  58. },
  59. {
  60. path: '/404',
  61. component: () => import('@/views/error-page/404'),
  62. hidden: true
  63. },
  64. {
  65. path: '/401',
  66. component: () => import('@/views/error-page/401'),
  67. hidden: true
  68. },
  69. {
  70. path: '/',
  71. component: Layout,
  72. redirect: '/dashboard',
  73. children: [
  74. {
  75. path: 'dashboard',
  76. component: () => import('@/views/dashboard/index'),
  77. name: 'Dashboard',
  78. meta: { title: '用户首页', icon: 'dashboard', affix: true }
  79. }
  80. ]
  81. },
  82. {
  83. path: '/profile',
  84. component: Layout,
  85. redirect: '/profile/index',
  86. hidden: true,
  87. children: [
  88. {
  89. path: 'index',
  90. component: () => import('@/views/profile/index'),
  91. name: 'Profile',
  92. meta: { title: 'Profile', icon: 'user', noCache: true }
  93. }
  94. ]
  95. },
  96. {
  97. path: '/document/create',
  98. component: () => import('@/views/document/create'),
  99. name: 'documentCreate',
  100. hidden:true,
  101. meta: { title: '创建文档', noCache: true }
  102. },
  103. {
  104. path: '/error',
  105. component: Layout,
  106. redirect: 'noRedirect',
  107. name: 'ErrorPages',
  108. hidden:true,
  109. meta: {
  110. title: 'Error Pages',
  111. icon: '404'
  112. },
  113. children: [
  114. {
  115. path: '401',
  116. component: () => import('@/views/error-page/401'),
  117. name: 'Page401',
  118. meta: { title: '401', noCache: true }
  119. },
  120. {
  121. path: '404',
  122. component: () => import('@/views/error-page/404'),
  123. name: 'Page404',
  124. meta: { title: '404', noCache: true }
  125. }
  126. ]
  127. }
  128. ]
  129. /**
  130. * asyncRoutes
  131. * the routes that need to be dynamically loaded based on user roles
  132. */
  133. export const asyncRoutes = [
  134. {
  135. path: '/project',
  136. component: Layout,
  137. type:1,
  138. meta: {
  139. title: '项目管理',
  140. icon: 'paizhao-01-20',
  141. roles: ['admin']
  142. },
  143. children: [
  144. {
  145. path: 'index',
  146. component: () => import('@/views/project/search'),
  147. name: 'project',
  148. meta: { title: '项目管理', noCache: true,roles: ['admin'] }
  149. },
  150. {
  151. path: 'category',
  152. component: () => import('@/views/project/category/search'),
  153. name: 'projectCategory',
  154. meta: { title: '项目分类', noCache: true ,roles: ['admin']}
  155. }
  156. ]
  157. },
  158. {
  159. path: '/customer',
  160. component: Layout,
  161. type:4,
  162. meta: {
  163. title: '客户管理',
  164. icon: 'kehu',
  165. roles: ['admin']
  166. },
  167. children: [
  168. {
  169. path: 'index',
  170. component: () => import('@/views/customer/search'),
  171. name: 'customerIndex',
  172. meta: { title: '客户管理', noCache: true,roles: ['admin'] }
  173. }
  174. ]
  175. },
  176. {
  177. path: '/product',
  178. component: Layout,
  179. type:5,
  180. meta: {
  181. title: '产品管理',
  182. icon: 'chanpin',
  183. roles: ['admin']
  184. },
  185. children: [
  186. {
  187. path: 'index',
  188. component: () => import('@/views/product/search'),
  189. name: 'product',
  190. meta: { title: '产品管理', noCache: true ,roles: ['admin']}
  191. },
  192. {
  193. path: 'category',
  194. component: () => import('@/views/product/category/search'),
  195. name: 'productCategory',
  196. meta: { title: '产品分类', noCache: true ,roles: ['admin']}
  197. },
  198. {
  199. path: '/supplier/search',
  200. component: () => import('@/views/product/supplier/search'),
  201. name: 'supplierSearch',
  202. meta: { title: '供应商管理', noCache: true ,roles: ['admin']}
  203. },
  204. {
  205. path: '/brand/search',
  206. component: () => import('@/views/product/brand/search'),
  207. name: 'brandSearch',
  208. meta: { title: '品牌设置', noCache: true ,roles: ['admin']}
  209. }
  210. ]
  211. },
  212. {
  213. path: '/document',
  214. component: Layout,
  215. type:10,
  216. meta: {
  217. title: '文档管理',
  218. icon: 'wendang'
  219. },
  220. children: [
  221. {
  222. path: 'index',
  223. component: () => import('@/views/document/search'),
  224. name: 'documentSearch',
  225. meta: { title: '文档管理', noCache: true }
  226. },
  227. {
  228. path: 'new',
  229. redirect: '/document/create',
  230. target:"_blank",
  231. name:"createNewDocument",
  232. meta: { title: '创建文档', noCache: true }
  233. },
  234. {
  235. path: 'temList',
  236. component: () => import('@/views/document/temList/temList'),
  237. name: 'documentTemList',
  238. meta: { title: '模板列表', noCache: true }
  239. },
  240. {
  241. path: 'category/search',
  242. component: () => import('@/views/document/category/search'),
  243. name: 'documentCategory',
  244. meta: { title: '文档分类', noCache: true ,roles: ['admin']}
  245. },
  246. {
  247. path: '/template/category/search',
  248. component: () => import('@/views/template/category/search'),
  249. name: 'templateCategory',
  250. meta: { title: '模块分类', noCache: true ,roles: ['admin']}
  251. },
  252. {
  253. path: '/template/search',
  254. component: () => import('@/views/template/search'),
  255. name: 'template',
  256. meta: { title: '模块列表', noCache: true ,roles: ['admin']}
  257. },
  258. {
  259. path: 'dataCenter/index',
  260. component: () => import('@/views/dataCenter/search'),
  261. name: 'dataCenter',
  262. meta: { title: '原始数据', noCache: true,roles: ['admin'] }
  263. },
  264. {
  265. path: 'dataCenter/create',
  266. component: () => import('@/views/dataCenter/create'),
  267. name: 'dataCreate',
  268. hidden:true,
  269. meta: { title: '创建原始数据', noCache: true,roles: ['admin'] }
  270. },
  271. {
  272. path: 'dataCenter/info',
  273. component: () => import('@/views/dataCenter/dataView'),
  274. name: 'dataView',
  275. hidden:true,
  276. meta: { title: '预览数据', noCache: true,roles: ['admin'] }
  277. },
  278. {
  279. path: 'dataCenter/category/index',
  280. component: () => import('@/views/dataCenter/category/search'),
  281. name: 'dataCenterCategorySearch',
  282. meta: { title: '原始数据分类', noCache: true,roles: ['admin'] }
  283. },
  284. ]
  285. },
  286. {
  287. path: '/system',
  288. component: Layout,
  289. type:21,
  290. meta: {
  291. title: '系统设置',
  292. icon: 'xitong',
  293. roles: ['admin']
  294. },
  295. children: [
  296. {
  297. path: 'user/index',
  298. component: () => import('@/views/user/search'),
  299. name: 'user',
  300. meta: { title: '用户管理', noCache: true,roles: ['admin']}
  301. },
  302. {
  303. path: 'role/index',
  304. component: () => import('@/views/role/search'),
  305. name: 'role',
  306. meta: { title: '角色权限', noCache: true,roles: ['admin'] }
  307. },
  308. {
  309. path: 'role/create',
  310. component: () => import('@/views/role/create'),
  311. name: 'createRole',
  312. hidden:true,
  313. meta: { title: '创建角色', noCache: true,roles: ['admin'] }
  314. },
  315. {
  316. path: 'role/edit',
  317. component: () => import('@/views/role/edit'),
  318. name: 'editRole',
  319. hidden:true,
  320. meta: { title: '修改角色', noCache: true,roles: ['admin'] }
  321. },
  322. {
  323. path: 'auth/index',
  324. component: () => import('@/views/auth/search'),
  325. name: 'auth',
  326. meta: { title: '权限配置', noCache: true,roles: ['admin'] }
  327. },
  328. // {
  329. // path: 'flow/index',
  330. // component: () => import('@/views/flow/search'),
  331. // name: 'flow',
  332. // meta: { title: '流程设计', noCache: true,roles: ['admin'] }
  333. // },
  334. ]
  335. }
  336. ,
  337. { path: '*', redirect: '/404', hidden: true }
  338. ]
  339. const saveRoute=(route)=>{
  340. let items=route.filter(o=>o.children!=undefined);
  341. let routes=[];
  342. items=items.map(res=>{
  343. res.children.map((subRes)=>{
  344. routes.push({
  345. code:subRes.name,
  346. name:subRes.meta.title,
  347. type:res.type==undefined?0:res.type
  348. });
  349. });
  350. })
  351. /* autoSaveAuth({data:JSON.stringify(routes)}) */
  352. }
  353. saveRoute([...asyncRoutes]);
  354. const createRouter = () => new Router({
  355. mode: 'hash', // require service support
  356. scrollBehavior: () => ({ y: 0 }),
  357. routes: constantRoutes
  358. })
  359. const router = createRouter()
  360. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  361. export function resetRouter() {
  362. const newRouter = createRouter()
  363. router.matcher = newRouter.matcher // reset router
  364. }
  365. /* const createRouter = () => new Router({
  366. mode: 'history', // require service support
  367. scrollBehavior: () => ({ y: 0 }),
  368. routes: constantRoutes
  369. })
  370. const router = createRouter()
  371. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  372. export function resetRouter() {
  373. const newRouter = createRouter()
  374. router.matcher = newRouter.matcher // reset router
  375. } */
  376. export default router