refactor(ai-chat): 统一调整语言文件引用路径

将所有硬编码的语言调用路径统一改为ai-chat.index下的命名空间,便于语言包管理和维护
This commit is contained in:
2026-07-03 11:07:34 +08:00
parent b8387de6c6
commit f628d7a0ef

View File

@@ -74,7 +74,7 @@
<view class="message-content"> <view class="message-content">
<!-- AI昵称固定,不可修改 - 左移到气泡上方 --> <!-- AI昵称固定,不可修改 - 左移到气泡上方 -->
<view class="message-nickname ai-nickname"> <view class="message-nickname ai-nickname">
<text class="ai-nickname-text">{{ $lang('aiNickname') }}</text> <text class="ai-nickname-text">{{ $lang('ai-chat.index.aiNickname') }}</text>
<text class="message-time">{{ formatTime(message.timestamp) }}</text> <text class="message-time">{{ formatTime(message.timestamp) }}</text>
</view> </view>
<view class="message-bubble" <view class="message-bubble"
@@ -119,7 +119,7 @@
<view v-else-if="message.type === 'audio'" class="audio-content"> <view v-else-if="message.type === 'audio'" class="audio-content">
<view class="audio-player"> <view class="audio-player">
<view class="audio-info"> <view class="audio-info">
<text class="audio-title">{{ message.title || $lang('audioMessage') }}</text> <text class="audio-title">{{ message.title || $lang('ai-chat.index.audioMessage') }}</text>
<text class="audio-duration">{{ formatDuration(message.duration) }}</text> <text class="audio-duration">{{ formatDuration(message.duration) }}</text>
</view> </view>
<view class="audio-controls"> <view class="audio-controls">
@@ -157,7 +157,7 @@
@pause="onVideoPause(message)"> @pause="onVideoPause(message)">
</video> </video>
<view class="video-info"> <view class="video-info">
<text class="video-title">{{ message.title || $lang('videoMessage') }}</text> <text class="video-title">{{ message.title || $lang('ai-chat.index.videoMessage') }}</text>
<text class="video-duration">{{ formatDuration(message.duration) }}</text> <text class="video-duration">{{ formatDuration(message.duration) }}</text>
</view> </view>
</view> </view>
@@ -187,7 +187,7 @@
<text class="dot"></text> <text class="dot"></text>
</view> </view>
<text class="loading-text"> <text class="loading-text">
<text class="loading-status">{{ message.loadingText || $lang('aiThinking') }}</text> <text class="loading-status">{{ message.loadingText || $lang('ai-chat.index.aiThinking') }}</text>
<text class="loading-ellipsis"> <text class="loading-ellipsis">
<text class="ellipsis-dot">.</text> <text class="ellipsis-dot">.</text>
<text class="ellipsis-dot">.</text> <text class="ellipsis-dot">.</text>
@@ -232,7 +232,7 @@
<textarea <textarea
v-model="inputText" v-model="inputText"
class="message-input" class="message-input"
:placeholder="$lang('inputPlaceholder')" :placeholder="$lang('ai-chat.index.inputPlaceholder')"
:maxlength="500" :maxlength="500"
:auto-height="true" :auto-height="true"
:show-confirm-bar="false" :show-confirm-bar="false"
@@ -258,7 +258,7 @@
:class="{ disabled: !canSendMessage }" :class="{ disabled: !canSendMessage }"
@click="sendMessage" @click="sendMessage"
:disabled="!canSendMessage"> :disabled="!canSendMessage">
<text>{{ $lang('send') }}</text> <text>{{ $lang('ai-chat.index.send') }}</text>
</button> </button>
</view> </view>
</view> </view>
@@ -283,7 +283,7 @@
<view class="expand-editor-mask" @click="closeExpandEditor"></view> <view class="expand-editor-mask" @click="closeExpandEditor"></view>
<view class="expand-editor-panel"> <view class="expand-editor-panel">
<view class="expand-editor-header"> <view class="expand-editor-header">
<text>{{ $lang('expandEditorTitle') }}</text> <text>{{ $lang('ai-chat.index.expandEditorTitle') }}</text>
<button class="close-btn" @click="closeExpandEditor"> <button class="close-btn" @click="closeExpandEditor">
<text>×</text> <text>×</text>
</button> </button>
@@ -291,14 +291,14 @@
<textarea <textarea
v-model="expandInputText" v-model="expandInputText"
class="expand-editor-input" class="expand-editor-input"
:placeholder="$lang('inputPlaceholder')" :placeholder="$lang('ai-chat.index.inputPlaceholder')"
:maxlength="500" :maxlength="500"
:auto-height="true" :auto-height="true"
:show-confirm-bar="false" :show-confirm-bar="false"
:adjust-position="true" :adjust-position="true"
:focus="true" /> :focus="true" />
<view class="expand-editor-footer"> <view class="expand-editor-footer">
<button class="expand-cancel-btn" @click="closeExpandEditor">{{ $lang('cancel') }}</button> <button class="expand-cancel-btn" @click="closeExpandEditor">{{ $lang('ai-chat.index.cancel') }}</button>
<button class="expand-send-btn" @click="sendFromExpandEditor" :disabled="!expandInputText.trim()">{{ $lang('send') }}</button> <button class="expand-send-btn" @click="sendFromExpandEditor" :disabled="!expandInputText.trim()">{{ $lang('send') }}</button>
</view> </view>
</view> </view>
@@ -397,7 +397,7 @@ export default {
scrollTop: 0, scrollTop: 0,
scrollIntoViewId: null, scrollIntoViewId: null,
hasMoreHistory: false, hasMoreHistory: false,
loadingText: this.$lang('loadMoreHistory'), loadingText: this.$lang('ai-chat.index.loadMoreHistory'),
voiceInputing: false, voiceInputing: false,
audioContext: null, audioContext: null,
currentAudio: null, currentAudio: null,
@@ -417,7 +417,7 @@ export default {
localUserAvatar: '', localUserAvatar: '',
showAvatarSelector: false, // 头像选择弹窗控制 showAvatarSelector: false, // 头像选择弹窗控制
localUserNickname: '', // 当前用户昵称 localUserNickname: '', // 当前用户昵称
defaultNickname: this.$lang('defaultNickname'), // 默认昵称 defaultNickname: this.$lang('ai-chat.index.defaultNickname'), // 默认昵称
showNicknameEditor: false, // 昵称编辑弹窗控制 showNicknameEditor: false, // 昵称编辑弹窗控制
// AI头像错误状态 // AI头像错误状态
avatarError: false, avatarError: false,
@@ -857,7 +857,7 @@ async loadChatHistoryIfExist() {
type: 'loading', type: 'loading',
content: '', content: '',
timestamp: Date.now(), timestamp: Date.now(),
loadingText: this.$lang('aiThinking'), loadingText: this.$lang('ai-chat.index.aiThinking'),
_loadingIndex: 0 _loadingIndex: 0
} }
this.shouldScrollToBottom = true this.shouldScrollToBottom = true
@@ -891,10 +891,10 @@ async loadChatHistoryIfExist() {
id: ++this.messageId, id: ++this.messageId,
role: 'ai', role: 'ai',
type: 'text', type: 'text',
content: this.$lang('serviceUnavailable'), content: this.$lang('ai-chat.index.serviceUnavailable'),
timestamp: Date.now(), timestamp: Date.now(),
actions: [ actions: [
{ id: 1, text: this.$lang('retry'), type: 'retry' } { id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }
] ]
} }
this.shouldScrollToBottom = true this.shouldScrollToBottom = true
@@ -975,7 +975,7 @@ async sendStreamMessage(userMessage) {
this.isStreaming = true this.isStreaming = true
const loadingMsg = this.messages[loadingIdx] const loadingMsg = this.messages[loadingIdx]
this._stopLoadingTextRotation(loadingMsg) this._stopLoadingTextRotation(loadingMsg)
loadingMsg.loadingText = this.$lang('receivingReply') loadingMsg.loadingText = this.$lang('ai-chat.index.receivingReply')
let transformed = false let transformed = false
@@ -1041,9 +1041,9 @@ async sendStreamMessage(userMessage) {
id: ++this.messageId, id: ++this.messageId,
role: 'ai', role: 'ai',
type: 'text', type: 'text',
content: this.$lang('serviceTemporaryUnavailable'), content: this.$lang('ai-chat.index.serviceTemporaryUnavailable'),
timestamp: Date.now(), timestamp: Date.now(),
actions: [{ id: 1, text: this.$lang('retry'), type: 'retry' }] actions: [{ id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }]
} }
this.messages.push(errorMsg) this.messages.push(errorMsg)
this.$emit('ai-response', errorMsg) this.$emit('ai-response', errorMsg)
@@ -1087,9 +1087,9 @@ _handleStreamError(msg) {
id: ++this.messageId, id: ++this.messageId,
role: 'ai', role: 'ai',
type: 'text', type: 'text',
content: this.$lang('serviceTemporaryUnavailable'), content: this.$lang('ai-chat.index.serviceTemporaryUnavailable'),
timestamp: Date.now(), timestamp: Date.now(),
actions: [{ id: 1, text: this.$lang('retry'), type: 'retry' }] actions: [{ id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }]
} }
this.messages.push(errorMsg) this.messages.push(errorMsg)
this.$emit('ai-response', errorMsg) this.$emit('ai-response', errorMsg)
@@ -1097,10 +1097,10 @@ _handleStreamError(msg) {
// 加载状态文字轮换 - 让AI看起来在处理不同阶段 // 加载状态文字轮换 - 让AI看起来在处理不同阶段
_startLoadingTextRotation(loadingMsg) { _startLoadingTextRotation(loadingMsg) {
const statusTexts = [ const statusTexts = [
this.$lang('aiThinkingStatus1'), this.$lang('ai-chat.index.aiThinkingStatus1'),
this.$lang('aiThinkingStatus2'), this.$lang('ai-chat.index.aiThinkingStatus2'),
this.$lang('aiThinkingStatus3'), this.$lang('ai-chat.index.aiThinkingStatus3'),
this.$lang('aiThinkingStatus4') this.$lang('ai-chat.index.aiThinkingStatus4')
] ]
loadingMsg._rotationTimer = setInterval(() => { loadingMsg._rotationTimer = setInterval(() => {
loadingMsg._loadingIndex = (loadingMsg._loadingIndex + 1) % statusTexts.length loadingMsg._loadingIndex = (loadingMsg._loadingIndex + 1) % statusTexts.length
@@ -1136,7 +1136,7 @@ _handleStreamError(msg) {
return responses[key]; return responses[key];
} }
} }
return this.$lang('autoReplyDefault', { question: userMessage }); return this.$lang('ai-chat.index.autoReplyDefault', { question: userMessage });
}, },
@@ -1365,10 +1365,10 @@ _handleStreamError(msg) {
return timeStr; return timeStr;
} }
if (msgDate.getTime() === yesterday.getTime()) { if (msgDate.getTime() === yesterday.getTime()) {
return `${this.$lang('timeFormatYesterday')} ${timeStr}`; return `${this.$lang('ai-chat.index.timeFormatYesterday')} ${timeStr}`;
} }
if (msgDate.getTime() === beforeYesterday.getTime()) { if (msgDate.getTime() === beforeYesterday.getTime()) {
return `${this.$lang('timeFormatBeforeYesterday')} ${timeStr}`; return `${this.$lang('ai-chat.index.timeFormatBeforeYesterday')} ${timeStr}`;
} }
const isCurrentYear = date.getFullYear() === now.getFullYear(); const isCurrentYear = date.getFullYear() === now.getFullYear();
@@ -1385,9 +1385,9 @@ _handleStreamError(msg) {
// 格式化文件大小 // 格式化文件大小
formatFileSize(bytes) { formatFileSize(bytes) {
if (!bytes) return this.$lang('about') if (!bytes) return this.$lang('ai-chat.index.about')
const k = 1024 const k = 1024
const sizes = [this.$lang('about'), 'KB', 'MB', 'GB'] const sizes = [this.$lang('ai-chat.index.about'), 'KB', 'MB', 'GB']
const i = Math.floor(Math.log(bytes) / Math.log(k)) const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + sizes[i] return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + sizes[i]
}, },
@@ -1426,7 +1426,7 @@ _handleStreamError(msg) {
} }
this.isFetchingHistory = true; this.isFetchingHistory = true;
this.isLoadingHistory = true; this.isLoadingHistory = true;
this.loadingText = this.$lang('loadingHistory'); this.loadingText = this.$lang('ai-chat.index.loadingHistory');
try { try {
const response = await aiService.getConversationHistory({ const response = await aiService.getConversationHistory({
@@ -1475,12 +1475,12 @@ _handleStreamError(msg) {
} }
} catch (error) { } catch (error) {
console.error('加载历史失败:', error); console.error('加载历史失败:', error);
uni.showToast({ title: this.$lang('loadHistoryFail'), icon: 'none' }); uni.showToast({ title: this.$lang('ai-chat.index.loadHistoryFail'), icon: 'none' });
this.hasMoreHistory = false; this.hasMoreHistory = false;
} finally { } finally {
this.isLoadingHistory = false; this.isLoadingHistory = false;
this.isFetchingHistory = false; this.isFetchingHistory = false;
this.loadingText = this.$lang('loadMoreHistory'); this.loadingText = this.$lang('ai-chat.index.loadMoreHistory');
} }
}, },
// 显示更多工具 // 显示更多工具
@@ -1490,7 +1490,7 @@ _handleStreamError(msg) {
// 预览文件 // 预览文件
previewFile(message) { previewFile(message) {
uni.showLoading({ title: this.$lang('openingFile') }) uni.showLoading({ title: this.$lang('ai-chat.index.openingFile') })
// #ifdef H5 // #ifdef H5
window.open(message.url, '_blank') window.open(message.url, '_blank')
@@ -1500,7 +1500,7 @@ _handleStreamError(msg) {
plus.runtime.openFile(message.url, { plus.runtime.openFile(message.url, {
error: (e) => { error: (e) => {
uni.showToast({ uni.showToast({
title: this.$lang('fileOpenFail'), title: this.$lang('ai-chat.index.fileOpenFail'),
icon: 'none' icon: 'none'
}) })
} }
@@ -1674,7 +1674,7 @@ _handleStreamError(msg) {
copyText = message.content || '' copyText = message.content || ''
} }
if (!copyText) { if (!copyText) {
uni.showToast({ title: this.$lang('noContentToCopy'), icon: 'none' }) uni.showToast({ title: this.$lang('ai-chat.index.noContentToCopy'), icon: 'none' })
return return
} }
@@ -1688,7 +1688,7 @@ _handleStreamError(msg) {
try { try {
if (navigator.clipboard && navigator.clipboard.writeText) { if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(finalText).then(() => { navigator.clipboard.writeText(finalText).then(() => {
uni.showToast({ title: selectedText ? this.$lang('copySelected') : this.$lang('copySuccess'), icon: 'success' }) uni.showToast({ title: selectedText ? this.$lang('ai-chat.index.copySelected') : this.$lang('ai-chat.index.copySuccess'), icon: 'success' })
}).catch(() => { }).catch(() => {
this._fallbackCopyH5(finalText) this._fallbackCopyH5(finalText)
}) })
@@ -1707,12 +1707,12 @@ _handleStreamError(msg) {
data: copyText, data: copyText,
success: () => { success: () => {
console.log('[AI Chat] 复制成功') console.log('[AI Chat] 复制成功')
uni.showToast({ title: this.$lang('copySuccess'), icon: 'success' }) uni.showToast({ title: this.$lang('ai-chat.index.copySuccess'), icon: 'success' })
}, },
fail: (err) => { fail: (err) => {
console.error('[AI Chat] 复制失败, 详细错误:', JSON.stringify(err)) console.error('[AI Chat] 复制失败, 详细错误:', JSON.stringify(err))
console.error('[AI Chat] 复制失败 errMsg:', err.errMsg || err.message || '无错误消息') console.error('[AI Chat] 复制失败 errMsg:', err.errMsg || err.message || '无错误消息')
uni.showToast({ title: this.$lang('copyFailWithReason', { reason: err.errMsg || this.$lang('serviceUnavailable') }), icon: 'none', duration: 3000 }) uni.showToast({ title: this.$lang('ai-chat.index.copyFailWithReason', { reason: err.errMsg || this.$lang('ai-chat.index.serviceUnavailable') }), icon: 'none', duration: 3000 })
} }
}) })
// #endif // #endif
@@ -1733,12 +1733,12 @@ _handleStreamError(msg) {
const success = document.execCommand('copy') const success = document.execCommand('copy')
document.body.removeChild(textarea) document.body.removeChild(textarea)
if (success) { if (success) {
uni.showToast({ title: this.$lang('copySuccess'), icon: 'success' }) uni.showToast({ title: this.$lang('ai-chat.index.copySuccess'), icon: 'success' })
} else { } else {
uni.showToast({ title: this.$lang('copyFail'), icon: 'none' }) uni.showToast({ title: this.$lang('ai-chat.index.copyFail'), icon: 'none' })
} }
} catch (e) { } catch (e) {
uni.showToast({ title: this.$lang('copyFail'), icon: 'none' }) uni.showToast({ title: this.$lang('ai-chat.index.copyFail'), icon: 'none' })
} }
}, },
@@ -1841,7 +1841,7 @@ _handleStreamError(msg) {
type: 'loading', type: 'loading',
content: '', content: '',
timestamp: Date.now(), timestamp: Date.now(),
loadingText: this.$lang('aiThinking'), loadingText: this.$lang('ai-chat.index.aiThinking'),
_loadingIndex: 0 _loadingIndex: 0
} }
@@ -1872,10 +1872,10 @@ _handleStreamError(msg) {
id: ++this.messageId, id: ++this.messageId,
role: 'ai', role: 'ai',
type: 'text', type: 'text',
content: this.$lang('serviceUnavailable'), content: this.$lang('ai-chat.index.serviceUnavailable'),
timestamp: Date.now(), timestamp: Date.now(),
actions: [ actions: [
{ id: 1, text: this.$lang('retry'), type: 'retry' } { id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }
] ]
} }