增加导入
This commit is contained in:
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.tik.muye.aiagent;
|
||||
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentDO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.service.AiAgentService;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportExcelVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportRespVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentRespVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentSaveReqVO;
|
||||
@@ -18,6 +20,8 @@ import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
@@ -101,4 +105,32 @@ public class AiAgentController {
|
||||
BeanUtils.toBean(list, AiAgentRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/get-import-template")
|
||||
@Operation(summary = "获得AI智能体导入模板")
|
||||
public void importTemplate(HttpServletResponse response) throws IOException {
|
||||
// 构造示例数据
|
||||
List<AiAgentImportExcelVO> list = Arrays.asList(
|
||||
AiAgentImportExcelVO.builder()
|
||||
.agentId("12345")
|
||||
.agentName("示例智能体")
|
||||
.categoryName("文案创作")
|
||||
.icon("https://example.com/icon.png")
|
||||
.status(1)
|
||||
.description("这是一个示例智能体的描述")
|
||||
.systemPrompt("你是一个有帮助的AI助手")
|
||||
.remark("备注信息")
|
||||
.build()
|
||||
);
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "AI智能体导入模板.xls", "智能体列表", AiAgentImportExcelVO.class, list);
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
@Operation(summary = "导入AI智能体")
|
||||
@PreAuthorize("@ss.hasPermission('muye:ai-agent:create')")
|
||||
public CommonResult<AiAgentImportRespVO> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
|
||||
List<AiAgentImportExcelVO> list = ExcelUtils.read(file, AiAgentImportExcelVO.class);
|
||||
return success(aiAgentService.importAiAgentList(list));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.tik.muye.aiagent.service;
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentDO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportExcelVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportRespVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentSaveReqVO;
|
||||
import jakarta.validation.*;
|
||||
@@ -67,4 +69,12 @@ public interface AiAgentService {
|
||||
*/
|
||||
List<AiAgentDO> getEnabledAgentList();
|
||||
|
||||
/**
|
||||
* 批量导入AI智能体
|
||||
*
|
||||
* @param importAgents 导入数据列表
|
||||
* @return 导入结果
|
||||
*/
|
||||
AiAgentImportRespVO importAiAgentList(List<AiAgentImportExcelVO> importAgents);
|
||||
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
package cn.iocoder.yudao.module.tik.muye.aiagent.service;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.dal.AiAgentDO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.mapper.AiAgentMapper;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportExcelVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentImportRespVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tik.muye.aiagent.vo.AiAgentSaveReqVO;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -12,6 +16,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
@@ -80,4 +85,71 @@ public class AiAgentServiceImpl implements AiAgentService {
|
||||
return aiAgentMapper.selectEnabledList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiAgentImportRespVO importAiAgentList(List<AiAgentImportExcelVO> importAgents) {
|
||||
// 1. 参数校验
|
||||
if (CollUtil.isEmpty(importAgents)) {
|
||||
throw exception(new ErrorCode(1005, "导入数据不能为空"));
|
||||
}
|
||||
|
||||
// 2. 初始化返回结果
|
||||
AiAgentImportRespVO respVO = AiAgentImportRespVO.builder()
|
||||
.createAgentNames(new ArrayList<>())
|
||||
.failureAgentNames(new LinkedHashMap<>())
|
||||
.build();
|
||||
|
||||
// 3. 获取当前登录用户信息
|
||||
Long operatorId = SecurityFrameworkUtils.getLoginUserId();
|
||||
String operatorName = String.valueOf(SecurityFrameworkUtils.getLoginUserNickname());
|
||||
|
||||
// 4. 遍历逐条处理
|
||||
importAgents.forEach(importAgent -> {
|
||||
try {
|
||||
// 4.1 必填字段校验
|
||||
if (importAgent.getAgentId() == null || importAgent.getAgentId().isEmpty()) {
|
||||
throw new RuntimeException("智能体ID不能为空");
|
||||
}
|
||||
if (importAgent.getAgentName() == null || importAgent.getAgentName().isEmpty()) {
|
||||
throw new RuntimeException("智能体名称不能为空");
|
||||
}
|
||||
if (importAgent.getCategoryName() == null || importAgent.getCategoryName().isEmpty()) {
|
||||
throw new RuntimeException("分类不能为空");
|
||||
}
|
||||
if (importAgent.getIcon() == null || importAgent.getIcon().isEmpty()) {
|
||||
throw new RuntimeException("图标URL不能为空");
|
||||
}
|
||||
if (importAgent.getStatus() == null) {
|
||||
throw new RuntimeException("状态不能为空");
|
||||
}
|
||||
if (importAgent.getDescription() == null || importAgent.getDescription().isEmpty()) {
|
||||
throw new RuntimeException("设定描述不能为空");
|
||||
}
|
||||
if (importAgent.getSystemPrompt() == null || importAgent.getSystemPrompt().isEmpty()) {
|
||||
throw new RuntimeException("预置提示词不能为空");
|
||||
}
|
||||
|
||||
// 4.2 检查 agentId 是否已存在
|
||||
AiAgentDO existAgent = aiAgentMapper.selectOne(
|
||||
new LambdaQueryWrapperX<AiAgentDO>()
|
||||
.eq(AiAgentDO::getAgentId, importAgent.getAgentId())
|
||||
);
|
||||
if (existAgent != null) {
|
||||
respVO.getFailureAgentNames().put(importAgent.getAgentName(), "智能体ID已存在");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4.3 创建智能体
|
||||
AiAgentDO aiAgent = BeanUtils.toBean(importAgent, AiAgentDO.class);
|
||||
aiAgent.setOperatorId(operatorId);
|
||||
aiAgent.setOperatorName(operatorName);
|
||||
aiAgentMapper.insert(aiAgent);
|
||||
respVO.getCreateAgentNames().add(importAgent.getAgentName());
|
||||
} catch (Exception ex) {
|
||||
respVO.getFailureAgentNames().put(importAgent.getAgentName(), ex.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
return respVO;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.iocoder.yudao.module.tik.muye.aiagent.vo;
|
||||
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* AI智能体导入 Excel VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Schema(description = "管理后台 - AI智能体导入 Excel VO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AiAgentImportExcelVO {
|
||||
|
||||
@ExcelProperty("智能体ID")
|
||||
private String agentId;
|
||||
|
||||
@ExcelProperty("智能体名称")
|
||||
private String agentName;
|
||||
|
||||
@ExcelProperty("分类")
|
||||
private String categoryName;
|
||||
|
||||
@ExcelProperty("图标URL")
|
||||
private String icon;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private Integer status;
|
||||
|
||||
@ExcelProperty("设定描述")
|
||||
private String description;
|
||||
|
||||
@ExcelProperty("预置提示词")
|
||||
private String systemPrompt;
|
||||
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package cn.iocoder.yudao.module.tik.muye.aiagent.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* AI智能体导入结果 Response VO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Schema(description = "管理后台 - AI智能体导入结果 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AiAgentImportRespVO {
|
||||
|
||||
@Schema(description = "创建成功的智能体名称数组")
|
||||
@Builder.Default
|
||||
private List<String> createAgentNames = new ArrayList<>();
|
||||
|
||||
@Schema(description = "导入失败的智能体集合,key 为智能体名称,value 为失败原因")
|
||||
@Builder.Default
|
||||
private Map<String, String> failureAgentNames = new LinkedHashMap<>();
|
||||
|
||||
}
|
||||
BIN
yudao-ui-admin-vue3/public/ai_agent_import_template.xlsx
Normal file
BIN
yudao-ui-admin-vue3/public/ai_agent_import_template.xlsx
Normal file
Binary file not shown.
@@ -6,7 +6,7 @@ export interface AiAgent {
|
||||
id: number; // 主键
|
||||
agentId?: string; // 智能体ID
|
||||
agentName?: string; // 智能体名称
|
||||
categoryId?: number; // 分类ID
|
||||
categoryName?: string; // 分类名称
|
||||
icon?: string; // 图标URL
|
||||
status?: number; // 状态(0-禁用 1-启用)
|
||||
description?: string; // 设定描述
|
||||
@@ -50,4 +50,9 @@ export const AiAgentApi = {
|
||||
exportAiAgent: async (params) => {
|
||||
return await request.download({ url: `/muye/ai-agent/export-excel`, params })
|
||||
},
|
||||
|
||||
// 下载AI智能体导入模板
|
||||
importAiAgentTemplate: async () => {
|
||||
return await request.download({ url: `/muye/ai-agent/get-import-template` })
|
||||
}
|
||||
}
|
||||
@@ -13,20 +13,23 @@
|
||||
<el-form-item label="智能体名称" prop="agentName">
|
||||
<el-input v-model="formData.agentName" placeholder="请输入智能体名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="categoryName">
|
||||
<el-input v-model="formData.categoryName" placeholder="请输入分类" />
|
||||
</el-form-item>
|
||||
<el-form-item label="图标URL" prop="icon">
|
||||
<el-input v-model="formData.icon" placeholder="请输入图标URL" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio value="0">禁用</el-radio>
|
||||
<el-radio value="1">启用</el-radio>
|
||||
<el-radio :value="0">禁用</el-radio>
|
||||
<el-radio :value="1">启用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="设定描述" prop="description">
|
||||
<Editor v-model="formData.description" height="150px" />
|
||||
<el-input v-model="formData.description" type="textarea" :rows="3" placeholder="请输入设定描述" />
|
||||
</el-form-item>
|
||||
<el-form-item label="预置提示词" prop="systemPrompt">
|
||||
<el-input v-model="formData.systemPrompt" placeholder="请输入预置提示词" />
|
||||
<el-input v-model="formData.systemPrompt" type="textarea" :rows="5" placeholder="请输入预置提示词" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" placeholder="请输入备注" />
|
||||
@@ -41,40 +44,35 @@
|
||||
<script setup lang="ts">
|
||||
import { AiAgentApi, AiAgent } from '@/api/muye/aiagent'
|
||||
|
||||
/** AI智能体 表单 */
|
||||
defineOptions({ name: 'AiAgentForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const dialogTitle = ref('')
|
||||
const formLoading = ref(false)
|
||||
const formType = ref('')
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
agentId: undefined,
|
||||
agentName: undefined,
|
||||
categoryName: undefined,
|
||||
icon: undefined,
|
||||
status: undefined,
|
||||
status: 1,
|
||||
description: undefined,
|
||||
systemPrompt: undefined,
|
||||
remark: undefined,
|
||||
operatorId: undefined,
|
||||
operatorName: undefined,
|
||||
})
|
||||
|
||||
const formRules = reactive({
|
||||
agentId: [{ required: true, message: '智能体ID不能为空', trigger: 'blur' }],
|
||||
agentName: [{ required: true, message: '智能体名称不能为空', trigger: 'blur' }],
|
||||
icon: [{ required: true, message: '图标URL不能为空', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '状态(0-禁用 1-启用)不能为空', trigger: 'blur' }],
|
||||
description: [{ required: true, message: '设定描述不能为空', trigger: 'blur' }],
|
||||
systemPrompt: [{ required: true, message: '预置提示词不能为空', trigger: 'blur' }],
|
||||
remark: [{ required: true, message: '备注不能为空', trigger: 'blur' }],
|
||||
operatorId: [{ required: true, message: '操作人用户编号不能为空', trigger: 'blur' }],
|
||||
operatorName: [{ required: true, message: '操作人账号不能为空', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '状态不能为空', trigger: 'change' }],
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
const formRef = ref()
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
@@ -82,7 +80,6 @@ const open = async (type: string, id?: number) => {
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
@@ -92,14 +89,12 @@ const open = async (type: string, id?: number) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
defineExpose({ open })
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const emit = defineEmits(['success'])
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as AiAgent
|
||||
@@ -111,7 +106,6 @@ const submitForm = async () => {
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
@@ -124,13 +118,12 @@ const resetForm = () => {
|
||||
id: undefined,
|
||||
agentId: undefined,
|
||||
agentName: undefined,
|
||||
categoryName: undefined,
|
||||
icon: undefined,
|
||||
status: undefined,
|
||||
status: 1,
|
||||
description: undefined,
|
||||
systemPrompt: undefined,
|
||||
remark: undefined,
|
||||
operatorId: undefined,
|
||||
operatorName: undefined,
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
|
||||
125
yudao-ui-admin-vue3/src/views/muye/aiagent/AiAgentImportForm.vue
Normal file
125
yudao-ui-admin-vue3/src/views/muye/aiagent/AiAgentImportForm.vue
Normal file
@@ -0,0 +1,125 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" title="AI智能体导入" width="400">
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
v-model:file-list="fileList"
|
||||
:action="importUrl"
|
||||
:auto-upload="false"
|
||||
:disabled="formLoading"
|
||||
:headers="uploadHeaders"
|
||||
:limit="1"
|
||||
:on-error="submitFormError"
|
||||
:on-exceed="handleExceed"
|
||||
:on-success="submitFormSuccess"
|
||||
accept=".xlsx, .xls"
|
||||
drag
|
||||
>
|
||||
<Icon icon="ep:upload" />
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||||
<template #tip>
|
||||
<div class="el-upload__tip text-center">
|
||||
<span>仅允许导入 xls、xlsx 格式文件。</span>
|
||||
<el-link
|
||||
:underline="false"
|
||||
style="font-size: 12px; vertical-align: baseline"
|
||||
type="primary"
|
||||
@click="importTemplate"
|
||||
>
|
||||
下载模板
|
||||
</el-link>
|
||||
</div>
|
||||
</template>
|
||||
</el-upload>
|
||||
<template #footer>
|
||||
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { getAccessToken, getTenantId } from '@/utils/auth'
|
||||
|
||||
defineOptions({ name: 'AiAgentImportForm' })
|
||||
|
||||
const message = useMessage()
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const formLoading = ref(false)
|
||||
const uploadRef = ref()
|
||||
const importUrl =
|
||||
import.meta.env.VITE_BASE_URL + import.meta.env.VITE_API_URL + '/muye/ai-agent/import'
|
||||
const uploadHeaders = ref()
|
||||
const fileList = ref([])
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = () => {
|
||||
dialogVisible.value = true
|
||||
fileList.value = []
|
||||
resetForm()
|
||||
}
|
||||
defineExpose({ open })
|
||||
|
||||
/** 提交表单 */
|
||||
const submitForm = async () => {
|
||||
if (fileList.value.length == 0) {
|
||||
message.error('请上传文件')
|
||||
return
|
||||
}
|
||||
uploadHeaders.value = {
|
||||
Authorization: 'Bearer ' + getAccessToken(),
|
||||
'tenant-id': getTenantId()
|
||||
}
|
||||
formLoading.value = true
|
||||
uploadRef.value!.submit()
|
||||
}
|
||||
|
||||
/** 文件上传成功 */
|
||||
const emits = defineEmits(['success'])
|
||||
const submitFormSuccess = (response: any) => {
|
||||
if (response.code !== 0) {
|
||||
message.error(response.msg)
|
||||
resetForm()
|
||||
return
|
||||
}
|
||||
const data = response.data
|
||||
let text = '创建成功数量:' + data.createAgentNames.length + ';'
|
||||
for (const name of data.createAgentNames) {
|
||||
text += '< ' + name + ' >'
|
||||
}
|
||||
text += '导入失败数量:' + Object.keys(data.failureAgentNames).length + ';'
|
||||
for (const name in data.failureAgentNames) {
|
||||
text += '< ' + name + ': ' + data.failureAgentNames[name] + ' >'
|
||||
}
|
||||
message.alert(text)
|
||||
formLoading.value = false
|
||||
dialogVisible.value = false
|
||||
emits('success')
|
||||
}
|
||||
|
||||
/** 上传错误提示 */
|
||||
const submitFormError = (): void => {
|
||||
message.error('上传失败,请您重新上传!')
|
||||
formLoading.value = false
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = async (): Promise<void> => {
|
||||
formLoading.value = false
|
||||
await nextTick()
|
||||
uploadRef.value?.clearFiles()
|
||||
}
|
||||
|
||||
/** 文件数超出提示 */
|
||||
const handleExceed = (): void => {
|
||||
message.error('最多只能上传一个文件!')
|
||||
}
|
||||
|
||||
/** 下载模板操作 */
|
||||
const importTemplate = () => {
|
||||
// 直接下载静态模板文件
|
||||
const link = document.createElement('a')
|
||||
link.href = '/ai_agent_import_template.xlsx'
|
||||
link.download = 'AI智能体导入模板.xlsx'
|
||||
link.click()
|
||||
}
|
||||
</script>
|
||||
@@ -17,10 +17,13 @@
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="categoryName">
|
||||
<el-input v-model="queryParams.categoryName" placeholder="请输入分类" clearable class="!w-240px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
|
||||
<el-option label="禁用" value="0" />
|
||||
<el-option label="启用" value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
<el-option label="启用" :value="1" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
@@ -43,6 +46,14 @@
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
plain
|
||||
@click="openImportForm"
|
||||
v-hasPermi="['muye:ai-agent:create']"
|
||||
>
|
||||
<Icon icon="ep:upload" class="mr-5px" /> 导入
|
||||
</el-button>
|
||||
<el-button
|
||||
type="danger"
|
||||
plain
|
||||
@@ -67,16 +78,25 @@
|
||||
@selection-change="handleRowCheckboxChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column label="智能体ID" align="center" prop="agentId" />
|
||||
<el-table-column label="智能体名称" align="center" prop="agentName" />
|
||||
<el-table-column label="图标URL" align="center" prop="icon" />
|
||||
<el-table-column label="状态(0-禁用 1-启用)" align="center" prop="status" />
|
||||
<el-table-column label="设定描述" align="center" prop="description" />
|
||||
<el-table-column label="预置提示词" align="center" prop="systemPrompt" />
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column label="操作人用户编号" align="center" prop="operatorId" />
|
||||
<el-table-column label="操作人账号" align="center" prop="operatorName" />
|
||||
<el-table-column label="操作" align="center" min-width="120px">
|
||||
<el-table-column label="智能体ID" align="center" prop="agentId" width="120" />
|
||||
<el-table-column label="名称" align="center" prop="agentName" width="150" />
|
||||
<el-table-column label="分类" align="center" prop="categoryName" width="100" />
|
||||
<el-table-column label="图标" align="center" prop="icon" width="80">
|
||||
<template #default="scope">
|
||||
<el-image v-if="scope.row.icon" :src="scope.row.icon" style="width: 40px; height: 40px" fit="cover" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" align="center" prop="status" width="80">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.status === 1 ? 'success' : 'danger'">
|
||||
{{ scope.row.status === 1 ? '启用' : '禁用' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="设定描述" align="center" prop="description" show-overflow-tooltip />
|
||||
<el-table-column label="预置提示词" align="center" prop="systemPrompt" show-overflow-tooltip />
|
||||
<el-table-column label="备注" align="center" prop="remark" width="120" />
|
||||
<el-table-column label="操作" align="center" width="120" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
@@ -108,6 +128,8 @@
|
||||
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<AiAgentForm ref="formRef" @success="getList" />
|
||||
<!-- 导入弹窗 -->
|
||||
<AiAgentImportForm ref="importFormRef" @success="getList" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -115,31 +137,27 @@ import { isEmpty } from '@/utils/is'
|
||||
import download from '@/utils/download'
|
||||
import { AiAgentApi, AiAgent } from '@/api/muye/aiagent'
|
||||
import AiAgentForm from './AiAgentForm.vue'
|
||||
import AiAgentImportForm from './AiAgentImportForm.vue'
|
||||
|
||||
/** AI智能体 列表 */
|
||||
defineOptions({ name: 'AiAgent' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage()
|
||||
const { t } = useI18n()
|
||||
|
||||
const loading = ref(true)
|
||||
const list = ref<AiAgent[]>([])
|
||||
const total = ref(0)
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<AiAgent[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
agentId: undefined,
|
||||
agentName: undefined,
|
||||
icon: undefined,
|
||||
categoryName: undefined,
|
||||
status: undefined,
|
||||
description: undefined,
|
||||
systemPrompt: undefined,
|
||||
remark: undefined,
|
||||
operatorId: undefined,
|
||||
operatorName: undefined,
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
const queryFormRef = ref()
|
||||
const exportLoading = ref(false)
|
||||
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
@@ -171,15 +189,18 @@ const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 导入操作 */
|
||||
const importFormRef = ref()
|
||||
const openImportForm = () => {
|
||||
importFormRef.value.open()
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await AiAgentApi.deleteAiAgent(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
@@ -187,26 +208,23 @@ const handleDelete = async (id: number) => {
|
||||
/** 批量删除AI智能体 */
|
||||
const handleDeleteBatch = async () => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
await AiAgentApi.deleteAiAgentList(checkedIds.value);
|
||||
checkedIds.value = [];
|
||||
await AiAgentApi.deleteAiAgentList(checkedIds.value)
|
||||
checkedIds.value = []
|
||||
message.success(t('common.delSuccess'))
|
||||
await getList();
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const checkedIds = ref<number[]>([])
|
||||
const handleRowCheckboxChange = (records: AiAgent[]) => {
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
checkedIds.value = records.map((item) => item.id!)
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
// 导出的二次确认
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await AiAgentApi.exportAiAgent(queryParams)
|
||||
download.excel(data, 'AI智能体.xls')
|
||||
|
||||
Reference in New Issue
Block a user