login.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. import { useWebSocketStore } from "@/stores/modules/webSocketStore.js";
  7. const imgHost = import.meta.env.VITE_IM_PATH_FIlE
  8. export async function sysLogin(address) {
  9. const walletStore = useWalletStore();
  10. const systemStore = useSystemStore();
  11. const wsStore = useWebSocketStore();
  12. wsStore.deleteData();
  13. systemStore.ImsessionList = [];
  14. const results = await Promise.allSettled([
  15. login({ wallet_address: address }),
  16. imLogin({ uuid: address }),
  17. ]);
  18. const loginResult = results[0].status === "fulfilled" ? results[0].value : null;
  19. const imLoginResult = results[1].status === "fulfilled" ? results[1].value : null;
  20. if (loginResult) {
  21. systemStore.token = loginResult.data.access_token;
  22. systemStore.USERID = loginResult.data.user_id;
  23. }
  24. walletStore.avatar = imLoginResult?.data?.avatar
  25. ? imgHost + imLoginResult.data.avatar
  26. : "";
  27. walletStore.username = imLoginResult?.data?.nickname || "游客";
  28. // 节点分红---获取用户是否为管理员以及是否加入了白名单
  29. const res = await userInfo({ address });
  30. if (res.ret) {
  31. const { is_super, is_white, is_exclusive } = res.data;
  32. const data = {
  33. is_super: typeof is_super === "boolean" ? is_super : false,
  34. is_white: typeof is_white === "boolean" ? is_white : false,
  35. is_exclusive: is_exclusive || false,
  36. };
  37. systemStore.Administrator = data;
  38. }
  39. }
  40. // 更新用户信息
  41. export async function updateUserInfo(address,id) {
  42. const walletStore = useWalletStore();
  43. const res = await imLogin({ uuid: address });
  44. walletStore.avatar = imgHost + res.data.avatar;
  45. walletStore.username = res.data.nickname;
  46. const index = walletStore.walletList.findIndex(item => item.id === id);
  47. if (index !== -1) {
  48. walletStore.walletList[index].username = res.data.nickname;
  49. walletStore.walletList[index].avatar = imgHost + res.data.avatar;
  50. }
  51. }