74 lines
2.0 KiB
Vue
74 lines
2.0 KiB
Vue
<script>
|
||
import {
|
||
wxLogin,
|
||
getUserInfo
|
||
} from './util/index'
|
||
|
||
|
||
export default {
|
||
onLaunch: function() {
|
||
console.log('App Launch')
|
||
// 注意:语言初始化已移至 main.js,确保每次 reLaunch 都能正确加载新语言
|
||
},
|
||
onShow: async function() {
|
||
console.log('========================================')
|
||
console.log('=== App onShow 被调用 ===')
|
||
console.log('时间戳:', new Date().toLocaleTimeString())
|
||
|
||
// 检查并更新语言(uni.reLaunch 会触发 onShow)
|
||
try {
|
||
const savedLang = uni.getStorageSync('language')
|
||
console.log('App onShow - 缓存中的语言:', savedLang)
|
||
|
||
// 获取当前 i18n 实例并检查语言
|
||
if (this.$i18n) {
|
||
const currentLocale = this.$i18n.locale
|
||
console.log('App onShow - 当前 i18n locale:', currentLocale)
|
||
|
||
if (savedLang && savedLang !== currentLocale) {
|
||
console.log('=== App onShow 检测到语言变化 ===')
|
||
console.log('旧语言:', currentLocale)
|
||
console.log('新语言:', savedLang)
|
||
|
||
// 强制更新语言
|
||
this.$i18n.locale = savedLang
|
||
console.log('App onShow - 语言已更新为:', this.$i18n.locale)
|
||
console.log('App onShow - 测试翻译:', this.$t('common.loading'))
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('App onShow - 语言检查失败:', e)
|
||
}
|
||
|
||
console.log('========================================')
|
||
},
|
||
onHide: function() {
|
||
console.log('App Hide')
|
||
},
|
||
methods: {
|
||
// 保留方法但不调用
|
||
async autoLogin() {
|
||
try {
|
||
const loginResult = await wxLogin()
|
||
// await getUserInfo()
|
||
} catch (error) {
|
||
console.error('自动登录失败:', error)
|
||
}
|
||
},
|
||
async getUserInfoData() {
|
||
try {
|
||
await getUserInfo()
|
||
} catch (error) {
|
||
console.error('获取用户信息失败:', error)
|
||
// 获取用户信息失败的处理逻辑
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
@import "@climblee/uv-ui/index.scss"
|
||
|
||
/*每个页面公共css */
|
||
</style> |