login.ts 945 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { createStore } from '../base'
  2. import { sessionData } from '../storage'
  3. /**
  4. * 登录存储对象
  5. */
  6. export const loginStore = createStore({
  7. state() {
  8. return {
  9. logining: false,
  10. loginInfo: sessionData.getRef('loginInfo'),
  11. }
  12. },
  13. getters: {
  14. // 登录令牌
  15. token() {
  16. return this.state.loginInfo.Token
  17. },
  18. // 用户ID
  19. userId() {
  20. return this.state.loginInfo.UserID
  21. },
  22. // 登录ID
  23. loginId() {
  24. return this.state.loginInfo.LoginID
  25. },
  26. // 首个资金账户ID
  27. firstAccountId() {
  28. const accounts = this.state.loginInfo.AccountIDs
  29. return accounts[0] ?? 0
  30. },
  31. },
  32. actions: {
  33. // 获取用户登录信息
  34. getLoginInfo<K extends keyof Proto.LoginRsp>(key: K) {
  35. return this.state.loginInfo[key]
  36. },
  37. }
  38. })