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

pull/138/MERGE
lifetime have you 2025-01-25 13:23:27 +00:00 committed by Gitee
commit bdc2c9d041
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 50 additions and 1 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.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

View File

@ -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,
};

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