From 8aff48128c0d1406590e2706b57039961a232a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com> Date: Thu, 6 Nov 2025 14:47:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=AC=E5=85=B1=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=8E=B7=E5=8F=96=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/common.ts | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index 4d407510..70f13a46 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -46,39 +46,47 @@ const extractIdFromUrl = (prefix: string): string => { if (slashIndex !== -1) { result = result.substring(0, slashIndex); } + + // 移除路径分隔符后的部分 + const index = result.indexOf('-'); + if (index !== -1) { + result = result.substring(0, index); + } return result; }; // 截取document.location.search字符串内id/后面的所有字段 export const get_id = () => { - // 先尝试匹配 id/ 模式 - const url = document.location.href; - const idIndex = url.indexOf('id/'); - if (idIndex !== -1) { - const result = url.substring(idIndex + 3); - const htmlIndex = result.indexOf('.html'); - if (htmlIndex !== -1) { - return result.substring(0, htmlIndex); - } - return result.split('.')[0].split('/')[0]; - } + const id = get_handle('id', ''); + if (id != '') return id; // 尝试匹配-saveinfo-模式 const saveinfoResult = extractIdFromUrl('-saveinfo-'); if (saveinfoResult) return saveinfoResult; - // 尝试匹配-forminputinfo-模式 + // 尝试匹配-diyinfo-模式 return extractIdFromUrl('-diyinfo-'); }; -// 获取当前业务类型 +// 获取当前类型 export const get_type = () => { - return data_handle('type/', ''); + return get_handle('type', ''); } -// 获取类型 +// 获取业务类型 export const get_business = () => { - return data_handle('business/', ''); + return get_handle('business', ''); +} + +function get_handle(type: string, default_value: string) { + const patterns = [`/${type}/`, `-${type}-`, `&${type}=`, `?${type}=`]; + + for (const pattern of patterns) { + const value = data_handle(pattern, default_value); + if (value !== default_value) return value; + } + + return default_value; } // 数据处理 export const data_handle = (val: string, default_val: string): string => {