feat:单位信息-文档管理-优化目录新增、编辑、删除功能

This commit is contained in:
2025-11-04 14:42:47 +08:00
parent 78f32a1728
commit 642d10f916
2 changed files with 203 additions and 44 deletions

View File

@@ -80,9 +80,35 @@
<div class="dir-tree-panel">
<div class="dir-header">
<span>文档目录</span>
<a-button type="link" size="small" @click="openAddDir" title="新增目录">
<template #icon><PlusOutlined /></template>
</a-button>
<a-space>
<a-button
type="link"
size="small"
@click="openEditDir"
title="编辑目录"
:disabled="!selectedKeys.length"
>
<template #icon><EditOutlined /></template>
</a-button>
<a-button
type="link"
size="small"
@click="openAddDir"
title="新增目录"
>
<template #icon><PlusOutlined /></template>
</a-button>
<a-button
type="link"
size="small"
@click="deleteSelectedDir"
title="删除目录"
:disabled="!selectedKeys.length"
class="ele-text-danger"
>
<template #icon><DeleteOutlined /></template>
</a-button>
</a-space>
</div>
<div class="tree-container">
<a-tree
@@ -151,18 +177,26 @@
:doc="selectedDoc"
/>
<!-- 新增目录弹窗 -->
<!-- 新增/编辑目录弹窗 -->
<a-modal
v-model:visible="showAddDir"
:title="`新增目录 - ${selectedDirName ? '在『' + selectedDirName + '』下' : '在根目录下'}`"
v-model:visible="showDirModal"
:title="dirModalTitle"
width="400px"
@ok="handleAddDir"
@cancel="showAddDir = false"
@ok="handleSaveDir"
@cancel="closeDirModal"
>
<a-form :model="dirForm" layout="vertical">
<a-form-item label="目录名称">
<a-input v-model:value="dirForm.name" placeholder="请输入目录名称" />
</a-form-item>
<a-form-item label="排序号">
<a-input-number
v-model:value="dirForm.sortNumber"
placeholder="请输入排序号"
:min="0"
style="width: 100%"
/>
</a-form-item>
</a-form>
</a-modal>
</a-page-header>
@@ -171,7 +205,7 @@
<script lang="ts" setup>
import { createVNode, ref, computed } from 'vue';
import { message, Modal, Empty } from 'ant-design-vue';
import { ExclamationCircleOutlined, PlusOutlined, UploadOutlined } from '@ant-design/icons-vue';
import { ExclamationCircleOutlined, PlusOutlined, UploadOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue';
import type { EleProTable } from 'ele-admin-pro';
import { toDateString } from 'ele-admin-pro';
import type {
@@ -190,7 +224,7 @@ import {
import type { OaCompany, OaCompanyParam } from '@/api/oa/oaCompany/model';
import { getPageTitle, isImage } from '@/utils/common';
// 导入AiCloudDoc API
import { listAiCloudDoc, addAiCloudDoc } from '@/api/ai/aiCloudDoc';
import { listAiCloudDoc, addAiCloudDoc, updateAiCloudDoc, removeAiCloudDoc } from '@/api/ai/aiCloudDoc';
import type { AiCloudDoc } from '@/api/ai/aiCloudDoc/model';
// 导入AiCloudFile API
import { listAiCloudFile, removeAiCloudFile } from '@/api/ai/aiCloudFile';
@@ -210,7 +244,7 @@ const showMove = ref(false);
// 文档管理相关响应式变量
const showDocManage = ref(false); // 是否显示文档管理弹窗
const showImport = ref(false); // 是否显示导入弹窗
const showAddDir = ref(false); // 是否显示新增目录弹窗
const showDirModal = ref(false); // 是否显示目录弹窗(新增/编辑)
// 加载状态
const loading = ref(true);
@@ -227,9 +261,21 @@ const expandedKeys = ref<(string | number)[]>([]);
const selectedKeys = ref<(string | number)[]>([]);
const simpleImage = Empty.PRESENTED_IMAGE_SIMPLE;
// 新增目录表单
// 目录弹窗相关
const isEditingDir = ref(false); // 是否为编辑模式
const currentDirId = ref<number>(); // 当前操作的目录ID
// 目录表单
const dirForm = ref({
name: ''
name: '',
sortNumber: 0
});
// 计算目录弹窗标题
const dirModalTitle = computed(() => {
const mode = isEditingDir.value ? '编辑' : '新增';
const location = selectedDirName.value ? `在『${selectedDirName.value}』下` : '在根目录下';
return `${mode}目录 - ${location}`;
});
// 分页配置
@@ -284,6 +330,11 @@ const selectedDoc = computed(() => {
} : null;
});
// 检查目录是否有子目录(简化版,只检查子目录)
const checkDirHasChildren = (dirId: number): boolean => {
return allDirs.value.some(item => item.parentId === dirId);
};
// 文档表格列配置 - 去掉固定宽度,使用自适应
const docColumns = ref([
{
@@ -439,11 +490,11 @@ const openDocManage = async (record: OaCompany) => {
selectedKeys.value = [];
// 加载目录列表
await loadAllCloudDocs();
await loadAllCloudDocs(true);
};
// 加载所有目录
const loadAllCloudDocs = async () => {
const loadAllCloudDocs = async (resetState = false) => {
try {
const params = {
companyId: currentCompanyId.value
@@ -452,13 +503,16 @@ const loadAllCloudDocs = async () => {
const result = await listAiCloudDoc(params);
allDirs.value = result || [];
// 默认展开根节点并选中第一个目录
if (allDirs.value.length > 0) {
const rootDirs = allDirs.value.filter(item => item.parentId === 0);
if (rootDirs.length > 0) {
expandedKeys.value = [0]; // 展开根节点
selectedKeys.value = [rootDirs[0].id!];
loadCloudFiles();
if (resetState) {
// 只在首次加载时重置状态
// 默认展开根节点并选中第一个目录
if (allDirs.value.length > 0) {
const rootDirs = allDirs.value.filter(item => item.parentId === 0);
if (rootDirs.length > 0) {
expandedKeys.value = [rootDirs[0].id!]; // 展开根节点
selectedKeys.value = [rootDirs[0].id!];
loadCloudFiles();
}
}
}
} catch (error) {
@@ -563,42 +617,141 @@ const openAddDir = () => {
message.info('请先选择一个目录');
return;
}
isEditingDir.value = false;
currentDirId.value = undefined;
dirForm.value.name = '';
showAddDir.value = true;
dirForm.value.sortNumber = 0;
showDirModal.value = true;
};
// 处理新增目录
const handleAddDir = async () => {
// 打开编辑目录弹窗
const openEditDir = () => {
if (selectedKeys.value.length === 0) {
message.info('请先选择一个目录');
return;
}
const selectedDir = allDirs.value.find(item => item.id === selectedKeys.value[0]);
if (!selectedDir) {
message.error('未找到选中的目录');
return;
}
isEditingDir.value = true;
currentDirId.value = selectedDir.id;
dirForm.value.name = selectedDir.name || '';
dirForm.value.sortNumber = selectedDir.sortNumber || 0;
showDirModal.value = true;
};
// 删除选中目录
const deleteSelectedDir = async () => {
if (selectedKeys.value.length === 0) {
message.info('请先选择一个目录');
return;
}
const selectedDir = allDirs.value.find(item => item.id === selectedKeys.value[0]);
if (!selectedDir) {
message.error('未找到选中的目录');
return;
}
await deleteDir(selectedDir.id!, selectedDir.name || '');
};
// 关闭目录弹窗
const closeDirModal = () => {
showDirModal.value = false;
dirForm.value.name = '';
dirForm.value.sortNumber = 0;
currentDirId.value = undefined;
};
// 处理保存目录(新增/编辑)
const handleSaveDir = async () => {
if (!dirForm.value.name) {
message.error('请输入目录名称');
return;
}
try {
const newDir: AiCloudDoc = {
companyId: currentCompanyId.value,
parentId: selectedKeys.value[0] as number,
name: dirForm.value.name,
sortNumber: 0
};
if (isEditingDir.value) {
// 编辑目录
const updateData: AiCloudDoc = {
id: currentDirId.value,
name: dirForm.value.name,
sortNumber: dirForm.value.sortNumber || 0
};
await updateAiCloudDoc(updateData);
message.success('修改目录成功');
} else {
// 新增目录
const newDir: AiCloudDoc = {
companyId: currentCompanyId.value,
parentId: selectedKeys.value[0] as number,
name: dirForm.value.name,
sortNumber: dirForm.value.sortNumber || 0
};
await addAiCloudDoc(newDir);
message.success('新增目录成功');
}
await addAiCloudDoc(newDir);
message.success('新增目录成功');
showAddDir.value = false;
showDirModal.value = false;
// 重新加载目录列表
await loadAllCloudDocs();
// 重新加载目录列表,但不重置状态
await loadAllCloudDocs(false);
// 展开父节点
if (!expandedKeys.value.includes(newDir.parentId!)) {
expandedKeys.value = [...expandedKeys.value, newDir.parentId!];
if (!isEditingDir.value) {
// 新增目录时展开父节点
const parentId = selectedKeys.value[0] as number;
if (!expandedKeys.value.includes(parentId)) {
expandedKeys.value = [...expandedKeys.value, parentId];
}
}
} catch (error) {
message.error('新增目录失败');
console.error('新增目录错误:', error);
message.error(isEditingDir.value ? '修改目录失败' : '新增目录失败');
console.error('目录操作错误:', error);
}
};
// 删除目录
const deleteDir = async (dirId: number, dirName: string) => {
// 检查目录是否有子目录
const hasChildren = checkDirHasChildren(dirId);
if (hasChildren) {
message.error(`目录「${dirName}」包含子目录,无法删除。请先删除该目录下的所有子目录。`);
return;
}
Modal.confirm({
title: '提示',
content: `确定要删除目录「${dirName}」吗?`,
icon: createVNode(ExclamationCircleOutlined),
maskClosable: true,
onOk: async () => {
try {
await removeAiCloudDoc(dirId);
message.success('删除目录成功');
// 重新加载目录列表
await loadAllCloudDocs(false);
// 如果删除的是当前选中的目录,清空选中状态
if (selectedKeys.value.includes(dirId)) {
selectedKeys.value = [];
docList.value = [];
pagination.value.total = 0;
}
} catch (error: any) {
// 显示后端返回的具体错误信息
message.error(error.message || '删除目录失败');
console.error('删除目录错误:', error);
}
}
});
};
/* 删除单个 */
const remove = (row: OaCompany) => {
const hide = message.loading('请求中..', 0);
@@ -755,6 +908,7 @@ export default {
:deep(.ant-tree-node-content-wrapper) {
border-radius: 4px;
transition: all 0.3s;
width: 100%;
}
:deep(.ant-tree-node-content-wrapper:hover) {
@@ -838,4 +992,9 @@ export default {
margin-bottom: 0;
flex-shrink: 0; /* 防止分页器被压缩 */
}
/* 删除按钮样式 */
:deep(.ele-text-danger) {
color: #ff4d4f;
}
</style>

View File

@@ -1537,19 +1537,19 @@ const changeTable3 = (title) => {
align: 'center'
},
{
title: '公司制',
title: '公司制',
dataIndex: 'companyFormulation',
key: 'companyFormulation',
align: 'center'
},
{
title: '检查的证据及测试内容',
title: '公司执行情况',
dataIndex: 'checkEvidence',
key: 'checkEvidence',
align: 'center'
},
{
title: '测试结果',
title: '执行结果',
dataIndex: 'testResult',
key: 'testResult',
align: 'center',