From b94b71d44d62802bb8093f64a202d0176fdade50 Mon Sep 17 00:00:00 2001 From: zhangwei <1504152376@qq.com> Date: 星期二, 05 八月 2025 17:00:46 +0800 Subject: [PATCH] '一些更改' --- src/utils/auth.ts | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 165 insertions(+), 6 deletions(-) diff --git a/src/utils/auth.ts b/src/utils/auth.ts index 37cda2f..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"; @@ -68,11 +195,19 @@ : {} ); - function setUserKey({ avatar, username, nickname, exRoles, permissions }) { + function setUserKey({ + avatar, + username, + nickname, + exRoles, + permissions, + roles + }) { 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); storageLocal().setItem(userKey, { refreshToken, @@ -81,17 +216,19 @@ username, nickname, exRoles, + roles, permissions }); } - if (data.exRoles) { - const { username, exRoles } = data; + if (data.exRoles && data.roles) { + const { username, exRoles, roles } = data; setUserKey({ avatar: data?.avatar ?? "", username, nickname: data?.nickname ?? "", exRoles, + roles, permissions: data?.permissions ?? [] }); } else { @@ -103,6 +240,8 @@ 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 ?? []; setUserKey({ @@ -110,12 +249,13 @@ username, nickname, exRoles, + roles, permissions }); } } -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 +263,25 @@ 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"); } -- Gitblit v1.9.1