From ec44a6b0fc07b6b7b0ea80d724029c553903fef7 Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 26 Dec 2025 08:48:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=AE=89=E5=85=A8):=20=E6=B7=BB=E5=8A=A0H?= =?UTF-8?q?TTP=E8=BD=ACHTTPS=E5=8A=9F=E8=83=BD=E5=B9=B6=E5=A2=9E=E5=BC=BAU?= =?UTF-8?q?RL=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增toHttpsUrl工具函数用于将http链接转换为https - 添加parseQueryParameters函数支持复杂URL参数解析 - 在地址选择面板中应用https转换功能 --- src/common/utils/common.ts | 63 +++++++++++++++++++ .../components/AddressSelectionPanel.vue | 3 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/common/utils/common.ts diff --git a/src/common/utils/common.ts b/src/common/utils/common.ts new file mode 100644 index 0000000..07ed5c0 --- /dev/null +++ b/src/common/utils/common.ts @@ -0,0 +1,63 @@ +/** + * 将URL中的 http:// 替换为 https:// + * @param url 原始URL字符串 + * @returns 替换后的URL字符串 + */ +export function toHttpsUrl(url: string): string { + // 严格类型检查 + if (typeof url !== 'string') { + return url; + } + // 检查是否以 http:// 开头 + if (!/^http:\/\//i.test(url)) { + return url; + } + return url.replace(/^http:\/\//i, 'https://'); +} + +/** + * 终极版URL参数解析函数(支持哈希内参数和各种异常格式) + * @param url 任意格式的URL字符串 + * @returns 解析后的参数对象 + */ +export function parseQueryParameters(url: string): Record { + const params: Record = {}; + if (!url) return params; + + try { + // 1. 分离URL主体和哈希部分 + const [urlMain, hashPart] = url.split('#'); + + // 2. 收集所有可能的参数来源 + const paramSources: string[] = []; + + // 2.1 处理URL主体中的标准查询参数 + if (urlMain?.includes('?')) { + paramSources.push(urlMain.split('?')[1]); + } + + // 2.2 处理哈希部分中可能存在的参数 + if (hashPart?.includes('?')) { + paramSources.push(hashPart.split('?')[1]); + } + + // 3. 合并并解析所有参数 + if (paramSources.length > 0) { + const allParams = paramSources.join('&'); + + allParams.split('&').forEach(param => { + // 处理编码的等号(%3D)和普通等号 + const decodedParam = decodeURIComponent(param); + const [key, value] = decodedParam.split('='); + + if (key) { + params[key] = value ? decodeURIComponent(value) : ''; + } + }); + } + } catch (e) { + console.error('参数解析失败:', e); + } + + return params; +} diff --git a/src/pages/cabinet/components/AddressSelectionPanel.vue b/src/pages/cabinet/components/AddressSelectionPanel.vue index f3c3798..e381bdb 100644 --- a/src/pages/cabinet/components/AddressSelectionPanel.vue +++ b/src/pages/cabinet/components/AddressSelectionPanel.vue @@ -14,7 +14,7 @@ @click="handleShopSelect(shop.shopId)" > @@ -43,6 +43,7 @@