login.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { login } from "@/api/path/login.api";
  2. import { imLogin } from "@/api/path/im.api";
  3. import { userInfo } from "@/api/path/jdfh.api";
  4. import { useWalletStore } from "@/stores/modules/walletStore";
  5. import { useSystemStore } from "@/stores/modules/systemStore";
  6. const imgHost = import.meta.env.VITE_PRO_IM_PATH + "/api/v1/file/";
  7. export async function sysLogin(address) {
  8. const walletStore = useWalletStore();
  9. const systemStore = useSystemStore();
  10. const results = await Promise.allSettled([
  11. login({ wallet_address: address }),
  12. imLogin({ uuid: address }),
  13. ]);
  14. const loginResult = results[0].value;
  15. const imLoginResult = results[1].value;
  16. systemStore.token = loginResult.data.access_token;
  17. walletStore.avatar = imgHost + imLoginResult.data.avatar;
  18. walletStore.username = imLoginResult.data.nickname;
  19. // 节点分红---获取用户是否为管理员以及是否加入了白名单
  20. const res = await userInfo({ address });
  21. if (res.ret) {
  22. const { is_super, is_white, is_exclusive } = res.data;
  23. const data = {
  24. is_super: typeof is_super === "boolean" ? is_super : false,
  25. is_white: typeof is_white === "boolean" ? is_white : false,
  26. is_exclusive: is_exclusive || false,
  27. };
  28. systemStore.Administrator = data;
  29. }
  30. }
  31. // 更新用户信息
  32. export async function updateUserInfo(address,id) {
  33. const walletStore = useWalletStore();
  34. const res = await imLogin({ uuid: address });
  35. walletStore.avatar = imgHost + res.data.avatar;
  36. walletStore.username = res.data.nickname;
  37. const index = walletStore.walletList.findIndex(item => item.id === id);
  38. if (index !== -1) {
  39. walletStore.walletList[index].username = res.data.nickname;
  40. walletStore.walletList[index].avatar = imgHost + res.data.avatar;
  41. }
  42. }