| | |
| | | permissionStore.getAddRouters.forEach((route) => { |
| | | router.addRoute(route as unknown as RouteRecordRaw) // 动态添加可访问路由表 |
| | | }) |
| | | const redirectPath = from.query.redirect || to.path |
| | | // 修复跳转时不带参数的问题 |
| | | const redirect = decodeURIComponent(redirectPath as string) |
| | | const { paramsObject: query } = parseURL(redirect) |
| | | const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect, query } |
| | | next(nextData) |
| | | |
| | | // 新增【诊室选择】逻辑 |
| | | if (userStore.getRoles.includes("doctor") && !userStore.getIsSetRoom ) { |
| | | next({path: "/login-room-select"}) |
| | | } |
| | | // <<<【诊室选择】<<< |
| | | else { |
| | | const redirectPath = from.query.redirect || to.path |
| | | // 修复跳转时不带参数的问题 |
| | | const redirect = decodeURIComponent(redirectPath as string) |
| | | const {paramsObject: query} = parseURL(redirect) |
| | | const nextData = to.path === redirect ? {...to, replace: true} : {path: redirect, query} |
| | | next(nextData) |
| | | } |
| | | } else { |
| | | next() |
| | | } |
| | |
| | | import { getAccessToken, removeToken } from '@/utils/auth' |
| | | import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache' |
| | | import { getInfo, loginOut } from '@/api/login' |
| | | import {RoomVO} from "@/api/ecg/room"; |
| | | |
| | | const { wsCache } = useCache() |
| | | |
| | |
| | | roles: string[] |
| | | isSetUser: boolean |
| | | user: UserVO |
| | | |
| | | // 医生诊室选择 |
| | | isSetRoom: boolean |
| | | room: RoomVO |
| | | } |
| | | |
| | | export const useUserStore = defineStore('admin-user', { |
| | |
| | | avatar: '', |
| | | nickname: '', |
| | | deptId: 0 |
| | | }, |
| | | // 医生诊室选择 |
| | | isSetRoom: false, |
| | | room: { |
| | | id: 0, |
| | | roomId: 0, |
| | | roomName: "", |
| | | bedNo: "", |
| | | onstage: true |
| | | } |
| | | }), |
| | | getters: { |
| | |
| | | }, |
| | | getUser(): UserVO { |
| | | return this.user |
| | | }, |
| | | // 医生诊室选择 |
| | | getIsSetRoom(): boolean { |
| | | return this.isSetRoom |
| | | }, |
| | | getRoom(): RoomVO { |
| | | return this.room |
| | | } |
| | | }, |
| | | actions: { |
| | |
| | | wsCache.set(CACHE_KEY.USER, userInfo) |
| | | wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus) |
| | | }, |
| | | // 医生诊室选择 |
| | | async setRoomInfoAction(room: RoomVO) { |
| | | if (!getAccessToken()) { |
| | | this.resetState() |
| | | return null |
| | | } |
| | | |
| | | // 更新 store |
| | | this.room = room |
| | | this.isSetRoom = true |
| | | |
| | | // 更新 cache |
| | | const userInfo2 = wsCache.get(CACHE_KEY.USER) |
| | | if (userInfo2) { |
| | | userInfo2.room = room |
| | | userInfo2.isSetRoom = true |
| | | wsCache.set(CACHE_KEY.USER, userInfo2) |
| | | } |
| | | }, |
| | | |
| | | async setUserAvatarAction(avatar: string) { |
| | | const userInfo = wsCache.get(CACHE_KEY.USER) |
| | | // NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null` |
| | |
| | | nickname: '', |
| | | deptId: 0 |
| | | } |
| | | // 医生诊室选择 |
| | | this.isSetRoom = false |
| | | this.room = { |
| | | id: 0, |
| | | roomId: 0, |
| | | roomName: "", |
| | | bedNo: "", |
| | | onstage: true |
| | | } |
| | | } |
| | | } |
| | | }) |
| | |
| | | </div> |
| | | </div> |
| | | <el-button type="primary" @click="roomConfirm">确认</el-button> |
| | | <el-button type="primary" @click="test">TEST</el-button> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import {RoomBedSelect} from "@/components/RoomBedSelect" |
| | | import { RoomApi, RoomVO } from '@/api/ecg/room' |
| | | import {useUserStore} from "@/store/modules/user"; |
| | | import {CACHE_KEY, useCache} from "@/hooks/web/useCache"; |
| | | const { currentRoute, push } = useRouter() |
| | | const { wsCache } = useCache() |
| | | |
| | | defineOptions({ name: 'RoomLoginSelect' }) |
| | | |
| | | const userStore = useUserStore() |
| | | |
| | | const bedMap = ref<Map<String, RoomVO[]>>() // 列表的数据 |
| | | |
| | |
| | | |
| | | const roomConfirm = () => { |
| | | console.info(curSel.value) |
| | | userStore.setRoomInfoAction(curSel.value) |
| | | push({ path: "/"}) |
| | | } |
| | | |
| | | const test = () => { |
| | | userStore.getRoom; |
| | | console.info(userStore.getRoom); |
| | | |
| | | const userInfo = wsCache.get(CACHE_KEY.USER) |
| | | console.info(userInfo); |
| | | } |
| | | |
| | | /** 初始化 **/ |