index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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: 'dashboards', 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: '/infoList',
  105. component: () => import('@/views/knowledgeMenu/category/infoList'),
  106. name: 'infoList',
  107. hidden:true,
  108. meta: { title: '解析块', noCache: true }
  109. },
  110. {
  111. path: '/error',
  112. component: Layout,
  113. redirect: 'noRedirect',
  114. name: 'ErrorPages',
  115. hidden:true,
  116. meta: {
  117. title: 'Error Pages',
  118. icon: '404'
  119. },
  120. children: [
  121. {
  122. path: '401',
  123. component: () => import('@/views/error-page/401'),
  124. name: 'Page401',
  125. meta: { title: '401', noCache: true }
  126. },
  127. {
  128. path: '404',
  129. component: () => import('@/views/error-page/404'),
  130. name: 'Page404',
  131. meta: { title: '404', noCache: true }
  132. }
  133. ]
  134. }
  135. ]
  136. /**
  137. * asyncRoutes
  138. * the routes that need to be dynamically loaded based on user roles
  139. */
  140. export const asyncRoutes = [
  141. /* {
  142. path: '/project',
  143. component: Layout,
  144. type:1,
  145. meta: {
  146. title: '项目管理',
  147. icon: 'paizhao-01-20',
  148. roles: ['admin']
  149. },
  150. children: [
  151. {
  152. path: 'index',
  153. component: () => import('@/views/project/search'),
  154. name: 'project',
  155. meta: { title: '项目管理', noCache: true,roles: ['admin'] }
  156. },
  157. {
  158. path: 'category',
  159. component: () => import('@/views/project/category/search'),
  160. name: 'projectCategory',
  161. meta: { title: '项目分类', noCache: true ,roles: ['admin']}
  162. }
  163. ]
  164. }, */
  165. {
  166. path: '/customer',
  167. component: Layout,
  168. type:4,
  169. meta: {
  170. title: '客户管理',
  171. icon: 'kehus',
  172. roles: ['admin']
  173. },
  174. children: [
  175. {
  176. path: 'index',
  177. component: () => import('@/views/customer/search'),
  178. name: 'customerIndex',
  179. meta: { title: '客户管理', noCache: true,roles: ['admin'] }
  180. }
  181. ]
  182. },
  183. /* {
  184. path: '/product',
  185. component: Layout,
  186. type:5,
  187. meta: {
  188. title: '产品管理',
  189. icon: 'chanpin',
  190. roles: ['admin']
  191. },
  192. children: [
  193. {
  194. path: 'index',
  195. component: () => import('@/views/product/search'),
  196. name: 'product',
  197. meta: { title: '产品管理', noCache: true ,roles: ['admin']}
  198. },
  199. {
  200. path: 'category',
  201. component: () => import('@/views/product/category/search'),
  202. name: 'productCategory',
  203. meta: { title: '产品分类', noCache: true ,roles: ['admin']}
  204. },
  205. {
  206. path: '/supplier/search',
  207. component: () => import('@/views/product/supplier/search'),
  208. name: 'supplierSearch',
  209. meta: { title: '供应商管理', noCache: true ,roles: ['admin']}
  210. },
  211. {
  212. path: '/brand/search',
  213. component: () => import('@/views/product/brand/search'),
  214. name: 'brandSearch',
  215. meta: { title: '品牌设置', noCache: true ,roles: ['admin']}
  216. }
  217. ]
  218. }, */
  219. {
  220. path: '/document',
  221. component: Layout,
  222. type:10,
  223. meta: {
  224. title: '文档管理',
  225. icon: 'wendangs'
  226. },
  227. children: [
  228. {
  229. path: 'index',
  230. component: () => import('@/views/document/search'),
  231. name: 'documentSearch',
  232. meta: { title: '文档管理', noCache: true }
  233. },
  234. /* {
  235. path: 'new',
  236. redirect: '/document/create',
  237. target:"_blank",
  238. name:"createNewDocument",
  239. meta: { title: '创建文档', noCache: true,hidden:true }
  240. }, */
  241. {
  242. path: 'category/search',
  243. component: () => import('@/views/document/category/search'),
  244. name: 'documentCategory',
  245. meta: { title: '文档分类', noCache: true ,roles: ['admin']}
  246. },
  247. {
  248. path: 'temList',
  249. component: () => import('@/views/document/temList/temList'),
  250. name: 'documentTemList',
  251. meta: { title: '模板列表', noCache: true }
  252. },
  253. {
  254. path: '/template/category/search',
  255. component: () => import('@/views/template/category/search'),
  256. name: 'templateCategory',
  257. meta: { title: '模块分类', noCache: true ,roles: ['admin']}
  258. },
  259. {
  260. path: '/template/search',
  261. component: () => import('@/views/template/search'),
  262. name: 'template',
  263. meta: { title: '模块列表', noCache: true ,roles: ['admin']}
  264. },
  265. /*{
  266. path: 'dataCenter/index',
  267. component: () => import('@/views/dataCenter/search'),
  268. name: 'dataCenter',
  269. meta: { title: '原始数据', noCache: true,roles: ['admin'] }
  270. },
  271. {
  272. path: 'dataCenter/create',
  273. component: () => import('@/views/dataCenter/create'),
  274. name: 'dataCreate',
  275. hidden:true,
  276. meta: { title: '创建原始数据', noCache: true,roles: ['admin'] }
  277. },
  278. {
  279. path: 'dataCenter/info',
  280. component: () => import('@/views/dataCenter/dataView'),
  281. name: 'dataView',
  282. hidden:true,
  283. meta: { title: '预览数据', noCache: true,roles: ['admin'] }
  284. },
  285. {
  286. path: 'dataCenter/category/index',
  287. component: () => import('@/views/dataCenter/category/search'),
  288. name: 'dataCenterCategorySearch',
  289. meta: { title: '原始数据分类', noCache: true,roles: ['admin'] }
  290. }, */
  291. ]
  292. },
  293. {
  294. path: '/knowledge',
  295. component: Layout,
  296. type:32,
  297. meta: {
  298. title: '知识库',
  299. icon: 'zhisk',
  300. roles: ['admin']
  301. },
  302. children: [
  303. {
  304. path: 'knowledgeMenu/index',
  305. component: () => import('@/views/knowledgeMenu/knowledgeList.vue'),
  306. name: 'KBM\n',
  307. meta: { title: '知识库管理', noCache: true,roles: ['admin'] }
  308. },
  309. {
  310. path: 'category/knowledgeSet',
  311. component: () => import('@/views/knowledgeMenu/category/knowledgeSet'),
  312. name: 'KBM\n_setting',
  313. hidden:true,
  314. meta: { title: '知识库配置', noCache: true ,roles: ['admin']}
  315. },
  316. /* {
  317. path: 'category/infoList',
  318. component: () => import('@/views/knowledgeMenu/category/infoList'),
  319. name: 'KBM_info',
  320. hidden:true,
  321. meta: { title: '解析块', noCache: true ,roles: ['admin']}
  322. } */
  323. ]
  324. },
  325. {
  326. path: '/applet',
  327. component: Layout,
  328. type:1,
  329. meta: {
  330. title: '小程序管理',
  331. icon: 'applets',
  332. roles: ['admin']
  333. },
  334. children: [
  335. {
  336. path: 'index',
  337. component: () => import('@/views/applet/index'),
  338. name: 'project',
  339. meta: { title: '小程序管理', noCache: true,roles: ['admin'] }
  340. },
  341. {
  342. path: 'complaint',
  343. component: () => import('@/views/applet/complaint'),
  344. name: 'complaintAndAdvice',
  345. meta: { title: '投诉建议', noCache: true,roles: ['admin'] }
  346. },
  347. ]
  348. },
  349. {
  350. path: '/system',
  351. component: Layout,
  352. type:21,
  353. meta: {
  354. title: '系统设置',
  355. icon: '系统设置',
  356. roles: ['admin']
  357. },
  358. children: [
  359. {
  360. path: 'user/index',
  361. component: () => import('@/views/user/search'),
  362. name: 'user',
  363. meta: { title: '用户管理', noCache: true,roles: ['admin']}
  364. },
  365. {
  366. path: 'role/index',
  367. component: () => import('@/views/role/search'),
  368. name: 'role',
  369. meta: { title: '角色权限', noCache: true,roles: ['admin'] }
  370. },
  371. {
  372. path: 'role/create',
  373. component: () => import('@/views/role/create'),
  374. name: 'createRole',
  375. hidden:true,
  376. meta: { title: '创建角色', noCache: true,roles: ['admin'] }
  377. },
  378. {
  379. path: 'role/edit',
  380. component: () => import('@/views/role/edit'),
  381. name: 'editRole',
  382. hidden:true,
  383. meta: { title: '修改角色', noCache: true,roles: ['admin'] }
  384. },
  385. /* {
  386. path: 'auth/index',
  387. component: () => import('@/views/auth/search'),
  388. name: 'auth',
  389. meta: { title: '权限配置', noCache: true,roles: ['admin'] }
  390. }, */
  391. // {
  392. // path: 'flow/index',
  393. // component: () => import('@/views/flow/search'),
  394. // name: 'flow',
  395. // meta: { title: '流程设计', noCache: true,roles: ['admin'] }
  396. // },
  397. ]
  398. }
  399. ,
  400. { path: '*', redirect: '/404', hidden: true }
  401. ]
  402. const saveRoute=(route)=>{
  403. let items=route.filter(o=>o.children!=undefined);
  404. let routes=[];
  405. items=items.map(res=>{
  406. res.children.map((subRes)=>{
  407. routes.push({
  408. code:subRes.name,
  409. name:subRes.meta.title,
  410. type:res.type==undefined?0:res.type
  411. });
  412. });
  413. })
  414. /* autoSaveAuth({data:JSON.stringify(routes)}) */
  415. }
  416. saveRoute([...asyncRoutes]);
  417. const createRouter = () => new Router({
  418. mode: 'hash', // require service support
  419. scrollBehavior: () => ({ y: 0 }),
  420. routes: constantRoutes
  421. })
  422. const router = createRouter()
  423. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  424. export function resetRouter() {
  425. const newRouter = createRouter()
  426. router.matcher = newRouter.matcher // reset router
  427. }
  428. /* const createRouter = () => new Router({
  429. mode: 'history', // require service support
  430. scrollBehavior: () => ({ y: 0 }),
  431. routes: constantRoutes
  432. })
  433. const router = createRouter()
  434. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  435. export function resetRouter() {
  436. const newRouter = createRouter()
  437. router.matcher = newRouter.matcher // reset router
  438. } */
  439. export default router