feat:添加中英文切换按钮
This commit is contained in:
29
App.vue
29
App.vue
@@ -4,6 +4,8 @@
|
||||
import {
|
||||
Weixin
|
||||
} from 'common/js/wx-jssdk.js';
|
||||
// 新增:引入多语言核心工具类
|
||||
import langConfig from '@/common/js/lang.js';
|
||||
|
||||
export default {
|
||||
mixins: [auth],
|
||||
@@ -15,6 +17,9 @@
|
||||
}
|
||||
uni.hideTabBar();
|
||||
|
||||
// 新增:应用启动时初始化多语言(核心修改)
|
||||
this.initLang();
|
||||
|
||||
// #ifdef MP
|
||||
const updateManager = uni.getUpdateManager();
|
||||
updateManager.onCheckForUpdate(function(res) {
|
||||
@@ -23,8 +28,8 @@
|
||||
|
||||
updateManager.onUpdateReady(function(res) {
|
||||
uni.showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
title: langConfig.lang('common.updateTip'), // 新增:多语言标题
|
||||
content: langConfig.lang('common.updateContent'), // 新增:多语言内容
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
@@ -48,8 +53,8 @@
|
||||
uni.onNetworkStatusChange(function(res) {
|
||||
if (!res.isConnected) {
|
||||
uni.showModal({
|
||||
title: '网络失去链接',
|
||||
content: '请检查网络链接',
|
||||
title: langConfig.lang('common.networkTip'), // 新增:多语言标题
|
||||
content: langConfig.lang('common.networkContent'), // 新增:多语言内容
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
@@ -144,6 +149,9 @@
|
||||
// #endif
|
||||
},
|
||||
onShow: function(options) {
|
||||
// 新增:应用前台显示时刷新多语言(确保切后台后语言仍生效)
|
||||
langConfig.refresh();
|
||||
|
||||
// #ifdef MP
|
||||
// 自动授权登录
|
||||
this.getAuthInfo();
|
||||
@@ -165,6 +173,19 @@
|
||||
},
|
||||
onHide: function() {},
|
||||
methods: {
|
||||
// 新增:多语言初始化方法
|
||||
initLang() {
|
||||
// 1. 读取本地存储的语言,无则默认中文
|
||||
const currentLang = uni.getStorageSync('lang') || 'zh-cn';
|
||||
// 2. 初始化lang.js的locale变量(确保全局语言一致)
|
||||
langConfig.locale = currentLang;
|
||||
// 3. 刷新多语言配置(标题、tabBar等)
|
||||
langConfig.refresh();
|
||||
// 4. 挂载全局多语言方法(方便所有页面直接调用)
|
||||
uni.$lang = langConfig.lang;
|
||||
// 5. 挂载全局语言切换方法(可选,方便全局调用)
|
||||
uni.$switchLang = langConfig.change;
|
||||
},
|
||||
/**
|
||||
* 获取授权信息
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user