From 2293a1b58a3227a4870466e3699b6baf0af29303 Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期一, 11 八月 2025 17:19:53 +0800
Subject: [PATCH] -

---
 src/utils/auth.ts |  179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 175 insertions(+), 4 deletions(-)

diff --git a/src/utils/auth.ts b/src/utils/auth.ts
index f2b28cb..65b67b0 100644
--- a/src/utils/auth.ts
+++ b/src/utils/auth.ts
@@ -1,6 +1,7 @@
 import Cookies from "js-cookie";
 import { useUserStoreHook } from "@/store/modules/user";
 import { storageLocal, isString, isIncludeAllChildren } from "@pureadmin/utils";
+import type { nowRoleType } from "@/store/types";
 
 export interface DataInfo<T> {
   /** token */
@@ -15,10 +16,136 @@
   username?: string;
   /** 鏄电О */
   nickname?: string;
+  /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勮鑹插垪琛� */
+  exRoles?: Array<string>;
   /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勮鑹� */
   roles?: Array<string>;
   /** 褰撳墠鐧诲綍鐢ㄦ埛鐨勬寜閽骇鍒潈闄� */
   permissions?: Array<string>;
+}
+/**
+ * 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";
@@ -43,7 +170,7 @@
  * @description 璁剧疆`token`浠ュ強涓�浜涘繀瑕佷俊鎭苟閲囩敤鏃犳劅鍒锋柊`token`鏂规
  * 鏃犳劅鍒锋柊锛氬悗绔繑鍥瀈accessToken`锛堣闂帴鍙d娇鐢ㄧ殑`token`锛夈�乣refreshToken`锛堢敤浜庤皟鐢ㄥ埛鏂癭accessToken`鐨勬帴鍙f椂鎵�闇�鐨刞token`锛宍refreshToken`鐨勮繃鏈熸椂闂达紙姣斿30澶╋級搴斿ぇ浜巂accessToken`鐨勮繃鏈熸椂闂达紙姣斿2灏忔椂锛夛級銆乣expires`锛坄accessToken`鐨勮繃鏈熸椂闂达級
  * 灏哷accessToken`銆乣expires`銆乣refreshToken`杩欎笁鏉′俊鎭斁鍦╧ey鍊间负authorized-token鐨刢ookie閲岋紙杩囨湡鑷姩閿�姣侊級
- * 灏哷avatar`銆乣username`銆乣nickname`銆乣roles`銆乣permissions`銆乣refreshToken`銆乣expires`杩欎竷鏉′俊鎭斁鍦╧ey鍊间负`user-info`鐨刲ocalStorage閲岋紙鍒╃敤`multipleTabsKey`褰撴祻瑙堝櫒瀹屽叏鍏抽棴鍚庤嚜鍔ㄩ攢姣侊級
+ * 灏哷avatar`銆乣username`銆乣nickname`銆乣exRoles`銆乣permissions`銆乣refreshToken`銆乣expires`杩欎竷鏉′俊鎭斁鍦╧ey鍊间负`user-info`鐨刲ocalStorage閲岋紙鍒╃敤`multipleTabsKey`褰撴祻瑙堝櫒瀹屽叏鍏抽棴鍚庤嚜鍔ㄩ攢姣侊級
  */
 export function setToken(data: DataInfo<Date>) {
   let expires = 0;
@@ -68,10 +195,18 @@
       : {}
   );
 
-  function setUserKey({ avatar, username, nickname, roles, permissions }) {
+  function setUserKey({
+    avatar,
+    username,
+    nickname,
+    exRoles,
+    permissions,
+    roles
+  }) {
     useUserStoreHook().SET_AVATAR(avatar);
     useUserStoreHook().SET_USERNAME(username);
     useUserStoreHook().SET_NICKNAME(nickname);
+    useUserStoreHook().SET_EXROLES(exRoles);
     useUserStoreHook().SET_ROLES(roles);
     useUserStoreHook().SET_PERMS(permissions);
     storageLocal().setItem(userKey, {
@@ -80,17 +215,19 @@
       avatar,
       username,
       nickname,
+      exRoles,
       roles,
       permissions
     });
   }
 
-  if (data.username && data.roles) {
-    const { username, roles } = data;
+  if (data.exRoles && data.roles) {
+    const { username, exRoles, roles } = data;
     setUserKey({
       avatar: data?.avatar ?? "",
       username,
       nickname: data?.nickname ?? "",
+      exRoles,
       roles,
       permissions: data?.permissions ?? []
     });
@@ -101,6 +238,8 @@
       storageLocal().getItem<DataInfo<number>>(userKey)?.username ?? "";
     const nickname =
       storageLocal().getItem<DataInfo<number>>(userKey)?.nickname ?? "";
+    const exRoles =
+      storageLocal().getItem<DataInfo<number>>(userKey)?.exRoles ?? [];
     const roles =
       storageLocal().getItem<DataInfo<number>>(userKey)?.roles ?? [];
     const permissions =
@@ -109,12 +248,44 @@
       avatar,
       username,
       nickname,
+      exRoles,
       roles,
       permissions
     });
   }
 }
 
+export function setEnterpriseInfo(data: CusExtendDto) {
+  useUserStoreHook().SET_ENTERPRISEINFO(data);
+  useUserStoreHook().SET_USERNAME(data.enterpriseName);
+  storageLocal().setItem("enterpriseInfo", data);
+  const obj = storageLocal().getItem(userKey);
+  obj.username = data.enterpriseName;
+  storageLocal().setItem(userKey, obj);
+}
+
+export function setRoleListInfo(data: DataInfo<string>) {
+  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 = { ...obj, ...data };
+  }
+  useUserStoreHook().SET_ROLES([data.name]);
+  useUserStoreHook().SET_NOW_ROLE(data);
+  storageLocal().setItem("nowRole", data);
+}
+
+export function removeEnterpriseInfo() {
+  storageLocal().removeItem("enterpriseInfo");
+}
+
 /** 鍒犻櫎`token`浠ュ強key鍊间负`user-info`鐨刲ocalStorage淇℃伅 */
 export function removeToken() {
   Cookies.remove(TokenKey);

--
Gitblit v1.9.1