mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 09:33:56 +08:00
updata:移动端添加语言切换功能
This commit is contained in:
@@ -4,6 +4,7 @@ import { computed, onMounted, ref } from 'vue'
|
||||
import { useMessage } from 'wot-design-uni'
|
||||
import { useToast } from 'wot-design-uni/components/wd-toast'
|
||||
import { createVoicePrint, deleteVoicePrint, getChatHistory, getVoicePrintList, updateVoicePrint } from '@/api/voiceprint'
|
||||
import { t } from '@/i18n'
|
||||
|
||||
defineOptions({
|
||||
name: 'VoicePrintManage',
|
||||
@@ -81,7 +82,7 @@ async function loadVoicePrintList() {
|
||||
|
||||
// 检查是否有当前选中的智能体
|
||||
if (!currentAgentId.value) {
|
||||
console.warn('没有选中的智能体')
|
||||
console.warn(t('voiceprint.noSelectedAgent'))
|
||||
voicePrintList.value = []
|
||||
return
|
||||
}
|
||||
@@ -117,7 +118,7 @@ async function refresh() {
|
||||
async function loadChatHistory() {
|
||||
try {
|
||||
if (!currentAgentId.value) {
|
||||
toast.error('请先选择智能体')
|
||||
toast.error(t('voiceprint.pleaseSelectAgent'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -133,24 +134,47 @@ async function loadChatHistory() {
|
||||
}
|
||||
catch (error) {
|
||||
console.error('获取对话记录失败:', error)
|
||||
toast.error('获取对话记录失败')
|
||||
toast.error(t('voiceprint.fetchHistoryFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// 打开添加弹窗
|
||||
function openAddDialog() {
|
||||
if (!currentAgentId.value) {
|
||||
toast.error('请先选择智能体')
|
||||
toast.error(t('voiceprint.pleaseSelectAgent'))
|
||||
return
|
||||
}
|
||||
|
||||
addForm.value = {
|
||||
agentId: currentAgentId.value,
|
||||
audioId: '',
|
||||
sourceName: '',
|
||||
introduce: '',
|
||||
// 检查声纹接口是否配置(通过尝试获取声纹列表来检测)
|
||||
const checkVoicePrintConfig = async () => {
|
||||
try {
|
||||
await getVoicePrintList(currentAgentId.value)
|
||||
// 接口正常,继续打开添加弹窗
|
||||
addForm.value = {
|
||||
agentId: currentAgentId.value,
|
||||
audioId: '',
|
||||
sourceName: '',
|
||||
introduce: '',
|
||||
}
|
||||
showAddDialog.value = true
|
||||
} catch (error: any) {
|
||||
// 捕捉声纹接口未配置错误
|
||||
if (error.message && error.message.includes('请求错误[10054]')) {
|
||||
toast.error(t('voiceprint.voiceprintInterfaceNotConfigured'))
|
||||
} else {
|
||||
// 其他错误,继续打开弹窗
|
||||
addForm.value = {
|
||||
agentId: currentAgentId.value,
|
||||
audioId: '',
|
||||
sourceName: '',
|
||||
introduce: '',
|
||||
}
|
||||
showAddDialog.value = true
|
||||
}
|
||||
}
|
||||
}
|
||||
showAddDialog.value = true
|
||||
|
||||
checkVoicePrintConfig()
|
||||
}
|
||||
|
||||
// 打开编辑弹窗
|
||||
@@ -162,7 +186,7 @@ function openEditDialog(item: VoicePrint) {
|
||||
// 获取选中音频的显示内容
|
||||
function getSelectedAudioContent(audioId: string) {
|
||||
if (!audioId)
|
||||
return '点击选择声纹向量'
|
||||
return t('voiceprint.clickToSelectVector')
|
||||
const chatItem = chatHistoryList.value.find(item => item.audioId === audioId)
|
||||
return chatItem ? chatItem.content : `已选择: ${audioId.substring(0, 8)}...`
|
||||
}
|
||||
@@ -181,34 +205,34 @@ function selectAudioId({ item }: { item: any }) {
|
||||
// 提交添加说话人
|
||||
async function submitAdd() {
|
||||
if (!addForm.value.sourceName.trim()) {
|
||||
toast.error('请输入姓名')
|
||||
toast.error(t('voiceprint.pleaseInputName'))
|
||||
return
|
||||
}
|
||||
if (!addForm.value.audioId) {
|
||||
toast.error('请选择声纹向量')
|
||||
toast.error(t('voiceprint.pleaseSelectVector'))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await createVoicePrint(addForm.value)
|
||||
toast.success('添加成功')
|
||||
toast.success(t('voiceprint.addSuccess'))
|
||||
showAddDialog.value = false
|
||||
await loadVoicePrintList()
|
||||
}
|
||||
catch (error) {
|
||||
console.error('添加说话人失败:', error)
|
||||
toast.error('添加说话人失败')
|
||||
toast.error(t('voiceprint.addFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// 提交编辑说话人
|
||||
async function submitEdit() {
|
||||
if (!editForm.value.sourceName.trim()) {
|
||||
toast.error('请输入姓名')
|
||||
toast.error(t('voiceprint.pleaseInputName'))
|
||||
return
|
||||
}
|
||||
if (!editForm.value.audioId) {
|
||||
toast.error('请选择声纹向量')
|
||||
toast.error(t('voiceprint.pleaseSelectVector'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -220,13 +244,13 @@ async function submitEdit() {
|
||||
introduce: editForm.value.introduce,
|
||||
createDate: editForm.value.createDate,
|
||||
})
|
||||
toast.success('编辑成功')
|
||||
toast.success(t('voiceprint.editSuccess'))
|
||||
showEditDialog.value = false
|
||||
await loadVoicePrintList()
|
||||
}
|
||||
catch (error) {
|
||||
console.error('编辑说话人失败:', error)
|
||||
toast.error('编辑说话人失败')
|
||||
toast.error(t('voiceprint.editFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,11 +263,11 @@ function handleEdit(item: VoicePrint) {
|
||||
// 删除声纹
|
||||
async function handleDelete(id: string) {
|
||||
message.confirm({
|
||||
msg: '确定要删除这个说话人吗?',
|
||||
title: '确认删除',
|
||||
msg: t('voiceprint.deleteConfirmMsg'),
|
||||
title: t('voiceprint.deleteConfirmTitle'),
|
||||
}).then(async () => {
|
||||
await deleteVoicePrint(id)
|
||||
toast.success('删除成功')
|
||||
toast.success(t('voiceprint.deleteSuccess'))
|
||||
await loadVoicePrintList()
|
||||
}).catch(() => {
|
||||
console.log('点击了取消按钮')
|
||||
@@ -268,7 +292,7 @@ defineExpose({
|
||||
<view v-if="loading && voicePrintList.length === 0" class="loading-container">
|
||||
<wd-loading color="#336cff" />
|
||||
<text class="loading-text">
|
||||
加载中...
|
||||
{{ t('voiceprint.loading') }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
@@ -302,7 +326,7 @@ defineExpose({
|
||||
@click="handleDelete(item.id)"
|
||||
>
|
||||
<wd-icon name="delete" />
|
||||
删除
|
||||
{{ t('voiceprint.delete') }}
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -315,11 +339,11 @@ defineExpose({
|
||||
<view v-else-if="!loading" class="empty-container">
|
||||
<view class="flex flex-col items-center justify-center p-[100rpx_40rpx] text-center">
|
||||
<wd-icon name="voice" custom-class="text-[120rpx] text-[#d9d9d9] mb-[32rpx]" />
|
||||
<text class="mb-[16rpx] text-[32rpx] text-[#666666] font-medium">
|
||||
暂无声纹数据
|
||||
<text class="mb-[32rpx] text-[32rpx] text-[#666666] font-medium">
|
||||
{{ t('voiceprint.emptyTitle') }}
|
||||
</text>
|
||||
<text class="text-[26rpx] text-[#999999] leading-[1.5]">
|
||||
点击右下角 + 号添加您的第一个说话人
|
||||
{{ t('voiceprint.emptyDesc') }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -341,7 +365,7 @@ defineExpose({
|
||||
<view>
|
||||
<view class="w-full flex items-center justify-between border-b-[2rpx] border-[#eeeeee] p-[32rpx_32rpx_24rpx]">
|
||||
<text class="w-full text-center text-[32rpx] text-[#232338] font-semibold">
|
||||
添加说话人
|
||||
{{ t('voiceprint.addSpeaker') }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
@@ -349,7 +373,7 @@ defineExpose({
|
||||
<!-- 声纹向量选择 -->
|
||||
<view class="mb-[32rpx]">
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 声纹向量
|
||||
* {{ t('voiceprint.voiceVector') }}
|
||||
</text>
|
||||
<view
|
||||
class="flex cursor-pointer items-center justify-between border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[20rpx] transition-all duration-300 active:bg-[#eef3ff]"
|
||||
@@ -368,22 +392,22 @@ defineExpose({
|
||||
<!-- 姓名 -->
|
||||
<view class="mb-[32rpx]">
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 姓名
|
||||
* {{ t('voiceprint.name') }}
|
||||
</text>
|
||||
<input
|
||||
v-model="addForm.sourceName"
|
||||
class="box-border h-[80rpx] w-full border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[16rpx_20rpx] text-[28rpx] text-[#232338] leading-[1.4] outline-none focus:border-[#336cff] focus:bg-white placeholder:text-[#9d9ea3]"
|
||||
type="text" placeholder="请输入姓名"
|
||||
type="text" :placeholder="t('voiceprint.pleaseInputName')"
|
||||
>
|
||||
</view>
|
||||
|
||||
<!-- 描述 -->
|
||||
<view>
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 描述
|
||||
* {{ t('voiceprint.description') }}
|
||||
</text>
|
||||
<textarea
|
||||
v-model="addForm.introduce" :maxlength="100" placeholder="请输入描述"
|
||||
v-model="addForm.introduce" :maxlength="100" :placeholder="t('voiceprint.pleaseInputDescription')"
|
||||
class="box-border h-[200rpx] w-full resize-none border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[20rpx] text-[26rpx] text-[#232338] leading-[1.6] outline-none focus:border-[#336cff] focus:bg-white placeholder:text-[#9d9ea3]"
|
||||
/>
|
||||
<view class="mt-[8rpx] text-right text-[22rpx] text-[#9d9ea3]">
|
||||
@@ -394,11 +418,11 @@ defineExpose({
|
||||
|
||||
<view class="flex gap-[16rpx] border-t-[2rpx] border-[#eeeeee] p-[24rpx_32rpx_32rpx]">
|
||||
<wd-button type="info" custom-class="flex-1" @click="showAddDialog = false">
|
||||
取消
|
||||
</wd-button>
|
||||
<wd-button type="primary" custom-class="flex-1" @click="submitAdd">
|
||||
保存
|
||||
</wd-button>
|
||||
{{ t('voiceprint.cancel') }}
|
||||
</wd-button>
|
||||
<wd-button type="primary" custom-class="flex-1" @click="submitAdd">
|
||||
{{ t('voiceprint.save') }}
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
@@ -411,7 +435,7 @@ defineExpose({
|
||||
<view>
|
||||
<view class="w-full flex items-center justify-between border-b-[2rpx] border-[#eeeeee] p-[32rpx_32rpx_24rpx]">
|
||||
<text class="w-full text-center text-[32rpx] text-[#232338] font-semibold">
|
||||
编辑说话人
|
||||
{{ t('voiceprint.editSpeaker') }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
@@ -419,7 +443,7 @@ defineExpose({
|
||||
<!-- 声纹向量选择 -->
|
||||
<view class="mb-[32rpx]">
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 声纹向量
|
||||
* {{ t('voiceprint.voiceVector') }}
|
||||
</text>
|
||||
<view
|
||||
class="flex cursor-pointer items-center justify-between border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[20rpx] transition-all duration-300 active:bg-[#eef3ff]"
|
||||
@@ -438,22 +462,22 @@ defineExpose({
|
||||
<!-- 姓名 -->
|
||||
<view class="mb-[32rpx]">
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 姓名
|
||||
* {{ t('voiceprint.name') }}
|
||||
</text>
|
||||
<input
|
||||
v-model="editForm.sourceName"
|
||||
class="box-border h-[80rpx] w-full border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[16rpx_20rpx] text-[28rpx] text-[#232338] leading-[1.4] outline-none focus:border-[#336cff] focus:bg-white placeholder:text-[#9d9ea3]"
|
||||
type="text" placeholder="请输入姓名"
|
||||
type="text" :placeholder="t('voiceprint.pleaseInputName')"
|
||||
>
|
||||
</view>
|
||||
|
||||
<!-- 描述 -->
|
||||
<view>
|
||||
<text class="mb-[16rpx] block text-[28rpx] text-[#232338] font-medium">
|
||||
* 描述
|
||||
* {{ t('voiceprint.description') }}
|
||||
</text>
|
||||
<textarea
|
||||
v-model="editForm.introduce" :maxlength="100" placeholder="请输入描述"
|
||||
v-model="editForm.introduce" :maxlength="100" :placeholder="t('voiceprint.pleaseInputDescription')"
|
||||
class="box-border h-[200rpx] w-full resize-none border-[1rpx] border-[#eeeeee] rounded-[12rpx] bg-[#f5f7fb] p-[20rpx] text-[26rpx] text-[#232338] leading-[1.6] outline-none focus:border-[#336cff] focus:bg-white placeholder:text-[#9d9ea3]"
|
||||
/>
|
||||
<view class="mt-[8rpx] text-right text-[22rpx] text-[#9d9ea3]">
|
||||
@@ -464,18 +488,18 @@ defineExpose({
|
||||
|
||||
<view class="flex gap-[16rpx] border-t-[2rpx] border-[#eeeeee] p-[24rpx_32rpx_32rpx]">
|
||||
<wd-button type="info" custom-class="flex-1" @click="showEditDialog = false">
|
||||
取消
|
||||
</wd-button>
|
||||
<wd-button type="primary" custom-class="flex-1" @click="submitEdit">
|
||||
保存
|
||||
</wd-button>
|
||||
{{ t('voiceprint.cancel') }}
|
||||
</wd-button>
|
||||
<wd-button type="primary" custom-class="flex-1" @click="submitEdit">
|
||||
{{ t('voiceprint.save') }}
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</wd-popup>
|
||||
|
||||
<!-- 语音对话记录选择动作面板 -->
|
||||
<wd-action-sheet
|
||||
v-model="showChatHistoryDialog" :actions="chatHistoryActions" title="选择声纹向量"
|
||||
v-model="showChatHistoryDialog" :actions="chatHistoryActions" :title="t('voiceprint.selectVector')"
|
||||
@select="selectAudioId"
|
||||
/>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user