eight
2024-11-18 adecd142412454acbd8f729c7230e9a90b3dcddc
src/store/modules/user.ts
@@ -3,7 +3,6 @@
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()
@@ -20,10 +19,6 @@
  roles: string[]
  isSetUser: boolean
  user: UserVO
  // 医生诊室选择
  isSetRoom: boolean
  room: RoomVO
}
export const useUserStore = defineStore('admin-user', {
@@ -37,20 +32,6 @@
      nickname: '',
      deptId: 0
    },
    // 医生诊室选择
    isSetRoom: false,
    room: {
      id: null,
      roomId: null,
      roomName: null,
      bedNo: null,
      ip: null,
      status: null,
      docId: null,
      docName: null,
      checkTypes: null,
      opType: null
    }
  }),
  getters: {
    getPermissions(): string[] {
@@ -65,13 +46,6 @@
    getUser(): UserVO {
      return this.user
    },
    // 医生诊室选择
    getIsSetRoom(): boolean {
      return this.isSetRoom
    },
    getRoom(): RoomVO | null {
      return this.room
    }
  },
  actions: {
    async setUserInfoAction() {
@@ -90,50 +64,6 @@
      wsCache.set(CACHE_KEY.USER, userInfo)
      wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
    },
    // 医生入座
    async setRoomInfoAction(room: RoomVO) {
      // 更新 store
      this.room!.id = room.id
      this.room!.roomId = room.roomId
      this.room!.roomName = room.roomName
      this.room!.bedNo = room.bedNo
      this.room!.status = room.status
      this.room!.docId = room.docId
      this.room!.docName = room.docName
      this.room!.checkTypes = room.checkTypes
      this.room!.opType = room.opType
      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 clearRoomInfoAction() {
      // 清 store
      this.room.id = null
      this.room.roomId = null
      this.room.roomName = null
      this.room.bedNo = null
      this.room.status = null
      this.room.docId = null
      this.room.docName = null
      this.isSetRoom = false
      // 更新 cache
      const userInfo2 = wsCache.get(CACHE_KEY.USER)
      if (userInfo2) {
        userInfo2.room = null
        userInfo2.isSetRoom = false
        wsCache.set(CACHE_KEY.USER, userInfo2)
      }
    },
    async setUserAvatarAction(avatar: string) {
      const userInfo = wsCache.get(CACHE_KEY.USER)
      // NOTE: 是否需要像`setUserInfoAction`一样判断`userInfo != null`
@@ -163,20 +93,6 @@
        avatar: '',
        nickname: '',
        deptId: 0
      }
      // 医生诊室选择
      this.isSetRoom = false
      this.room = {
        id: 0,
        roomId: 0,
        roomName: "",
        bedNo: "",
        ip: "",
        status: null,
        docId: null,
        docName: null,
        checkTypes: null,
        opType: null
      }
    }
  }