router.ts 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * @Author: wanglj wanglijie@dashoo.cn
  3. * @Date: 2025-03-10 11:40:15
  4. * @LastEditors: wanglj wanglijie@dashoo.cn
  5. * @LastEditTime: 2025-04-16 10:58:21
  6. * @FilePath: \vue3-ts\src\router.ts
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import { createRouter, createWebHistory } from 'vue-router'
  10. import { Local } from './utils/storage'
  11. import { useUserInfo } from '/@/stores/userInfo'
  12. import { showDialog } from 'vant'
  13. const routes = [
  14. {
  15. name: 'notFound',
  16. path: '/:path(.*)+',
  17. redirect: {
  18. name: 'home'
  19. }
  20. },
  21. {
  22. name: 'login',
  23. path: '/login',
  24. component: () => import('/@/view/login/index.vue'),
  25. meta: {
  26. title: '登录'
  27. }
  28. },
  29. {
  30. name: 'register',
  31. path: '/register',
  32. component: () => import('/@/view/register/index.vue'),
  33. meta: {
  34. title: '注册'
  35. }
  36. },
  37. {
  38. name: 'instrList',
  39. path: '/instr-list',
  40. component: () => import('/@/view/instr/list.vue'),
  41. meta: {
  42. title: '仪器列表'
  43. }
  44. },
  45. {
  46. name: 'instrFollow',
  47. path: '/instr-follow',
  48. component: () => import('/@/view/instr/list-follow.vue'),
  49. meta: {
  50. title: '关注仪器'
  51. }
  52. },
  53. {
  54. name: 'instrDetail',
  55. path: '/instr-detail',
  56. component: () => import('/@/view/instr/detail.vue'),
  57. meta: {
  58. title: '仪器详情'
  59. }
  60. },
  61. {
  62. name: 'instrAppoint',
  63. path: '/instr-appoint',
  64. component: () => import('/@/view/instr/appoint.vue'),
  65. meta: {
  66. title: '仪器预约'
  67. }
  68. },
  69. {
  70. name: 'instrCalendar',
  71. path: '/instr-calendar',
  72. component: () => import('/@/view/instr/calendar.vue'),
  73. meta: {
  74. title: '预约日历'
  75. }
  76. },
  77. {
  78. name: 'appointInfo',
  79. path: '/instr-appoint-record',
  80. component: () => import('/@/view/instr/appointList/index.vue'),
  81. meta: {
  82. title: '预约详情'
  83. }
  84. },
  85. {
  86. name: 'onlineInfo',
  87. path: '/onlineInfo',
  88. component: () => import('/@/view/instr/appointList/onlineInfo/index.vue'),
  89. meta: {
  90. title: '上机详情'
  91. }
  92. },
  93. {
  94. name: 'appoint',
  95. path: '/inst/appoint',
  96. component: () => import('/@/view/instr/appoint/index.vue'),
  97. meta: {
  98. title: '仪器预约'
  99. }
  100. },
  101. {
  102. name: 'approvalDetail',
  103. path: '/todo/detail',
  104. component: () => import('/@/view/todo/detail.vue'),
  105. meta: {
  106. title: '审批详情'
  107. }
  108. },
  109. {
  110. name: 'entryDetail',
  111. path: '/entry/detail',
  112. component: () => import('/@/view/entry/detail.vue'),
  113. meta: {
  114. title: '入室详情'
  115. }
  116. },
  117. {
  118. path: '/',
  119. redirect: '/login',
  120. component: () => import('/@/layout/index.vue'),
  121. children: [
  122. {
  123. name: 'home',
  124. path: '/home',
  125. component: () => import('/@/view/home/index.vue'),
  126. meta: {
  127. title: '首页'
  128. }
  129. },
  130. {
  131. name: 'service',
  132. path: '/service',
  133. component: () => import('/@/view/service/index.vue'),
  134. meta: {
  135. title: '服务'
  136. }
  137. },
  138. {
  139. name: 'todo',
  140. path: '/todo',
  141. component: () => import('/@/view/todo/index.vue'),
  142. meta: {
  143. title: '待办事项'
  144. }
  145. },
  146. {
  147. name: 'notice',
  148. path: '/notice',
  149. component: () => import('/@/view/notice/index.vue'),
  150. meta: {
  151. title: '通知公告'
  152. }
  153. },
  154. {
  155. name: 'noticeDetail',
  156. path: '/notice/detail',
  157. component: () => import('/@/view/notice/detail.vue'),
  158. meta: {
  159. title: '通知详情'
  160. }
  161. },
  162. {
  163. name: 'user',
  164. path: '/user',
  165. component: () => import('/@/view/user/index.vue'),
  166. meta: {
  167. title: '个人中心'
  168. }
  169. },
  170. {
  171. name: 'userEdit',
  172. path: '/user/edit',
  173. component: () => import('/@/view/user/edit.vue'),
  174. meta: {
  175. title: '个人信息编辑'
  176. }
  177. },
  178. {
  179. name: 'userPassword',
  180. path: '/user/password',
  181. component: () => import('/@/view/user/password.vue'),
  182. meta: {
  183. title: '修改密码'
  184. }
  185. }
  186. ]
  187. },
  188. {
  189. path: '/',
  190. redirect: '/login',
  191. component: () => import('/@/layout/entry.vue'),
  192. children: [
  193. {
  194. name: 'entry',
  195. path: '/entry',
  196. component: () => import('/@/view/entry/index.vue'),
  197. meta: {
  198. title: '入室申请'
  199. }
  200. },
  201. {
  202. name: 'entryManage',
  203. path: '/entry/manage',
  204. component: () => import('/@/view/entry/manage.vue'),
  205. meta: {
  206. title: '入室管理'
  207. }
  208. },
  209. {
  210. name: 'entryMine',
  211. path: '/entry/mine',
  212. component: () => import('/@/view/entry/mine.vue'),
  213. meta: {
  214. title: '我的入室'
  215. }
  216. },
  217. {
  218. name: 'entryAppoint',
  219. path: '/entry/appoint',
  220. component: () => import('/@/view/entry/appoint.vue'),
  221. meta: {
  222. title: '入室预约'
  223. }
  224. },
  225. {
  226. name: 'entryAdd',
  227. path: '/entry/add',
  228. component: () => import('/@/view/entry/add.vue'),
  229. // component: () => import('/@/view/entry/index.vue'),
  230. meta: {
  231. title: '新增入室申请'
  232. }
  233. }
  234. ]
  235. },
  236. {
  237. path: '/',
  238. redirect: '/login',
  239. component: () => import('/@/layout/animal.vue'),
  240. children: [
  241. {
  242. name: 'myCage',
  243. path: '/my-cage',
  244. component: () => import('/@/view/animal/myCage/index.vue'),
  245. meta: {
  246. title: '我的笼位'
  247. }
  248. },
  249. {
  250. name: 'animalApplication',
  251. path: '/animal-application',
  252. component: () => import('/@/view/animal/application/index.vue'),
  253. meta: {
  254. title: '笼位申请'
  255. }
  256. },
  257. {
  258. name: 'animalReturn',
  259. path: '/animal-return',
  260. component: () => import('/@/view/animal/return/index.vue'),
  261. meta: {
  262. title: '笼位退还'
  263. }
  264. }
  265. ]
  266. },
  267. {
  268. path: '/',
  269. redirect: '/login',
  270. component: () => import('/@/layout/training.vue'),
  271. children: [
  272. {
  273. name: 'training',
  274. path: '/training',
  275. component: () => import('/@/view/training/index.vue'),
  276. meta: {
  277. title: '全部培训'
  278. }
  279. },
  280. {
  281. name: 'trainingDone',
  282. path: '/training/done',
  283. component: () => import('/@/view/training/done.vue'),
  284. meta: {
  285. title: '我的培训'
  286. }
  287. },
  288. {
  289. name: 'trainingEnroll',
  290. path: '/training/enroll',
  291. component: () => import('/@/view/training/enroll.vue'),
  292. meta: {
  293. title: '培训报名'
  294. }
  295. },
  296. {
  297. name: 'examMine',
  298. path: '/exam/mine',
  299. component: () => import('/@/view/exam/mine.vue'),
  300. meta: {
  301. title: '我的考试'
  302. }
  303. },
  304. {
  305. name: 'examResult',
  306. path: '/exam/result',
  307. component: () => import('/@/view/exam/result.vue'),
  308. meta: {
  309. title: '考试成绩'
  310. }
  311. }
  312. ]
  313. },
  314. {
  315. name: 'trainingDetail',
  316. path: '/training/detail',
  317. component: () => import('/@/view/training/detail.vue'),
  318. meta: {
  319. title: '培训详情'
  320. }
  321. },
  322. {
  323. name: 'examCover',
  324. path: '/exam/cover',
  325. component: () => import('/@/view/exam/cover.vue'),
  326. meta: {
  327. title: '开始考试'
  328. }
  329. },
  330. {
  331. name: 'exam',
  332. path: '/exam',
  333. component: () => import('/@/view/exam/index.vue'),
  334. meta: {
  335. title: '在线考试'
  336. }
  337. }
  338. ]
  339. const router = createRouter({
  340. routes: routes as any[],
  341. history: createWebHistory()
  342. })
  343. const whiteList = ['/login', '/register', '/training', '/training/enroll']
  344. router.beforeEach(async (to, from, next) => {
  345. const storesUseUserInfo = useUserInfo()
  346. // // 微信授权码获取openId
  347. // const code = to.query.code
  348. // if (!storesUseUserInfo.openId && code) {
  349. // if (typeof code === 'string') {
  350. // storesUseUserInfo.setOpenId(code)
  351. // }
  352. // }
  353. const title = to?.meta?.title
  354. if (title) {
  355. document.title = title as string
  356. }
  357. const token = Local.get('token')
  358. if (whiteList.indexOf(to.path) > -1 && !token) {
  359. next()
  360. } else {
  361. if (!token) {
  362. next({
  363. path: '/login',
  364. query: to.query
  365. })
  366. } else {
  367. if (!storesUseUserInfo.userInfos.id) {
  368. await storesUseUserInfo.setUserInfos()
  369. }
  370. if (to.path == '/login') {
  371. const code = to.query.code
  372. storesUseUserInfo.setOpenId(code as string)
  373. next('/home')
  374. }
  375. next()
  376. }
  377. }
  378. })
  379. export default router