refactor(ai-chat): 统一调整语言文件引用路径
将所有硬编码的语言调用路径统一改为ai-chat.index下的命名空间,便于语言包管理和维护
This commit is contained in:
@@ -74,7 +74,7 @@
|
||||
<view class="message-content">
|
||||
<!-- AI昵称固定,不可修改 - 左移到气泡上方 -->
|
||||
<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>
|
||||
</view>
|
||||
<view class="message-bubble"
|
||||
@@ -119,7 +119,7 @@
|
||||
<view v-else-if="message.type === 'audio'" class="audio-content">
|
||||
<view class="audio-player">
|
||||
<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>
|
||||
</view>
|
||||
<view class="audio-controls">
|
||||
@@ -157,7 +157,7 @@
|
||||
@pause="onVideoPause(message)">
|
||||
</video>
|
||||
<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>
|
||||
</view>
|
||||
</view>
|
||||
@@ -187,7 +187,7 @@
|
||||
<text class="dot"></text>
|
||||
</view>
|
||||
<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="ellipsis-dot">.</text>
|
||||
<text class="ellipsis-dot">.</text>
|
||||
@@ -232,7 +232,7 @@
|
||||
<textarea
|
||||
v-model="inputText"
|
||||
class="message-input"
|
||||
:placeholder="$lang('inputPlaceholder')"
|
||||
:placeholder="$lang('ai-chat.index.inputPlaceholder')"
|
||||
:maxlength="500"
|
||||
:auto-height="true"
|
||||
:show-confirm-bar="false"
|
||||
@@ -258,7 +258,7 @@
|
||||
:class="{ disabled: !canSendMessage }"
|
||||
@click="sendMessage"
|
||||
:disabled="!canSendMessage">
|
||||
<text>{{ $lang('send') }}</text>
|
||||
<text>{{ $lang('ai-chat.index.send') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
@@ -283,7 +283,7 @@
|
||||
<view class="expand-editor-mask" @click="closeExpandEditor"></view>
|
||||
<view class="expand-editor-panel">
|
||||
<view class="expand-editor-header">
|
||||
<text>{{ $lang('expandEditorTitle') }}</text>
|
||||
<text>{{ $lang('ai-chat.index.expandEditorTitle') }}</text>
|
||||
<button class="close-btn" @click="closeExpandEditor">
|
||||
<text>×</text>
|
||||
</button>
|
||||
@@ -291,14 +291,14 @@
|
||||
<textarea
|
||||
v-model="expandInputText"
|
||||
class="expand-editor-input"
|
||||
:placeholder="$lang('inputPlaceholder')"
|
||||
:placeholder="$lang('ai-chat.index.inputPlaceholder')"
|
||||
:maxlength="500"
|
||||
:auto-height="true"
|
||||
:show-confirm-bar="false"
|
||||
:adjust-position="true"
|
||||
:focus="true" />
|
||||
<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>
|
||||
</view>
|
||||
</view>
|
||||
@@ -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' }
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user