feat: 新增单位信息文档管理功能(知识库管理)
This commit is contained in:
110
src/views/oa/oaCompany/components/Import.vue
Normal file
110
src/views/oa/oaCompany/components/Import.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<!-- 文档导入弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="520"
|
||||
:footer="null"
|
||||
:title="`批量导入文档 - ${kbId}`"
|
||||
:visible="visible"
|
||||
@update:visible="updateVisible"
|
||||
>
|
||||
<a-spin :spinning="loading">
|
||||
<a-upload-dragger
|
||||
accept=".pdf,.doc,.docx,.txt,.md,.xls,.xlsx"
|
||||
:show-upload-list="false"
|
||||
:customRequest="doUpload"
|
||||
:multiple="true"
|
||||
style="padding: 24px 0; margin-bottom: 16px"
|
||||
>
|
||||
<p class="ant-upload-drag-icon">
|
||||
<cloud-upload-outlined />
|
||||
</p>
|
||||
<p class="ant-upload-hint">将文件拖到此处,或点击上传</p>
|
||||
<p class="ant-upload-hint" style="font-size: 12px; color: #999;">
|
||||
支持格式:PDF、Word、Excel、TXT、MD 等文档格式
|
||||
</p>
|
||||
</a-upload-dragger>
|
||||
</a-spin>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { message } from 'ant-design-vue/es';
|
||||
import { CloudUploadOutlined } from '@ant-design/icons-vue';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { uploadKnowledgeBaseDocument } from '@/api/ai/knowledgeBase';
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 在顶层定义 props
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
kbId: string;
|
||||
}>();
|
||||
|
||||
const loading = ref(false);
|
||||
|
||||
// 新增批量上传方法
|
||||
const handleBatchUpload = debounce(async () => {
|
||||
if (uploadQueue.length === 0) return;
|
||||
|
||||
const files = [...uploadQueue];
|
||||
uploadQueue.length = 0; // 清空队列
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const msg = await uploadKnowledgeBaseDocument(props.kbId, files);
|
||||
message.success(msg || '上传成功');
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
} catch (e) {
|
||||
message.error(e.message || '上传失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}, 500);
|
||||
|
||||
// 修改后的上传方法
|
||||
const doUpload = ({ file }: { file: File }) => {
|
||||
// 检查文件类型
|
||||
const allowedTypes = [
|
||||
'application/pdf',
|
||||
'application/msword',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'text/plain',
|
||||
'text/markdown',
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
];
|
||||
|
||||
const allowedExtensions = ['.pdf', '.doc', '.docx', '.txt', '.md', '.xls', '.xlsx'];
|
||||
const fileExtension = '.' + file.name.split('.').pop()?.toLowerCase();
|
||||
|
||||
if (!allowedTypes.includes(file.type) && !allowedExtensions.includes(fileExtension)) {
|
||||
message.error('只能上传文档文件(PDF、Word、Excel、TXT、MD)');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.size / 1024 / 1024 > 100) {
|
||||
message.error('文件大小不能超过 100MB');
|
||||
return false;
|
||||
}
|
||||
|
||||
// 将文件加入队列并触发防抖上传
|
||||
uploadQueue.push(file);
|
||||
handleBatchUpload();
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// 新增文件队列
|
||||
const uploadQueue: File[] = [];
|
||||
|
||||
/* 更新 visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
</script>
|
||||
@@ -49,6 +49,15 @@
|
||||
v-model:value="form.companyCode"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="知识库ID" name="kbId">
|
||||
<a-input
|
||||
:class="{ 'disabled-text': !form.kbId }"
|
||||
:style="!form.kbId ? 'cursor: not-allowed; color: #999' : 'background-color: #f5f5f5'"
|
||||
:placeholder="form.kbId ? '' : '未创建'"
|
||||
:value="form.kbId"
|
||||
readonly
|
||||
/>
|
||||
</a-form-item>
|
||||
<!-- <a-form-item label="类型" name="companyType">-->
|
||||
<!-- <a-radio-group v-model:value="form.companyType">-->
|
||||
<!-- <a-radio :value="10">企业</a-radio>-->
|
||||
@@ -260,7 +269,8 @@
|
||||
oaCompanyName: '',
|
||||
status: 0,
|
||||
comments: '',
|
||||
sortNumber: 100
|
||||
sortNumber: 100,
|
||||
kbId: undefined,
|
||||
});
|
||||
|
||||
/* 更新visible */
|
||||
|
||||
@@ -35,6 +35,13 @@
|
||||
<a-space>
|
||||
<a @click="openEdit(record)">修改</a>
|
||||
<a-divider type="vertical"/>
|
||||
<!-- 文档管理按钮 -->
|
||||
<a
|
||||
:class="{ 'disabled-text': !record.kbId }"
|
||||
:style="!record.kbId ? 'cursor: not-allowed; color: #999' : ''"
|
||||
@click="record.kbId && openDocManage(record)"
|
||||
>文档管理</a>
|
||||
<a-divider type="vertical"/>
|
||||
<a-popconfirm
|
||||
title="确定要删除此记录吗?"
|
||||
@confirm="remove(record)"
|
||||
@@ -49,6 +56,48 @@
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<OaCompanyEdit v-model:visible="showEdit" :data="current" @done="reload"/>
|
||||
|
||||
<!-- 文档管理弹窗 -->
|
||||
<a-modal
|
||||
v-model:visible="showDocManage"
|
||||
:title="`文档管理 - ${currentKbName}`"
|
||||
width="800px"
|
||||
:footer="null"
|
||||
>
|
||||
<div style="margin-bottom: 16px;">
|
||||
<a-button type="primary" @click="openImport">新增文档</a-button>
|
||||
</div>
|
||||
<a-table
|
||||
:dataSource="docList"
|
||||
:columns="docColumns"
|
||||
:loading="docLoading"
|
||||
rowKey="id"
|
||||
:pagination="{
|
||||
current: currentPage,
|
||||
pageSize: 10,
|
||||
total: total,
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => `共 ${total} 条`
|
||||
}"
|
||||
@change="(pag) => { currentPage = pag.current; loadDocuments(); }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-popconfirm
|
||||
title="确定要删除此文档吗?"
|
||||
@confirm="deleteDoc(record)"
|
||||
>
|
||||
<a class="ele-text-danger">删除</a>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
</a-modal>
|
||||
|
||||
<!-- 导入弹窗 -->
|
||||
<Import v-model:visible="showImport" @done="loadDocuments" :kbId="currentKbId"/>
|
||||
</a-page-header>
|
||||
</template>
|
||||
|
||||
@@ -64,9 +113,13 @@ import type {
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import Search from './components/search.vue';
|
||||
import OaCompanyEdit from './components/oaCompanyEdit.vue';
|
||||
// 导入Import组件和API
|
||||
import Import from './components/Import.vue';
|
||||
import {pageOaCompany, removeOaCompany, removeBatchOaCompany} from '@/api/oa/oaCompany';
|
||||
import type {OaCompany, OaCompanyParam} from '@/api/oa/oaCompany/model';
|
||||
import {getPageTitle,isImage} from "@/utils/common";
|
||||
// 导入知识库API
|
||||
import {getKnowledgeBaseDocuments, deleteKnowledgeBaseDocument} from '@/api/ai/knowledgeBase'; // 请修改为正确的API路径
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
@@ -79,8 +132,44 @@ const current = ref<OaCompany | null>(null);
|
||||
const showEdit = ref(false);
|
||||
// 是否显示批量移动弹窗
|
||||
const showMove = ref(false);
|
||||
// 文档管理相关响应式变量
|
||||
const showDocManage = ref(false); // 是否显示文档管理弹窗
|
||||
const showImport = ref(false); // 是否显示导入弹窗
|
||||
// 加载状态
|
||||
const loading = ref(true);
|
||||
// 新增分页状态变量
|
||||
const currentPage = ref(1);
|
||||
const total = ref(0);
|
||||
|
||||
// 文档管理相关变量
|
||||
const currentKbId = ref(''); // 当前知识库ID
|
||||
const currentKbName = ref(''); // 当前知识库名称
|
||||
const docList = ref<any[]>([]); // 文档列表数据
|
||||
const docLoading = ref(false); // 文档加载状态
|
||||
// 文档表格列配置
|
||||
const docColumns = ref([
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'name', // 改为接口返回的name字段
|
||||
key: 'fileName',
|
||||
},
|
||||
{
|
||||
title: '文件大小',
|
||||
dataIndex: 'size', // 改为接口返回的size字段
|
||||
key: 'fileSize',
|
||||
},
|
||||
{
|
||||
title: '上传时间',
|
||||
dataIndex: 'gmtModified', // 改为接口返回的gmtModified字段
|
||||
key: 'createTime',
|
||||
customRender: ({ text }) => toDateString(text) // 添加时间格式化
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 100,
|
||||
}
|
||||
]);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({
|
||||
@@ -170,7 +259,7 @@ const columns = ref<ColumnItem[]>([
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 180,
|
||||
width: 220,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
hideInSetting: true
|
||||
@@ -194,6 +283,60 @@ const openMove = () => {
|
||||
showMove.value = true;
|
||||
};
|
||||
|
||||
// 打开文档管理弹窗
|
||||
const openDocManage = (record: OaCompany) => {
|
||||
currentKbId.value = record.kbId; // 使用record中的kbId
|
||||
currentKbName.value = record.companyName; // 使用单位名称作为知识库名称
|
||||
currentPage.value = 1;
|
||||
showDocManage.value = true;
|
||||
loadDocuments();
|
||||
};
|
||||
|
||||
// 加载文档列表
|
||||
const loadDocuments = async () => {
|
||||
docLoading.value = true;
|
||||
try {
|
||||
const response = await getKnowledgeBaseDocuments(
|
||||
currentKbId.value,
|
||||
10,
|
||||
currentPage.value
|
||||
);
|
||||
docList.value = Array.isArray(response?.list) ? response.list : [];
|
||||
total.value = response?.count || 0;
|
||||
} catch (error) {
|
||||
message.error('加载文档列表失败');
|
||||
console.error('加载文档错误:', error);
|
||||
} finally {
|
||||
docLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 删除文档
|
||||
const deleteDoc = async (record: any) => {
|
||||
try {
|
||||
// 执行删除操作
|
||||
await deleteKnowledgeBaseDocument(currentKbId.value, record.id);
|
||||
|
||||
// 立即本地删除(核心修改)
|
||||
const index = docList.value.findIndex(item => item.id === record.id);
|
||||
if (index > -1) {
|
||||
docList.value.splice(index, 1);
|
||||
total.value -= 1;
|
||||
}
|
||||
message.success('删除成功');
|
||||
// 阿里云异步删除,需等待异步删除完成再重新查询
|
||||
// await loadDocuments();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
console.error(error);
|
||||
}
|
||||
};
|
||||
|
||||
// 打开导入弹窗
|
||||
const openImport = () => {
|
||||
showImport.value = true;
|
||||
};
|
||||
|
||||
/* 删除单个 */
|
||||
const remove = (row: OaCompany) => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
|
||||
Reference in New Issue
Block a user