Compare commits

10 Commits

9 changed files with 1728 additions and 4264 deletions

View File

@@ -7,7 +7,7 @@ export default {
computed: { computed: {
// 是否是英文环境 // 是否是英文环境
isEnEnv() { isEnEnv() {
return this.$langConfig.getCurrentLocale() === 'en-us'; return uni.getStorageSync('lang') === 'en-us';
}, },
themeStyle() { themeStyle() {
return this.$store.state.themeStyle; return this.$store.state.themeStyle;
@@ -65,6 +65,10 @@ export default {
componentRefresh() { componentRefresh() {
return this.$store.state.componentRefresh; return this.$store.state.componentRefresh;
}, },
// AI客服配置
globalAIKefuConfig() {
return this.$store.state.globalAIKefuConfig;
},
// 客服配置 // 客服配置
servicerConfig() { servicerConfig() {
return this.$store.state.servicerConfig; return this.$store.state.servicerConfig;

View File

@@ -1,215 +1,161 @@
import { langConfig } from './config-external.js'; import { langConfig } from './config-external.js';
// 缓存已加载的语言包 // 缓存已加载的语言包
const loadedLangPacks = {}; const loadedLangPacks = {};
// 处理页面目录映射 // 处理页面目录映射
function processRoutePath(route) { function processRoutePath(route) {
let routeParts = route.split("/"); let routeParts = route.split("/");
// ---- 处理页面目录映射 <begin> 分包造成的,需要根据实际目录结构进行映射---- // ---- 处理页面目录映射 <begin> 分包造成的,需要根据实际目录结构进行映射----
// 先处理特殊的分包路径 if (routeParts[0] === 'pages_tool') {
if (routeParts[0] === 'pages_tool') { routeParts = [routeParts[1], ...routeParts.slice(2)];
// pages_tool 分包下的页面,直接使用子目录作为语言包路径 } else if (routeParts[0] === 'pages_goods') {
routeParts = [routeParts[1], ...routeParts.slice(2)]; routeParts[0] = 'goods';
} else if (routeParts[0] === 'pages_goods') { } else if (routeParts[0] === 'pages_member') {
// pages_goods 分包映射到 goods 目录 routeParts[0] = 'member';
routeParts[0] = 'goods'; } else if (routeParts[0] === 'pages_order') {
} else if (routeParts[0] === 'pages_member') { routeParts[0] = 'order';
// pages_member 分包映射到 member 目录 } else if (routeParts[0] === 'pages_promotion') {
routeParts[0] = 'member'; const promotionModules = ['point', 'fenxiao', 'merch'];
} else if (routeParts[0] === 'pages_order') { if (routeParts[1] && promotionModules.includes(routeParts[1])) {
// pages_order 分包映射到 order 目录 routeParts = [routeParts[1], ...routeParts.slice(2)];
routeParts[0] = 'order'; }
} else if (routeParts[0] === 'pages_promotion') { }
// pages_promotion 分包特殊处理 // ---- 处理页面目录映射 <end>----
const promotionModules = ['point', 'fenxiao', 'merch'];
if (routeParts[1] && promotionModules.includes(routeParts[1])) { if (routeParts[0] === 'pages') {
routeParts = [routeParts[1], ...routeParts.slice(2)]; routeParts = routeParts.slice(1);
} }
}
// ---- 处理页面目录映射 <end>---- return routeParts.join("/");
// 去掉pages目录只保留子目录
if (routeParts[0] === 'pages') {
routeParts = routeParts.slice(1);
}
return routeParts.join("/");
} }
// 加载语言包(同步方式) // 加载语言包(同步方式)
function loadLangPackSync(lang, path) { function loadLangPackSync(lang, path) {
try { try {
if (loadedLangPacks[`${lang}_${path}`]) { if (loadedLangPacks[`${lang}_${path}`]) {
return loadedLangPacks[`${lang}_${path}`]; return loadedLangPacks[`${lang}_${path}`];
} }
const langData = require(`@/lang/${lang}/${path}.js`).lang; const langData = require(`@/lang/${lang}/${path}.js`).lang;
loadedLangPacks[`${lang}_${path}`] = langData; loadedLangPacks[`${lang}_${path}`] = langData;
return langData; return langData;
} catch (error) { } catch (error) {
console.error(`加载语言包 ${lang}/${path} 失败:`, error); console.error(`加载语言包 ${lang}/${path} 失败:`, error);
return {}; return {};
} }
} }
export default { export default {
langList: langConfig.langList, langList: langConfig.langList,
/**
* 解析多语言
*/
lang(field) {
let _this = getCurrentPages()[getCurrentPages().length - 1];
if (!_this) return;
/** const locale = uni.getStorageSync('lang') || "zh-cn";
* 获得当前本地语言
* @returns
*/
getCurrentLocale() {
return uni.getStorageSync('lang') || "zh-cn";
},
/** let value = '';
* * 解析多语言 let langPath = '';
* @param {Object} field
*/
lang(field) {
let _page = getCurrentPages()[getCurrentPages().length - 1];
if (!_page) return;
const locale = this.getCurrentLocale(); // 获得当前本地语言 try {
var lang = loadLangPackSync(locale, 'common');
let route = _this.route;
langPath = processRoutePath(route);
let currentPageLang = loadLangPackSync(locale, langPath);
let value = ''; // 存放解析后的语言值 let mergedLang = { ...lang, ...currentPageLang };
let langPath = ''; // 存放当前页面语言包路径
try { var arr = field.split(".");
//公共语言包(同步加载) if (arr.length > 1) {
var lang = loadLangPackSync(locale, 'common'); let temp = mergedLang;
let found = true;
//当前页面语言包(同步加载) for (let key of arr) {
let route = _page.route; if (temp[key] !== undefined) {
langPath = processRoutePath(route); temp = temp[key];
} else {
// 加载当前页面语言包 found = false;
let currentPageLang = loadLangPackSync(locale, langPath); break;
}
}
value = found ? temp : field;
} else {
value = mergedLang[field] !== undefined ? mergedLang[field] : field;
}
} catch (e) {
console.error('解析语言包失败:', e, { langPath, field, locale });
value = field;
}
// 合并语言包 if (arguments.length > 1) {
let mergedLang = { ...lang, ...currentPageLang }; for (var i = 1; i < arguments.length; i++) {
value = value.replace("{" + (i - 1) + "}", arguments[i]);
}
}
if (value == undefined || (value == 'title' && field == 'title')) value = '';
// 解析字段 if (field == value) {
var arr = field.split("."); console.warn(`警告: 字段 ${field} 在语言包 ${langPath} 中未找到对应值,使用默认值 ${field} 当前语言: ${locale}`);
if (arr.length > 1) { }
// 处理嵌套属性,如 common.currencySymbol
let temp = mergedLang;
let found = true;
for (let key of arr) {
if (temp[key] !== undefined) {
temp = temp[key];
} else {
found = false;
break;
}
}
value = found ? temp : field;
} else {
value = mergedLang[field] !== undefined ? mergedLang[field] : field;
}
} catch (e) {
console.error('解析语言包失败:', e, { langPath, field, locale });
value = field;
}
if (arguments.length > 1) { return value;
//有参数,需要替换 },
for (var i = 1; i < arguments.length; i++) { /**
value = value.replace("{" + (i - 1) + "}", arguments[i]); * 切换语言
} */
} change(value, url = '/pages_tool/member/index') {
if (value == undefined || (value == 'title' && field == 'title')) value = ''; // field let _this = getCurrentPages()[getCurrentPages().length - 1];
if (!_this) return;
// 多语言调试,注释后可以关闭控制台输出 uni.setStorageSync("lang", value);
if (field == value) { const locale = uni.getStorageSync('lang') || "zh-cn";
console.warn(`警告: 字段 ${field} 在语言包 ${langPath} 中未找到对应值,使用默认值 ${field} 当前语言: ${locale}`);
}
return value; // ✅ 关键修复:清空所有语言包缓存(不再保留任何旧缓存)
}, for (let key in loadedLangPacks) {
/** delete loadedLangPacks[key];
* * 切换语言 }
* @param {String} value 语言值
* @param {String} url 切换后跳转的页面url
*/
change(value, url = '/pages_tool/member/index') {
let _page = getCurrentPages()[getCurrentPages().length - 1];
if (!_page) return;
uni.setStorageSync("lang", value); this.refresh();
const locale = this.getCurrentLocale();
// 清空已加载的语言包缓存 if (url) {
for (let key in loadedLangPacks) { uni.reLaunch({ url: url });
if (!key.startsWith(locale)) { }
delete loadedLangPacks[key]; },
} //刷新标题、tabbar
} refresh() {
let _this = getCurrentPages()[getCurrentPages().length - 1];
this.refresh(); if (!_this) return;
const locale = uni.getStorageSync('lang') || "zh-cn";
if (url) {
uni.reLaunch({ url: url }); this.title(this.lang("title"));
} },
}, title(str) {
//刷新标题、tabbar if (str) {
refresh() { uni.setNavigationBarTitle({
let _page = getCurrentPages()[getCurrentPages().length - 1]; title: str
if (!_page) return; });
}
const locale = this.getCurrentLocale(); },
// 获取语言包列表
this.title(this.lang("title")); list() {
var list = [];
//设置tabbar的文字语言 try {
// uni.setTabBarItem({ for (var i = 0; i < langConfig.langList.length; i++) {
// index: 0, let langType = langConfig.langList[i];
// text: this.lang("tabBar.home") let item = loadLangPackSync(langType, 'common');
// }); list.push({
// uni.setTabBarItem({ name: item.common ? item.common.name : langType,
// index: 1, value: langType
// text: this.lang("tabBar.category") });
// }); }
// uni.setTabBarItem({ } catch (e) {
// index: 2, console.error('获取语言包列表失败:', e);
// text: this.lang("tabBar.cart") }
// }); return list;
// uni.setTabBarItem({ }
// index: 3, }
// text: this.lang("tabBar.member")
// });
},
title(str) {
if (str) {
uni.setNavigationBarTitle({
title: str,
success: function (res) {
},
fail: function (err) {
}
});
}
},
// 获取语言包列表
list() {
var list = [];
try {
//公共语言包
for (var i = 0; i < langConfig.langList.length; i++) {
let langType = langConfig.langList[i];
let item = loadLangPackSync(langType, 'common');
list.push({
name: item.common ? item.common.name : langType,
value: langType
});
}
} catch (e) {
console.error('获取语言包列表失败:', e);
}
return list;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -104,7 +104,7 @@
}, },
"router" : { "router" : {
"mode" : "history", "mode" : "history",
"base" : "/hwappx/2811/" "base" : "/hwappx/common/"
}, },
"title" : "", "title" : "",
"devServer" : { "devServer" : {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,7 @@
"setting": { "setting": {
"urlCheck": true, "urlCheck": true,
"es6": true, "es6": true,
"enhance": true, "enhance": false,
"postcss": true, "postcss": true,
"preloadBackgroundData": false, "preloadBackgroundData": false,
"minified": true, "minified": true,
@@ -39,27 +39,19 @@
"packNpmManually": false, "packNpmManually": false,
"packNpmRelationList": [], "packNpmRelationList": [],
"minifyWXSS": true, "minifyWXSS": true,
"condition": true, "compileWorklet": false,
"swc": false,
"disableSWC": true,
"minifyWXML": true, "minifyWXML": true,
"compileWorklet": true,
"localPlugins": false, "localPlugins": false,
"disableUseStrict": false, "disableUseStrict": false,
"useCompilerPlugins": false "useCompilerPlugins": false,
"condition": false,
"swc": false,
"disableSWC": true
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.16.1", "libVersion": "3.12.0",
"appid": "wx29215aa1bd97bbd6", "appid": "wx29215aa1bd97bbd6",
"projectname": "uniapp", "projectname": "uniapp",
"debugOptions": {
"hidedInDevtools": []
},
"scripts": {},
"staticServerOptions": {
"baseURL": "",
"servePath": ""
},
"isGameTourist": false, "isGameTourist": false,
"condition": { "condition": {
"search": { "search": {
@@ -80,5 +72,7 @@
"miniprogram": { "miniprogram": {
"list": [] "list": []
} }
} },
"simulatorPluginLibVersion": {},
"editorSetting": {}
} }

View File

@@ -1,4 +1,4 @@
module.exports = { module.exports = {
baseUrl: "https://xcx6.aigc-quickapp.com/",//修改域名 baseUrl: "https://dev.aigc-quickapp.com/",//修改域名
uniacid: 2811,//后台对应uniacid uniacid: 1,//后台对应uniacid
}; };

View File

@@ -65,6 +65,7 @@ const store = new Vuex.Store({
bottomNavHidden: false, // 底部导航是否隐藏true隐藏false显示 bottomNavHidden: false, // 底部导航是否隐藏true隐藏false显示
aiUnreadCount: 10, // AI未读消息数量 aiUnreadCount: 10, // AI未读消息数量
globalAIKefuConfig: null, // AI客服配置 globalAIKefuConfig: null, // AI客服配置
customerServiceType: 'ai',
globalStoreConfig: null, // 门店配置 globalStoreConfig: null, // 门店配置
globalStoreInfo: null, // 门店信息 globalStoreInfo: null, // 门店信息
defaultStoreInfo: null, // 默认门店 defaultStoreInfo: null, // 默认门店
@@ -159,6 +160,9 @@ const store = new Vuex.Store({
state.globalAIKefuConfig = value; state.globalAIKefuConfig = value;
uni.setStorageSync('globalAIKefuConfig', value); // 初始化数据调用 uni.setStorageSync('globalAIKefuConfig', value); // 初始化数据调用
}, },
setCustomerServiceType(state, type) {
state.customerServiceType = type;
},
setGlobalStoreConfig(state, value) { setGlobalStoreConfig(state, value) {
state.globalStoreConfig = value; state.globalStoreConfig = value;
uni.setStorageSync('globalStoreConfig', value); // 初始化数据调用 uni.setStorageSync('globalStoreConfig', value); // 初始化数据调用
@@ -412,7 +416,7 @@ const store = new Vuex.Store({
}, },
// 生成主题颜色CSS变量 // 生成主题颜色CSS变量
themeColorSet() { themeColorSet() {
// console.log('样式颜色设置...'); console.log('样式颜色设置...');
let theme = this.state.themeStyle; let theme = this.state.themeStyle;
if (!theme?.main_color || !theme?.aux_color) return; if (!theme?.main_color || !theme?.aux_color) return;
try { try {
@@ -436,7 +440,7 @@ const store = new Vuex.Store({
} catch (e) { } catch (e) {
console.error('设置主题颜色失败', e); console.error('设置主题颜色失败', e);
} }
// console.log('themeColor => ', this.state.themeColor); console.log('themeColor => ', this.state.themeColor);
} }
} }
}) })