zhangwei
2025-08-15 7339b8a9ccf09e6262cb71ac6c9b724cdfa6fe22
src/store/modules/user.ts
@@ -17,6 +17,8 @@
import { useMultiTagsStoreHook } from "./multiTags";
import {
  type DataInfo,
  type ResponseEnterprise,
  type CusExtendDto,
  setToken,
  setRoleListInfo,
  setNowRole,
@@ -26,6 +28,7 @@
} from "@/utils/auth";
import { exRole } from "@/api/register/index";
import { cusExtendInfo } from "@/api/mine";
import type { nowRoleType } from "@/store/types";
export const useUserStore = defineStore("pure-user", {
  state: (): userType => ({
@@ -35,7 +38,7 @@
    username: storageLocal().getItem<DataInfo<number>>(userKey)?.username ?? "",
    // 昵称
    nickname: storageLocal().getItem<DataInfo<number>>(userKey)?.nickname ?? "",
    // 页面级别权限
    // 当前角色列表
    exRoles: storageLocal().getItem<DataInfo<number>>(userKey)?.exRoles ?? [],
    // 按钮级别权限
    permissions:
@@ -46,10 +49,11 @@
    loginDay: 1,
    // 企业资料
    enterpriseInfo:
      storageLocal().getItem<DataInfo<number>>("enterpriseInfo") ?? {},
    nowRole: storageLocal().getItem<DataInfo<number>>("nowRole") ?? {},
      storageLocal().getItem<CusExtendDto>("enterpriseInfo") ?? {},
    nowRole: storageLocal().getItem<nowRoleType>("nowRole") ?? {},
    rolesList: storageLocal().getItem<DataInfo<number>>("rolesList") ?? [],
    isFlsh: storageLocal().getItem<DataInfo<number>>("isFlsh") ?? false
    // 页面级别权限
    roles: storageLocal().getItem<DataInfo<number>>(userKey)?.roles ?? []
  }),
  actions: {
    /** 存储头像 */
@@ -65,20 +69,20 @@
      this.nickname = nickname;
    },
    /** 存储用户角色 */
    SET_ROLES(exRoles: Array<string>) {
    SET_EXROLES(exRoles: Array<string>) {
      this.exRoles = exRoles;
    },
    /** 存储角色 */
    SET_ROLES(roles: Array<string>) {
      this.roles = roles;
    },
    /** 存储角色当前角色 */
    SET_NOW_ROLE(nowRole: object) {
    SET_NOW_ROLE(nowRole: nowRoleType) {
      this.nowRole = nowRole;
    },
    /** 存储角色列表 */
    SET_ROLES_LIST(rolesList: Array<string>) {
    SET_EXROLES_LIST(rolesList: Array<string>) {
      this.rolesList = rolesList;
    },
    /** 当前角色是否审核 */
    SET_IS_FLSH(isFlsh: boolean | string) {
      this.isFlsh = isFlsh;
    },
    /** 存储按钮级别权限 */
    SET_PERMS(permissions: Array<string>) {
@@ -93,8 +97,8 @@
      this.loginDay = Number(value);
    },
    // 设置企业资料
    SET_ENTERPRISEINFO(value: object) {
      this.loginDay = Number(value);
    SET_ENTERPRISEINFO(enterpriseInfo: CusExtendDto) {
      this.enterpriseInfo = enterpriseInfo;
    },
    /** 登入 */
    async loginByUsername(obj) {
@@ -102,6 +106,7 @@
        getLogin(obj)
          .then(data => {
            if (data?.code == 200) {
              data.result.roles = [obj.exRuleCode];
              setToken(data.result);
              this.getNowRole(obj.exRuleCode);
            }
@@ -144,13 +149,14 @@
    async changeLogoInExRule(obj) {
      return new Promise<LoginResult>((resolve, reject) => {
        getChangeLogoInExRule(obj)
          .then(data => {
          .then(async data => {
            if (data?.code == 200) {
              data.result.roles = [obj.ruleCode];
              setToken(data.result);
              this.getNowRole(obj.ruleCode);
              this.getCusExtendInfo();
              await this.getCusExtendInfo();
              resolve(data);
            }
            resolve(data);
          })
          .catch(error => {
            reject(error);
@@ -158,12 +164,12 @@
      });
    },
    async getCusExtendInfo() {
      return new Promise<LoginResult>((resolve, reject) => {
      return new Promise<ResponseEnterprise>((resolve, reject) => {
        cusExtendInfo()
          .then(data => {
            data.result.username = data.result.enterpriseName;
            setEnterpriseInfo(data.result);
            if (data?.code == 200) {
              setEnterpriseInfo(data.result);
              data.result.username = data.result?.enterpriseName;
              resolve(data);
            }
          })
@@ -176,6 +182,7 @@
    logOut() {
      this.username = "";
      this.exRoles = [];
      this.roles = [];
      this.permissions = [];
      removeToken();
      useMultiTagsStoreHook().handleTags("equal", [...routerArrays]);