login.ts 925 Bytes
import router from '@/router'
import { ElMessage } from "element-plus";
interface LoginUser {
  token: string,
  organizationId: number,
  id: number,
  userName: string
}
const id: string = 'login'
const state: Function = () => ({
  token: '',
  organizationId: null,
  id: null,
  userName: ''
})
const getters = {
  getToken() {
    return this.token
  },
  getOid() {
    return this.organizationId
  },
  getId() {
    return this.id
  },
  getUserName() {
    return this.userName
  }
}
const actions = {
  setUserInfo(obj: LoginUser) {
    this.token = obj.token
    this.organizationId = obj.organizationId
    this.id = obj.id
    this.userName = obj.userName
  },
  removeToken(msg: string | null) {
    this.token = ''
    ElMessage.success(msg || '已退出登录');
    setTimeout(() => {
      router.replace('/login')
    }, 500)
  }
}

export default {
  namespace: true,
  actions,
  getters,
  state,
  id
}