feat: 新增单位信息文档管理功能(知识库管理)
This commit is contained in:
@@ -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