xiaozhi-esp32-server/main/manager-web/src/components/DeviceItem.vue

257 lines
No EOL
7.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="device-item">
<div style="display: flex;justify-content: space-between;">
<el-tooltip :content="device.agentName" placement="top" effect="light">
<div class="device-item-title">
{{ device.agentName }}
</div>
</el-tooltip>
<div>
<img src="@/assets/home/delete.png" alt="" style="width: 18px;height: 18px;margin-right: 10px;"
@click.stop="handleDelete" />
<el-tooltip class="item" effect="light" :content="device.systemPrompt" placement="top"
popper-class="device-item-tooltip">
<img src="@/assets/home/info.png" alt="" style="width: 18px;height: 18px;" />
</el-tooltip>
</div>
</div>
<div class="device-name">
{{ $t('home.languageModel') }}:{{ device.llmModelName }}
</div>
<div class="device-name">
{{ $t('home.voiceModel') }}:{{ device.ttsModelName }} ({{ device.ttsVoiceName }})
</div>
<div style="display: flex;gap: 10px;align-items: center;">
<div class="settings-btn" @click="handleConfigure">
{{ $t('home.configureRole') }}
</div>
<el-dropdown trigger="click" @command="handleSwitchPersona">
<div class="settings-btn">
换角色<i class="el-icon-arrow-down el-icon--right"></i>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-for="a in personaOptions" :key="a.id" :command="a.id">{{ a.agentName }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<div class="settings-btn" @click="handleResetAuto">
恢复自动匹配
</div>
<div v-if="featureStatus.voiceprintRecognition" class="settings-btn" @click="handleVoicePrint">
{{ $t('home.voiceprintRecognition') }}
</div>
<div class="settings-btn" @click="handleDeviceManage">
{{ $t('home.deviceManagement') }}({{ device.deviceCount }})
</div>
<div :class="['settings-btn', { 'disabled-btn': device.memModelId === 'Memory_nomem' }]"
@click="handleChatHistory">
<el-tooltip effect="light" v-if="device.memModelId === 'Memory_nomem'" :content="$t('home.enableMemory')" placement="top">
<span>{{ $t('home.chatHistory') }}</span>
</el-tooltip>
<span v-else>{{ $t('home.chatHistory') }}</span>
</div>
</div>
<div class="version-info">
<div>{{ $t('home.lastConversation') }}:{{ formattedLastConnectedTime }}</div>
<el-tooltip :content="tags.join()" placement="top" effect="light">
<div class="version-info-scroll">
{{ tags.join() }}
</div>
</el-tooltip>
</div>
</div>
</template>
<script>
import i18n from '@/i18n';
import Api from '@/apis/api';
export default {
name: 'DeviceItem',
props: {
device: { type: Object, required: true },
featureStatus: {
type: Object,
default: () => ({
voiceprintRecognition: false,
voiceClone: false,
knowledgeBase: false
})
}
},
data() {
return { switchValue: false, personaOptions: [] }
},
mounted() {
this.fetchPersonaOptions();
},
computed: {
formattedLastConnectedTime() {
if (!this.device.lastConnectedAt) return this.$t('home.noConversation');
const lastTime = new Date(this.device.lastConnectedAt);
const now = new Date();
const diffMinutes = Math.floor((now - lastTime) / (1000 * 60));
if (diffMinutes <= 1) {
return this.$t('home.justNow');
} else if (diffMinutes < 60) {
return this.$t('home.minutesAgo', { minutes: diffMinutes });
} else if (diffMinutes < 24 * 60) {
const hours = Math.floor(diffMinutes / 60);
const minutes = diffMinutes % 60;
return this.$t('home.hoursAgo', { hours, minutes });
} else {
return this.device.lastConnectedAt;
}
},
tags() {
if (!this.device.tags) return [];
return this.device.tags.map((tag) => tag.tagName);
}
},
methods: {
handleDelete() {
this.$emit('delete', this.device.agentId)
},
handleConfigure() {
this.$router.push({ path: '/role-config', query: { agentId: this.device.agentId } });
},
handleVoicePrint() {
this.$router.push({ path: '/voice-print', query: { agentId: this.device.agentId } });
},
handleDeviceManage() {
this.$router.push({ path: '/device-management', query: { agentId: this.device.agentId } });
},
fetchPersonaOptions() {
Api.persona.candidates(({ data }) => {
if (data?.data) {
this.personaOptions = data.data.map(item => ({ id: item.id, agentName: item.agentName }));
}
});
},
handleSwitchPersona(agentId) {
Api.persona.switchPersona(agentId, (res) => {
if (res.data.code === 0) {
this.$message.success({ message: '已切换角色', showClose: true });
this.$emit('persona-changed');
} else {
this.$message.error({ message: res.data.msg || '切换失败', showClose: true });
}
});
},
handleResetAuto() {
Api.persona.resetAuto((res) => {
if (res.data.code === 0) {
this.$message.success({ message: '已恢复自动匹配', showClose: true });
this.$emit('persona-changed');
} else {
this.$message.error({ message: res.data.msg || '操作失败', showClose: true });
}
});
},
handleChatHistory() {
if (this.device.memModelId === 'Memory_nomem') {
return
}
this.$emit('chat-history', { agentId: this.device.agentId, agentName: this.device.agentName })
}
},
}
</script>
<style lang="scss" scoped>
.device-item {
width: 342px;
border-radius: 20px;
background: #fafcfe;
padding: 22px 22px 14px;
box-sizing: border-box;
&-title {
flex: 1;
font-weight: bold;
font-size: 18px;
color: #3d4566;
text-align: left;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
}
.device-name {
margin: 7px 0 10px;
font-weight: 400;
font-size: 11px;
color: #3d4566;
text-align: left;
}
.settings-btn {
font-weight: 500;
font-size: 12px;
color: #5778ff;
background: #e6ebff;
width: auto;
padding: 0 12px;
height: 21px;
line-height: 21px;
cursor: pointer;
border-radius: 14px;
}
.version-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 15px;
font-size: 12px;
color: #979db1;
font-weight: 400;
&-scroll {
margin-left: 20px;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
text-wrap: nowrap;
text-align: right;
}
}
.more-tag {
cursor: pointer;
flex-shrink: 0;
}
.all-tags-popover {
display: flex;
flex-wrap: wrap;
gap: 4px;
}
.disabled-btn {
background: #e6e6e6;
color: #999;
cursor: not-allowed;
}
</style>
<style>
.device-item-tooltip {
max-height: 60vh !important;
max-width: 400px !important;
overflow-y: auto !important;
scrollbar-width: thin;
word-break: break-word;
}
.device-item-tooltip .popper__arrow {
display: none !important;
}
.device-item-tooltip[x-placement^="top"] .popper__arrow {
border-top-color: transparent !important;
}
.device-item-tooltip[x-placement^="bottom"] .popper__arrow {
border-bottom-color: transparent !important;
}
</style>