router.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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: 'repairReportHome',
  103. path: '/inst/repairReport/home',
  104. component: () => import('/@/view/instr/repairReport/index.vue'),
  105. meta: {
  106. title: '仪器故障报修'
  107. }
  108. },
  109. {
  110. name: 'repairReportAdd',
  111. path: '/inst/repairReport/add',
  112. component: () => import('/@/view/instr/repairReport/add.vue'),
  113. meta: {
  114. title: '新增故障报修'
  115. }
  116. },
  117. {
  118. name: 'inspectionHome',
  119. path: '/lab/inspection/home',
  120. component: () => import('/@/view/laboratory/inspection/index.vue'),
  121. meta: {
  122. title: '巡检信息'
  123. }
  124. },
  125. {
  126. name: 'inspectionDetails',
  127. path: '/lab/inspection/details',
  128. component: () => import('/@/view/laboratory/inspection/details.vue'),
  129. meta: {
  130. title: '巡检信息详情'
  131. }
  132. },
  133. {
  134. name: 'addInspTask',
  135. path: '/lab/inspection/addInspTask',
  136. component: () => import('/@/view/laboratory/inspection/addInspTask.vue'),
  137. meta: {
  138. title: '巡检任务创建'
  139. }
  140. },
  141. {
  142. name: 'inspectionFeedback',
  143. path: '/lab/inspection/feedback',
  144. component: () => import('/@/view/laboratory/inspection/feedback.vue'),
  145. meta: {
  146. title: '隐患整改'
  147. }
  148. },
  149. {
  150. name: 'repairReportConfirm',
  151. path: '/inst/repairReport/confirm',
  152. component: () => import('/@/view/instr/repairReport/confirm.vue'),
  153. meta: {
  154. title: '确认故障报修'
  155. }
  156. },
  157. {
  158. name: 'approvalDetail',
  159. path: '/todo/detail',
  160. component: () => import('/@/view/todo/detail.vue'),
  161. meta: {
  162. title: '审批详情'
  163. }
  164. },
  165. {
  166. name: 'entryDetail',
  167. path: '/entry/detail',
  168. component: () => import('/@/view/entry/detail.vue'),
  169. meta: {
  170. title: '入室详情'
  171. }
  172. },
  173. {
  174. path: '/',
  175. redirect: '/login',
  176. component: () => import('/@/layout/index.vue'),
  177. children: [
  178. {
  179. name: 'home',
  180. path: '/home',
  181. component: () => import('/@/view/home/index.vue'),
  182. meta: {
  183. title: '首页'
  184. }
  185. },
  186. {
  187. name: 'service',
  188. path: '/service',
  189. component: () => import('/@/view/service/index.vue'),
  190. meta: {
  191. title: '服务'
  192. }
  193. },
  194. {
  195. name: 'todo',
  196. path: '/todo',
  197. component: () => import('/@/view/todo/index.vue'),
  198. meta: {
  199. title: '待办事项'
  200. }
  201. },
  202. {
  203. name: 'notice',
  204. path: '/notice',
  205. component: () => import('/@/view/notice/index.vue'),
  206. meta: {
  207. title: '通知公告'
  208. }
  209. },
  210. {
  211. name: 'noticeDetail',
  212. path: '/notice/detail',
  213. component: () => import('/@/view/notice/detail.vue'),
  214. meta: {
  215. title: '通知详情'
  216. }
  217. },
  218. {
  219. name: 'user',
  220. path: '/user',
  221. component: () => import('/@/view/user/index.vue'),
  222. meta: {
  223. title: '个人中心'
  224. }
  225. },
  226. {
  227. name: 'myCashFlow',
  228. path: '/my-cash-flow',
  229. component: () => import('/@/view/myCashFlow/index.vue'),
  230. meta: {
  231. title: '我的资金流水'
  232. }
  233. },
  234. {
  235. name: 'userEdit',
  236. path: '/user/edit',
  237. component: () => import('/@/view/user/edit.vue'),
  238. meta: {
  239. title: '个人信息编辑'
  240. }
  241. },
  242. {
  243. name: 'userPassword',
  244. path: '/user/password',
  245. component: () => import('/@/view/user/password.vue'),
  246. meta: {
  247. title: '修改密码'
  248. }
  249. }
  250. ]
  251. },
  252. {
  253. path: '/',
  254. redirect: '/login',
  255. component: () => import('/@/layout/entry.vue'),
  256. children: [
  257. {
  258. name: 'entry',
  259. path: '/entry',
  260. component: () => import('/@/view/entry/index.vue'),
  261. meta: {
  262. title: '入室申请'
  263. }
  264. },
  265. {
  266. name: 'entryManage',
  267. path: '/entry/manage',
  268. component: () => import('/@/view/entry/manage.vue'),
  269. meta: {
  270. title: '入室管理'
  271. }
  272. },
  273. {
  274. name: 'entryMine',
  275. path: '/entry/mine',
  276. component: () => import('/@/view/entry/mine.vue'),
  277. meta: {
  278. title: '我的入室'
  279. }
  280. },
  281. {
  282. name: 'entryAppoint',
  283. path: '/entry/appoint',
  284. component: () => import('/@/view/entry/appoint.vue'),
  285. meta: {
  286. title: '入室预约'
  287. }
  288. },
  289. {
  290. name: 'entryAdd',
  291. path: '/entry/add',
  292. component: () => import('/@/view/entry/add.vue'),
  293. // component: () => import('/@/view/entry/index.vue'),
  294. meta: {
  295. title: '新增入室申请'
  296. }
  297. }
  298. ]
  299. },
  300. {
  301. path: '/',
  302. redirect: '/login',
  303. component: () => import('/@/layout/animal.vue'),
  304. children: [
  305. {
  306. name: 'myCage',
  307. path: '/my-cage',
  308. component: () => import('/@/view/animal/myCage/index.vue'),
  309. meta: {
  310. title: '我的笼位'
  311. }
  312. },
  313. {
  314. name: 'animalApplication',
  315. path: '/animal-application',
  316. component: () => import('/@/view/animal/application/index.vue'),
  317. meta: {
  318. title: '笼位申请'
  319. }
  320. },
  321. {
  322. name: 'animalApplicationRemoval',
  323. path: '/animal-application-removal',
  324. component: () => import('/@/view/animal/applicationRemoval/index.vue'),
  325. meta: {
  326. title: '申请带离'
  327. }
  328. },
  329. {
  330. name: 'animalReturn',
  331. path: '/animal-return',
  332. component: () => import('/@/view/animal/return/index.vue'),
  333. meta: {
  334. title: '笼位退还'
  335. }
  336. }
  337. ]
  338. },
  339. {
  340. path: '/',
  341. redirect: '/login',
  342. component: () => import('/@/layout/training.vue'),
  343. children: [
  344. {
  345. name: 'training',
  346. path: '/training',
  347. component: () => import('/@/view/training/index.vue'),
  348. meta: {
  349. title: '全部培训'
  350. }
  351. },
  352. {
  353. name: 'trainingDone',
  354. path: '/training/done',
  355. component: () => import('/@/view/training/done.vue'),
  356. meta: {
  357. title: '我的培训'
  358. }
  359. },
  360. {
  361. name: 'trainingEnroll',
  362. path: '/training/enroll',
  363. component: () => import('/@/view/training/enroll.vue'),
  364. meta: {
  365. title: '培训报名'
  366. }
  367. },
  368. {
  369. name: 'examMine',
  370. path: '/exam/mine',
  371. component: () => import('/@/view/exam/mine.vue'),
  372. meta: {
  373. title: '我的考试'
  374. }
  375. },
  376. {
  377. name: 'examResult',
  378. path: '/exam/result',
  379. component: () => import('/@/view/exam/result.vue'),
  380. meta: {
  381. title: '考试成绩'
  382. }
  383. }
  384. ]
  385. },
  386. {
  387. name: 'trainingDetail',
  388. path: '/training/detail',
  389. component: () => import('/@/view/training/detail.vue'),
  390. meta: {
  391. title: '培训详情'
  392. }
  393. },
  394. {
  395. name: 'examCover',
  396. path: '/exam/cover',
  397. component: () => import('/@/view/exam/cover.vue'),
  398. meta: {
  399. title: '开始考试'
  400. }
  401. },
  402. {
  403. name: 'exam',
  404. path: '/exam',
  405. component: () => import('/@/view/exam/index.vue'),
  406. meta: {
  407. title: '在线考试'
  408. }
  409. }
  410. ]
  411. const router = createRouter({
  412. routes: routes as any[],
  413. history: createWebHistory()
  414. })
  415. const whiteList = ['/login', '/register']
  416. router.beforeEach(async (to, from, next) => {
  417. const storesUseUserInfo = useUserInfo()
  418. // // 微信授权码获取openId
  419. // const code = to.query.code
  420. // if (!storesUseUserInfo.openId && code) {
  421. // if (typeof code === 'string') {
  422. // storesUseUserInfo.setOpenId(code)
  423. // }
  424. // }
  425. const title = to?.meta?.title
  426. if (title) {
  427. document.title = title as string
  428. }
  429. const token = Local.get('token')
  430. //alert(token)
  431. if (whiteList.indexOf(to.path) > -1 && !token) {
  432. console.log('0. token不存在');
  433. next()
  434. } else {
  435. if (!token) {
  436. console.log('1. token不存在');
  437. next({
  438. path: '/login',
  439. query: to.query
  440. })
  441. } else {
  442. if (!storesUseUserInfo.userInfos.id) {
  443. console.log('2. 获取用户信息');
  444. await storesUseUserInfo.setUserInfos()
  445. }
  446. if (to.path == '/login') {
  447. console.log('3. 微信授权码获取openId');
  448. const code = to.query.code
  449. // if (!code) {
  450. // const appid = "wxdd446f7e55c80c16";
  451. // const redirect_uri = encodeURIComponent(window.location.href);
  452. // const scope = "snsapi_base"; // 静默授权
  453. // const state = "dashoo88888";
  454. // const auth_url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
  455. // window.location.href = auth_url;
  456. // } else {
  457. // storesUseUserInfo.setOpenId(code as string)
  458. // }
  459. if (code) {
  460. storesUseUserInfo.setOpenId(code as string)
  461. }
  462. next('/home')
  463. }
  464. next()
  465. }
  466. }
  467. })
  468. export default router