From f628d7a0efc644da1e4c6a2d0762f25a8a56644b Mon Sep 17 00:00:00 2001
From: ZF sun <34314687@qq.com>
Date: Fri, 3 Jul 2026 11:07:34 +0800
Subject: [PATCH] =?UTF-8?q?refactor(ai-chat):=20=E7=BB=9F=E4=B8=80?=
=?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AF=AD=E8=A8=80=E6=96=87=E4=BB=B6=E5=BC=95?=
=?UTF-8?q?=E7=94=A8=E8=B7=AF=E5=BE=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
将所有硬编码的语言调用路径统一改为ai-chat.index下的命名空间,便于语言包管理和维护
---
pages_tool/ai-chat/ai-chat-message.vue | 86 +++++++++++++-------------
1 file changed, 43 insertions(+), 43 deletions(-)
diff --git a/pages_tool/ai-chat/ai-chat-message.vue b/pages_tool/ai-chat/ai-chat-message.vue
index eddb703..df63950 100644
--- a/pages_tool/ai-chat/ai-chat-message.vue
+++ b/pages_tool/ai-chat/ai-chat-message.vue
@@ -74,7 +74,7 @@
- {{ $lang('aiNickname') }}
+ {{ $lang('ai-chat.index.aiNickname') }}
{{ formatTime(message.timestamp) }}
- {{ message.title || $lang('audioMessage') }}
+ {{ message.title || $lang('ai-chat.index.audioMessage') }}
{{ formatDuration(message.duration) }}
@@ -157,7 +157,7 @@
@pause="onVideoPause(message)">
- {{ message.title || $lang('videoMessage') }}
+ {{ message.title || $lang('ai-chat.index.videoMessage') }}
{{ formatDuration(message.duration) }}
@@ -187,7 +187,7 @@
- {{ message.loadingText || $lang('aiThinking') }}
+ {{ message.loadingText || $lang('ai-chat.index.aiThinking') }}
.
.
@@ -232,7 +232,7 @@
@@ -283,7 +283,7 @@
- {{ $lang('expandEditorTitle') }}
+ {{ $lang('ai-chat.index.expandEditorTitle') }}
@@ -291,14 +291,14 @@
-
+
@@ -397,7 +397,7 @@ export default {
scrollTop: 0,
scrollIntoViewId: null,
hasMoreHistory: false,
- loadingText: this.$lang('loadMoreHistory'),
+ loadingText: this.$lang('ai-chat.index.loadMoreHistory'),
voiceInputing: false,
audioContext: null,
currentAudio: null,
@@ -417,7 +417,7 @@ export default {
localUserAvatar: '',
showAvatarSelector: false, // 头像选择弹窗控制
localUserNickname: '', // 当前用户昵称
- defaultNickname: this.$lang('defaultNickname'), // 默认昵称
+ defaultNickname: this.$lang('ai-chat.index.defaultNickname'), // 默认昵称
showNicknameEditor: false, // 昵称编辑弹窗控制
// AI头像错误状态
avatarError: false,
@@ -857,7 +857,7 @@ async loadChatHistoryIfExist() {
type: 'loading',
content: '',
timestamp: Date.now(),
- loadingText: this.$lang('aiThinking'),
+ loadingText: this.$lang('ai-chat.index.aiThinking'),
_loadingIndex: 0
}
this.shouldScrollToBottom = true
@@ -891,10 +891,10 @@ async loadChatHistoryIfExist() {
id: ++this.messageId,
role: 'ai',
type: 'text',
- content: this.$lang('serviceUnavailable'),
+ content: this.$lang('ai-chat.index.serviceUnavailable'),
timestamp: Date.now(),
actions: [
- { id: 1, text: this.$lang('retry'), type: 'retry' }
+ { id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }
]
}
this.shouldScrollToBottom = true
@@ -975,7 +975,7 @@ async sendStreamMessage(userMessage) {
this.isStreaming = true
const loadingMsg = this.messages[loadingIdx]
this._stopLoadingTextRotation(loadingMsg)
- loadingMsg.loadingText = this.$lang('receivingReply')
+ loadingMsg.loadingText = this.$lang('ai-chat.index.receivingReply')
let transformed = false
@@ -1041,9 +1041,9 @@ async sendStreamMessage(userMessage) {
id: ++this.messageId,
role: 'ai',
type: 'text',
- content: this.$lang('serviceTemporaryUnavailable'),
+ content: this.$lang('ai-chat.index.serviceTemporaryUnavailable'),
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.$emit('ai-response', errorMsg)
@@ -1087,9 +1087,9 @@ _handleStreamError(msg) {
id: ++this.messageId,
role: 'ai',
type: 'text',
- content: this.$lang('serviceTemporaryUnavailable'),
+ content: this.$lang('ai-chat.index.serviceTemporaryUnavailable'),
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.$emit('ai-response', errorMsg)
@@ -1097,10 +1097,10 @@ _handleStreamError(msg) {
// 加载状态文字轮换 - 让AI看起来在处理不同阶段
_startLoadingTextRotation(loadingMsg) {
const statusTexts = [
- this.$lang('aiThinkingStatus1'),
- this.$lang('aiThinkingStatus2'),
- this.$lang('aiThinkingStatus3'),
- this.$lang('aiThinkingStatus4')
+ this.$lang('ai-chat.index.aiThinkingStatus1'),
+ this.$lang('ai-chat.index.aiThinkingStatus2'),
+ this.$lang('ai-chat.index.aiThinkingStatus3'),
+ this.$lang('ai-chat.index.aiThinkingStatus4')
]
loadingMsg._rotationTimer = setInterval(() => {
loadingMsg._loadingIndex = (loadingMsg._loadingIndex + 1) % statusTexts.length
@@ -1136,7 +1136,7 @@ _handleStreamError(msg) {
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;
}
if (msgDate.getTime() === yesterday.getTime()) {
- return `${this.$lang('timeFormatYesterday')} ${timeStr}`;
+ return `${this.$lang('ai-chat.index.timeFormatYesterday')} ${timeStr}`;
}
if (msgDate.getTime() === beforeYesterday.getTime()) {
- return `${this.$lang('timeFormatBeforeYesterday')} ${timeStr}`;
+ return `${this.$lang('ai-chat.index.timeFormatBeforeYesterday')} ${timeStr}`;
}
const isCurrentYear = date.getFullYear() === now.getFullYear();
@@ -1385,9 +1385,9 @@ _handleStreamError(msg) {
// 格式化文件大小
formatFileSize(bytes) {
- if (!bytes) return this.$lang('about')
+ if (!bytes) return this.$lang('ai-chat.index.about')
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))
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + sizes[i]
},
@@ -1426,7 +1426,7 @@ _handleStreamError(msg) {
}
this.isFetchingHistory = true;
this.isLoadingHistory = true;
- this.loadingText = this.$lang('loadingHistory');
+ this.loadingText = this.$lang('ai-chat.index.loadingHistory');
try {
const response = await aiService.getConversationHistory({
@@ -1475,12 +1475,12 @@ _handleStreamError(msg) {
}
} catch (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;
} finally {
this.isLoadingHistory = 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) {
- uni.showLoading({ title: this.$lang('openingFile') })
+ uni.showLoading({ title: this.$lang('ai-chat.index.openingFile') })
// #ifdef H5
window.open(message.url, '_blank')
@@ -1500,7 +1500,7 @@ _handleStreamError(msg) {
plus.runtime.openFile(message.url, {
error: (e) => {
uni.showToast({
- title: this.$lang('fileOpenFail'),
+ title: this.$lang('ai-chat.index.fileOpenFail'),
icon: 'none'
})
}
@@ -1674,7 +1674,7 @@ _handleStreamError(msg) {
copyText = message.content || ''
}
if (!copyText) {
- uni.showToast({ title: this.$lang('noContentToCopy'), icon: 'none' })
+ uni.showToast({ title: this.$lang('ai-chat.index.noContentToCopy'), icon: 'none' })
return
}
@@ -1688,7 +1688,7 @@ _handleStreamError(msg) {
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
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(() => {
this._fallbackCopyH5(finalText)
})
@@ -1707,12 +1707,12 @@ _handleStreamError(msg) {
data: copyText,
success: () => {
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) => {
console.error('[AI Chat] 复制失败, 详细错误:', JSON.stringify(err))
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
@@ -1733,12 +1733,12 @@ _handleStreamError(msg) {
const success = document.execCommand('copy')
document.body.removeChild(textarea)
if (success) {
- uni.showToast({ title: this.$lang('copySuccess'), icon: 'success' })
+ uni.showToast({ title: this.$lang('ai-chat.index.copySuccess'), icon: 'success' })
} else {
- uni.showToast({ title: this.$lang('copyFail'), icon: 'none' })
+ uni.showToast({ title: this.$lang('ai-chat.index.copyFail'), icon: 'none' })
}
} 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',
content: '',
timestamp: Date.now(),
- loadingText: this.$lang('aiThinking'),
+ loadingText: this.$lang('ai-chat.index.aiThinking'),
_loadingIndex: 0
}
@@ -1872,10 +1872,10 @@ _handleStreamError(msg) {
id: ++this.messageId,
role: 'ai',
type: 'text',
- content: this.$lang('serviceUnavailable'),
+ content: this.$lang('ai-chat.index.serviceUnavailable'),
timestamp: Date.now(),
actions: [
- { id: 1, text: this.$lang('retry'), type: 'retry' }
+ { id: 1, text: this.$lang('ai-chat.index.retry'), type: 'retry' }
]
}