Files
xiaozhi-esp32-server/main/manager-web/src/views/roleConfig.vue
T

395 lines
12 KiB
Vue
Raw Normal View History

2025-03-14 23:48:59 +08:00
<template>
<div class="welcome">
2025-04-05 20:19:28 +08:00
<HeaderBar />
2025-03-18 21:49:57 +08:00
<el-main style="padding: 16px;display: flex;flex-direction: column;">
<div style="border-radius: 16px;background: #fafcfe; border: 1px solid #e8f0ff;">
2025-03-14 23:48:59 +08:00
<div
2025-04-05 20:19:28 +08:00
style="padding: 15px 24px;font-weight: 700;font-size: 19px;text-align: left;color: #3d4566;display: flex;gap: 13px;align-items: center;">
2025-03-14 23:48:59 +08:00
<div
2025-04-05 20:19:28 +08:00
style="width: 37px;height: 37px;background: #5778ff;border-radius: 50%;display: flex;align-items: center;justify-content: center;">
<img loading="lazy" src="@/assets/home/setting-user.png" alt="" style="width: 19px;height: 19px;" />
2025-03-14 23:48:59 +08:00
</div>
2025-03-28 11:20:08 +08:00
{{ form.agentName }}
2025-03-14 23:48:59 +08:00
</div>
2025-04-05 20:19:28 +08:00
<div style="height: 1px;background: #e8f0ff;" />
2025-03-18 21:49:57 +08:00
<el-form ref="form" :model="form" label-width="72px">
<div style="padding: 16px 24px;max-width: 792px;">
2025-03-14 23:48:59 +08:00
<el-form-item label="助手昵称:">
2025-03-18 21:49:57 +08:00
<div class="input-46" style="width: 100%; max-width: 412px;">
2025-04-05 20:19:28 +08:00
<el-input v-model="form.agentName" />
2025-03-14 23:48:59 +08:00
</div>
</el-form-item>
<el-form-item label="角色模版:">
2025-03-18 21:49:57 +08:00
<div style="display: flex;gap: 8px;">
2025-04-05 20:19:28 +08:00
<div v-for="template in templates" :key="template" class="template-item"
:class="{ 'template-loading': loadingTemplate }" @click="selectTemplate(template)">
2025-03-18 23:08:13 +08:00
{{ template }}
2025-03-14 23:48:59 +08:00
</div>
</div>
</el-form-item>
<el-form-item label="角色音色:">
2025-03-18 21:49:57 +08:00
<div style="display: flex;gap: 8px;align-items: center;">
2025-03-14 23:48:59 +08:00
<div class="input-46" style="flex:1.4;">
2025-03-24 17:27:08 +08:00
<el-select v-model="form.ttsVoiceId" placeholder="请选择" style="width: 100%;">
2025-04-05 20:19:28 +08:00
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
2025-03-14 23:48:59 +08:00
</el-option>
</el-select>
</div>
<div class="audio-box">
<audio src="http://music.163.com/song/media/outer/url?id=447925558.mp3" controls
2025-04-05 20:19:28 +08:00
style="height: 100%;width: 100%;" />
2025-03-14 23:48:59 +08:00
</div>
</div>
</el-form-item>
<el-form-item label="角色介绍:">
<div class="textarea-box">
2025-04-05 20:19:28 +08:00
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容" v-model="form.systemPrompt"
maxlength="2000" show-word-limit />
2025-03-14 23:48:59 +08:00
</div>
</el-form-item>
<el-form-item label="记忆体:">
<div class="textarea-box">
2025-04-05 20:19:28 +08:00
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容" v-model="form.langCode"
maxlength="1000" />
2025-03-25 00:01:13 +08:00
<div class="prompt-bottom" @click="clearMemory">
2025-03-18 21:49:57 +08:00
<div style="display: flex;gap: 8px;align-items: center;">
<div style="color: #979db1;font-size: 11px;">当前记忆每次对话后重新生成</div>
2025-03-25 00:01:13 +08:00
<div class="clear-btn">
2025-04-05 20:19:28 +08:00
<i class="el-icon-delete-solid" style="font-size: 11px;" />
2025-03-14 23:48:59 +08:00
清除
</div>
</div>
2025-04-02 10:16:12 +08:00
<div style="color: #979db1;font-size:11px;">{{ (form.langCode || '').length }}/1000</div>
2025-03-14 23:48:59 +08:00
</div>
</div>
</el-form-item>
2025-03-18 23:08:13 +08:00
<el-form-item v-for="model in models" :key="model.label" :label="model.label" class="model-item">
<el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="select-field">
2025-04-05 20:19:28 +08:00
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
2025-03-18 23:08:13 +08:00
</el-select>
2025-03-18 21:49:57 +08:00
</el-form-item>
<el-form-item label="" class="lh-form-item" style="margin-top: -25px;">
2025-03-14 23:48:59 +08:00
<div style="color: #979db1;text-align: left;">除了Qwen
实时”,其他模型通常会增加约1秒的延迟改变模型后建议清空记忆体以免影响体验
</div>
</el-form-item>
</div>
</el-form>
2025-03-18 21:49:57 +08:00
<div style="display: flex;padding: 16px;gap: 8px;align-items: center;">
2025-03-14 23:48:59 +08:00
<div class="save-btn" @click="saveConfig">
保存配置
</div>
<div class="reset-btn" @click="resetConfig">
重制
</div>
<div class="clear-text">
2025-04-05 20:19:28 +08:00
<img loading="lazy" src="@/assets/home/red-info.png" alt="" style="width: 19px;height: 19px;" />
2025-03-14 23:48:59 +08:00
保存配置后需要重启设备新的配置才会生效
</div>
</div>
</div>
<div class="copyright">
2025-03-14 23:48:59 +08:00
©2025 xiaozhi-esp32-server
</div>
</el-main>
</div>
</template>
<script>
2025-04-05 21:03:46 +08:00
import Api from '@/apis/api';
2025-03-14 23:48:59 +08:00
import HeaderBar from "@/components/HeaderBar.vue";
2025-04-05 21:03:46 +08:00
2025-03-14 23:48:59 +08:00
export default {
name: 'RoleConfigPage',
2025-04-05 20:19:28 +08:00
components: { HeaderBar },
2025-03-14 23:48:59 +08:00
data() {
return {
form: {
2025-03-28 11:20:08 +08:00
agentCode: "",
2025-03-24 17:27:08 +08:00
agentName: "",
ttsVoiceId: "",
systemPrompt: "",
2025-03-28 11:20:08 +08:00
langCode: "",
language: "",
sort: "",
2025-03-18 21:49:57 +08:00
model: {
2025-03-24 17:27:08 +08:00
ttsModelId: "",
vadModelId: "",
2025-03-28 11:20:08 +08:00
asrModelId: "",
2025-03-24 17:27:08 +08:00
llmModelId: "",
memModelId: "",
intentModelId: "",
2025-03-18 21:49:57 +08:00
}
2025-03-14 23:48:59 +08:00
},
2025-03-24 17:27:08 +08:00
options: [
2025-04-05 20:19:28 +08:00
{ value: '选项1', label: '黄金糕' },
{ value: '选项2', label: '双皮奶' }
2025-03-24 17:27:08 +08:00
],
2025-03-18 23:08:13 +08:00
models: [
2025-04-05 20:19:28 +08:00
{ label: '大语言模型(LLM)', key: 'llmModelId' },
{ label: '语音识别(ASR)', key: 'asrModelId' },
{ label: '语音活动检测(VAD)', key: 'vadModelId' },
{ label: '语音合成(TTS)', key: 'ttsModelId' },
{ label: '意图识别(Intent)', key: 'intentModelId' },
{ label: '记忆(Memory)', key: 'memModelId' }
2025-03-24 17:27:08 +08:00
],
2025-04-02 10:16:12 +08:00
templates: ['湾湾小何', '星际游子', '英语老师', '好奇男孩', '汪汪队长'],
2025-03-28 11:20:08 +08:00
loadingTemplate: false
2025-03-14 23:48:59 +08:00
}
},
methods: {
saveConfig() {
2025-03-28 11:20:08 +08:00
const configData = {
agentCode: this.form.agentCode,
agentName: this.form.agentName,
asrModelId: this.form.model.asrModelId,
vadModelId: this.form.model.vadModelId,
llmModelId: this.form.model.llmModelId,
ttsModelId: this.form.model.ttsModelId,
ttsVoiceId: this.form.ttsVoiceId,
memModelId: this.form.model.memModelId,
intentModelId: this.form.model.intentModelId,
systemPrompt: this.form.systemPrompt,
langCode: this.form.langCode,
language: this.form.language,
sort: this.form.sort
};
2025-04-05 21:03:46 +08:00
Api.agent.updateAgentConfig(this.$route.query.agentId, configData, ({ data }) => {
if (data.code === 0) {
this.$message.success('配置保存成功');
} else {
this.$message.error(data.msg || '配置保存失败');
}
2025-03-28 11:20:08 +08:00
});
2025-03-14 23:48:59 +08:00
},
resetConfig() {
this.$confirm('确定要重置配置吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 重置表单
this.form = {
2025-03-28 11:20:08 +08:00
agentCode: "",
2025-03-24 17:27:08 +08:00
agentName: "",
ttsVoiceId: "",
systemPrompt: "",
2025-03-28 11:20:08 +08:00
langCode: "",
language: "",
sort: "",
2025-03-24 17:27:08 +08:00
model: {
ttsModelId: "",
vadModelId: "",
2025-03-28 11:20:08 +08:00
asrModelId: "",
2025-03-24 17:27:08 +08:00
llmModelId: "",
memModelId: "",
intentModelId: "",
}
2025-03-14 23:48:59 +08:00
}
this.$message.success('配置已重置')
}).catch(() => {
})
2025-03-18 23:08:13 +08:00
},
2025-03-28 11:20:08 +08:00
selectTemplate(templateName) {
2025-04-05 20:19:28 +08:00
if (this.loadingTemplate) return;
this.loadingTemplate = true;
2025-04-05 21:03:46 +08:00
Api.agent.getAgentTemplate((response) => { // 移除参数传递
this.loadingTemplate = false;
if (response.data.code === 0) {
// 在客户端过滤匹配的模板
const matchedTemplate = response.data.data.find(
t => t.agentName === templateName
);
if (matchedTemplate) {
this.applyTemplateData(matchedTemplate);
this.$message.success(`「${templateName}」模板已应用`);
2025-04-05 20:19:28 +08:00
} else {
2025-04-05 21:03:46 +08:00
this.$message.warning(`未找到「${templateName}」模板`);
2025-04-05 20:19:28 +08:00
}
2025-04-05 21:03:46 +08:00
} else {
this.$message.error(response.data.msg || '获取模板失败');
}
2025-04-05 20:19:28 +08:00
}).catch((error) => {
this.loadingTemplate = false;
this.$message.error('模板加载失败');
console.error('接口异常:', error);
});
2025-03-24 22:41:32 +08:00
},
2025-03-28 11:20:08 +08:00
applyTemplateData(templateData) {
this.form = {
...this.form,
agentName: templateData.agentName || this.form.agentName,
ttsVoiceId: templateData.ttsVoiceId || this.form.ttsVoiceId,
systemPrompt: templateData.systemPrompt || this.form.systemPrompt,
langCode: templateData.langCode || this.form.langCode,
model: {
ttsModelId: templateData.ttsModelId || this.form.model.ttsModelId,
vadModelId: templateData.vadModelId || this.form.model.vadModelId,
asrModelId: templateData.asrModelId || this.form.model.asrModelId,
llmModelId: templateData.llmModelId || this.form.model.llmModelId,
memModelId: templateData.memModelId || this.form.model.memModelId,
intentModelId: templateData.intentModelId || this.form.model.intentModelId
}
};
2025-03-24 22:41:32 +08:00
},
2025-04-05 20:19:28 +08:00
fetchAgentConfig(agentId) {
2025-04-05 21:03:46 +08:00
Api.agent.getDeviceConfig(agentId, ({ data }) => {
if (data.code === 0) {
this.form = {
...this.form,
...data.data,
model: {
ttsModelId: data.data.ttsModelId,
vadModelId: data.data.vadModelId,
asrModelId: data.data.asrModelId,
llmModelId: data.data.llmModelId,
memModelId: data.data.memModelId,
intentModelId: data.data.intentModelId
}
};
} else {
this.$message.error(data.msg || '获取配置失败');
}
2025-03-28 11:20:08 +08:00
});
2025-04-05 20:19:28 +08:00
},
// 清空记忆体内容
clearMemory() {
this.form.langCode = "";
this.$message.success("记忆体已清空");
},
2025-03-28 11:20:08 +08:00
},
2025-03-24 17:27:08 +08:00
mounted() {
const agentId = this.$route.query.agentId;
if (agentId) {
this.fetchAgentConfig(agentId);
2025-03-14 23:48:59 +08:00
}
}
}
</script>
<style scoped>
.welcome {
2025-03-18 21:49:57 +08:00
min-width: 900px;
min-height: 506px;
2025-03-14 23:48:59 +08:00
height: 100vh;
2025-03-18 21:49:57 +08:00
display: flex;
flex-direction: column;
background: linear-gradient(145deg, #e6eeff, #eff0ff);
2025-03-14 23:48:59 +08:00
background-size: cover;
/* 确保背景图像覆盖整个元素 */
background-position: center;
/* 从顶部中心对齐 */
-webkit-background-size: cover;
/* 兼容老版本WebKit浏览器 */
-o-background-size: cover;
/* 兼容老版本Opera浏览器 */
}
2025-03-18 21:49:57 +08:00
.el-form-item ::v-deep .el-form-item__label {
font-size: 10px !important;
color: #3d4566 !important;
font-weight: 400;
line-height: 22px;
padding-bottom: 2px;
}
2025-04-05 20:19:28 +08:00
.select-field {
2025-03-18 23:08:13 +08:00
width: 100%;
max-width: 720px;
border: 1px solid #e4e6ef;
background: #f6f8fb;
border-radius: 8px;
height: 36px !important;
}
2025-03-18 21:49:57 +08:00
2025-03-14 23:48:59 +08:00
.audio-box {
flex: 1;
2025-03-18 21:49:57 +08:00
height: 37px;
border-radius: 20px;
2025-03-14 23:48:59 +08:00
border: 1px solid #e4e6ef;
}
.clear-btn {
2025-03-18 21:49:57 +08:00
width: 48px;
height: 19px;
2025-03-14 23:48:59 +08:00
background: #fd8383;
2025-03-18 21:49:57 +08:00
border-radius: 10px;
line-height: 19px;
font-size: 11px;
2025-03-14 23:48:59 +08:00
color: #fff;
cursor: pointer;
}
.clear-text {
color: #979db1;
2025-03-18 21:49:57 +08:00
font-size: 11px;
2025-03-14 23:48:59 +08:00
display: flex;
align-items: center;
2025-03-18 21:49:57 +08:00
gap: 8px;
margin-left: 16px;
2025-03-14 23:48:59 +08:00
}
.template-item {
2025-03-18 21:49:57 +08:00
height: 37px;
2025-03-18 23:08:13 +08:00
width: 76px;
2025-03-18 21:49:57 +08:00
border-radius: 8px;
2025-03-14 23:48:59 +08:00
background: #e6ebff;
2025-03-18 21:49:57 +08:00
line-height: 37px;
2025-03-14 23:48:59 +08:00
font-weight: 400;
2025-03-18 21:49:57 +08:00
font-size: 11px;
2025-03-14 23:48:59 +08:00
text-align: center;
color: #5778ff;
2025-03-18 23:08:13 +08:00
cursor: pointer;
transition: background-color 0.3s ease;
}
.template-item:hover {
background-color: #d0d8ff;
2025-03-14 23:48:59 +08:00
}
.prompt-bottom {
2025-03-18 21:49:57 +08:00
margin-bottom: 4px;
2025-03-14 23:48:59 +08:00
display: flex;
justify-content: space-between;
2025-03-18 21:49:57 +08:00
padding: 0 16px;
2025-03-14 23:48:59 +08:00
align-items: center;
}
.input-46 {
border: 1px solid #e4e6ef;
background: #f6f8fb;
2025-03-18 21:49:57 +08:00
border-radius: 8px;
height: 36px !important;
2025-03-14 23:48:59 +08:00
}
.save-btn,
.reset-btn {
2025-03-18 21:49:57 +08:00
width: 112px;
height: 37px;
border-radius: 18px;
line-height: 37px;
2025-03-14 23:48:59 +08:00
box-sizing: border-box;
cursor: pointer;
2025-03-18 21:49:57 +08:00
font-size: 11px
2025-03-14 23:48:59 +08:00
}
.save-btn {
2025-03-18 21:49:57 +08:00
border-radius: 18px;
2025-03-14 23:48:59 +08:00
background: #5778ff;
color: #fff;
}
.reset-btn {
border: 1px solid #adbdff;
background: #e6ebff;
color: #5778ff;
}
.textarea-box {
border: 1px solid #e4e6ef;
2025-03-18 21:49:57 +08:00
border-radius: 8px;
2025-03-14 23:48:59 +08:00
background: #f6f8fb;
}
2025-03-18 21:49:57 +08:00
</style>