index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import { getConfig } from '@/utils/auth';
  2. import { Message, Loading } from 'element-ui';
  3. import Vue from 'vue'
  4. import Router from 'vue-router'
  5. Vue.use(Router)
  6. /**
  7. * Note: sub-menu only appear when route children.length >= 1
  8. * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
  9. *
  10. * hidden: true if set true, item will not show in the sidebar(default is false)
  11. * alwaysShow: true if set true, will always show the root menu
  12. * if not set alwaysShow, when item has more than one children route,
  13. * it will becomes nested mode, otherwise not show the root menu
  14. * redirect: noRedirect if set noRedirect will no redirect in the breadcrumb
  15. * name:'router-name' the name is used by <keep-alive> (must set!!!)
  16. * meta : {
  17. roles: ['admin','editor'] control the page roles (you can set multiple roles)
  18. title: 'title' the name show in sidebar and breadcrumb (recommend set)
  19. icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
  20. breadcrumb: false if set false, the item will hidden in breadcrumb(default is true)
  21. activeMenu: '/example/list' if set path, the sidebar will highlight the path you set
  22. }
  23. */
  24. /**
  25. * constantRoutes
  26. * a base page that does not have permission requirements
  27. * all roles can be accessed
  28. */
  29. export const constantRoutes = [{
  30. path: '/404',
  31. component: () =>
  32. import('@/views/404'),
  33. hidden: true
  34. },
  35. {
  36. path: '/login',
  37. component: () =>
  38. import('@/views/login'),
  39. hidden: true
  40. },
  41. {
  42. path: '/EnterSys',
  43. beforeEnter: (to, from, next) => {
  44. let loadingInstance = Loading.service({
  45. text: '跳转中...'
  46. });
  47. let config = getConfig();
  48. if (config) {
  49. let configObj = JSON.parse(config);
  50. let path = handleSysType(configObj.sys_type, 'home');
  51. if (path) {
  52. loadingInstance.close();
  53. if (configObj.sys_type == 'GCLS') {
  54. next(path);
  55. } else {
  56. window.location.href = path
  57. }
  58. } else {
  59. loadingInstance.close();
  60. Message({
  61. message: '此路径不存在',
  62. type: 'error',
  63. showClose: true,
  64. duration: 0
  65. })
  66. }
  67. }
  68. }
  69. },
  70. // {
  71. // path: '/',
  72. // redirect: '/EnterSys',
  73. // hidden: true
  74. // },
  75. {
  76. path: '/input',
  77. component: () =>
  78. import('@/views/input'),
  79. hidden: true
  80. },
  81. {
  82. path: '/cate',
  83. component: () =>
  84. import('@/views/catelog'),
  85. hidden: true
  86. },
  87. {
  88. path: '/input2',
  89. component: () =>
  90. import('@/views/input2'),
  91. hidden: true
  92. },
  93. {
  94. path: '/input3',
  95. component: () =>
  96. import('@/views/input3'),
  97. hidden: true
  98. },
  99. {
  100. path: '/',
  101. component: () =>
  102. import('@/views/courseList'),
  103. },
  104. {
  105. path: '/preview',
  106. component: () =>
  107. import('@/views/preview')
  108. },
  109. {
  110. path: '/login',
  111. component: () =>
  112. import('@/views/login')
  113. },
  114. {
  115. path: '/courseView',
  116. component: () =>
  117. import('@/views/courseView')
  118. },
  119. {
  120. path: '/bookView',
  121. component: () =>
  122. import('@/views/bookView')
  123. },
  124. {
  125. path: '/GoodsDetail',
  126. beforeEnter: (to, from, next) => {
  127. let loadingInstance = Loading.service({
  128. text: '跳转中...'
  129. });
  130. let config = getConfig();
  131. if (config) {
  132. let configObj = JSON.parse(config);
  133. let path = handleSysType(configObj.sys_type, 'goods');
  134. if (path) {
  135. loadingInstance.close();
  136. if (configObj.sys_type == 'GCLS') {
  137. next(path);
  138. } else {
  139. window.location.href = path
  140. }
  141. } else {
  142. loadingInstance.close();
  143. Message({
  144. message: '此路径不存在',
  145. type: 'error',
  146. showClose: true,
  147. duration: 0
  148. })
  149. }
  150. }
  151. }
  152. },
  153. {
  154. path: '/curGoodsDetail',
  155. component: () =>
  156. import('@/views/TextbookDetail')
  157. },
  158. {
  159. path: '/discountCodeList',
  160. component: () =>
  161. import('@/views/discountCodeList')
  162. },
  163. {
  164. path: '/adultInput',
  165. component: () =>
  166. import('@/views/adultInput')
  167. },
  168. {
  169. path: '/adultInput2',
  170. component: () =>
  171. import('@/views/adultInput2')
  172. },
  173. // 404 page must be placed at the end !!!
  174. { path: '*', redirect: '/', hidden: true }
  175. ]
  176. const createRouter = () =>
  177. new Router({
  178. // mode: 'history', // require service support
  179. scrollBehavior: () => ({ y: 0 }),
  180. routes: constantRoutes
  181. })
  182. const router = createRouter()
  183. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  184. export function resetRouter() {
  185. const newRouter = createRouter()
  186. router.matcher = newRouter.matcher // reset router
  187. }
  188. export function handleSysType(sys_type, path_type) {
  189. let path = '';
  190. let csArr = window.location.href.split('?');
  191. let cs = csArr[1];
  192. switch (sys_type) {
  193. case 'GCLS':
  194. console.log('全球汉语教学平台')
  195. if (path_type == 'home') {
  196. path = '/';
  197. } else if (path_type == 'goods') {
  198. path = '/curGoodsDetail?' + cs
  199. }
  200. break;
  201. case 'AILP':
  202. console.log('课后三点半')
  203. if (path_type == 'home') {
  204. path = '/GCLS-Book-AILP/#/EnterSys';
  205. } else if (path_type == 'goods') {
  206. path = '/GCLS-Book-AILP/#/GoodsDetail?' + cs;
  207. }
  208. break;
  209. default:
  210. path = '';
  211. break;
  212. }
  213. return path;
  214. }
  215. export default router