diff --git a/common/js/diy.js b/common/js/diy.js index 526d53f..e3c1c78 100644 --- a/common/js/diy.js +++ b/common/js/diy.js @@ -609,10 +609,10 @@ export default { }, // 分享给好友 onShareAppMessage() { - return this.mpShareData.appMessage; + return this.mpShareData?.appMessage; }, // 分享到朋友圈 onShareTimeline() { - return this.mpShareData.timeLine; + return this.mpShareData?.timeLine; } } \ No newline at end of file diff --git a/common/js/golbalConfig.js b/common/js/golbalConfig.js index d412a07..c38a69f 100644 --- a/common/js/golbalConfig.js +++ b/common/js/golbalConfig.js @@ -7,7 +7,7 @@ export default { computed: { // 是否是英文环境 isEnEnv() { - return uni.getStorageSync('lang') === 'en-us'; + return this.$langConfig.getCurrentLocale() === 'en-us'; }, themeStyle() { return this.$store.state.themeStyle; diff --git a/common/js/lang.js b/common/js/lang.js index c8ca741..fbe7908 100644 --- a/common/js/lang.js +++ b/common/js/lang.js @@ -30,12 +30,12 @@ function processRoutePath(route) { } } // ---- 处理页面目录映射 ---- - + // 去掉pages目录,只保留子目录 if (routeParts[0] === 'pages') { routeParts = routeParts.slice(1); - } - + } + return routeParts.join("/"); } @@ -54,17 +54,32 @@ function loadLangPackSync(lang, path) { } } +/** + * 获得当前本地语言 + * @returns + */ +function getCurrentLocale() { + return uni.getStorageSync('lang') || "zh-cn"; +} + export default { langList: langConfig.langList, + + /** + * 获得当前本地语言 + * @returns + */ + getCurrentLocale, + /** * * 解析多语言 * @param {Object} field */ lang(field) { - let _this = getCurrentPages()[getCurrentPages().length - 1]; - if (!_this) return; + let _page = getCurrentPages()[getCurrentPages().length - 1]; + if (!_page) return; - const locale = uni.getStorageSync('lang') || "zh-cn"; //设置语言 + const locale = getCurrentLocale(); // 获得当前本地语言 let value = ''; // 存放解析后的语言值 let langPath = ''; // 存放当前页面语言包路径 @@ -72,11 +87,11 @@ export default { try { //公共语言包(同步加载) var lang = loadLangPackSync(locale, 'common'); - + //当前页面语言包(同步加载) - let route = _this.route; + let route = _page.route; langPath = processRoutePath(route); - + // 加载当前页面语言包 let currentPageLang = loadLangPackSync(locale, langPath); @@ -101,7 +116,7 @@ export default { } else { value = mergedLang[field] !== undefined ? mergedLang[field] : field; } - + } catch (e) { console.error('解析语言包失败:', e, { langPath, field, locale }); value = field; @@ -117,7 +132,7 @@ export default { // 多语言调试,注释后可以关闭控制台输出 if (field == value) { - console.warn(`警告: 字段 ${field} 在语言包 ${langPath} 中未找到对应值,使用默认值 ${field} 当前语言: ${locale}`); + console.warn(`警告: 字段 ${field} 在语言包 ${langPath} 中未找到对应值,使用默认值 ${field} 当前语言: ${locale}`); } return value; @@ -128,11 +143,11 @@ export default { * @param {String} url 切换后跳转的页面url */ change(value, url = '/pages_tool/member/index') { - let _this = getCurrentPages()[getCurrentPages().length - 1]; - if (!_this) return; + let _page = getCurrentPages()[getCurrentPages().length - 1]; + if (!_page) return; uni.setStorageSync("lang", value); - const locale = uni.getStorageSync('lang') || "zh-cn"; //设置语言 + const locale = getCurrentLocale(); // 清空已加载的语言包缓存 for (let key in loadedLangPacks) { @@ -149,10 +164,11 @@ export default { }, //刷新标题、tabbar refresh() { - let _this = getCurrentPages()[getCurrentPages().length - 1]; - if (!_this) return; - const locale = uni.getStorageSync('lang') || "zh-cn"; //设置语言 - + let _page = getCurrentPages()[getCurrentPages().length - 1]; + if (!_page) return; + + const locale = getCurrentLocale(); + this.title(this.lang("title")); //设置tabbar的文字语言 diff --git a/components-diy/diy-article.vue b/components-diy/diy-article.vue index 2f4097a..71b3888 100644 --- a/components-diy/diy-article.vue +++ b/components-diy/diy-article.vue @@ -7,7 +7,7 @@ :autoplay="swiperConfig.autoplay !== false" :circular="swiperConfig.circular !== false" :interval="swiperConfig.interval || 3000" :duration="swiperConfig.duration || 500" :display-multiple-items="safeDisplayMultipleItems"> - + diff --git a/components-diy/diy-audio.vue b/components-diy/diy-audio.vue index 22ba175..316c3e7 100644 --- a/components-diy/diy-audio.vue +++ b/components-diy/diy-audio.vue @@ -11,7 +11,7 @@ {{ audiotime }} - @@ -30,7 +30,7 @@ {{ audiotime }} - + diff --git a/components-diy/diy-bargain.vue b/components-diy/diy-bargain.vue index a264fee..ef68915 100644 --- a/components-diy/diy-bargain.vue +++ b/components-diy/diy-bargain.vue @@ -15,7 +15,7 @@ :style="{ color: value.titleStyle.textColor }">低至0元免费拿 + @tap.stop="$util.redirectTo('/pages_promotion/bargain/list')"> {{ value.titleStyle.more }} @@ -23,7 +23,7 @@ + +