From f41ea5aeb429beb17e388a3a460722252ebaffdc Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sat, 25 Jan 2025 21:14:36 +0800 Subject: [PATCH 1/6] =?UTF-8?q?1=E3=80=81=E5=B0=86h5=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=BA=A4=E7=94=B1.env=E9=85=8D=E7=BD=AE=202?= =?UTF-8?q?=E3=80=81=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=86=85=E5=A4=8D=E5=88=B6=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E7=8B=AC=E7=AB=8B=E9=85=8D=E7=BD=AE=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=203=E3=80=81=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=A4=9A=E5=9F=9F=E5=90=8D=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E9=9A=8F=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 8 ++++++++ sheep/config/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ sheep/store/app.js | 3 ++- 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 0c3c73f7..f24fc458 100644 --- a/.env +++ b/.env @@ -29,3 +29,11 @@ SHOPRO_MPLIVE_ON=0 # 租户ID 默认 1 SHOPRO_TENANT_ID=1 + +# H5 分享链接(普通浏览器使用,多个链接用逗号分隔) +# SHOPRO_H5SHARE_URL=https://h5-1.example.com,https://h5-2.example.com +SHOPRO_H5SHARE_URL=https://java.qiye.ekcc.vip + +# 小程序 分享链接(多个链接用逗号分隔) +# SHOPRO_MINI_BASE_URL=https://mini-1.example.com,https://mini-2.example.com +SHOPRO_MINI_BASE_URL=https://java.qiye.ekcc.vip \ No newline at end of file diff --git a/sheep/config/index.js b/sheep/config/index.js index 9aa4f523..91cf8405 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -14,10 +14,50 @@ export const staticUrl = import.meta.env.SHOPRO_STATIC_URL; export const tenantId = import.meta.env.SHOPRO_TENANT_ID; export const websocketPath = import.meta.env.SHOPRO_WEBSOCKET_PATH; +// 判断是否在小程序环境中 +const isMiniProgram = typeof wx !== 'undefined' && typeof wx.getSystemInfoSync === 'function' && typeof window === 'undefined'; + +// 解析逗号分隔的域名 +const parseCommaSeparatedUrls = (urls) => { + if (!urls) { + console.warn('未配置分享链接'); + return null; + } + const urlList = urls + .split(',') // 按逗号分割 + .map(url => url.trim()) // 去除空白 + .filter(url => url); // 过滤空字符串 + if (urlList.length === 0) { + console.warn('分享链接配置为空或无效'); + return null; + } + return urlList[Math.floor(Math.random() * urlList.length)]; // 随机选择一个域名 +}; + +// 获取 H5 分享链接 +// 普通浏览器:使用 SHOPRO_H5SHARE_URL +// 小程序环境:使用 SHOPRO_MINI_BASE_URL +export const h5shareUrl = isMiniProgram + ? parseCommaSeparatedUrls(import.meta.env.SHOPRO_MINI_BASE_URL) + : parseCommaSeparatedUrls(import.meta.env.SHOPRO_H5SHARE_URL); + +// 确保 h5shareUrl 是完整的 URL +if (h5shareUrl && !h5shareUrl.startsWith('http')) { + console.warn('h5shareUrl 必须是完整的 URL,不能是路径'); + h5shareUrl = null; // 如果配置错误,设置为 null +} + +// 调试信息 +console.log('wx:', wx); +console.log('wx.getSystemInfoSync:', wx && wx.getSystemInfoSync); +console.log('isMiniProgram:', isMiniProgram); +console.log('h5shareUrl:', h5shareUrl); + export default { baseUrl, apiPath, staticUrl, tenantId, websocketPath, + h5shareUrl, }; diff --git a/sheep/store/app.js b/sheep/store/app.js index 36f767f1..1f6bece8 100644 --- a/sheep/store/app.js +++ b/sheep/store/app.js @@ -4,6 +4,7 @@ import $platform from '@/sheep/platform'; import $router from '@/sheep/router'; import user from './user'; import sys from './sys'; +import { h5shareUrl } from '@/sheep/config'; const app = defineStore({ id: 'app', @@ -72,7 +73,7 @@ const app = defineStore({ this.platform = { share: { methods: ['forward', 'poster', 'link'], - linkAddress: 'http://127.0.0.1:3000', // TODO 芋艿:可以考虑改到 .env 那 + linkAddress: h5shareUrl, // 已交由.env接管 posterInfo: { user_bg: '/static/img/shop/config/user-poster-bg.png', goods_bg: '/static/img/shop/config/goods-poster-bg.png', From 5cdaa82f83748b5f0474c2a73fcba530899d3b77 Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sat, 25 Jan 2025 21:29:03 +0800 Subject: [PATCH 2/6] =?UTF-8?q?1=E3=80=81=E5=B0=86h5=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=BA=A4=E7=94=B1.env=E9=85=8D=E7=BD=AE=202?= =?UTF-8?q?=E3=80=81=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=E5=B0=8F=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F=E5=86=85=E5=A4=8D=E5=88=B6=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E7=8B=AC=E7=AB=8B=E9=85=8D=E7=BD=AE=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=203=E3=80=81=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E5=A4=9A=E5=9F=9F=E5=90=8D=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E9=9A=8F=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index f24fc458..c98d9040 100644 --- a/.env +++ b/.env @@ -32,8 +32,8 @@ SHOPRO_TENANT_ID=1 # H5 分享链接(普通浏览器使用,多个链接用逗号分隔) # SHOPRO_H5SHARE_URL=https://h5-1.example.com,https://h5-2.example.com -SHOPRO_H5SHARE_URL=https://java.qiye.ekcc.vip +SHOPRO_H5SHARE_URL=https://h5.example.com # 小程序 分享链接(多个链接用逗号分隔) # SHOPRO_MINI_BASE_URL=https://mini-1.example.com,https://mini-2.example.com -SHOPRO_MINI_BASE_URL=https://java.qiye.ekcc.vip \ No newline at end of file +SHOPRO_MINI_BASE_URL=https://mini.example.com \ No newline at end of file From 49bbe4922e15c899a3cf46a15fa642703fe30dd8 Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sat, 25 Jan 2025 23:14:30 +0800 Subject: [PATCH 3/6] =?UTF-8?q?h5=E5=88=86=E4=BA=AB=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 8 ++++---- sheep/config/index.js | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.env b/.env index c98d9040..9e33693a 100644 --- a/.env +++ b/.env @@ -31,9 +31,9 @@ SHOPRO_MPLIVE_ON=0 SHOPRO_TENANT_ID=1 # H5 分享链接(普通浏览器使用,多个链接用逗号分隔) -# SHOPRO_H5SHARE_URL=https://h5-1.example.com,https://h5-2.example.com -SHOPRO_H5SHARE_URL=https://h5.example.com +# SHOPRO_H5SHARE_URL=https://h5-1.iocoder.cn,https://h5-2.iocoder.cn +SHOPRO_H5SHARE_URL=https://h5.iocoder.cn,https://h5-2.iocoder.cn # 小程序 分享链接(多个链接用逗号分隔) -# SHOPRO_MINI_BASE_URL=https://mini-1.example.com,https://mini-2.example.com -SHOPRO_MINI_BASE_URL=https://mini.example.com \ No newline at end of file +# SHOPRO_MINI_BASE_URL=https://mini-1.iocoder.cn,https://mini-2.iocoder.cn +SHOPRO_MINI_BASE_URL=https://mini.yudao.iocoder.cn,https://mini-2.iocoder.cn \ No newline at end of file diff --git a/sheep/config/index.js b/sheep/config/index.js index 91cf8405..b268ae87 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -37,19 +37,18 @@ const parseCommaSeparatedUrls = (urls) => { // 获取 H5 分享链接 // 普通浏览器:使用 SHOPRO_H5SHARE_URL // 小程序环境:使用 SHOPRO_MINI_BASE_URL -export const h5shareUrl = isMiniProgram +export let h5shareUrl = isMiniProgram ? parseCommaSeparatedUrls(import.meta.env.SHOPRO_MINI_BASE_URL) : parseCommaSeparatedUrls(import.meta.env.SHOPRO_H5SHARE_URL); // 确保 h5shareUrl 是完整的 URL if (h5shareUrl && !h5shareUrl.startsWith('http')) { console.warn('h5shareUrl 必须是完整的 URL,不能是路径'); - h5shareUrl = null; // 如果配置错误,设置为 null + h5shareUrl = 'https://default-h5.example.com'; // 如果配置错误,设置为默认值 } // 调试信息 -console.log('wx:', wx); -console.log('wx.getSystemInfoSync:', wx && wx.getSystemInfoSync); +console.log('当前环境:', process.env.NODE_ENV); console.log('isMiniProgram:', isMiniProgram); console.log('h5shareUrl:', h5shareUrl); @@ -60,4 +59,4 @@ export default { tenantId, websocketPath, h5shareUrl, -}; +}; \ No newline at end of file From df64ac9aea00067516b2b64abad763ceb62385ff Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sat, 25 Jan 2025 23:33:57 +0800 Subject: [PATCH 4/6] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BE=BF=E4=BA=8E=E7=90=86?= =?UTF-8?q?=E8=A7=A3=202=E3=80=81=E5=A2=9E=E5=8A=A0=E6=9C=AA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5=E6=88=96=E8=80=85?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=87=BA=E9=94=99=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=9F=9F=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 8 ++++---- sheep/config/index.js | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.env b/.env index 9e33693a..31ee04cf 100644 --- a/.env +++ b/.env @@ -30,10 +30,10 @@ SHOPRO_MPLIVE_ON=0 # 租户ID 默认 1 SHOPRO_TENANT_ID=1 -# H5 分享链接(普通浏览器使用,多个链接用逗号分隔) +# H5 分享链接(在浏览器内复制得到的链接,多个链接用逗号分隔) # SHOPRO_H5SHARE_URL=https://h5-1.iocoder.cn,https://h5-2.iocoder.cn -SHOPRO_H5SHARE_URL=https://h5.iocoder.cn,https://h5-2.iocoder.cn +SHOPRO_H5SHARE_URL=https://h5.iocoder.cn -# 小程序 分享链接(多个链接用逗号分隔) +# 小程序 分享链接(在小程序内复制得到的链接,多个链接用逗号分隔) # SHOPRO_MINI_BASE_URL=https://mini-1.iocoder.cn,https://mini-2.iocoder.cn -SHOPRO_MINI_BASE_URL=https://mini.yudao.iocoder.cn,https://mini-2.iocoder.cn \ No newline at end of file +SHOPRO_MINI_BASE_URL=https://mini.iocoder.cn \ No newline at end of file diff --git a/sheep/config/index.js b/sheep/config/index.js index b268ae87..7940e04e 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -20,7 +20,7 @@ const isMiniProgram = typeof wx !== 'undefined' && typeof wx.getSystemInfoSync = // 解析逗号分隔的域名 const parseCommaSeparatedUrls = (urls) => { if (!urls) { - console.warn('未配置分享链接'); + console.warn('未配置分享链接,使用默认域名'); return null; } const urlList = urls @@ -28,9 +28,10 @@ const parseCommaSeparatedUrls = (urls) => { .map(url => url.trim()) // 去除空白 .filter(url => url); // 过滤空字符串 if (urlList.length === 0) { - console.warn('分享链接配置为空或无效'); + console.warn('分享链接配置为空或无效,使用默认域名'); return null; } + console.log('可用域名列表:', urlList); // 打印可用域名列表 return urlList[Math.floor(Math.random() * urlList.length)]; // 随机选择一个域名 }; @@ -38,13 +39,13 @@ const parseCommaSeparatedUrls = (urls) => { // 普通浏览器:使用 SHOPRO_H5SHARE_URL // 小程序环境:使用 SHOPRO_MINI_BASE_URL export let h5shareUrl = isMiniProgram - ? parseCommaSeparatedUrls(import.meta.env.SHOPRO_MINI_BASE_URL) - : parseCommaSeparatedUrls(import.meta.env.SHOPRO_H5SHARE_URL); + ? parseCommaSeparatedUrls(import.meta.env.SHOPRO_MINI_BASE_URL) || 'https://doc.iocoder.cn/' + : parseCommaSeparatedUrls(import.meta.env.SHOPRO_H5SHARE_URL) || 'https://doc.iocoder.cn/'; // 确保 h5shareUrl 是完整的 URL if (h5shareUrl && !h5shareUrl.startsWith('http')) { - console.warn('h5shareUrl 必须是完整的 URL,不能是路径'); - h5shareUrl = 'https://default-h5.example.com'; // 如果配置错误,设置为默认值 + console.warn('h5shareUrl 必须是完整的 URL,不能是路径,使用默认域名'); + h5shareUrl = 'https://doc.iocoder.cn/'; // 如果配置错误,设置为默认值 } // 调试信息 From f34035f0b4a7c0292d8c04e0f4ed8b50a0448874 Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sun, 26 Jan 2025 00:17:18 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BC=98=E5=8C=96h5=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=BD=93=E5=9F=9F=E5=90=8D=E6=9C=AA?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=88=96=E9=85=8D=E7=BD=AE=E6=9C=89=E8=AF=AF?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/config/index.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/sheep/config/index.js b/sheep/config/index.js index 7940e04e..1f0e8186 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -17,11 +17,14 @@ export const websocketPath = import.meta.env.SHOPRO_WEBSOCKET_PATH; // 判断是否在小程序环境中 const isMiniProgram = typeof wx !== 'undefined' && typeof wx.getSystemInfoSync === 'function' && typeof window === 'undefined'; -// 解析逗号分隔的域名 -const parseCommaSeparatedUrls = (urls) => { +// 默认域名 +const DEFAULT_DOMAIN = 'https://doc.iocoder.cn/'; + +// 解析域名并设置默认值 +const parseDomain = (urls, defaultDomain) => { if (!urls) { console.warn('未配置分享链接,使用默认域名'); - return null; + return defaultDomain; } const urlList = urls .split(',') // 按逗号分割 @@ -29,24 +32,23 @@ const parseCommaSeparatedUrls = (urls) => { .filter(url => url); // 过滤空字符串 if (urlList.length === 0) { console.warn('分享链接配置为空或无效,使用默认域名'); - return null; + return defaultDomain; } console.log('可用域名列表:', urlList); // 打印可用域名列表 - return urlList[Math.floor(Math.random() * urlList.length)]; // 随机选择一个域名 + const selectedDomain = urlList[Math.floor(Math.random() * urlList.length)]; // 随机选择一个域名 + if (!selectedDomain.startsWith('http')) { + console.warn('域名必须是完整的 URL,不能是路径,使用默认域名'); + return defaultDomain; + } + return selectedDomain; }; // 获取 H5 分享链接 // 普通浏览器:使用 SHOPRO_H5SHARE_URL // 小程序环境:使用 SHOPRO_MINI_BASE_URL export let h5shareUrl = isMiniProgram - ? parseCommaSeparatedUrls(import.meta.env.SHOPRO_MINI_BASE_URL) || 'https://doc.iocoder.cn/' - : parseCommaSeparatedUrls(import.meta.env.SHOPRO_H5SHARE_URL) || 'https://doc.iocoder.cn/'; - -// 确保 h5shareUrl 是完整的 URL -if (h5shareUrl && !h5shareUrl.startsWith('http')) { - console.warn('h5shareUrl 必须是完整的 URL,不能是路径,使用默认域名'); - h5shareUrl = 'https://doc.iocoder.cn/'; // 如果配置错误,设置为默认值 -} + ? parseDomain(import.meta.env.SHOPRO_MINI_BASE_URL, DEFAULT_DOMAIN) + : parseDomain(import.meta.env.SHOPRO_H5SHARE_URL, DEFAULT_DOMAIN); // 调试信息 console.log('当前环境:', process.env.NODE_ENV); From 1e8ccf1fafd3e1c9cdebcdef54d5d5fb7e5b4996 Mon Sep 17 00:00:00 2001 From: lifetime have you <121815889@qq.com> Date: Sun, 26 Jan 2025 00:35:33 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BC=98=E5=8C=96h5=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=BD=93=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E6=9C=AA=E9=85=8D=E7=BD=AE=E6=88=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=9C=89=E8=AF=AF=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E5=9F=9F?= =?UTF-8?q?=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/config/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sheep/config/index.js b/sheep/config/index.js index 1f0e8186..22c8b5e5 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -18,7 +18,7 @@ export const websocketPath = import.meta.env.SHOPRO_WEBSOCKET_PATH; const isMiniProgram = typeof wx !== 'undefined' && typeof wx.getSystemInfoSync === 'function' && typeof window === 'undefined'; // 默认域名 -const DEFAULT_DOMAIN = 'https://doc.iocoder.cn/'; +const DEFAULT_DOMAIN = 'http://127.0.0.1:3000/'; // 解析域名并设置默认值 const parseDomain = (urls, defaultDomain) => {