From db26a85c8b33ab05943307017363b6bd1a3093de Mon Sep 17 00:00:00 2001 From: jinhhanhan <1683105490@qq.com> Date: Wed, 4 Feb 2026 17:09:57 +0800 Subject: [PATCH] =?UTF-8?q?chore=EF=BC=9A=E5=95=86=E5=93=81=EF=BC=8C?= =?UTF-8?q?=E5=90=8D=E7=89=87=EF=BC=8C=E6=88=91=E7=9A=84=E9=83=BD=E8=83=BD?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E8=B7=B3=E8=BD=AC=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/lang.js | 17 ++++++++++------- main.js | 1 + 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/js/lang.js b/common/js/lang.js index ab15bb1..996c0ab 100644 --- a/common/js/lang.js +++ b/common/js/lang.js @@ -54,6 +54,11 @@ function loadLangPackSync(lang, path) { } } +function getCurrentLocale() { + return uni.getStorageSync('lang') || "zh-cn"; +} + + export default { langList: langConfig.langList, @@ -61,9 +66,7 @@ export default { * 获得当前本地语言 * @returns */ - getCurrentLocale() { - return uni.getStorageSync('lang') || "zh-cn"; - }, + getCurrentLocale, /** * * 解析多语言 @@ -73,8 +76,8 @@ export default { let _page = getCurrentPages()[getCurrentPages().length - 1]; if (!_page) return; - const locale = this.getCurrentLocale(); // 获得当前本地语言 - + const locale = getCurrentLocale(); // 获得当前本地语言 + let value = ''; // 存放解析后的语言值 let langPath = ''; // 存放当前页面语言包路径 @@ -141,7 +144,7 @@ export default { if (!_page) return; uni.setStorageSync("lang", value); - const locale = this.getCurrentLocale(); + const locale = getCurrentLocale(); // 清空已加载的语言包缓存 for (let key in loadedLangPacks) { @@ -161,7 +164,7 @@ export default { let _page = getCurrentPages()[getCurrentPages().length - 1]; if (!_page) return; - const locale = this.getCurrentLocale(); + const locale = getCurrentLocale(); this.title(this.lang("title")); diff --git a/main.js b/main.js index df494e4..5306f21 100644 --- a/main.js +++ b/main.js @@ -26,6 +26,7 @@ Vue.prototype.$langConfig = Lang; //语言包对象 Vue.prototype.$lang = Lang.lang; //解析语言包 Vue.prototype.$config = Config; +Vue.prototype.getCurrentLocale = Lang.lang // #ifdef H5