From 381abcea606768c25350cd007c8484409d2e893f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E8=82=96=E7=A3=8A?= <18851179580@163.com> Date: Fri, 8 Aug 2025 18:39:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E7=9A=84?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/common.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/utils/common.ts b/src/utils/common.ts index f6cddb18..dd98671f 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -19,16 +19,18 @@ export const font_weight = [ // 截取document.location.search字符串内id/后面的所有字段 export const get_id = () => { let new_id = ''; - if (document.location.search.indexOf('id/') != -1) { - new_id = document.location.search.substring(document.location.search.indexOf('id/') + 3); + // 去除origin的数据 + const url = document.location.href.replace(document.location.origin, ''); + if (url.indexOf('id/') != -1) { + new_id = url.substring(url.indexOf('id/') + 3); // 去除字符串的.html let html_index = new_id.indexOf('.html'); if (html_index != -1) { new_id = new_id.substring(0, html_index); } return new_id; - } else if (document.location.search.indexOf('shop-diy-saveinfo') != -1) { - new_id = document.location.search.substring(document.location.search.indexOf('shop-diy-saveinfo-') + 18); + } else if (url.indexOf('shop-diy-saveinfo') != -1) { + new_id = url.substring(url.indexOf('shop-diy-saveinfo-') + 18); // 去除字符串的.html const dot_data = new_id.split('.')[0]; if (dot_data != '') { @@ -42,8 +44,10 @@ export const get_id = () => { export const get_type = () => { let new_type = ''; - if (document.location.search.indexOf('type/') != -1) { - new_type = document.location.search.substring(document.location.search.indexOf('type/') + 5); + // 去除origin的数据 + const url = document.location.href.replace(document.location.origin, ''); + if (url.indexOf('type/') != -1) { + new_type = url.substring(url.indexOf('type/') + 5); // 去除字符串的.html // 去除字符串的.html const dot_data = new_type.split('.')[0];