feat: 智控台加「换角色/恢复自动匹配」按钮

DeviceItem 用户侧设备卡操作区新增:
- 换角色(el-dropdown): 列出候选 agent,选中调 POST /persona/switch {agentId}
- 恢复自动匹配(按钮): 调 POST /persona/auto
成功后 $emit persona-changed,home.vue 刷新 agent 列表。
新增 apis/module/persona.js 并在 api.js 注册,沿用既有 RequestService 封装(自动带 token)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SerenNoble 2026-06-28 17:28:52 +08:00
parent be72b14650
commit b94536fe7a
4 changed files with 87 additions and 7 deletions

View file

@ -11,6 +11,7 @@ import voiceClone from './module/voiceClone.js'
import voiceResource from './module/voiceResource.js'
import knowledgeBase from './module/knowledgeBase.js'
import correctWord from './module/correctWord.js'
import persona from './module/persona.js'
@ -43,5 +44,6 @@ export default {
voiceResource,
voiceClone,
knowledgeBase,
correctWord
correctWord,
persona
}

View file

@ -0,0 +1,36 @@
import { getServiceUrl } from '../api';
import RequestService from '../httpRequest';
export default {
// 手动切换角色(标 manual=1,自动任务不再覆盖)
switchPersona(agentId, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/persona/switch`)
.method('POST')
.data({ agentId })
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.switchPersona(agentId, callback);
});
}).send();
},
// 恢复自动匹配(manual=0)
resetAuto(callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/persona/auto`)
.method('POST')
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.resetAuto(callback);
});
}).send();
},
}

View file

@ -25,6 +25,17 @@
<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>
@ -52,6 +63,7 @@
<script>
import i18n from '@/i18n';
import Api from '@/apis/api';
export default {
name: 'DeviceItem',
@ -67,7 +79,10 @@ export default {
}
},
data() {
return { switchValue: false }
return { switchValue: false, personaOptions: [] }
},
mounted() {
this.fetchPersonaOptions();
},
computed: {
formattedLastConnectedTime() {
@ -107,6 +122,33 @@ export default {
handleDeviceManage() {
this.$router.push({ path: '/device-management', query: { agentId: this.device.agentId } });
},
fetchPersonaOptions() {
Api.agent.getAgentList(({ 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

View file

@ -41,7 +41,7 @@
<template v-else>
<DeviceItem v-for="(item, index) in devices" :key="index" :device="item" :feature-status="featureStatus"
@configure="goToRoleConfig" @deviceManage="handleDeviceManage" @delete="handleDeleteAgent"
@chat-history="handleShowChatHistory" />
@chat-history="handleShowChatHistory" @persona-changed="fetchAgentList" />
</template>
</div>
</div>