index.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Store from '../store'
  4. import Cookies from 'js-cookie'
  5. Vue.use(VueRouter)
  6. const originalPush = VueRouter.prototype.push
  7. VueRouter.prototype.push = function push(location) {
  8. return originalPush.call(this, location).catch(err => err)
  9. }
  10. const routes = [
  11. {
  12. path: "/",
  13. component: () => import('@/views/index'),
  14. },
  15. {
  16. path: '/register',
  17. name: 'Register',
  18. meta: {
  19. title: '注册'
  20. },
  21. component: () => import("@/views/register/index.vue")
  22. },
  23. {
  24. path: "",
  25. component: () => import('@/views/layout/index.vue'),
  26. children: [
  27. {
  28. path: '/home',
  29. name: 'Home',
  30. meta: {
  31. // title: '首页',
  32. sign: 'home',
  33. belong: 'home'
  34. },
  35. component: () => import('@/views/home/index.vue'),
  36. },
  37. ]
  38. }
  39. ]
  40. /* 后台管理系统Layout */
  41. import administrator_layout from '@/views/backStageManage/layout/Layout.vue'
  42. export const backStageManageRouterItem = [
  43. {
  44. path: '/administrator',
  45. component: administrator_layout,
  46. redirect: '/administrator/home',
  47. meta: { title: '首页', icon: 'home' },
  48. children: [
  49. {
  50. path: 'home',
  51. name: 'Administrator_home',
  52. component: () => import('@/views/backStageManage/home/index.vue'),
  53. meta: { title: '首页', icon: 'home' }
  54. },
  55. ]
  56. },
  57. {
  58. path: '/administrator',
  59. name: 'Administrator_organization',
  60. component: administrator_layout,
  61. redirect: '/administrator/personnel',
  62. meta: { title: '人员组织管理', icon: '人员组织' },
  63. children: [
  64. {
  65. path: 'tenant',
  66. name: 'Administrator_tenant',
  67. component: () => import('@/views/backStageManage/organization/tenant/index.vue'),
  68. meta: {title: '企业管理',icon: '企业'},
  69. },
  70. {
  71. path: 'personnel',
  72. name: 'Administrator_personnel',
  73. component: () => import('@/views/backStageManage/organization/personnel/index.vue'),
  74. meta: {title: '人员清单',icon: '人员'},
  75. },
  76. // {
  77. // path: 'personnel',
  78. // name: 'Administrator_personnel',
  79. // component: () => import('@/views/backStageManage/organization/personnel/index.vue'),
  80. // meta: {title: '部门管理',icon: '部门'},
  81. // },
  82. // {
  83. // path: 'personnel',
  84. // name: 'Administrator_personnel',
  85. // component: () => import('@/views/backStageManage/organization/personnel/index.vue'),
  86. // meta: {title: '职位管理',icon: '职位'},
  87. // },
  88. ]
  89. },
  90. {
  91. path: '/administrator',
  92. name: 'Administrator_application',
  93. component: administrator_layout,
  94. redirect: '/administrator/vision',
  95. meta: { title: '应用管理', icon: 'application' },
  96. children: [
  97. // {
  98. // path: 'addApply',
  99. // name: 'Administrator_addApply',
  100. // component: () => import('@/views/backStageManage/application/apply/components/addApply.vue'),
  101. // meta: {title: '添加应用功能', icon: 'apply', keepAlive:true},
  102. // hidden:true
  103. // },
  104. // {
  105. // path: 'apply',
  106. // name: 'Administrator_apply',
  107. // component: () => import('@/views/backStageManage/application/apply/index.vue'),
  108. // meta: { title: '应用功能清单', icon: 'apply' }
  109. // },
  110. {
  111. path: 'vision',
  112. name: 'Administrator_vision',
  113. component: () => import('@/views/backStageManage/application/vision/index.vue'),
  114. meta: { title: '应用版本清单', icon: '版本' }
  115. },
  116. {
  117. path: 'addVersion',
  118. name: 'Administrator_addVersion',
  119. component: () => import('@/views/backStageManage/application/vision/addVersion.vue'),
  120. meta: {title: '添加应用版本', icon: 'addVision',keepAlive:true},
  121. hidden:true
  122. },
  123. {
  124. path: 'editVersion',
  125. name: 'Administrator_editVersion',
  126. component: () => import('@/views/backStageManage/application/vision/editVersion.vue'),
  127. meta: {title: '编辑应用版本', icon: 'editVision'},
  128. hidden:true
  129. },
  130. {
  131. path: 'vip',
  132. name: 'Administrator_vip',
  133. component: () => import('@/views/backStageManage/application/vip/index.vue'),
  134. meta: {title: '应用会员类型', icon: '会员类型'}
  135. },
  136. {
  137. path: 'addVip',
  138. name: 'Administrator_addVip',
  139. component: () => import('@/views/backStageManage/application/vip/components/addVipForm.vue'),
  140. meta: {title: '添加应用会员类型', icon: 'addVip',keepAlive:true},
  141. hidden:true
  142. },
  143. {
  144. path: 'editVip',
  145. name: 'Administrator_editVip',
  146. component: () => import('@/views/backStageManage/application/vip/components/editVipForm.vue'),
  147. meta: {title: '编辑应用会员', icon: 'editVip'},
  148. hidden:true
  149. },
  150. ]
  151. },
  152. {
  153. path: '/administrator',
  154. name: 'Administrator_examine',
  155. component: administrator_layout,
  156. redirect: '/administrator/examine',
  157. meta: { title: '审核管理', icon: '审核'},
  158. children: [
  159. {
  160. path: 'examine',
  161. name: 'Administrator_examine',
  162. component: () => import('@/views/backStageManage/examine/examine/index.vue'),
  163. meta: {title: '账号审核', icon: '审核'},
  164. },
  165. ]
  166. },
  167. ]
  168. export const backStageManage = [
  169. {
  170. path: '/administrator',
  171. name: 'Administrator',
  172. component: { render(c) { return c('router-view') } },
  173. redirect: '/administrator',
  174. children: [
  175. {
  176. path: '/',
  177. name: 'Administrator_Index',
  178. meta: {
  179. title: '后台管理',
  180. },
  181. component: () => import('@/views/backStageManage/index/index.vue'),
  182. },
  183. {
  184. path: 'login',
  185. name: 'Administrator_login',
  186. meta: {
  187. title: '后台管理-登录',
  188. },
  189. component: () => import('@/views/backStageManage/login/index.vue'),
  190. },
  191. ...backStageManageRouterItem
  192. ]
  193. }
  194. ]
  195. const router = new VueRouter({
  196. mode: 'history',
  197. base: '/',
  198. routes: process.env.NODE_ENV !== 'production' ? [...routes, ...backStageManage] : routes
  199. })
  200. router.beforeEach((to, from, next) => {
  201. if (to.meta.title) {
  202. document.title = to.meta.title;
  203. }
  204. if (to.path == '/administrator/login'|| routeExists(routes,to.path) || to.meta.notLogin) {
  205. Cookies.remove("token")
  206. localStorage.removeItem('vuex')
  207. next()
  208. }
  209. else {
  210. const tokenStr = Cookies.get('token')
  211. switch (tokenStr) {
  212. case undefined:
  213. if (to.meta.title) {
  214. document.title = to.meta.title;
  215. }
  216. next({ name: 'Administrator_login' })
  217. break;
  218. default:
  219. if (to.meta.title) {
  220. document.title = to.meta.title;
  221. }
  222. next()
  223. break;
  224. }
  225. }
  226. })
  227. function routeExists(array, path, parentPath) {
  228. for (var i = 0; i < array.length; i++) {
  229. var item = array[i]
  230. var nowPath = item.path
  231. if (item.path.indexOf('/') != 0) {
  232. nowPath = parentPath + '/' + nowPath
  233. }
  234. if (!item.children || item.children.length == 0) {
  235. if (path == nowPath) {
  236. return true
  237. }
  238. } else {
  239. var data = item.children
  240. var sign = routeExists(data, path, nowPath)
  241. if (sign) {
  242. return true
  243. }
  244. }
  245. }
  246. return false
  247. }
  248. // 在你的路由配置文件中
  249. router.afterEach((to, from) => {
  250. var sign = routeExists(backStageManageRouterItem, to.path)
  251. if (!sign) {
  252. return
  253. }
  254. var obj = {
  255. name: to.meta.title,
  256. path: to.path,
  257. route: {
  258. name: to.name,
  259. path: to.path,
  260. query: to.query,
  261. params: to.params
  262. }
  263. }
  264. Store.commit('addHistory', obj);
  265. Store.commit('addHistoryPath', to.path);
  266. });
  267. export default router