From 83af3dd309889489f541fc8e21894c9f79e5788c Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期五, 22 八月 2025 16:09:58 +0800
Subject: [PATCH] 用户管理

---
 src/utils/auth.ts |  188 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 178 insertions(+), 10 deletions(-)

diff --git a/src/utils/auth.ts b/src/utils/auth.ts
index 37cda2f..2049238 100644
--- a/src/utils/auth.ts
+++ b/src/utils/auth.ts
@@ -1,6 +1,8 @@
 import Cookies from "js-cookie";
 import { useUserStoreHook } from "@/store/modules/user";
 import { storageLocal, isString, isIncludeAllChildren } from "@pureadmin/utils";
+import type { nowRoleType } from "@/store/types";
+import type { LoginResult, RoleItem } from "@/api/types";
 
 export interface DataInfo<T> {
   /** token */
@@ -15,10 +17,137 @@
   username?: string;
   /** 鏄电О */
   nickname?: string;
+  /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勮鑹插垪琛� */
+  exRoles?: RoleItem[];
   /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勮鑹� */
-  exRoles?: Array<string>;
+  roles?: Array<string>;
   /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勬寜閽骇鍒潈闄� */
   permissions?: Array<string>;
+  isManager: boolean;
+}
+/**
+ * AdminResult_CusExtendDto锛屽叏灞�杩斿洖缁撴灉
+ */
+export interface ResponseEnterprise {
+  /**
+   * 鐘舵�佺爜
+   */
+  code?: number;
+  /**
+   * 闄勫姞鏁版嵁
+   */
+  extras?: null;
+  /**
+   * 閿欒淇℃伅
+   */
+  message?: null | string;
+  result?: CusExtendDto;
+  /**
+   * 鏃堕棿
+   */
+  time?: Date;
+  /**
+   * 绫诲瀷success銆亀arning銆乪rror
+   */
+  type?: null | string;
+}
+
+/**
+ * CusExtendDto锛岀敤鎴疯鑹茶祫鏂�
+ */
+export interface CusExtendDto {
+  /**
+   * 浼佷笟閾惰璐﹀彿
+   */
+  bankAccount?: null | string;
+  /**
+   * 浼佷笟寮�鎴疯
+   */
+  bankName?: null | string;
+  /**
+   * 钀ヤ笟鎵х収鏂囦欢璺緞
+   */
+  businessLicense?: null | string;
+  /**
+   * 浼佷笟閭
+   */
+  enterpriseEmail?: null | string;
+  /**
+   * 浼佷笟鍚嶇О
+   */
+  enterpriseName?: null | string;
+  /**
+   * 浼佷笟鑱旂郴鐢佃瘽
+   */
+  enterprisePhone?: null | string;
+  /**
+   * 浼佷笟绫诲瀷 浠庝紒涓氱被鍨嬩腑閫夋嫨 鏉ユ簮浼佷笟绫诲瀷
+   */
+  enterpriseType?: null | string;
+  /**
+   * 浼佷笟鎴愮珛鏃堕棿
+   */
+  establishmentTime?: Date;
+  /**
+   * 涓婚敭
+   */
+  id?: number | null;
+  /**
+   * 娉曞畾浠h〃浜鸿韩浠借瘉鏂囦欢璺緞
+   */
+  legalRepresentativeIdCard?: null | string;
+  /**
+   * 娉曞畾浠h〃浜鸿韩浠借瘉鍙风爜
+   */
+  legalRepresentativeIdNumber?: null | string;
+  /**
+   * 娉曞畾浠h〃浜哄鍚�
+   */
+  legalRepresentativeName?: null | string;
+  /**
+   * 娉曞畾浠h〃浜鸿仈绯荤數璇�
+   */
+  legalRepresentativePhone?: null | string;
+  /**
+   * 浼佷笟涓昏惀涓氬姟
+   */
+  mainBusiness?: null | string;
+  /**
+   * 涓氬姟缁忓姙浜鸿韩浠借瘉鏂囦欢璺緞鎴栨爣璇嗭紙涓婁紶鍚庡瓨鍌ㄤ俊鎭級
+   */
+  operatorIdCard?: null | string;
+  /**
+   * 涓氬姟缁忓姙浜鸿韩浠借瘉鍙风爜
+   */
+  operatorIdNumber?: null | string;
+  /**
+   * 涓氬姟缁忓姙浜哄鍚�
+   */
+  operatorName?: null | string;
+  /**
+   * 涓氬姟缁忓姙浜鸿仈绯荤數璇�
+   */
+  operatorPhone?: null | string;
+  /**
+   * 娉ㄥ唽璧勯噾锛堝崟浣嶏細涓囧厓 锛�
+   */
+  registeredCapital?: null | string;
+  /**
+   * 浼佷笟浣忔墍锛堜笅鎷夐�夋嫨锛岄渶缁撳悎瀹為檯鍙�夊�硷紝鍏堝瓧绗︿覆鎺ユ敹 锛�
+   */
+  residence?: null | string;
+  /**
+   * 浜ゆ槗涓讳綋 浠g爜 鍚岃鑹蹭唬鐮�
+   */
+  transactionCode?: string;
+  /**
+   * 浜ゆ槗涓讳綋鍚嶇О
+   */
+  transactionName?: null | string;
+  /**
+   * 缁熶竴绀句細淇$敤浠g爜
+   */
+  unifiedSocialCreditCode?: null | string;
 }
 
 export const userKey = "user-info";
@@ -45,7 +174,7 @@
  * 灏哷accessToken`銆乣expires`銆乣refreshToken`杩欎笁鏉′俊鎭斁鍦╧ey鍊间负authorized-token鐨刢ookie閲岋紙杩囨湡鑷姩閿�姣侊級
  * 灏哷avatar`銆乣username`銆乣nickname`銆乣exRoles`銆乣permissions`銆乣refreshToken`銆乣expires`杩欎竷鏉′俊鎭斁鍦╧ey鍊间负`user-info`鐨刲ocalStorage閲岋紙鍒╃敤`multipleTabsKey`褰撴祻瑙堝櫒瀹屽叏鍏抽棴鍚庤嚜鍔ㄩ攢姣侊級
  */
-export function setToken(data: DataInfo<Date>) {
+export function setToken(data: LoginResult) {
   let expires = 0;
   const { accessToken, refreshToken } = data;
   const { isRemembered, loginDay } = useUserStoreHook();
@@ -68,12 +197,22 @@
       : {}
   );
 
-  function setUserKey({ avatar, username, nickname, exRoles, permissions }) {
+  function setUserKey({
+    avatar,
+    username,
+    nickname,
+    exRoles,
+    permissions,
+    roles,
+    isManager
+  }) {
     useUserStoreHook().SET_AVATAR(avatar);
     useUserStoreHook().SET_USERNAME(username);
     useUserStoreHook().SET_NICKNAME(nickname);
-    useUserStoreHook().SET_ROLES(exRoles);
+    useUserStoreHook().SET_EXROLES(exRoles);
+    useUserStoreHook().SET_ROLES(roles);
     useUserStoreHook().SET_PERMS(permissions);
+    useUserStoreHook().SET_ISMANAGER(isManager);
     storageLocal().setItem(userKey, {
       refreshToken,
       expires,
@@ -81,18 +220,22 @@
       username,
       nickname,
       exRoles,
-      permissions
+      roles,
+      permissions,
+      isManager
     });
   }
 
-  if (data.exRoles) {
-    const { username, exRoles } = data;
+  if (data.exRoles && data.roles) {
+    const { username, exRoles, roles, isManager } = data;
     setUserKey({
       avatar: data?.avatar ?? "",
       username,
       nickname: data?.nickname ?? "",
       exRoles,
-      permissions: data?.permissions ?? []
+      roles,
+      permissions: data?.permissions ?? [],
+      isManager
     });
   } else {
     const avatar =
@@ -103,19 +246,25 @@
       storageLocal().getItem<DataInfo<number>>(userKey)?.nickname ?? "";
     const exRoles =
       storageLocal().getItem<DataInfo<number>>(userKey)?.exRoles ?? [];
+    const roles =
+      storageLocal().getItem<DataInfo<number>>(userKey)?.roles ?? [];
     const permissions =
       storageLocal().getItem<DataInfo<number>>(userKey)?.permissions ?? [];
+    const isManager =
+      storageLocal().getItem<DataInfo<number>>(userKey)?.isManager ?? false;
     setUserKey({
       avatar,
       username,
       nickname,
       exRoles,
-      permissions
+      roles,
+      permissions,
+      isManager
     });
   }
 }
 
-export function setEnterpriseInfo(data: DataInfo<Date>) {
+export function setEnterpriseInfo(data: CusExtendDto) {
   useUserStoreHook().SET_ENTERPRISEINFO(data);
   useUserStoreHook().SET_USERNAME(data.enterpriseName);
   storageLocal().setItem("enterpriseInfo", data);
@@ -123,6 +272,25 @@
   obj.username = data.enterpriseName;
   storageLocal().setItem(userKey, obj);
 }
+
+export function setRoleListInfo(data: RoleItem[]) {
+  useUserStoreHook().SET_EXROLES_LIST(data);
+  storageLocal().setItem("rolesList", data);
+}
+
+export function setNowRole(data: nowRoleType) {
+  const list = storageLocal().getItem<DataInfo<number>>(userKey)?.exRoles ?? [];
+  if (list.length > 0) {
+    const obj = list.find(item => {
+      return item.code == data.code;
+    });
+    data = Object.assign(obj, data);
+  }
+  useUserStoreHook().SET_ROLES([data.name]);
+  useUserStoreHook().SET_NOW_ROLE(data);
+  storageLocal().setItem("nowRole", data);
+}
+
 export function removeEnterpriseInfo() {
   storageLocal().removeItem("enterpriseInfo");
 }

--
Gitblit v1.9.1