-
-
-
-
-
-
-
-
-
-
-
- {{ scope.row.agentName }}
-
-
-
-
-
- {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
-
-
-
-
-
-
- {{
- $t("agentTemplateManagement.editTemplate")
- }}
- {{
- $t("agentTemplateManagement.deleteTemplate")
- }}
-
-
-
-
-
-
-
-
-
- {{
- isAllSelected
- ? $t("agentTemplateManagement.deselectAll")
- : $t("agentTemplateManagement.selectAll")
- }}
-
-
- {{ $t("agentTemplateManagement.createTemplate") }}
-
-
- {{ $t("agentTemplateManagement.batchDelete") }}
-
-
-
-
-
+
+
+
+
+
+ {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
+
+
+
+ {{ $t("agentTemplateManagement.editTemplate") }}
+
+
+ {{ $t("agentTemplateManagement.deleteTemplate") }}
+
+
+
+
+
+ {{ isAllSelected ? $t("agentTemplateManagement.deselectAll") : $t("agentTemplateManagement.selectAll") }}
+
+
+ {{ $t("agentTemplateManagement.createTemplate") }}
+
+
+ {{ $t("agentTemplateManagement.batchDelete") }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -146,136 +108,196 @@
import HeaderBar from "@/components/HeaderBar";
import agentApi from "@/apis/module/agent";
import VersionFooter from "@/components/VersionFooter.vue";
+import CustomButton from "@/components/CustomButton.vue";
+import CustomTable from "@/components/CustomTable.vue";
+import CustomDialog from "@/components/CustomDialog.vue";
+
+const DEFAULT_MODEL_CONFIG = {
+ ttsModelId: "TTS_EdgeTTS",
+ vadModelId: "VAD_SileroVAD",
+ asrModelId: "ASR_FunASR",
+ llmModelId: "LLM_ChatGLMLLM",
+ vllmModelId: "VLLM_ChatGLMVLLM",
+ memModelId: "Memory_nomem",
+ intentModelId: "Intent_function_call"
+};
export default {
name: "AgentTemplateManagement",
components: {
HeaderBar,
- VersionFooter
+ VersionFooter,
+ CustomButton,
+ CustomTable,
+ CustomDialog
},
data() {
return {
- // 模板相关
templateList: [],
templateLoading: false,
selectedTemplates: [],
- isAllSelected: false, // 添加全选状态
-
+ isAllSelected: false,
search: "",
- // 分页相关数据
pageSizeOptions: [10, 20, 50, 100],
currentPage: 1,
pageSize: 10,
total: 0,
+ tableColumns: [],
+ dialogVisible: false,
+ dialogTitle: "",
+ confirmLoading: false,
+ form: {
+ id: null,
+ agentCode: "小智",
+ agentName: "",
+ systemPrompt: "",
+ sort: 0,
+ model: { ...DEFAULT_MODEL_CONFIG }
+ },
+ originalForm: null
};
},
created() {
+ this.initTableColumns();
this.loadTemplateList();
},
- // 在computed部分添加hasSelected属性
computed: {
- pageCount() {
- return Math.ceil(this.total / this.pageSize);
- },
- visiblePages() {
- return this.getVisiblePages();
- },
hasSelected() {
return this.selectedTemplates.length > 0;
- },
+ }
},
methods: {
- // 加载模板列表
- // 改进loadTemplateList方法的错误处理逻辑
+ initTableColumns() {
+ this.tableColumns = [
+ {
+ prop: "agentName",
+ label: this.$t("agentTemplateManagement.templateName"),
+ },
+ {
+ prop: "serialNumber",
+ label: this.$t("agentTemplateManagement.serialNumber"),
+ }
+ ];
+ },
loadTemplateList() {
this.templateLoading = true;
const params = {
page: this.currentPage,
- limit: this.pageSize,
+ limit: this.pageSize
};
if (this.search) {
params.agentName = this.search;
}
- try {
- agentApi.getAgentTemplatesPage(
- params,
- (res) => {
- // 更健壮的响应处理逻辑
- if (res && typeof res === "object") {
- if (res.data && res.data.code === 0) {
- const responseData = res.data.data || {};
- // 为每个模板添加selected属性
- this.templateList = Array.isArray(responseData.list)
- ? responseData.list.map((item) => ({ ...item, selected: false }))
- : [];
- this.total =
- typeof responseData.total === "number" ? responseData.total : 0;
- } else {
- this.templateList = [];
- this.total = 0;
- this.$message.error(
- res?.data?.msg || this.$t("agentTemplateManagement.fetchTemplateFailed")
- );
- }
- } else {
- this.templateList = [];
- this.total = 0;
- this.$message.error(
- this.$t("agentTemplateManagement.fetchTemplateBackendError")
- );
- }
- this.templateLoading = false;
- },
- (error) => {
+ agentApi.getAgentTemplatesPage(
+ params,
+ (res) => {
+ if (res && res.data && res.data.code === 0) {
+ const responseData = res.data.data || {};
+ this.templateList = Array.isArray(responseData.list)
+ ? responseData.list.map((item) => ({ ...item, selected: false }))
+ : [];
+ this.total = typeof responseData.total === "number" ? responseData.total : 0;
+ } else {
this.templateList = [];
this.total = 0;
- this.templateLoading = false;
- this.$message.error(this.$t("common.networkError"));
+ this.$message.error(res?.data?.msg || this.$t("agentTemplateManagement.fetchTemplateFailed"));
}
- );
- } catch (error) {
- this.templateList = [];
- this.total = 0;
- this.templateLoading = false;
- this.$message.error(this.$t("agentTemplateManagement.fetchTemplateBackendError"));
- }
+ this.templateLoading = false;
+ },
+ (error) => {
+ this.templateList = [];
+ this.total = 0;
+ this.templateLoading = false;
+ this.$message.error(this.$t("common.networkError"));
+ }
+ );
},
-
- // 搜索模板
handleSearch() {
- if (this.search) {
- const searchValue = this.search.toLowerCase();
- const filteredList = this.templateList.filter((template) =>
- template.agentName.toLowerCase().includes(searchValue)
- );
- this.templateList = filteredList;
- this.total = filteredList.length;
- } else {
- this.loadTemplateList();
- }
+ this.currentPage = 1;
+ this.loadTemplateList();
},
-
- // 修改showAddTemplateDialog方法,使其跳转到与编辑页面相同的页面
- // 显示新增模板弹窗
showAddTemplateDialog() {
- // 跳转到模板快速配置页面,不传递templateId参数表示新增
- this.$router.push({
- path: "/template-quick-config",
- });
+ this.dialogTitle = this.$t("templateQuickConfig.addTemplate");
+ this.form = {
+ id: null,
+ agentCode: "小智",
+ agentName: this.$t("templateQuickConfig.newTemplate"),
+ systemPrompt: "",
+ sort: 1,
+ model: { ...DEFAULT_MODEL_CONFIG }
+ };
+ this.originalForm = JSON.parse(JSON.stringify(this.form));
+ this.dialogVisible = true;
},
-
- // 编辑模板
editTemplate(row) {
- // 跳转到模板快速配置页面,并传递模板ID参数
- this.$router.push({
- path: "/template-quick-config",
- query: { templateId: row.id },
+ this.dialogTitle = this.$t("templateQuickConfig.editTemplate");
+ this.fetchTemplateById(row.id);
+ },
+ fetchTemplateById(templateId) {
+ agentApi.getAgentTemplateById(templateId, (res) => {
+ if (res && res.data && res.data.code === 0 && res.data.data) {
+ const template = res.data.data;
+ this.form = {
+ id: template.id,
+ agentCode: template.agentCode || "小智",
+ agentName: template.agentName || "",
+ systemPrompt: template.systemPrompt || "",
+ sort: template.sort || 0,
+ model: {
+ ttsModelId: template.ttsModelId || DEFAULT_MODEL_CONFIG.ttsModelId,
+ vadModelId: template.vadModelId || DEFAULT_MODEL_CONFIG.vadModelId,
+ asrModelId: template.asrModelId || DEFAULT_MODEL_CONFIG.asrModelId,
+ llmModelId: template.llmModelId || DEFAULT_MODEL_CONFIG.llmModelId,
+ vllmModelId: template.vllmModelId || DEFAULT_MODEL_CONFIG.vllmModelId,
+ memModelId: template.memModelId || DEFAULT_MODEL_CONFIG.memModelId,
+ intentModelId: template.intentModelId || DEFAULT_MODEL_CONFIG.intentModelId
+ }
+ };
+ this.originalForm = JSON.parse(JSON.stringify(this.form));
+ this.dialogVisible = true;
+ } else {
+ this.$message.error(res?.data?.msg || this.$t("templateQuickConfig.templateNotFound"));
+ }
});
},
+ handleDialogConfirm() {
+ const configData = {
+ id: this.form.id || "",
+ agentCode: this.form.agentCode,
+ agentName: this.form.agentName,
+ systemPrompt: this.form.systemPrompt,
+ sort: this.form.sort,
+ functions: [],
+ ...this.form.model
+ };
- // 删除模板
+ this.confirmLoading = true;
+ const apiCall = this.form.id
+ ? agentApi.updateAgentTemplate
+ : agentApi.addAgentTemplate;
+
+ apiCall(configData, (res) => {
+ this.confirmLoading = false;
+ if (res && res.data && res.data.code === 0) {
+ this.$message.success({
+ message: this.$t("templateQuickConfig.saveSuccess"),
+ showClose: true
+ });
+ this.dialogVisible = false;
+ this.loadTemplateList();
+ } else {
+ this.$message.error({
+ message: res?.data?.msg || this.$t("templateQuickConfig.saveFailed"),
+ showClose: true
+ });
+ }
+ }, (error) => {
+ this.confirmLoading = false;
+ this.$message.error(this.$t("common.networkError"));
+ });
+ },
deleteTemplate(row) {
this.$confirm(
this.$t("agentTemplateManagement.confirmSingleDelete"),
@@ -283,23 +305,18 @@ export default {
{
confirmButtonText: this.$t("common.confirm"),
cancelButtonText: this.$t("common.cancel"),
- type: "warning",
+ type: "warning"
}
)
.then(() => {
agentApi.deleteAgentTemplate(row.id, (res) => {
- if (res && typeof res === "object") {
- // 检查res.data是否存在且包含code=0
- if (res.data && res.data.code === 0) {
- this.$message.success(this.$t("agentTemplateManagement.deleteSuccess"));
- this.loadTemplateList();
- } else {
- this.$message.error(
- res?.data?.msg || this.$t("agentTemplateManagement.deleteFailed")
- );
- }
+ if (res && res.data && res.data.code === 0) {
+ this.$message.success(this.$t("agentTemplateManagement.deleteSuccess"));
+ this.selectedTemplates = [];
+ this.isAllSelected = false;
+ this.loadTemplateList();
} else {
- this.$message.error(this.$t("agentTemplateManagement.deleteBackendError"));
+ this.$message.error(res?.data?.msg || this.$t("agentTemplateManagement.deleteFailed"));
}
});
})
@@ -307,47 +324,30 @@ export default {
this.$message.info(this.$t("common.deleteCancelled"));
});
},
-
- // 批量删除模板
batchDeleteTemplate() {
if (this.selectedTemplates.length === 0) {
this.$message.warning(this.$t("agentTemplateManagement.selectTemplate"));
return;
}
-
this.$confirm(
- this.$t("agentTemplateManagement.confirmBatchDelete", {
- count: this.selectedTemplates.length,
- }),
+ this.$t("agentTemplateManagement.confirmBatchDelete", { count: this.selectedTemplates.length }),
this.$t("common.warning"),
{
confirmButtonText: this.$t("common.confirm"),
cancelButtonText: this.$t("common.cancel"),
- type: "warning",
+ type: "warning"
}
)
.then(() => {
- // 确保参数格式正确 - 将id数组作为请求体
const ids = this.selectedTemplates.map((template) => template.id);
-
agentApi.batchDeleteAgentTemplate(ids, (res) => {
- if (res && typeof res === "object") {
- if (res.data && res.data.code === 0) {
- this.$message.success(
- this.$t("agentTemplateManagement.batchDeleteSuccess")
- );
- // 重新加载模板列表
- this.loadTemplateList();
- // 清空选中状态
- this.selectedTemplates = [];
- this.isAllSelected = false;
- } else {
- this.$message.error(
- res?.data?.msg || this.$t("agentTemplateManagement.batchDeleteFailed")
- );
- }
+ if (res && res.data && res.data.code === 0) {
+ this.$message.success(this.$t("agentTemplateManagement.batchDeleteSuccess"));
+ this.loadTemplateList();
+ this.selectedTemplates = [];
+ this.isAllSelected = false;
} else {
- this.$message.error(this.$t("agentTemplateManagement.deleteBackendError"));
+ this.$message.error(res?.data?.msg || this.$t("agentTemplateManagement.batchDeleteFailed"));
}
});
})
@@ -355,150 +355,81 @@ export default {
this.$message.info(this.$t("common.deleteCancelled"));
});
},
-
- // 完善分页相关方法
handlePageChange(page) {
this.currentPage = page;
this.loadTemplateList();
},
-
handlePageSizeChange(size) {
this.pageSize = size;
this.currentPage = 1;
this.loadTemplateList();
},
-
- goFirst() {
- this.currentPage = 1;
- },
- goPrev() {
- this.currentPage--;
- },
- goNext() {
- this.currentPage++;
- },
- goToPage(page) {
- this.currentPage = page;
- },
- getVisiblePages() {
- const pages = [];
- const totalPages = this.pageCount;
- const currentPage = this.currentPage;
-
- if (totalPages <= 7) {
- for (let i = 1; i <= totalPages; i++) {
- pages.push(i);
- }
- } else {
- if (currentPage <= 4) {
- for (let i = 1; i <= 5; i++) {
- pages.push(i);
- }
- pages.push("...");
- pages.push(totalPages);
- } else if (currentPage >= totalPages - 3) {
- pages.push(1);
- pages.push("...");
- for (let i = totalPages - 4; i <= totalPages; i++) {
- pages.push(i);
- }
- } else {
- pages.push(1);
- pages.push("...");
- for (let i = currentPage - 1; i <= currentPage + 1; i++) {
- pages.push(i);
- }
- pages.push("...");
- pages.push(totalPages);
- }
- }
-
- return pages;
- },
-
- // 修改handleSelectAll方法
handleSelectAll() {
this.isAllSelected = !this.isAllSelected;
this.templateList.forEach((row) => {
row.selected = this.isAllSelected;
});
- // 更新选中的模板列表
this.selectedTemplates = this.isAllSelected ? [...this.templateList] : [];
},
-
- // 处理行选择变化
handleRowSelectionChange(row) {
- // 查找选中的模板
this.selectedTemplates = this.templateList.filter((template) => template.selected);
- // 更新全选状态
this.isAllSelected =
this.templateList.length > 0 &&
this.selectedTemplates.length === this.templateList.length;
- },
- },
+ }
+ }
};
-
+
+:deep(.el-table .el-button--text) {
+ color: #7079aa;
+}
+
+:deep(.el-table .el-button--text:hover) {
+ color: #5a64b5;
+}
+
\ No newline at end of file