mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
优化代码,调整权限设置( 非管理员打开提示拒绝访问并自动跳转到首页),修复bug;
This commit is contained in:
+14
-97
@@ -26,6 +26,7 @@ import jakarta.validation.Valid;
|
|||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import xiaozhi.common.constant.Constant;
|
import xiaozhi.common.constant.Constant;
|
||||||
import xiaozhi.common.page.PageData;
|
import xiaozhi.common.page.PageData;
|
||||||
|
import xiaozhi.common.utils.ConvertUtils;
|
||||||
import xiaozhi.common.utils.Result;
|
import xiaozhi.common.utils.Result;
|
||||||
import xiaozhi.common.utils.ResultUtils;
|
import xiaozhi.common.utils.ResultUtils;
|
||||||
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
import xiaozhi.modules.agent.entity.AgentTemplateEntity;
|
||||||
@@ -42,42 +43,17 @@ public class AgentTemplateController {
|
|||||||
|
|
||||||
@GetMapping("/all")
|
@GetMapping("/all")
|
||||||
@Operation(summary = "获取所有模板列表")
|
@Operation(summary = "获取所有模板列表")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<List<AgentTemplateVO>> getAgentTemplates() {
|
public Result<List<AgentTemplateVO>> getAgentTemplates() {
|
||||||
List<AgentTemplateEntity> templates = agentTemplateService.list();
|
List<AgentTemplateEntity> templates = agentTemplateService.list();
|
||||||
// 转换为VO列表
|
// 使用ConvertUtils转换为VO列表
|
||||||
List<AgentTemplateVO> voList = templates.stream().map(template -> {
|
List<AgentTemplateVO> voList = ConvertUtils.sourceToTarget(templates, AgentTemplateVO.class);
|
||||||
AgentTemplateVO vo = new AgentTemplateVO();
|
|
||||||
// 复制属性
|
|
||||||
vo.setId(template.getId());
|
|
||||||
vo.setAgentCode(template.getAgentCode());
|
|
||||||
vo.setAgentName(template.getAgentName());
|
|
||||||
vo.setAsrModelId(template.getAsrModelId());
|
|
||||||
vo.setVadModelId(template.getVadModelId());
|
|
||||||
vo.setLlmModelId(template.getLlmModelId());
|
|
||||||
vo.setVllmModelId(template.getVllmModelId());
|
|
||||||
vo.setTtsModelId(template.getTtsModelId());
|
|
||||||
vo.setTtsVoiceId(template.getTtsVoiceId());
|
|
||||||
vo.setMemModelId(template.getMemModelId());
|
|
||||||
vo.setIntentModelId(template.getIntentModelId());
|
|
||||||
vo.setChatHistoryConf(template.getChatHistoryConf());
|
|
||||||
vo.setSystemPrompt(template.getSystemPrompt());
|
|
||||||
vo.setSummaryMemory(template.getSummaryMemory());
|
|
||||||
vo.setLangCode(template.getLangCode());
|
|
||||||
vo.setLanguage(template.getLanguage());
|
|
||||||
vo.setSort(template.getSort());
|
|
||||||
vo.setCreator(template.getCreator());
|
|
||||||
vo.setCreatedAt(template.getCreatedAt());
|
|
||||||
vo.setUpdater(template.getUpdater());
|
|
||||||
vo.setUpdatedAt(template.getUpdatedAt());
|
|
||||||
return vo;
|
|
||||||
}).toList();
|
|
||||||
return new Result<List<AgentTemplateVO>>().ok(voList);
|
return new Result<List<AgentTemplateVO>>().ok(voList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获取模板分页列表")
|
@Operation(summary = "获取模板分页列表")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
@Parameters({
|
@Parameters({
|
||||||
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
@Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true),
|
||||||
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
@Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true),
|
||||||
@@ -102,33 +78,8 @@ public class AgentTemplateController {
|
|||||||
// 执行分页查询
|
// 执行分页查询
|
||||||
IPage<AgentTemplateEntity> pageResult = agentTemplateService.page(pageInfo, wrapper);
|
IPage<AgentTemplateEntity> pageResult = agentTemplateService.page(pageInfo, wrapper);
|
||||||
|
|
||||||
// 转换为PageData对象
|
// 使用ConvertUtils转换为VO列表
|
||||||
List<AgentTemplateVO> voList = pageResult.getRecords().stream().map(template -> {
|
List<AgentTemplateVO> voList = ConvertUtils.sourceToTarget(pageResult.getRecords(), AgentTemplateVO.class);
|
||||||
AgentTemplateVO vo = new AgentTemplateVO();
|
|
||||||
// 复制属性
|
|
||||||
vo.setId(template.getId());
|
|
||||||
vo.setAgentCode(template.getAgentCode());
|
|
||||||
vo.setAgentName(template.getAgentName());
|
|
||||||
vo.setAsrModelId(template.getAsrModelId());
|
|
||||||
vo.setVadModelId(template.getVadModelId());
|
|
||||||
vo.setLlmModelId(template.getLlmModelId());
|
|
||||||
vo.setVllmModelId(template.getVllmModelId());
|
|
||||||
vo.setTtsModelId(template.getTtsModelId());
|
|
||||||
vo.setTtsVoiceId(template.getTtsVoiceId());
|
|
||||||
vo.setMemModelId(template.getMemModelId());
|
|
||||||
vo.setIntentModelId(template.getIntentModelId());
|
|
||||||
vo.setChatHistoryConf(template.getChatHistoryConf());
|
|
||||||
vo.setSystemPrompt(template.getSystemPrompt());
|
|
||||||
vo.setSummaryMemory(template.getSummaryMemory());
|
|
||||||
vo.setLangCode(template.getLangCode());
|
|
||||||
vo.setLanguage(template.getLanguage());
|
|
||||||
vo.setSort(template.getSort());
|
|
||||||
vo.setCreator(template.getCreator());
|
|
||||||
vo.setCreatedAt(template.getCreatedAt());
|
|
||||||
vo.setUpdater(template.getUpdater());
|
|
||||||
vo.setUpdatedAt(template.getUpdatedAt());
|
|
||||||
return vo;
|
|
||||||
}).toList();
|
|
||||||
|
|
||||||
// 修复:使用构造函数创建PageData对象,而不是无参构造+setter
|
// 修复:使用构造函数创建PageData对象,而不是无参构造+setter
|
||||||
PageData<AgentTemplateVO> pageData = new PageData<>(voList, pageResult.getTotal());
|
PageData<AgentTemplateVO> pageData = new PageData<>(voList, pageResult.getTotal());
|
||||||
@@ -138,44 +89,22 @@ public class AgentTemplateController {
|
|||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
@Operation(summary = "获取模板详情")
|
@Operation(summary = "获取模板详情")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<AgentTemplateVO> getAgentTemplateById(@PathVariable("id") String id) {
|
public Result<AgentTemplateVO> getAgentTemplateById(@PathVariable("id") String id) {
|
||||||
AgentTemplateEntity template = agentTemplateService.getById(id);
|
AgentTemplateEntity template = agentTemplateService.getById(id);
|
||||||
if (template == null) {
|
if (template == null) {
|
||||||
return ResultUtils.error("模板不存在");
|
return ResultUtils.error("模板不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换为VO
|
// 使用ConvertUtils转换为VO
|
||||||
AgentTemplateVO vo = new AgentTemplateVO();
|
AgentTemplateVO vo = ConvertUtils.sourceToTarget(template, AgentTemplateVO.class);
|
||||||
// 复制属性
|
|
||||||
vo.setId(template.getId());
|
|
||||||
vo.setAgentCode(template.getAgentCode());
|
|
||||||
vo.setAgentName(template.getAgentName());
|
|
||||||
vo.setAsrModelId(template.getAsrModelId());
|
|
||||||
vo.setVadModelId(template.getVadModelId());
|
|
||||||
vo.setLlmModelId(template.getLlmModelId());
|
|
||||||
vo.setVllmModelId(template.getVllmModelId());
|
|
||||||
vo.setTtsModelId(template.getTtsModelId());
|
|
||||||
vo.setTtsVoiceId(template.getTtsVoiceId());
|
|
||||||
vo.setMemModelId(template.getMemModelId());
|
|
||||||
vo.setIntentModelId(template.getIntentModelId());
|
|
||||||
vo.setChatHistoryConf(template.getChatHistoryConf());
|
|
||||||
vo.setSystemPrompt(template.getSystemPrompt());
|
|
||||||
vo.setSummaryMemory(template.getSummaryMemory());
|
|
||||||
vo.setLangCode(template.getLangCode());
|
|
||||||
vo.setLanguage(template.getLanguage());
|
|
||||||
vo.setSort(template.getSort());
|
|
||||||
vo.setCreator(template.getCreator());
|
|
||||||
vo.setCreatedAt(template.getCreatedAt());
|
|
||||||
vo.setUpdater(template.getUpdater());
|
|
||||||
vo.setUpdatedAt(template.getUpdatedAt());
|
|
||||||
|
|
||||||
return ResultUtils.success(vo);
|
return ResultUtils.success(vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@Operation(summary = "创建模板")
|
@Operation(summary = "创建模板")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<AgentTemplateEntity> createAgentTemplate(@Valid @RequestBody AgentTemplateEntity template) {
|
public Result<AgentTemplateEntity> createAgentTemplate(@Valid @RequestBody AgentTemplateEntity template) {
|
||||||
boolean saved = agentTemplateService.save(template);
|
boolean saved = agentTemplateService.save(template);
|
||||||
if (saved) {
|
if (saved) {
|
||||||
@@ -187,7 +116,7 @@ public class AgentTemplateController {
|
|||||||
|
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@Operation(summary = "更新模板")
|
@Operation(summary = "更新模板")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<AgentTemplateEntity> updateAgentTemplate(@Valid @RequestBody AgentTemplateEntity template) {
|
public Result<AgentTemplateEntity> updateAgentTemplate(@Valid @RequestBody AgentTemplateEntity template) {
|
||||||
boolean updated = agentTemplateService.updateById(template);
|
boolean updated = agentTemplateService.updateById(template);
|
||||||
if (updated) {
|
if (updated) {
|
||||||
@@ -199,7 +128,7 @@ public class AgentTemplateController {
|
|||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
@Operation(summary = "删除模板")
|
@Operation(summary = "删除模板")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<String> deleteAgentTemplate(@PathVariable("id") String id) {
|
public Result<String> deleteAgentTemplate(@PathVariable("id") String id) {
|
||||||
boolean deleted = agentTemplateService.removeById(id);
|
boolean deleted = agentTemplateService.removeById(id);
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
@@ -209,23 +138,11 @@ public class AgentTemplateController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除原有的批量删除方法
|
|
||||||
// @PostMapping("/batch-delete")
|
|
||||||
// @Operation(summary = "批量删除模板")
|
|
||||||
// @RequiresPermissions("sys:role:normal")
|
|
||||||
// public Result<String> batchDeleteAgentTemplates(@RequestBody List<String> ids) {
|
|
||||||
// boolean deleted = agentTemplateService.removeByIds(ids);
|
|
||||||
// if (deleted) {
|
|
||||||
// return ResultUtils.success("批量删除成功");
|
|
||||||
// } else {
|
|
||||||
// return ResultUtils.error("批量删除模板失败");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 添加新的批量删除方法,使用不同的URL
|
// 添加新的批量删除方法,使用不同的URL
|
||||||
@PostMapping("/batch-remove")
|
@PostMapping("/batch-remove")
|
||||||
@Operation(summary = "批量删除模板")
|
@Operation(summary = "批量删除模板")
|
||||||
@RequiresPermissions("sys:role:normal")
|
@RequiresPermissions("sys:role:superAdmin")
|
||||||
public Result<String> batchRemoveAgentTemplates(@RequestBody List<String> ids) {
|
public Result<String> batchRemoveAgentTemplates(@RequestBody List<String> ids) {
|
||||||
boolean deleted = agentTemplateService.removeByIds(ids);
|
boolean deleted = agentTemplateService.removeByIds(ids);
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-dialog :title="title" :visible.sync="visible" width="60%" @close="handleClose">
|
|
||||||
<el-form ref="templateForm" :model="templateData" label-width="120px" :rules="rules">
|
|
||||||
<el-form-item :label="$t('agentTemplateManagement.templateDialog.templateName')" prop="agentName">
|
|
||||||
<el-input v-model="templateData.agentName" :placeholder="$t('agentTemplateManagement.templateDialog.templateNamePlaceholder')" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item :label="$t('agentTemplateManagement.templateDialog.description')" prop="description">
|
|
||||||
<el-input v-model="templateData.description" :placeholder="$t('agentTemplateManagement.templateDialog.descriptionPlaceholder')" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item :label="$t('agentTemplateManagement.templateDialog.roleName')" prop="roleName">
|
|
||||||
<el-input v-model="templateData.roleName" :placeholder="$t('agentTemplateManagement.templateDialog.roleNamePlaceholder')" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="语言编码" prop="langCode">
|
|
||||||
<el-input v-model="templateData.langCode" placeholder="请输入语言编码,如zh-CN" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="交互语种" prop="language">
|
|
||||||
<el-input v-model="templateData.language" placeholder="请输入交互语种,如中文" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="排序" prop="sort">
|
|
||||||
<el-input-number v-model="templateData.sort" :min="0" placeholder="请输入排序值" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="聊天记录配置">
|
|
||||||
<el-select v-model="templateData.chatHistoryConf" placeholder="请选择聊天记录配置">
|
|
||||||
<el-option label="不记录" :value="0" />
|
|
||||||
<el-option label="仅记录文本" :value="1" />
|
|
||||||
<el-option label="记录文本和语音" :value="2" />
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item :label="$t('agentTemplateManagement.templateDialog.systemPrompt')" prop="systemPrompt">
|
|
||||||
<el-input v-model="templateData.systemPrompt" type="textarea" :placeholder="$t('agentTemplateManagement.templateDialog.systemPromptPlaceholder')" :rows="4" />
|
|
||||||
<div class="form-tip">角色设定参数将作为智能体的系统提示,定义智能体的行为和回答风格</div>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="总结记忆" prop="summaryMemory">
|
|
||||||
<el-input v-model="templateData.summaryMemory" type="textarea" placeholder="请输入总结记忆" :rows="4" />
|
|
||||||
<div class="form-tip">总结记忆将作为智能体的初始记忆,帮助智能体理解上下文</div>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button @click="handleClose">{{ $t('agentTemplateManagement.templateDialog.cancel') }}</el-button>
|
|
||||||
<el-button type="primary" @click="handleSave">{{ $t('agentTemplateManagement.templateDialog.save') }}</el-button>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'AgentTemplateDialog',
|
|
||||||
props: {
|
|
||||||
visible: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
templateData: {
|
|
||||||
type: Object,
|
|
||||||
default: () => ({})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// 表单验证规则
|
|
||||||
rules: {
|
|
||||||
agentName: [
|
|
||||||
{ required: true, message: this.$t('agentTemplateManagement.templateDialog.nameRequired'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
roleName: [
|
|
||||||
{ required: true, message: this.$t('agentTemplateManagement.templateDialog.roleNameRequired'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
systemPrompt: [
|
|
||||||
{ required: true, message: this.$t('agentTemplateManagement.templateDialog.systemPromptRequired'), trigger: 'blur' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
// 处理关闭对话框
|
|
||||||
handleClose() {
|
|
||||||
this.$emit('update:visible', false)
|
|
||||||
},
|
|
||||||
|
|
||||||
// 处理保存模板
|
|
||||||
handleSave() {
|
|
||||||
this.$refs.templateForm.validate((valid) => {
|
|
||||||
if (valid) {
|
|
||||||
this.$emit('save', this.templateData)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.form-tip {
|
|
||||||
color: #909399;
|
|
||||||
font-size: 12px;
|
|
||||||
margin-top: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dialog-footer {
|
|
||||||
display: flex;
|
|
||||||
justify-content: flex-end;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -827,7 +827,7 @@ export default {
|
|||||||
'providerDialog.confirmBatchDeleteFields': 'Are you sure to delete {count} selected fields?',
|
'providerDialog.confirmBatchDeleteFields': 'Are you sure to delete {count} selected fields?',
|
||||||
'providerDialog.batchDeleteFieldsSuccess': 'Successfully deleted {count} fields',
|
'providerDialog.batchDeleteFieldsSuccess': 'Successfully deleted {count} fields',
|
||||||
|
|
||||||
// ...existing code ...
|
// 在agentTemplateManagement对象中添加以下键
|
||||||
agentTemplateManagement: {
|
agentTemplateManagement: {
|
||||||
title: 'Default Role Management',
|
title: 'Default Role Management',
|
||||||
templateName: 'Template Name',
|
templateName: 'Template Name',
|
||||||
@@ -848,6 +848,14 @@ export default {
|
|||||||
serialNumber: 'Serial Number',
|
serialNumber: 'Serial Number',
|
||||||
selectAll: 'Select All',
|
selectAll: 'Select All',
|
||||||
deselectAll: 'Deselect All',
|
deselectAll: 'Deselect All',
|
||||||
|
loading: 'Loading...',
|
||||||
|
confirmSingleDelete: 'Are you sure you want to delete this template?',
|
||||||
|
confirmBatchDelete: 'Are you sure you want to delete the selected {count} templates?',
|
||||||
|
deleteSuccess: 'Template deleted successfully',
|
||||||
|
deleteFailed: 'Template deletion failed',
|
||||||
|
batchDeleteSuccess: 'Templates deleted successfully',
|
||||||
|
batchDeleteFailed: 'Template batch deletion failed',
|
||||||
|
deleteBackendError: 'Deletion failed, please check if the backend service is working properly',
|
||||||
templateDialog: {
|
templateDialog: {
|
||||||
title: 'Template Configuration',
|
title: 'Template Configuration',
|
||||||
templateName: 'Template Name',
|
templateName: 'Template Name',
|
||||||
|
|||||||
@@ -827,7 +827,7 @@ export default {
|
|||||||
'providerDialog.batchDeleteFieldsSuccess': '成功删除{count}个字段',
|
'providerDialog.batchDeleteFieldsSuccess': '成功删除{count}个字段',
|
||||||
|
|
||||||
// 默认角色模版和模版快速配置页面
|
// 默认角色模版和模版快速配置页面
|
||||||
// 在agentTemplateManagement对象中添加
|
// 在agentTemplateManagement对象中添加以下键
|
||||||
agentTemplateManagement: {
|
agentTemplateManagement: {
|
||||||
title: '默认角色管理',
|
title: '默认角色管理',
|
||||||
templateName: '模板名称',
|
templateName: '模板名称',
|
||||||
@@ -848,6 +848,12 @@ export default {
|
|||||||
serialNumber: '序号',
|
serialNumber: '序号',
|
||||||
selectAll: '全选',
|
selectAll: '全选',
|
||||||
deselectAll: '取消全选',
|
deselectAll: '取消全选',
|
||||||
|
loading: '拼命加载中',
|
||||||
|
confirmSingleDelete: '确定要删除这个模板吗?',
|
||||||
|
confirmBatchDelete: '确定要删除选中的 {count} 个模板吗?',
|
||||||
|
deleteFailed: '模板删除失败',
|
||||||
|
batchDeleteFailed: '模板批量删除失败',
|
||||||
|
deleteBackendError: '删除失败,请检查后端服务是否正常',
|
||||||
templateDialog: {
|
templateDialog: {
|
||||||
title: '模板配置',
|
title: '模板配置',
|
||||||
templateName: '模板名称',
|
templateName: '模板名称',
|
||||||
|
|||||||
@@ -847,6 +847,14 @@ agentTemplateManagement: {
|
|||||||
serialNumber:'序號',
|
serialNumber:'序號',
|
||||||
selectAll: '全選',
|
selectAll: '全選',
|
||||||
deselectAll: '取消全選',
|
deselectAll: '取消全選',
|
||||||
|
deselectAll: '取消全選',
|
||||||
|
loading: '拼命加載中',
|
||||||
|
confirmSingleDelete: '確定要刪除這個模板嗎?',
|
||||||
|
confirmBatchDelete: '確定要刪除選中的 {count} 個模板嗎?',
|
||||||
|
deleteFailed: '模板刪除失敗',
|
||||||
|
batchDeleteFailed: '批次刪除失敗',
|
||||||
|
deleteBackendError: '刪除失敗,請檢查後端服務是否正常',
|
||||||
|
deleteCancelled: '已取消刪除',
|
||||||
templateDialog: {
|
templateDialog: {
|
||||||
title: '模板配置',
|
title: '模板配置',
|
||||||
templateName: '模板名稱',
|
templateName: '模板名稱',
|
||||||
|
|||||||
@@ -168,12 +168,15 @@ VueRouter.prototype.push = function push(location) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 需要登录才能访问的路由
|
// 需要登录才能访问的路由
|
||||||
const protectedRoutes = ['home', 'RoleConfig', 'DeviceManagement', 'UserManagement', 'ModelConfig', 'TemplateQuickConfig']
|
const protectedRoutes = ['home', 'RoleConfig', 'DeviceManagement', 'UserManagement', 'ModelConfig']
|
||||||
|
|
||||||
|
// 需要管理员权限才能访问的路由
|
||||||
|
const adminRoutes = ['TemplateQuickConfig', 'AgentTemplateManagement']
|
||||||
|
|
||||||
// 路由守卫
|
// 路由守卫
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
// 检查是否是需要保护的路由
|
// 检查是否是需要保护的路由
|
||||||
if (protectedRoutes.includes(to.name)) {
|
if (protectedRoutes.includes(to.name) || adminRoutes.includes(to.name)) {
|
||||||
// 从localStorage获取token
|
// 从localStorage获取token
|
||||||
const token = localStorage.getItem('token')
|
const token = localStorage.getItem('token')
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@@ -181,6 +184,16 @@ router.beforeEach((to, from, next) => {
|
|||||||
next({ name: 'login', query: { redirect: to.fullPath } })
|
next({ name: 'login', query: { redirect: to.fullPath } })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对于需要管理员权限的路由,检查用户是否是超级管理员
|
||||||
|
if (adminRoutes.includes(to.name)) {
|
||||||
|
const isSuperAdmin = localStorage.getItem('isSuperAdmin') === 'true'
|
||||||
|
if (!isSuperAdmin) {
|
||||||
|
// 不是管理员,跳转到首页或显示无权限提示
|
||||||
|
next({ name: 'home' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<el-table ref="templateTable" :data="templateList" style="width: 100%" v-loading="templateLoading"
|
<el-table ref="templateTable" :data="templateList" style="width: 100%" v-loading="templateLoading"
|
||||||
element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
|
:element-loading-text="$t('agentTemplateManagement.loading')" element-loading-spinner="el-icon-loading"
|
||||||
element-loading-background="rgba(255, 255, 255, 0.7)"
|
element-loading-background="rgba(255, 255, 255, 0.7)"
|
||||||
class="transparent-table" :header-cell-style="{padding: '10px 20px'}" :cell-style="{padding: '10px 20px'}"> <!-- 移除@row-click="handleRowClick" -->
|
class="transparent-table" :header-cell-style="{padding: '10px 20px'}" :cell-style="{padding: '10px 20px'}"> <!-- 移除@row-click="handleRowClick" -->
|
||||||
<!-- 自定义选择列,实现表头是"选择"文字,数据行是小方框 -->
|
<!-- 自定义选择列,实现表头是"选择"文字,数据行是小方框 -->
|
||||||
@@ -30,23 +30,43 @@
|
|||||||
<el-checkbox v-model="scope.row.selected" @change="handleRowSelectionChange(scope.row)" @click.stop></el-checkbox>
|
<el-checkbox v-model="scope.row.selected" @change="handleRowSelectionChange(scope.row)" @click.stop></el-checkbox>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('agentTemplateManagement.templateName')" prop="agentName" min-width="250" show-overflow-tooltip>
|
<!-- 修改为序号列 -->
|
||||||
<template slot-scope="scope">
|
|
||||||
<span>{{ scope.row.agentName }}</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<!-- 修改为序号列1 -->
|
|
||||||
<el-table-column :label="$t('agentTemplateManagement.serialNumber')" min-width="120" align="center">
|
<el-table-column :label="$t('agentTemplateManagement.serialNumber')" min-width="120" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
|
<span>{{ (currentPage - 1) * pageSize + scope.$index + 1 }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<!-- 删除重复的序号列2 -->
|
<!-- 模板名称 -->
|
||||||
|
<el-table-column :label="$t('agentTemplateManagement.templateName')" prop="agentName" min-width="250" show-overflow-tooltip>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ scope.row.agentName }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<!-- 模板描述 -->
|
||||||
|
<el-table-column :label="$t('agentTemplateManagement.description')" prop="description" min-width="200" show-overflow-tooltip>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ scope.row.description }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<!-- 语言 -->
|
||||||
|
<el-table-column :label="$t('templateQuickConfig.agentSettings.agentName')" prop="language" min-width="100" show-overflow-tooltip>
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ scope.row.language }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<!-- 创建时间 -->
|
||||||
|
<el-table-column :label="$t('agentTemplateManagement.createTime')" min-width="180" align="center">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ formatDate(scope.row.createdAt) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<!-- 操作列 -->
|
||||||
<el-table-column :label="$t('agentTemplateManagement.action')" min-width="250" align="center">
|
<el-table-column :label="$t('agentTemplateManagement.action')" min-width="250" align="center">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<div style="display: flex; justify-content: center; gap: 15px;">
|
<div style="display: flex; justify-content: center; gap: 15px;">
|
||||||
<el-button type="text" @click="editTemplate(scope.row)">{{ $t('agentTemplateManagement.editTemplate') }}</el-button>
|
<el-button type="text" @click="editTemplate(scope.row)">{{ $t('agentTemplateManagement.editTemplate') }}</el-button>
|
||||||
<el-button type="text" @click="handleDelete(scope.row.id)">{{ $t('agentTemplateManagement.deleteTemplate') }}</el-button>
|
<!-- 修复:调用正确的方法名 -->
|
||||||
|
<el-button type="text" @click="deleteTemplate(scope.row)">{{ $t('agentTemplateManagement.deleteTemplate') }}</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
@@ -84,30 +104,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 模板编辑弹框 -->
|
|
||||||
<AgentTemplateDialog
|
|
||||||
ref="templateDialog"
|
|
||||||
:visible.sync="templateDialogVisible"
|
|
||||||
:title="templateDialogTitle"
|
|
||||||
:template-data="templateForm"
|
|
||||||
@save="saveTemplate"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import agentApi from '@/apis/module/agent'
|
import HeaderBar from '@/components/HeaderBar';
|
||||||
import AgentTemplateDialog from '@/components/AgentTemplateDialog.vue'
|
import agentApi from '@/apis/module/agent';
|
||||||
import HeaderBar from '@/components/HeaderBar.vue'
|
|
||||||
import VersionFooter from '@/components/VersionFooter.vue'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AgentTemplateManagement',
|
name: 'AgentTemplateManagement',
|
||||||
components: {
|
components: {
|
||||||
HeaderBar,
|
HeaderBar
|
||||||
AgentTemplateDialog,
|
|
||||||
VersionFooter
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// 1. 首先确保在 data 部分添加了 isAllSelected 状态
|
// 1. 首先确保在 data 部分添加了 isAllSelected 状态
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -116,27 +125,7 @@ export default {
|
|||||||
templateLoading: false,
|
templateLoading: false,
|
||||||
selectedTemplates: [],
|
selectedTemplates: [],
|
||||||
isAllSelected: false, // 添加全选状态
|
isAllSelected: false, // 添加全选状态
|
||||||
templateDialogVisible: false,
|
|
||||||
templateDialogTitle: '新增模板',
|
|
||||||
templateForm: {
|
|
||||||
id: null,
|
|
||||||
agentCode: '',
|
|
||||||
agentName: '',
|
|
||||||
asrModelId: '',
|
|
||||||
vadModelId: '',
|
|
||||||
llmModelId: '',
|
|
||||||
vllmModelId: '',
|
|
||||||
ttsModelId: '',
|
|
||||||
ttsVoiceId: '',
|
|
||||||
memModelId: '',
|
|
||||||
intentModelId: '',
|
|
||||||
chatHistoryConf: 0,
|
|
||||||
systemPrompt: '',
|
|
||||||
summaryMemory: '',
|
|
||||||
langCode: '',
|
|
||||||
language: '',
|
|
||||||
sort: 0
|
|
||||||
},
|
|
||||||
search: '',
|
search: '',
|
||||||
// 分页相关数据
|
// 分页相关数据
|
||||||
pageSizeOptions: [10, 20, 50, 100],
|
pageSizeOptions: [10, 20, 50, 100],
|
||||||
@@ -250,39 +239,11 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
// 保存模板
|
|
||||||
saveTemplate(data) {
|
|
||||||
// 这里需要调用保存模板的API
|
|
||||||
if (data.id) {
|
|
||||||
// 更新模板
|
|
||||||
agentApi.updateAgentTemplate(data, (res) => {
|
|
||||||
if (res.code === 0) {
|
|
||||||
this.$message.success('模板更新成功')
|
|
||||||
this.templateDialogVisible = false
|
|
||||||
this.loadTemplateList()
|
|
||||||
} else {
|
|
||||||
this.$message.error('模板更新失败')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// 新增模板
|
|
||||||
agentApi.addAgentTemplate(data, (res) => {
|
|
||||||
if (res.code === 0) {
|
|
||||||
this.$message.success('模板新增成功')
|
|
||||||
this.templateDialogVisible = false
|
|
||||||
this.loadTemplateList()
|
|
||||||
} else {
|
|
||||||
this.$message.error('模板新增失败')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// 删除模板
|
// 删除模板
|
||||||
deleteTemplate(row) {
|
deleteTemplate(row) {
|
||||||
this.$confirm('确定要删除这个模板吗?', '提示', {
|
this.$confirm(this.$t('agentTemplateManagement.confirmSingleDelete'), this.$t('common.warning'), {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: this.$t('common.confirm'),
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: this.$t('common.cancel'),
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
agentApi.deleteAgentTemplate(row.id, (res) => {
|
agentApi.deleteAgentTemplate(row.id, (res) => {
|
||||||
@@ -292,18 +253,18 @@ export default {
|
|||||||
if (res && typeof res === 'object') {
|
if (res && typeof res === 'object') {
|
||||||
// 检查res.data是否存在且包含code=0
|
// 检查res.data是否存在且包含code=0
|
||||||
if (res.data && res.data.code === 0) {
|
if (res.data && res.data.code === 0) {
|
||||||
this.$message.success('模板删除成功')
|
this.$message.success(this.$t('agentTemplateManagement.deleteSuccess'))
|
||||||
this.loadTemplateList()
|
this.loadTemplateList()
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(res?.data?.msg || '模板删除失败')
|
this.$message.error(res?.data?.msg || this.$t('agentTemplateManagement.deleteFailed'))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('无效的响应对象:', res);
|
console.error('无效的响应对象:', res);
|
||||||
this.$message.error('删除失败,请检查后端服务是否正常')
|
this.$message.error(this.$t('agentTemplateManagement.deleteBackendError'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.$message.info('已取消删除')
|
this.$message.info(this.$t('common.deleteCancelled'))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -311,13 +272,13 @@ export default {
|
|||||||
// 批量删除模板 - 完全重写这个方法
|
// 批量删除模板 - 完全重写这个方法
|
||||||
batchDeleteTemplate() {
|
batchDeleteTemplate() {
|
||||||
if (this.selectedTemplates.length === 0) {
|
if (this.selectedTemplates.length === 0) {
|
||||||
this.$message.warning('请选择要删除的模板')
|
this.$message.warning(this.$t('agentTemplateManagement.selectTemplate'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$confirm(`确定要删除选中的 ${this.selectedTemplates.length} 个模板吗?`, '提示', {
|
this.$confirm(this.$t('agentTemplateManagement.confirmBatchDelete', { count: this.selectedTemplates.length }), this.$t('common.warning'), {
|
||||||
confirmButtonText: '确定',
|
confirmButtonText: this.$t('common.confirm'),
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: this.$t('common.cancel'),
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// 确保参数格式正确 - 将id数组作为请求体
|
// 确保参数格式正确 - 将id数组作为请求体
|
||||||
@@ -329,22 +290,22 @@ export default {
|
|||||||
console.log('批量删除响应:', res)
|
console.log('批量删除响应:', res)
|
||||||
if (res && typeof res === 'object') {
|
if (res && typeof res === 'object') {
|
||||||
if (res.data && res.data.code === 0) {
|
if (res.data && res.data.code === 0) {
|
||||||
this.$message.success('模板批量删除成功')
|
this.$message.success(this.$t('agentTemplateManagement.batchDeleteSuccess'))
|
||||||
// 重新加载模板列表
|
// 重新加载模板列表
|
||||||
this.loadTemplateList()
|
this.loadTemplateList()
|
||||||
// 清空选中状态
|
// 清空选中状态
|
||||||
this.selectedTemplates = []
|
this.selectedTemplates = []
|
||||||
this.isAllSelected = false
|
this.isAllSelected = false
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(res?.data?.msg || '模板批量删除失败')
|
this.$message.error(res?.data?.msg || this.$t('agentTemplateManagement.batchDeleteFailed'))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.error('无效的响应对象:', res)
|
console.error('无效的响应对象:', res)
|
||||||
this.$message.error('删除失败,请检查后端服务是否正常')
|
this.$message.error(this.$t('agentTemplateManagement.deleteBackendError'))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
this.$message.info('已取消删除')
|
this.$message.info(this.$t('common.deleteCancelled'))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user