index.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. const loadingInstance = Loading.service({
  45. text: '跳转中...'
  46. })
  47. const config = getConfig()
  48. if (config) {
  49. const configObj = JSON.parse(config)
  50. const 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: '/input2',
  83. component: () =>
  84. import ('@/views/input2'),
  85. hidden: true
  86. },
  87. {
  88. path: '/input3',
  89. component: () =>
  90. import ('@/views/input3'),
  91. hidden: true
  92. },
  93. {
  94. path: '/',
  95. component: () =>
  96. import ('@/views/courseList')
  97. },
  98. {
  99. path: '/preview',
  100. component: () =>
  101. import ('@/views/preview')
  102. },
  103. {
  104. path: '/login',
  105. component: () =>
  106. import ('@/views/login')
  107. },
  108. {
  109. path: '/courseView',
  110. component: () =>
  111. import ('@/views/courseView')
  112. },
  113. {
  114. path: '/bookView',
  115. component: () =>
  116. import ('@/views/bookView')
  117. },
  118. {
  119. path: '/GoodsDetail',
  120. beforeEnter: (to, from, next) => {
  121. const loadingInstance = Loading.service({
  122. text: '跳转中...'
  123. })
  124. const config = getConfig()
  125. if (config) {
  126. const configObj = JSON.parse(config)
  127. const path = handleSysType(configObj.sys_type, 'goods')
  128. if (path) {
  129. loadingInstance.close()
  130. if (configObj.sys_type == 'GCLS') {
  131. next(path)
  132. } else {
  133. if (configObj.sys_type == 'NPC' || configObj.sys_type == 'NNPE' || configObj.sys_type == 'RLC') {
  134. if (path.indexOf('/curGoodsDetail') > -1) {
  135. next(path)
  136. } else {
  137. window.location.href = path
  138. }
  139. } else {
  140. window.location.href = path
  141. }
  142. }
  143. } else {
  144. loadingInstance.close()
  145. Message({
  146. message: '此路径不存在',
  147. type: 'error',
  148. showClose: true,
  149. duration: 0
  150. })
  151. }
  152. }
  153. }
  154. },
  155. {
  156. path: '/curGoodsDetail',
  157. component: () =>
  158. import ('@/views/TextbookDetail')
  159. },
  160. {
  161. path: '/discountCodeList',
  162. component: () =>
  163. import ('@/views/discountCodeList')
  164. },
  165. {
  166. path: '/adultInput',
  167. component: () =>
  168. import ('@/views/adultInput')
  169. },
  170. {
  171. path: '/adultInput2',
  172. component: () =>
  173. import ('@/views/adultInput2')
  174. },
  175. {
  176. path: '/BookBrowsing',
  177. name: 'BookBrowsing',
  178. component: () =>
  179. import ('@/views/BookView2')
  180. },
  181. {
  182. path: '/TextbookDetailPdf',
  183. name: 'TextbookDetailPdf',
  184. component: () =>
  185. import ('@/views/textbook-detail/TextbookDetailPdf')
  186. },
  187. {
  188. path: '/TextbookDetailVideo',
  189. name: 'TextbookDetailVideo',
  190. component: () =>
  191. import ('@/views/textbook-detail/TextbookDetailVideo')
  192. },
  193. {
  194. path: '/Integration/Courseware',
  195. name: 'courseware',
  196. component: () =>
  197. import ('@/views/courseWare')
  198. },
  199. // 404 page must be placed at the end !!!
  200. { path: '*', redirect: '/', hidden: true }
  201. ]
  202. const createRouter = () =>
  203. new Router({
  204. // mode: 'history', // require service support
  205. scrollBehavior: () => ({ y: 0 }),
  206. routes: constantRoutes
  207. })
  208. const router = createRouter()
  209. // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
  210. export function resetRouter() {
  211. const newRouter = createRouter()
  212. router.matcher = newRouter.matcher // reset router
  213. }
  214. export function handleSysType(sys_type, path_type) {
  215. let path = ''
  216. const csArr = window.location.href.split('?')
  217. const cs = csArr[1]
  218. switch (sys_type) {
  219. case 'GCLS':
  220. console.log('全球汉语教学平台')
  221. if (path_type == 'home') {
  222. path = '/'
  223. } else if (path_type == 'goods') {
  224. path = '/curGoodsDetail?' + cs
  225. }
  226. break
  227. case 'NPC':
  228. if (path_type == 'home') {
  229. path = '/GCLS-Book-Component-NPC/#/EnterSys'
  230. } else if (path_type == 'goods') {
  231. // path = '/GCLS-Book-Component-NPC/#/GoodsDetail?' + cs
  232. path = '/curGoodsDetail?' + cs
  233. }
  234. break
  235. case 'NNPE':
  236. if (path_type == 'home') {
  237. path = '/GCLS-Book-Component-NNPE/#/EnterSys'
  238. } else if (path_type == 'goods') {
  239. // path = '/GCLS-Book-Component-NNPE/#/GoodsDetail?' + cs;
  240. path = '/curGoodsDetail?' + cs
  241. }
  242. break
  243. case 'RLC':
  244. if (path_type == 'home') {
  245. path = '/GCLS-Book-Component-RLC/#/EnterSys'
  246. } else if (path_type == 'goods') {
  247. // path = '/GCLS-Book-Component-NNPE/#/GoodsDetail?' + cs;
  248. path = '/curGoodsDetail?' + cs
  249. }
  250. break
  251. case 'AILP':
  252. console.log('课后三点半')
  253. if (path_type == 'home') {
  254. path = '/GCLS-Book-AILP/#/EnterSys'
  255. } else if (path_type == 'goods') {
  256. path = '/GCLS-Book-AILP/#/GoodsDetail?' + cs
  257. }
  258. break
  259. default:
  260. path = ''
  261. break
  262. }
  263. return path
  264. }
  265. export default router