import { defineStore } from 'pinia'

export interface UserInfo {
  id: number,
  name: string,
  opmId: number,
  satoken: string
}
export interface RoomData {
  id: number,
  name: string
}

// id必填，且需要唯一
const useStore = defineStore('index', {
  state: () => ({
    userInfro: {} as UserInfo,
    token: '',
    loading: false,
    newRoomData: null as RoomData | null
  }),
  actions: {
    setUserInfo(data: UserInfo) {
      this.userInfro = data
      this.token = data.satoken || ''
    },
    setRoomData(data: RoomData | null) {
      this.newRoomData = data
    }
  },
  persist: {
    enabled: true // true 表示开启持久化保存
  }
})
export default useStore