index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Store from '../store'
  4. import Cookies from 'js-cookie'
  5. import NProgress from 'nprogress' // Progress 进度条
  6. import 'nprogress/nprogress.css'// Progress 进度条样式
  7. import permissions from '@/utils/permissions'
  8. import {stringifyQuery,parseQuery} from '@/utils/query'
  9. Vue.use(VueRouter)
  10. const originalPush = VueRouter.prototype.push
  11. // VueRouter.prototype.push = function push(location) {
  12. // return originalPush.call(this, location).catch(err => err)
  13. // }
  14. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  15. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  16. return originalPush.call(this, location).catch(err => err)
  17. }
  18. const routes = [
  19. {
  20. path: "/",
  21. component: () => import('@/views/index'),
  22. },
  23. {
  24. path: '/register',
  25. name: 'Register',
  26. meta: {
  27. title: '注册'
  28. },
  29. component: () => import("@/views/register/index.vue")
  30. },
  31. {
  32. path: "",
  33. component: () => import('@/views/layout/index.vue'),
  34. children: [
  35. {
  36. path: '/home',
  37. name: 'Home',
  38. meta: {
  39. // title: '首页',
  40. sign: 'home',
  41. belong: 'home'
  42. },
  43. component: () => import('@/views/home/index.vue'),
  44. },
  45. {
  46. path: '/introduction',
  47. name: 'Introduction',
  48. meta: {
  49. // title: '首页',
  50. sign: 'introduction',
  51. belong: 'introduction'
  52. },
  53. component: () => import('@/views/home/components/downLoad/introduction/index.vue'),
  54. },
  55. {
  56. path: '/moreMessage',
  57. name: 'moreMessage',
  58. meta: {
  59. // title: '首页',
  60. sign: 'moreMessage',
  61. belong: 'moreMessage'
  62. },
  63. component: () => import('@/views/moreMessage/index.vue'),
  64. },
  65. ]
  66. }
  67. ]
  68. /* 后台管理系统Layout */
  69. import administrator_layout from '@/views/backStageManage/layout/Layout.vue'
  70. export let backStageManageRouterItem = [
  71. {
  72. path: '/administrator',
  73. component: administrator_layout,
  74. redirect: '/administrator/home',
  75. meta: { title: '首页', icon: 'home' },
  76. children: [
  77. {
  78. path: 'home',
  79. name: 'Administrator_home',
  80. component: () => import('@/views/backStageManage/home/index.vue'),
  81. meta: { title: '首页', icon: 'home' },
  82. },
  83. ],
  84. },
  85. {
  86. path: '/administrator',
  87. component: administrator_layout,
  88. redirect: '/administrator/personalMessage',
  89. meta: { title: '人员信息', icon: 'home' },
  90. hidden:true,
  91. children: [
  92. {
  93. path: 'personalMessage',
  94. name: 'Administrator_personalMessage',
  95. component: () => import('@/views/backStageManage/organization/personnel/details.vue'),
  96. meta: { title: '个人信息', icon: 'home' },
  97. hidden:true
  98. },
  99. ],
  100. },
  101. ]
  102. export const defaultBackStageManageRouterItem = [
  103. {
  104. path: '/administrator',
  105. name: 'Administrator_organization',
  106. component: administrator_layout,
  107. redirect: '/administrator/personnel',
  108. meta: { title: '人员组织管理', icon: '人员组织' },
  109. children: [
  110. {
  111. path: 'tenant',
  112. name: 'Administrator_tenant',
  113. component: () => import('@/views/backStageManage/organization/tenant/index.vue'),
  114. meta: {title: '企业管理',icon: '企业',sign:'administrator/tenant'},
  115. },
  116. {
  117. path: 'personnel',
  118. name: 'Administrator_personnel',
  119. component: () => import('@/views/backStageManage/organization/personnel/index.vue'),
  120. meta: {title: '人员清单',icon: '人员',sign:'administrator/personnel'},
  121. },
  122. {
  123. path: 'department',
  124. name: 'Administrator_department',
  125. component: () => import('@/views/backStageManage/organization/department/index.vue'),
  126. meta: {title: '部门管理',icon: '部门',sign:'administrator/department'},
  127. },
  128. {
  129. path: 'position',
  130. name: 'Administrator_position',
  131. component: () => import('@/views/backStageManage/organization/position/index.vue'),
  132. meta: {title: '职位管理',icon: '职位',sign:'administrator/position'},
  133. },
  134. {
  135. path: 'editTenant',
  136. name: 'Administrator_editTenant',
  137. component: () => import('@/views/backStageManage/organization/tenant/editTenant.vue'),
  138. meta: {title: '编辑企业信息',icon: '企业',keepAlive:true},
  139. hidden:true
  140. },
  141. {
  142. path: 'invitationMessage',
  143. name: 'Administrator_invitationMessage',
  144. component: () => import('@/views/backStageManage/organization/personnel/components/invitationMessage/index.vue'),
  145. meta: {title: '邀请人员清单',icon: '人员',sign:'administrator/invitationMessage'},
  146. hidden:true
  147. },
  148. {
  149. path: 'addDepartment',
  150. name: 'Administrator_addDepartment',
  151. component: () => import('@/views/backStageManage/organization/department/addDepartment.vue'),
  152. meta: {title: '添加部门',keepAlive:true},
  153. hidden:true
  154. },
  155. {
  156. path: 'editDepartment',
  157. name: 'Administrator_editDepartment',
  158. component: () => import('@/views/backStageManage/organization/department/editDepartment.vue'),
  159. meta: {title: '编辑部门', keepAlive:true},
  160. hidden:true
  161. },
  162. {
  163. path: 'addPosition',
  164. name: 'Administrator_addPosition',
  165. component: () => import('@/views/backStageManage/organization/position/addPosition.vue'),
  166. meta: {title: '添加职位',keepAlive:true},
  167. hidden:true
  168. },
  169. {
  170. path: 'editPosition',
  171. name: 'Administrator_editPosition',
  172. component: () => import('@/views/backStageManage/organization/position/editPosition.vue'),
  173. meta: {title: '编辑职位', keepAlive:true},
  174. hidden:true
  175. },
  176. ]
  177. },
  178. {
  179. path: '/administrator',
  180. name: 'Administrator_application',
  181. component: administrator_layout,
  182. redirect: '/administrator/vision',
  183. meta: { title: '应用管理', icon: 'application' },
  184. children: [
  185. // {
  186. // path: 'addApply',
  187. // name: 'Administrator_addApply',
  188. // component: () => import('@/views/backStageManage/application/apply/components/addApply.vue'),
  189. // meta: {title: '添加应用功能', icon: 'apply', keepAlive:true},
  190. // hidden:true
  191. // },
  192. // {
  193. // path: 'apply',
  194. // name: 'Administrator_apply',
  195. // component: () => import('@/views/backStageManage/application/apply/index.vue'),
  196. // meta: { title: '应用功能清单', icon: 'apply' }
  197. // },
  198. {
  199. path: 'function',
  200. name: 'Administrator_function',
  201. component: () => import('@/views/backStageManage/application/function/index.vue'),
  202. meta: { title: '应用功能清单', icon: '应用功能',sign:'administrator/function'}
  203. },
  204. {
  205. path: 'vision',
  206. name: 'Administrator_vision',
  207. component: () => import('@/views/backStageManage/application/vision/index.vue'),
  208. meta: { title: '应用版本管理', icon: '版本' ,sign:'administrator/vision'},
  209. },
  210. {
  211. path: 'vipType',
  212. name: 'Administrator_vipType',
  213. component: () => import('@/views/backStageManage/application/vipType/index.vue'),
  214. meta: {title: '应用会员类型', icon: '会员类型',sign:'administrator/vipType'},
  215. },
  216. {
  217. path: 'addVersion',
  218. name: 'Administrator_addVersion',
  219. component: () => import('@/views/backStageManage/application/vision/addVersion.vue'),
  220. meta: {title: '添加应用版本', icon: 'addVision',keepAlive:true},
  221. hidden:true
  222. },
  223. {
  224. path: 'editVersion',
  225. name: 'Administrator_editVersion',
  226. component: () => import('@/views/backStageManage/application/vision/editVersion.vue'),
  227. meta: {title: '编辑应用版本', icon: 'editVision',keepAlive:true},
  228. hidden:true,
  229. },
  230. {
  231. path: 'versionDetail',
  232. name: 'Administrator_versionDetail',
  233. component: () => import('@/views/backStageManage/application/vision/versionDetail.vue'),
  234. meta: {title: '应用版本详情', icon: 'editVision'},
  235. hidden:true
  236. },
  237. {
  238. path: 'addVipType',
  239. name: 'Administrator_addVipType',
  240. component: () => import('@/views/backStageManage/application/vipType/addVipType.vue'),
  241. meta: {title: '添加应用会员类型',keepAlive:true},
  242. hidden:true
  243. },
  244. {
  245. path: 'editVipType',
  246. name: 'Administrator_editVipType',
  247. component: () => import('@/views/backStageManage/application/vipType/editVipType.vue'),
  248. meta: {title: '编辑应用会员类型', keepAlive:true},
  249. hidden:true
  250. },
  251. {
  252. path: 'vipTypeDetail',
  253. name: 'Administrator_vipTypeDetail',
  254. component: () => import('@/views/backStageManage/application/vipType/vipTypeDetail.vue'),
  255. meta: {title: '应用会员类型详情'},
  256. hidden:true
  257. },
  258. ]
  259. },
  260. {
  261. path: '/administrator',
  262. name: 'Administrator_goodsManage',
  263. component: administrator_layout,
  264. redirect: '/administrator/goods',
  265. meta: { title: '商品管理', icon: '商品管理'},
  266. children: [
  267. {
  268. path: 'goods',
  269. name: 'Administrator_goods',
  270. component: () => import('@/views/backStageManage/goods/goods/index.vue'),
  271. meta: {title: '商品管理', icon: '商品管理',sign:'administrator/goods'},
  272. },
  273. {
  274. path: 'addGoods',
  275. name: 'Administrator_addGoods',
  276. component: () => import('@/views/backStageManage/goods/goods/addGoods.vue'),
  277. meta: {title: '添加商品',keepAlive:true},
  278. hidden:true
  279. },
  280. {
  281. path: 'editGoods',
  282. name: 'Administrator_editGoods',
  283. component: () => import('@/views/backStageManage/goods/goods/editGoods.vue'),
  284. meta: {title: '修改商品', keepAlive:true},
  285. hidden:true
  286. },
  287. {
  288. path: 'goodsDetails',
  289. name: 'Administrator_goodsDetails',
  290. component: () => import('@/views/backStageManage/goods/goods/goodsDetails.vue'),
  291. meta: {title: '商品详情'},
  292. hidden:true
  293. },
  294. ]
  295. },
  296. {
  297. path: '/administrator',
  298. name: 'Administrator_paymentAndStat',
  299. component: administrator_layout,
  300. redirect: '/administrator/paymentRecord',
  301. meta: { title: '支付与统计', icon: 'shouzhitongji'},
  302. children: [
  303. {
  304. path: 'paymentRecord',
  305. name: 'Administrator_paymentRecord',
  306. component: () => import('@/views/backStageManage/paymentAndStat/paymentRecord/index.vue'),
  307. meta: {title: '支付记录', icon: 'zhifujilu',sign:'administrator/payRecord'},
  308. },
  309. {
  310. path: 'statPayRecord',
  311. name: 'Administrator_statPayRecord',
  312. component: () => import('@/views/backStageManage/paymentAndStat/statPayRecord/index.vue'),
  313. meta: {title: '支付统计', icon: 'zijinzhifutongjibaobiao',sign:'administrator/payCount'},
  314. },
  315. ]
  316. },
  317. {
  318. path: '/administrator',
  319. name: 'Administrator_paymentCodeManage',
  320. component: administrator_layout,
  321. redirect: '/administrator/paymentCode',
  322. meta: { title: '付费码管理', icon: '付费'},
  323. children: [
  324. {
  325. path: 'paymentCode',
  326. name: 'Administrator_paymentCode',
  327. component: () => import('@/views/backStageManage/paymentCode/paymentCode/index.vue'),
  328. meta: {title: '付费码管理', icon: '付费',sign:'administrator/paymentCode'},
  329. },
  330. {
  331. path: 'addPaymentCode',
  332. name: 'Administrator_addPaymentCode',
  333. component: () => import('@/views/backStageManage/paymentCode/paymentCode/addPaymentCode.vue'),
  334. meta: {title: '添加付费码',keepAlive:true},
  335. hidden:true
  336. },
  337. {
  338. path: 'editPaymentCode',
  339. name: 'Administrator_editPaymentCode',
  340. component: () => import('@/views/backStageManage/paymentCode/paymentCode/editPaymentCode.vue'),
  341. meta: {title: '编辑付费码', keepAlive:true},
  342. hidden:true
  343. },
  344. {
  345. path: 'paymentCodeDetail',
  346. name: 'Administrator_paymentCodeDetail',
  347. component: () => import('@/views/backStageManage/paymentCode/paymentCode/paymentCodeDetail.vue'),
  348. meta: {title: '付费码详情'},
  349. hidden:true
  350. },
  351. ]
  352. },
  353. {
  354. path: '/administrator',
  355. name: 'Administrator_examine',
  356. component: administrator_layout,
  357. redirect: '/administrator/examine',
  358. meta: { title: '审核管理', icon: '审核'},
  359. children: [
  360. {
  361. path: 'examine',
  362. name: 'Administrator_examine',
  363. component: () => import('@/views/backStageManage/examine/examine/index.vue'),
  364. meta: {title: '审核任务', icon: '审核',sign:'administrator/examine'},
  365. },
  366. ]
  367. },
  368. ]
  369. export const backStageManage = [
  370. {
  371. path: '/administrator',
  372. name: 'Administrator',
  373. component: { render(c) { return c('router-view') } },
  374. redirect: '/administrator',
  375. children: [
  376. {
  377. path: '/',
  378. name: 'Administrator_Index',
  379. meta: {
  380. title: '后台管理',
  381. notLogin:true
  382. },
  383. component: () => import('@/views/backStageManage/index/index.vue'),
  384. },
  385. {
  386. path: 'login',
  387. name: 'Administrator_login',
  388. meta: {
  389. title: '后台管理-登录',
  390. notLogin:true
  391. },
  392. component: () => import('@/views/backStageManage/login/index.vue'),
  393. },
  394. {
  395. path: 'register',
  396. name: 'Administrator_register',
  397. meta: {
  398. title: '后台管理-企业注册',
  399. notLogin:true
  400. },
  401. component: () => import('@/views/backStageManage/login/component/register.vue'),
  402. },
  403. {
  404. path: '/administrator',
  405. component: administrator_layout,
  406. redirect: '/administrator/403',
  407. meta: { title: '错误访问' },
  408. children: [
  409. {
  410. path: '403',
  411. name:'Administrator_403',
  412. meta: {
  413. title: '无权限',
  414. },
  415. hidden:true,
  416. component: () => import('@/views/errorPage/403.vue'),
  417. },
  418. ],
  419. },
  420. ...backStageManageRouterItem
  421. ]
  422. }
  423. ]
  424. const router = new VueRouter({
  425. mode: 'history',
  426. base: '/',
  427. stringifyQuery: stringifyQuery, // 序列化query参数
  428. parseQuery: parseQuery, // 反序列化query参数
  429. routes: [...routes, ...backStageManage]
  430. })
  431. router.beforeEach((to, from, next) => {
  432. NProgress.start()
  433. if (to.meta.title) {
  434. document.title = to.meta.title;
  435. }
  436. if (to.path == '/administrator/login'|| routeExists(routes,to.path) || to.meta.notLogin) {
  437. if(to.path == '/administrator/login'){
  438. Cookies.remove("token")
  439. Store.commit('SET_PERMISSION',null)
  440. localStorage.removeItem('vuex')
  441. sessionStorage.removeItem('showMessage')
  442. }
  443. next()
  444. }
  445. else {
  446. const tokenStr = Cookies.get('token')
  447. switch (tokenStr) {
  448. case undefined:
  449. if (to.meta.title) {
  450. document.title = to.meta.title;
  451. }
  452. next({ name: 'Administrator_login' })
  453. break;
  454. default:
  455. if(Store.getters.permission === null){
  456. Store.dispatch('getPersonPermission').then(response=>{
  457. var permission = response.data
  458. // if(permission.length>0){}
  459. setRoutePermission(permission).then(() => { // 生成可访问的路由表
  460. backStageManageRouterItem = backStageManageRouterItem.concat(Store.state.permission.addRouters)
  461. router.addRoutes(Store.state.permission.addRouters); // 动态添加可访问路由表
  462. next({ ...to, replace: true })
  463. })
  464. }).catch(error=>{
  465. next()
  466. })
  467. }else{
  468. if(to.meta.sign && !permissions.FunPermissions(to.meta.sign)){
  469. next({ name: 'Administrator_403' })
  470. }else{
  471. next()
  472. }
  473. }
  474. break;
  475. }
  476. }
  477. })
  478. function setRoutePermission(data){
  479. return new Promise((resolve, reject)=>{
  480. if(permissions.hasPermission([1,3])){
  481. Store.commit('SET_ROUTERS', defaultBackStageManageRouterItem);
  482. resolve();
  483. return
  484. }
  485. var addRouters = []
  486. for(var i = 0;i<defaultBackStageManageRouterItem.length;i++){
  487. var item = defaultBackStageManageRouterItem[i]
  488. if(item.meta.sign){
  489. var index = data.indexOf(item.meta.sign)
  490. if(index == -1){
  491. continue;
  492. }
  493. }
  494. var childrenRouter = []
  495. if(item.children && item.children.length){
  496. childrenRouter = item.children.filter(child=>{
  497. return !child.meta.sign || data.indexOf(child.meta.sign) != -1
  498. })
  499. }
  500. item.children = childrenRouter
  501. if(item.children.length>0){
  502. var child = item.children.find(i=>{
  503. return !i.hidden
  504. })
  505. if(child){
  506. item.redirect = item.path + '/' +child.path
  507. }else{
  508. item.children = []
  509. }
  510. }
  511. if(item.meta.sign || item.children.length>0){
  512. addRouters.push(item)
  513. }
  514. }
  515. Store.commit('SET_ROUTERS', addRouters);
  516. resolve();
  517. })
  518. }
  519. function routeExists(array, path, parentPath) {
  520. for (var i = 0; i < array.length; i++) {
  521. var item = array[i]
  522. var nowPath = item.path
  523. if (item.path.indexOf('/') != 0) {
  524. nowPath = parentPath + '/' + nowPath
  525. }
  526. if (!item.children || item.children.length == 0) {
  527. if (path == nowPath) {
  528. return true
  529. }
  530. } else {
  531. var data = item.children
  532. var sign = routeExists(data, path, nowPath)
  533. if (sign) {
  534. return true
  535. }
  536. }
  537. }
  538. return false
  539. }
  540. // 在你的路由配置文件中
  541. router.afterEach((to, from) => {
  542. NProgress.done()
  543. var sign = routeExists(backStageManageRouterItem, to.path)
  544. if (!sign) {
  545. return
  546. }
  547. var obj = {
  548. name: to.meta.title,
  549. path: to.path,
  550. route: {
  551. name: to.name,
  552. path: to.path,
  553. query: to.query,
  554. params: to.params
  555. }
  556. }
  557. Store.commit('addHistory', obj);
  558. Store.commit('addHistoryPath', to.path);
  559. });
  560. export default router