| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- /*
- * @Author: wanglj wanglijie@dashoo.cn
- * @Date: 2025-03-10 11:40:15
- * @LastEditors: wanglj wanglijie@dashoo.cn
- * @LastEditTime: 2025-04-16 10:58:21
- * @FilePath: \vue3-ts\src\router.ts
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- import { createRouter, createWebHistory } from 'vue-router'
- import { Local } from './utils/storage'
- import { useUserInfo } from '/@/stores/userInfo'
- import { showDialog } from 'vant'
- const routes = [
- {
- name: 'notFound',
- path: '/:path(.*)+',
- redirect: {
- name: 'home'
- }
- },
- {
- name: 'login',
- path: '/login',
- component: () => import('/@/view/login/index.vue'),
- meta: {
- title: '登录'
- }
- },
- {
- name: 'register',
- path: '/register',
- component: () => import('/@/view/register/index.vue'),
- meta: {
- title: '注册'
- }
- },
- {
- name: 'instrList',
- path: '/instr-list',
- component: () => import('/@/view/instr/list.vue'),
- meta: {
- title: '仪器列表'
- }
- },
- {
- name: 'instrFollow',
- path: '/instr-follow',
- component: () => import('/@/view/instr/list-follow.vue'),
- meta: {
- title: '关注仪器'
- }
- },
- {
- name: 'instrDetail',
- path: '/instr-detail',
- component: () => import('/@/view/instr/detail.vue'),
- meta: {
- title: '仪器详情'
- }
- },
- {
- name: 'instrAppoint',
- path: '/instr-appoint',
- component: () => import('/@/view/instr/appoint.vue'),
- meta: {
- title: '仪器预约'
- }
- },
- {
- name: 'instrCalendar',
- path: '/instr-calendar',
- component: () => import('/@/view/instr/calendar.vue'),
- meta: {
- title: '预约日历'
- }
- },
- {
- name: 'appointInfo',
- path: '/instr-appoint-record',
- component: () => import('/@/view/instr/appointList/index.vue'),
- meta: {
- title: '预约详情'
- }
- },
- {
- name: 'onlineInfo',
- path: '/onlineInfo',
- component: () => import('/@/view/instr/appointList/onlineInfo/index.vue'),
- meta: {
- title: '上机详情'
- }
- },
- {
- name: 'appoint',
- path: '/inst/appoint',
- component: () => import('/@/view/instr/appoint/index.vue'),
- meta: {
- title: '仪器预约'
- }
- },
- {
- name: 'approvalDetail',
- path: '/todo/detail',
- component: () => import('/@/view/todo/detail.vue'),
- meta: {
- title: '审批详情'
- }
- },
- {
- name: 'entryDetail',
- path: '/entry/detail',
- component: () => import('/@/view/entry/detail.vue'),
- meta: {
- title: '入室详情'
- }
- },
- {
- path: '/',
- redirect: '/login',
- component: () => import('/@/layout/index.vue'),
- children: [
- {
- name: 'home',
- path: '/home',
- component: () => import('/@/view/home/index.vue'),
- meta: {
- title: '首页'
- }
- },
- {
- name: 'service',
- path: '/service',
- component: () => import('/@/view/service/index.vue'),
- meta: {
- title: '服务'
- }
- },
- {
- name: 'todo',
- path: '/todo',
- component: () => import('/@/view/todo/index.vue'),
- meta: {
- title: '待办事项'
- }
- },
- {
- name: 'notice',
- path: '/notice',
- component: () => import('/@/view/notice/index.vue'),
- meta: {
- title: '通知公告'
- }
- },
- {
- name: 'noticeDetail',
- path: '/notice/detail',
- component: () => import('/@/view/notice/detail.vue'),
- meta: {
- title: '通知详情'
- }
- },
- {
- name: 'user',
- path: '/user',
- component: () => import('/@/view/user/index.vue'),
- meta: {
- title: '个人中心'
- }
- },
- {
- name: 'userEdit',
- path: '/user/edit',
- component: () => import('/@/view/user/edit.vue'),
- meta: {
- title: '个人信息编辑'
- }
- },
- {
- name: 'userPassword',
- path: '/user/password',
- component: () => import('/@/view/user/password.vue'),
- meta: {
- title: '修改密码'
- }
- }
- ]
- },
- {
- path: '/',
- redirect: '/login',
- component: () => import('/@/layout/entry.vue'),
- children: [
- {
- name: 'entry',
- path: '/entry',
- component: () => import('/@/view/entry/index.vue'),
- meta: {
- title: '入室申请'
- }
- },
- {
- name: 'entryManage',
- path: '/entry/manage',
- component: () => import('/@/view/entry/manage.vue'),
- meta: {
- title: '入室管理'
- }
- },
- {
- name: 'entryMine',
- path: '/entry/mine',
- component: () => import('/@/view/entry/mine.vue'),
- meta: {
- title: '我的入室'
- }
- },
- {
- name: 'entryAppoint',
- path: '/entry/appoint',
- component: () => import('/@/view/entry/appoint.vue'),
- meta: {
- title: '入室预约'
- }
- },
- {
- name: 'entryAdd',
- path: '/entry/add',
- component: () => import('/@/view/entry/add.vue'),
- // component: () => import('/@/view/entry/index.vue'),
- meta: {
- title: '新增入室申请'
- }
- }
- ]
- },
- {
- path: '/',
- redirect: '/login',
- component: () => import('/@/layout/animal.vue'),
- children: [
- {
- name: 'myCage',
- path: '/my-cage',
- component: () => import('/@/view/animal/myCage/index.vue'),
- meta: {
- title: '我的笼位'
- }
- },
- {
- name: 'animalApplication',
- path: '/animal-application',
- component: () => import('/@/view/animal/application/index.vue'),
- meta: {
- title: '笼位申请'
- }
- },
- {
- name: 'animalReturn',
- path: '/animal-return',
- component: () => import('/@/view/animal/return/index.vue'),
- meta: {
- title: '笼位退还'
- }
- }
- ]
- },
- {
- path: '/',
- redirect: '/login',
- component: () => import('/@/layout/training.vue'),
- children: [
- {
- name: 'training',
- path: '/training',
- component: () => import('/@/view/training/index.vue'),
- meta: {
- title: '全部培训'
- }
- },
- {
- name: 'trainingDone',
- path: '/training/done',
- component: () => import('/@/view/training/done.vue'),
- meta: {
- title: '我的培训'
- }
- },
- {
- name: 'trainingEnroll',
- path: '/training/enroll',
- component: () => import('/@/view/training/enroll.vue'),
- meta: {
- title: '培训报名'
- }
- },
- {
- name: 'examMine',
- path: '/exam/mine',
- component: () => import('/@/view/exam/mine.vue'),
- meta: {
- title: '我的考试'
- }
- },
- {
- name: 'examResult',
- path: '/exam/result',
- component: () => import('/@/view/exam/result.vue'),
- meta: {
- title: '考试成绩'
- }
- }
- ]
- },
- {
- name: 'trainingDetail',
- path: '/training/detail',
- component: () => import('/@/view/training/detail.vue'),
- meta: {
- title: '培训详情'
- }
- },
- {
- name: 'examCover',
- path: '/exam/cover',
- component: () => import('/@/view/exam/cover.vue'),
- meta: {
- title: '开始考试'
- }
- },
- {
- name: 'exam',
- path: '/exam',
- component: () => import('/@/view/exam/index.vue'),
- meta: {
- title: '在线考试'
- }
- }
- ]
- const router = createRouter({
- routes: routes as any[],
- history: createWebHistory()
- })
- const whiteList = ['/login', '/register', '/training', '/training/enroll']
- router.beforeEach(async (to, from, next) => {
- const storesUseUserInfo = useUserInfo()
- // // 微信授权码获取openId
- // const code = to.query.code
- // if (!storesUseUserInfo.openId && code) {
- // if (typeof code === 'string') {
- // storesUseUserInfo.setOpenId(code)
- // }
- // }
- const title = to?.meta?.title
- if (title) {
- document.title = title as string
- }
- const token = Local.get('token')
- if (whiteList.indexOf(to.path) > -1 && !token) {
- next()
- } else {
- if (!token) {
- next({
- path: '/login',
- query: to.query
- })
- } else {
- if (!storesUseUserInfo.userInfos.id) {
- await storesUseUserInfo.setUserInfos()
- }
- if (to.path == '/login') {
- const code = to.query.code
- storesUseUserInfo.setOpenId(code as string)
- next('/home')
- }
- next()
- }
- }
- })
- export default router
|