Pre Merge pull request !139 from lifetime have you/master-Pull

pull/139/MERGE
lifetime have you 2025-01-25 16:36:28 +00:00 committed by Gitee
commit 0415021bf0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 53 additions and 2 deletions

8
.env
View File

@ -29,3 +29,11 @@ SHOPRO_MPLIVE_ON=0
# 租户ID 默认 1
SHOPRO_TENANT_ID=1
# H5 分享链接(在浏览器内复制得到的链接,多个链接用逗号分隔)
# SHOPRO_H5SHARE_URL=https://h5-1.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.iocoder.cn

View File

@ -14,10 +14,52 @@ 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 DEFAULT_DOMAIN = 'http://127.0.0.1:3000/';
// 解析域名并设置默认值
const parseDomain = (urls, defaultDomain) => {
if (!urls) {
console.warn('未配置分享链接,使用默认域名');
return defaultDomain;
}
const urlList = urls
.split(',') // 按逗号分割
.map(url => url.trim()) // 去除空白
.filter(url => url); // 过滤空字符串
if (urlList.length === 0) {
console.warn('分享链接配置为空或无效,使用默认域名');
return defaultDomain;
}
console.log('可用域名列表:', urlList); // 打印可用域名列表
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
? 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);
console.log('isMiniProgram:', isMiniProgram);
console.log('h5shareUrl:', h5shareUrl);
export default {
baseUrl,
apiPath,
staticUrl,
tenantId,
websocketPath,
};
h5shareUrl,
};

View File

@ -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',