user.ts 810 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { AuthModule } from "../..";
  2. import { User } from "../../typings";
  3. import { Dict_Auth_Storage } from "../dicts/storage";
  4. const initialState = {
  5. alipay: "",
  6. avatar: "",
  7. city: "",
  8. company: "",
  9. companyKey: "",
  10. desc: "",
  11. email: "",
  12. name: "",
  13. phone: "",
  14. wechat: "",
  15. userType: 2,
  16. _id: "",
  17. };
  18. export const userStore = AuthModule.store({
  19. state: () => ({
  20. token: Dict_Auth_Storage.get("token"),
  21. userInfo: initialState,
  22. }),
  23. actions: {
  24. setToken(token: string) {
  25. Dict_Auth_Storage.set("token", (this.store.token = token));
  26. },
  27. setUserInfo(userInfo: User) {
  28. Dict_Auth_Storage.set("userInfo", (this.store.userInfo = userInfo));
  29. },
  30. clearUserInfo() {
  31. this.store.setUserInfo({ ...initialState });
  32. this.store.setToken("");
  33. },
  34. },
  35. });