From 3caa6f535e0442143d0e313a723de03472028213 Mon Sep 17 00:00:00 2001 From: eight <641137800@qq.com> Date: 星期五, 16 八月 2024 18:18:33 +0800 Subject: [PATCH] 医生选择诊室和工位 PASS --- src/views/ecg/room/RoomLoginSelect.vue | 17 ++++++++ src/store/modules/user.ts | 50 +++++++++++++++++++++++++ src/permission.ts | 20 +++++++--- 3 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/permission.ts b/src/permission.ts index b04bc3c..a2e58d1 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -80,12 +80,20 @@ 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() } diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index b386180..2d5600b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -3,6 +3,7 @@ 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() @@ -19,6 +20,10 @@ roles: string[] isSetUser: boolean user: UserVO + + // 鍖荤敓璇婂閫夋嫨 + isSetRoom: boolean + room: RoomVO } export const useUserStore = defineStore('admin-user', { @@ -31,6 +36,15 @@ avatar: '', nickname: '', deptId: 0 + }, + // 鍖荤敓璇婂閫夋嫨 + isSetRoom: false, + room: { + id: 0, + roomId: 0, + roomName: "", + bedNo: "", + onstage: true } }), getters: { @@ -45,6 +59,13 @@ }, getUser(): UserVO { return this.user + }, + // 鍖荤敓璇婂閫夋嫨 + getIsSetRoom(): boolean { + return this.isSetRoom + }, + getRoom(): RoomVO { + return this.room } }, actions: { @@ -64,6 +85,26 @@ 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` @@ -94,6 +135,15 @@ nickname: '', deptId: 0 } + // 鍖荤敓璇婂閫夋嫨 + this.isSetRoom = false + this.room = { + id: 0, + roomId: 0, + roomName: "", + bedNo: "", + onstage: true + } } } }) diff --git a/src/views/ecg/room/RoomLoginSelect.vue b/src/views/ecg/room/RoomLoginSelect.vue index 44d3009..4b1c033 100644 --- a/src/views/ecg/room/RoomLoginSelect.vue +++ b/src/views/ecg/room/RoomLoginSelect.vue @@ -6,14 +6,21 @@ </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[]>>() // 鍒楄〃鐨勬暟鎹� @@ -33,6 +40,16 @@ 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); } /** 鍒濆鍖� **/ -- Gitblit v1.9.3