feat(i18n): 中英文框架(命名空间字典+语言切换)+profile 接入参考+注册3个新页面

这个提交包含在:
Guoguo
2026-07-18 20:07:13 -07:00
父节点 cc5159ebb7
当前提交 d8eb6677c6
修改 11 个文件,包含 431 行新增38 行删除
+35 -11
查看文件
@@ -1,5 +1,6 @@
var api = require('../../utils/api')
var config = require('../../config/env')
var i18n = require('../../i18n/index')
var app = getApp()
Page({
@@ -16,9 +17,30 @@ Page({
},
onShow: function () {
i18n.bind(this)
this.loadProfile()
},
onLightInfo: function () {
wx.navigateTo({ url: '/pages/light-info/light-info' })
},
onSwitchLanguage: function () {
var self = this
var supported = i18n.SUPPORTED
var names = supported.map(function (l) { return i18n.LOCALE_NAMES[l] || l })
wx.showActionSheet({
itemList: names,
success: function (res) {
var target = supported[res.tapIndex]
if (target && target !== i18n.getLocale()) {
i18n.setLocale(target)
i18n.bind(self)
}
}
})
},
loadProfile: function () {
var self = this
self.setData({ loading: true })
@@ -33,9 +55,11 @@ Page({
})
var p2 = api.getSubscription().then(function (sub) {
var remaining = sub.remaining_days || 0
self.setData({
subscription: sub,
subRemaining: sub.remaining_days || 0
subRemaining: remaining,
subRemainingText: i18n.t('profile.remainDays', { days: remaining })
})
}).catch(function (err) {
console.error('getSubscription failed', err)
@@ -50,19 +74,19 @@ Page({
var self = this
if (this.data.deviceCount > 0) {
wx.showActionSheet({
itemList: ['解绑当前设备'],
itemList: [i18n.t('profile.unbindAction')],
success: function (res) {
if (res.tapIndex === 0) {
wx.showModal({
title: '确认解绑',
content: '解绑后将无法使用该设备,确定要解绑吗?',
title: i18n.t('profile.unbindConfirmTitle'),
content: i18n.t('profile.unbindConfirmText'),
success: function (modalRes) {
if (modalRes.confirm) {
api.unbindDevice().then(function () {
wx.showToast({ title: '已解绑', icon: 'success' })
wx.showToast({ title: i18n.t('profile.unbindDone'), icon: 'success' })
self.loadProfile()
}).catch(function (err) {
wx.showToast({ title: err.message || '解绑失败', icon: 'none' })
wx.showToast({ title: err.message || i18n.t('profile.unbindFailed'), icon: 'none' })
})
}
}
@@ -151,7 +175,7 @@ Page({
var self = this
var nickname = (self.data.editNickname || '').trim()
if (!nickname) {
wx.showToast({ title: '昵称不能为空', icon: 'none' })
wx.showToast({ title: i18n.t('profile.nicknameRequired'), icon: 'none' })
return
}
@@ -170,18 +194,18 @@ Page({
})
}).then(function () {
self.setData({ saving: false, editing: false })
wx.showToast({ title: '保存成功', icon: 'success' })
wx.showToast({ title: i18n.t('common.saveSuccess'), icon: 'success' })
self.loadProfile()
}).catch(function (err) {
self.setData({ saving: false })
wx.showToast({ title: err.message || '保存失败', icon: 'none' })
wx.showToast({ title: err.message || i18n.t('common.saveFailed'), icon: 'none' })
})
},
onLogout: function () {
wx.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
title: i18n.t('profile.logoutConfirmTitle'),
content: i18n.t('profile.logoutConfirmText'),
success: function (res) {
if (res.confirm) {
wx.removeStorageSync('token')