From 70f58df4daebf7dba7f4a24aee506e14885761bd Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期二, 19 八月 2025 14:45:41 +0800 Subject: [PATCH] fix: bug --- src/utils/common/common.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 40 insertions(+), 0 deletions(-) diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts index b05dfc3..2a52bc0 100644 --- a/src/utils/common/common.ts +++ b/src/utils/common/common.ts @@ -106,3 +106,43 @@ export function filterNumbersFromString(str: string) { return str.replace(/\D/g, ''); } + +export function formatRoleName(roleName: string) { + let lastUnderscoreIndex = roleName.lastIndexOf('_'); + + if (lastUnderscoreIndex !== -1) { + roleName = roleName.substring(0, lastUnderscoreIndex); + } + return roleName; +} + +/** + * 鍓旈櫎瀵硅薄涓�间负 ''銆乽ndefined銆乶ull 鐨勯敭锛屾敮鎸佸祵濂楀璞� + * @param {Object} obj - 闇�瑕佸鐞嗙殑瀵硅薄 + * @returns {Object} 澶勭悊鍚庣殑鏂板璞� + */ +export function removeEmptyKeys<T extends object>(obj: T) { + // 濡傛灉涓嶆槸瀵硅薄鎴栦负null锛岀洿鎺ヨ繑鍥炲師鍊� + if (obj === null || typeof obj !== 'object') { + return obj; + } + + // 澶勭悊鏁扮粍锛堥�掑綊澶勭悊姣忎釜鍏冪礌锛� + if (Array.isArray(obj)) { + return obj.map((item) => removeEmptyKeys(item)); + } + + // 澶勭悊瀵硅薄 + const result = {} as T; + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + //@ts-ignore + const value = removeEmptyKeys(obj[key]); // 閫掑綊澶勭悊宓屽瀵硅薄 + // 鍙繚鐣欓潪绌哄�硷紙鎺掗櫎''銆乽ndefined銆乶ull锛� + if (value !== '' && value !== undefined && value !== null) { + result[key] = value; + } + } + } + return result; +} -- Gitblit v1.9.1