refactor: 国际化文本迁移至全局 locales/messages.js

将组件级 i18n 对象重构为统一由全局 locales/messages.js 管理,确保中英文语言切换时正确显示对应文本。

- 新增 utils/i18n.js 国际化工具函数
- 更新 store/$t.mixin.js 翻译混入逻辑
- 迁移 pkgService、pkgBooking、pkgAccount、pkgExplore、pages 等共 58 个组件的中英文文本至全局消息表
This commit is contained in:
liangjian
2026-07-24 13:43:41 +08:00
parent 445bd850f4
commit 6e721ccc7e
58 changed files with 1810 additions and 4065 deletions

View File

@@ -1,7 +1,7 @@
<template>
<view class="smart-page">
<tn-nav-bar :isBack="true" :bottomShadow="false" backgroundColor="transparent" fontColor="#ffffff">
<view class="tn-text-bold tn-text-xl">{{ t('navTitle') }}</view>
<view class="tn-text-bold tn-text-xl">{{ $tr('全屋智能') }}</view>
</tn-nav-bar>
<view class="header-section" :style="{ paddingTop: (vuex_custom_bar_height + 20) + 'px' }">
@@ -13,31 +13,31 @@
</view>
<view class="toolbar">
<view class="toolbar-tip">{{ t('toolbarTip') }}</view>
<view class="toolbar-tip">{{ $tr('点击设备进入详情并下发控制指令') }}</view>
<view class="toolbar-action" @click="reloadDevices">
<text class="tn-icon-refresh" :class="{'spin-anim': isLoading}" style="margin-right: 8rpx;"></text>
<text>{{ isLoading ? t('loadingShort') : t('refreshStatus') }}</text>
<text>{{ isLoading ? $tr('加载中') : $tr('刷新状态') }}</text>
</view>
</view>
<!-- Feedback States -->
<view v-if="isLoading && !devices.length" class="empty-state">
<view class="loading-ring"></view>
<view class="empty-title">{{ t('loadingTitle') }}</view>
<view class="empty-desc">{{ t('loadingDesc') }}</view>
<view class="empty-title">{{ $tr('正在连接设备') }}</view>
<view class="empty-desc">{{ $tr('正在查询当前房间的可控设备...') }}</view>
</view>
<view v-else-if="loadError && !devices.length" class="empty-state error-state">
<text class="tn-icon-warning empty-icon"></text>
<view class="empty-title">{{ t('loadFailedTitle') }}</view>
<view class="empty-title">{{ $tr('设备加载失败') }}</view>
<view class="empty-desc">{{ loadError }}</view>
<view class="retry-btn" @click="reloadDevices">{{ t('retry') }}</view>
<view class="retry-btn" @click="reloadDevices">{{ $tr('重新加载') }}</view>
</view>
<view v-else-if="!devices.length" class="empty-state">
<text class="tn-icon-empty empty-icon"></text>
<view class="empty-title">{{ t('emptyTitle') }}</view>
<view class="empty-desc">{{ t('emptyDesc') }}</view>
<view class="empty-title">{{ $tr('暂无可控设备') }}</view>
<view class="empty-desc">{{ $tr('当前房间未绑定智能设备') }}</view>
</view>
<scroll-view v-else scroll-y class="device-scroll">
@@ -58,7 +58,7 @@
</view>
<view class="card-bottom">
<view class="device-name">{{ item.deviceName }}</view>
<view class="device-state" :class="{'is-active': item.active}">{{ item.stateText || (item.active ? t('deviceRunning') : t('deviceOff')) }}</view>
<view class="device-state" :class="{'is-active': item.active}">{{ item.stateText || (item.active ? $tr('运行中') : $tr('已关闭')) }}</view>
</view>
</view>
</view>
@@ -126,60 +126,6 @@ function resolveDeviceListPollingInterval(deviceList = [], fallback = 1000) {
}
export default {
i18n: {
zh: {
navTitle: '全屋智能',
toolbarTip: '点击设备进入详情并下发控制指令',
loadingShort: '加载中',
refreshStatus: '刷新状态',
loadingTitle: '正在连接设备',
loadingDesc: '正在查询当前房间的可控设备...',
loadFailedTitle: '设备加载失败',
retry: '重新加载',
emptyTitle: '暂无可控设备',
emptyDesc: '当前房间未绑定智能设备',
deviceSummary: '共 {count} 台设备,可进入详情页控制',
deviceRunning: '运行中',
deviceOff: '已关闭',
currentRoom: '当前房间',
missingRoomCode: '缺少房间编码',
syncingStatus: '正在同步设备状态',
unsupportedQuickControl: '设备暂不支持快捷控制',
unsupportedSwitch: '该设备不支持快捷开关',
missingFunctionCode: '功能编码缺失',
sending: '发送中...',
enabled: '已开启',
disabled: '已关闭',
commandFailed: '指令下发失败',
requestFailed: '设备列表请求失败'
},
en: {
navTitle: 'Smart Home',
toolbarTip: 'Tap a device to open details and send control commands',
loadingShort: 'Loading',
refreshStatus: 'Refresh Status',
loadingTitle: 'Connecting devices',
loadingDesc: 'Checking controllable devices in the current room...',
loadFailedTitle: 'Failed to load devices',
retry: 'Retry',
emptyTitle: 'No controllable devices',
emptyDesc: 'No smart devices are bound to this room',
deviceSummary: '{count} devices available. Tap to control in detail view',
deviceRunning: 'Running',
deviceOff: 'Off',
currentRoom: 'Current Room',
missingRoomCode: 'Missing room code',
syncingStatus: 'Syncing device status',
unsupportedQuickControl: 'Quick control is not supported for this device',
unsupportedSwitch: 'This device does not support quick switching',
missingFunctionCode: 'Missing function code',
sending: 'Sending...',
enabled: 'Enabled',
disabled: 'Disabled',
commandFailed: 'Failed to send command',
requestFailed: 'Failed to request device list'
}
},
data() {
return {
brandId: DEFAULT_BRAND_ID,
@@ -202,19 +148,19 @@ export default {
return this.$getLanguage()
},
displayRoomName() {
return this.roomName || this.roomCode || this.t('currentRoom')
return this.roomName || this.roomCode || this.$tr('当前房间')
},
summaryText() {
if (!this.roomCode) {
return this.t('missingRoomCode')
return this.$tr('缺少房间编码')
}
if (this.isLoading) {
return this.t('syncingStatus')
return this.$tr('正在同步设备状态')
}
if (this.devices.length) {
return this.t('deviceSummary', { count: this.devices.length })
return this.$tr('共 {count} 台设备,可进入详情页控制', { count: this.devices.length })
}
return this.t('emptyTitle')
return this.$tr('暂无可控设备')
}
},
onLoad(options) {
@@ -236,9 +182,6 @@ export default {
this.stopPolling()
},
methods: {
t(key, params) {
return this.$tm('pkgService.smart_control.smart_control', key, params)
},
resolvePageContext(options = {}) {
const session = getSessionSnapshot()
const roomData = (session && session.myRoomData) || {}
@@ -321,7 +264,7 @@ export default {
if (!this.roomCode) {
this.devices = []
this.loadError = this.t('missingRoomCode')
this.loadError = this.$tr('缺少房间编码')
if (stopRefresh) {
uni.stopPullDownRefresh()
}
@@ -361,7 +304,7 @@ export default {
this.devices = []
}
if (!silent) {
this.loadError = (error && (error.message || error.msg)) || this.t('requestFailed')
this.loadError = (error && (error.message || error.msg)) || this.$tr('设备列表请求失败')
}
})
.finally(() => {
@@ -397,7 +340,7 @@ export default {
const functions = getDeviceFunctions(item)
if (!functions || !functions.length) {
uni.showToast({ title: this.t('unsupportedQuickControl'), icon: 'none' })
uni.showToast({ title: this.$tr('设备暂不支持快捷控制'), icon: 'none' })
return
}
@@ -409,13 +352,13 @@ export default {
const category = getControlTypeCategory(targetFunc.controlType)
if (category !== 'switch') {
uni.showToast({ title: this.t('unsupportedSwitch'), icon: 'none' })
uni.showToast({ title: this.$tr('该设备不支持快捷开关'), icon: 'none' })
return
}
const functionCode = String((targetFunc && targetFunc.functionCode) || '').trim()
if (!functionCode) {
uni.showToast({ title: this.t('missingFunctionCode'), icon: 'none' })
uni.showToast({ title: this.$tr('功能编码缺失'), icon: 'none' })
return
}
@@ -433,7 +376,7 @@ export default {
}
this.isSubmitting = true
uni.showLoading({ title: this.t('sending') })
uni.showLoading({ title: this.$tr('发送中...') })
gatewayExecuteDeviceCommand(this.brandId, item.deviceNo, functionCode, commandPayload)
.then(() => {
@@ -447,11 +390,11 @@ export default {
renderKey: this.devices[index].renderKey
})
}
uni.showToast({ title: enabled ? this.t('enabled') : this.t('disabled'), icon: 'success' })
uni.showToast({ title: enabled ? this.$tr('已开启') : this.$tr('已关闭'), icon: 'success' })
})
.catch((error) => {
console.error('execute device command failed', error)
uni.showToast({ title: (error && (error.message || error.msg)) || this.t('commandFailed'), icon: 'none' })
uni.showToast({ title: (error && (error.message || error.msg)) || this.$tr('指令下发失败'), icon: 'none' })
})
.finally(() => {
this.isSubmitting = false