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

448 lines
13 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">
2025-04-06 15:45:18 +08:00
<div style="padding: 16px 24px;">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 24px;">
<div>
<el-form-item label="助手昵称:">
<div class="input-46" style="width: 100%;">
<el-input v-model="form.agentName" />
</div>
</el-form-item>
<el-form-item label="角色模版:">
<div style="display: flex;gap: 8px;flex-wrap: wrap;">
<div v-for="(template, index) in templates" :key="`template-${index}`" class="template-item"
:class="{ 'template-loading': loadingTemplate }" @click="selectTemplate(template)">
{{ template.agentName }}
2025-03-14 23:48:59 +08:00
</div>
</div>
2025-04-06 15:45:18 +08:00
</el-form-item>
<el-form-item label="角色介绍:">
<div class="textarea-box">
<el-input type="textarea" rows="5" resize="none" placeholder="请输入内容" v-model="form.systemPrompt"
maxlength="2000" show-word-limit />
</div>
</el-form-item>
<el-form-item label="语言编码:">
<div class="input-46" style="width: 100%;">
<el-input v-model="form.langCode" placeholder="请输入语言编码,如:zh_CN" maxlength="10" show-word-limit />
</div>
</el-form-item>
<el-form-item label="交互语种:">
<div class="input-46" style="width: 100%;">
<el-input v-model="form.language" placeholder="请输入交互语种,如:中文" maxlength="10" show-word-limit />
</div>
</el-form-item>
2025-03-14 23:48:59 +08:00
</div>
2025-04-06 15:45:18 +08:00
<div>
<el-form-item v-for="(model, index) in models" :key="`model-${index}`" :label="model.label"
class="model-item">
<el-select v-model="form.model[model.key]" filterable placeholder="请选择" class="select-field">
<el-option v-for="(item, optionIndex) in modelOptions[model.type]"
:key="`option-${index}-${optionIndex}`" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="角色音色:">
<div style="display: flex;gap: 8px;align-items: center;">
<div class="input-46" style="width: 100%;">
<el-select v-model="form.ttsVoiceId" placeholder="请选择" style="width: 100%;">
<el-option v-for="(item, index) in voiceOptions" :key="`voice-${index}`" :label="item.label"
:value="item.value" />
</el-select>
</div>
</div>
</el-form-item>
2025-03-14 23:48:59 +08:00
</div>
2025-04-06 15:45:18 +08:00
</div>
2025-03-14 23:48:59 +08:00
</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-18 23:08:13 +08:00
models: [
2025-04-06 15:45:18 +08:00
{ label: '语音活动检测(VAD)', key: 'vadModelId', type: 'VAD' },
{ label: '语音识别(ASR)', key: 'asrModelId', type: 'ASR' },
{ label: '大语言模型(LLM)', key: 'llmModelId', type: 'LLM' },
{ label: '意图识别(Intent)', key: 'intentModelId', type: 'Intent' },
{ label: '记忆(Memory)', key: 'memModelId', type: 'Memory' },
{ label: '语音合成(TTS)', key: 'ttsModelId', type: 'TTS' },
2025-03-24 17:27:08 +08:00
],
2025-04-06 15:45:18 +08:00
modelOptions: {},
templates: [],
loadingTemplate: false,
voiceOptions: [],
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({
message: '配置保存成功',
showClose: true
});
2025-04-05 21:03:46 +08:00
} else {
this.$message.error({
message: data.msg || '配置保存失败',
showClose: true
});
2025-04-05 21:03:46 +08:00
}
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({
message: '配置已重置',
showClose: true
})
2025-03-14 23:48:59 +08:00
}).catch(() => {
})
2025-03-18 23:08:13 +08:00
},
2025-04-06 15:45:18 +08:00
fetchTemplates() {
Api.agent.getAgentTemplate(({ data }) => {
if (data.code === 0) {
this.templates = data.data;
} else {
this.$message.error(data.msg || '获取模板列表失败');
}
});
},
selectTemplate(template) {
2025-04-05 20:19:28 +08:00
if (this.loadingTemplate) return;
this.loadingTemplate = true;
2025-04-06 15:45:18 +08:00
try {
this.applyTemplateData(template);
this.$message.success({
message: `「${template.agentName}」模板已应用`,
showClose: true
});
2025-04-06 15:45:18 +08:00
} catch (error) {
this.$message.error({
message: '应用模板失败',
showClose: true
});
2025-04-06 15:45:18 +08:00
console.error('应用模板失败:', error);
} finally {
2025-04-05 21:03:46 +08:00
this.loadingTemplate = false;
2025-04-06 15:45:18 +08:00
}
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
},
2025-04-06 15:45:18 +08:00
fetchModelOptions() {
// 为每个模型类型获取选项
this.models.forEach(model => {
Api.model.getModelNames(model.type, '', ({ data }) => {
if (data.code === 0) {
this.$set(this.modelOptions, model.type, data.data.map(item => ({
value: item.id,
label: item.modelName
})));
} else {
this.$message.error(data.msg || '获取模型列表失败');
}
});
});
2025-04-05 20:19:28 +08:00
},
2025-04-06 15:45:18 +08:00
fetchVoiceOptions(modelId) {
if (!modelId) {
this.voiceOptions = [];
return;
}
Api.model.getModelVoices(modelId, '', ({ data }) => {
if (data.code === 0 && data.data) {
this.voiceOptions = data.data.map(voice => ({
value: voice.id,
label: voice.name
}));
} else {
this.voiceOptions = [];
}
});
}
},
watch: {
'form.model.ttsModelId': {
handler(newVal, oldVal) {
console.log('TTS模型变化:', newVal);
if (oldVal && newVal !== oldVal) {
this.form.ttsVoiceId = '';
this.fetchVoiceOptions(newVal);
} else {
this.fetchVoiceOptions(newVal);
}
},
immediate: true
},
voiceOptions: {
handler(newVal) {
if (newVal && newVal.length > 0 && !this.form.ttsVoiceId) {
this.form.ttsVoiceId = newVal[0].value;
}
},
immediate: true
}
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
}
2025-04-06 15:45:18 +08:00
this.fetchModelOptions();
this.fetchTemplates();
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>