zhengyiming
2025-02-10 0470145fcd755d3f87bffc7a985bd3cc82c5f3f6
apps/cMiniApp/src/stores/modules/user.ts
@@ -26,7 +26,7 @@
  LocationUtils,
} from '@12333/utils';
import DefaultAvatar from '@/assets/components/icon-default-avatar.png';
import { MatchMakingIdentityEnum, WxMiniAppEnum } from '@12333/constants';
import { WxMiniAppEnum } from '@12333/constants';
import { myClient } from '@/constants/query';
import { globalEventEmitter } from '@12333/hooks';
@@ -36,9 +36,6 @@
  refreshToken?: Nullable<string>;
  userDetail?: Nullable<API.UserInfoV2>;
  firstGetUserDetail?: boolean;
  matchMakingIdentity?: MatchMakingIdentityEnum;
  /**是否有设置过身份 */
  isSetMatchMakingIdentity?: boolean;
  locationCity?: string;
  locationProvince?: string;
@@ -61,18 +58,6 @@
  }
);
function initMatchMakingIdentity(userDetail: API.UserInfoV2): MatchMakingIdentityEnum {
  if (!userDetail) {
    const cacheMatchMakingIdentity = getMatchMakingIdentity();
    return cacheMatchMakingIdentity
      ? cacheMatchMakingIdentity
      : MatchMakingIdentityEnum.Contributors;
  } else if (!userDetail?.matchMakingIdentity) {
    return MatchMakingIdentityEnum.Contributors;
  }
  return userDetail?.matchMakingIdentity;
}
export const useUserStore = defineStore({
  id: 'app-user',
  state: (): UserState => {
@@ -89,10 +74,6 @@
      refreshToken: userInfo?.refreshToken ?? '',
      userDetail: userDetail,
      firstGetUserDetail: true,
      matchMakingIdentity: initMatchMakingIdentity(userDetail),
      isSetMatchMakingIdentity: userDetail
        ? !!userDetail.matchMakingIdentity || !!getMatchMakingIdentity()
        : !!getMatchMakingIdentity(),
      locationCity: storageLocation?.city ?? '北京市',
      locationProvince: storageLocation?.province ?? '北京',
      firstSetLocation: true,
@@ -227,8 +208,6 @@
          res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
          this.setUserDetail(res);
          this.firstGetUserDetail = false;
          this.matchMakingIdentity = initMatchMakingIdentity(res);
          this.isSetMatchMakingIdentity = true;
        }
      } catch (error) {}
    },
@@ -303,25 +282,6 @@
          return res;
        } else {
          throw new Error('刷新token失败');
        }
      } catch (error) {
        throw new Error('error');
      }
    },
    async setMatchMakingIdentity(params: API.SetMatchMakingIdentityInput) {
      try {
        let res = 1;
        if (this.userDetail) {
          res = await userServices.setMatchMakingIdentity(params);
        }
        if (res) {
          if (!this.userDetail) {
            setMatchMakingIdentity(params.matchMakingIdentity);
          }
          this.matchMakingIdentity = params.matchMakingIdentity;
          this.isSetMatchMakingIdentity = true;
          return res;
        }
      } catch (error) {
        throw new Error('error');