增加导入
This commit is contained in:
@@ -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