| | |
| | | </div> |
| | | <div class="right"> |
| | | <el-row :gutter="24"> |
| | | <el-col :span="2" :offset="20"><el-button :icon="Delete" type="danger">删除</el-button></el-col> |
| | | <el-col :span="2"><el-button :icon="Plus" type="primary">新增</el-button></el-col> |
| | | <el-col :span="2" :offset="20" |
| | | ><el-button :icon="Delete" type="danger" @click="delHandler">删除</el-button></el-col |
| | | > |
| | | <el-col :span="2" |
| | | ><el-button |
| | | :icon="Plus" |
| | | type="primary" |
| | | @click="add" |
| | | :disabled="!tableData.length" |
| | | >新增</el-button |
| | | ></el-col |
| | | > |
| | | </el-row> |
| | | <ETable |
| | | :maxHeight="1200" |
| | | :loading="loading" |
| | | :table-data="tableData" |
| | | :columns="columns" |
| | |
| | | </ETable> |
| | | <Pagination |
| | | :total="total" |
| | | :page-size="10" |
| | | :page-count="Math.ceil(total / 10)" |
| | | @page-change="currentPageChange" |
| | | :page="queryParams.current" |
| | | :limit="queryParams.pageSize" |
| | | :show-total="true" |
| | | @pagination="handlePageChange" |
| | | :layout="'total, prev, pager, next, jumper'" |
| | | ></Pagination> |
| | | </div> |
| | | <archiveDialog |
| | | v-model:centerDialogVisible="dialogVisible" |
| | | @centerDialogVisible="centerDialogVisible" |
| | | :row="row" |
| | | @submitForm="submitForm" |
| | | ref="archiveDialogs" |
| | | |
| | | > |
| | | </archiveDialog> |
| | | </el-card> |
| | | </template> |
| | | <script setup> |
| | | import { onMounted, ref, nextTick } from "vue"; |
| | | import { onMounted, ref, nextTick, reactive } from "vue"; |
| | | import ETable from "@/components/Table/ETable.vue"; |
| | | import { ElButton, ElInput, ElIcon } from "element-plus"; |
| | | import { ElButton, ElInput, ElIcon, ElMessage } from "element-plus"; |
| | | import archiveDialog from "./mould/archiveDialog.vue"; |
| | | import Pagination from "@/components/Pagination/index.vue"; |
| | | import { |
| | | Plus, |
| | |
| | | addOrEditArchive, |
| | | delArchive, |
| | | } from "@/api/archiveManagement"; |
| | | const dialogVisible = ref(false); // 控制归档对话框显示 |
| | | const loading = ref(false); |
| | | const tableData = ref([]); |
| | | const treeData = ref([]); |
| | |
| | | const filterText = ref(""); // 搜索关键字 |
| | | const treeRef = ref(); // 树组件引用 |
| | | const total = ref(0); // 总记录数 |
| | | const current = ref(1); // 当前页码 |
| | | const columns = [ |
| | | { prop: "name", label: "名称", minWidth: 180 }, |
| | | { prop: "type", label: "类型", minWidth: 120 }, |
| | | { prop: "status", label: "状态", minWidth: 100 }, |
| | | ]; |
| | | const selectedRows = reactive([]); // 存储选中行数据 |
| | | const handleSelectionChange = (selection) => { |
| | | console.log("Selected rows:", selection); |
| | | selectedRows.splice(0, selectedRows.length, ...selection); |
| | | }; |
| | | |
| | | const queryParams = reactive({ |
| | | searchAll: "", |
| | | current: 1, |
| | | pageSize: 10, // 固定每页10条 |
| | | treeId: null, // 当前树节点ID |
| | | }); |
| | | // 搜索过滤功能 |
| | | const handleFilter = () => { |
| | | treeRef.value?.filter(filterText.value); |
| | | }; |
| | | |
| | | const row = ref({}); // 当前选中行数据 |
| | | const filterNode = (value, data) => { |
| | | if (!value) return true; |
| | | return data.name?.toLowerCase().includes(value.toLowerCase()); |
| | | }; |
| | | |
| | | const submitForm = async (res) => { |
| | | if (res && res.code === 200) { |
| | | ElMessage.success("操作成功"); |
| | | // 刷新列表数据 |
| | | await getArchiveListData(); |
| | | } else { |
| | | ElMessage.error("操作失败: " + (res?.message || "未知错误")); |
| | | } |
| | | } |
| | | const centerDialogVisible = (val) => { |
| | | }; |
| | | // 处理节点点击 |
| | | const handleNodeClick = async (data) => { |
| | | console.log("点击节点:", data); |
| | | let res = await getArchiveList(data.id); |
| | | tableData.value = res.data?.records || res.data || []; |
| | | console.log(data) |
| | | // 切换节点时重置到第一页 |
| | | queryParams.current = 1; |
| | | queryParams.treeId = data.id; |
| | | getArchiveListData(); |
| | | }; |
| | | const currentPageChange = (id) => { |
| | | console.log(id); |
| | | const archiveDialogs = ref(null); // 表格组件引用 |
| | | // add |
| | | const add = () => { |
| | | row.value = {}; // 清空行数据,确保是新增模式 |
| | | dialogVisible.value = true; |
| | | newName.value = ""; // 清空输入框 |
| | | archiveDialogs.value.initForm(); // 重置表单 |
| | | }; |
| | | // 处理分页变化 |
| | | const handlePageChange = ({ page }) => { |
| | | queryParams.current = page; |
| | | // pageSize 固定为20,不再从参数中获取 |
| | | getArchiveListData(); |
| | | }; |
| | | |
| | | const getArchiveListData = async () => { |
| | | try { |
| | | loading.value = true; |
| | | let res = await getArchiveList({ |
| | | treeId: queryParams.treeId, |
| | | current: queryParams.current, |
| | | size: queryParams.pageSize, |
| | | }); |
| | | |
| | | if (res.code !== 200) { |
| | | ElMessage.error("获取数据失败: " + res.message); |
| | | tableData.value = []; |
| | | total.value = 0; |
| | | return; |
| | | } |
| | | |
| | | tableData.value = res.data?.records || res.data || []; |
| | | total.value = res.data?.total || 0; |
| | | // 确保分页参数正确更新 |
| | | if (res.data?.current) { |
| | | queryParams.current = res.data.current; |
| | | } |
| | | // pageSize 固定为20,不从后端获取 |
| | | |
| | | } catch (error) { |
| | | ElMessage.error("获取数据失败"); |
| | | tableData.value = []; |
| | | total.value = 0; |
| | | } finally { |
| | | loading.value = false; |
| | | } |
| | | }; |
| | | const delHandler = async () => { |
| | | if (selectedRows.length === 0) { |
| | | ElMessage.warning("请选择要删除的数据"); |
| | | return; |
| | | } |
| | | try { |
| | | const ids = selectedRows.map((row) => row.id); |
| | | const { code, msg } = await delArchive(ids); |
| | | if (code !== 200) { |
| | | ElMessage.warning("删除失败: " + msg); |
| | | } else { |
| | | ElMessage.success("删除成功"); |
| | | // 删除成功后重新获取数据 |
| | | await getArchiveListData(); |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error("删除归档失败"); |
| | | } |
| | | }; |
| | | // 双击编辑节点 |
| | | const headerDbClick = (comeTreeData) => { |
| | |
| | | comeTreeData.isEdit = false; |
| | | const newValue = newName.value.trim(); |
| | | if (comeTreeData.name === newValue) { |
| | | console.log("没有修改内容"); |
| | | return; |
| | | } |
| | | if (newValue === "") { |
| | | console.warn("输入不能为空"); |
| | | newName.value = comeTreeData.name || "新节点"; |
| | | return; |
| | | } |
| | |
| | | parentId: parentId || null, // 如果没有父节点,则为 null |
| | | }); |
| | | } catch (error) { |
| | | console.error("存储失败", error); |
| | | comeTreeData.name = comeTreeData.name || "新节点"; |
| | | } |
| | | console.log("保存成功:", newValue); |
| | | }; |
| | | |
| | | onMounted(async () => { |
| | |
| | | }; |
| | | |
| | | const remove = async (node, data) => { |
| | | console.log("删除节点:", data); |
| | | if (!data || !data.id) { |
| | | console.warn("无法删除未定义或无效的节点"); |
| | | return; |
| | | } |
| | | console.log("删除节点 ID:", data.id); |
| | | let { code, msg } = await delTree([data.id]); |
| | | if (code !== 200) { |
| | | ElMessage.warning("删除失败, " + msg); |
| | |
| | | const append = async (data) => { |
| | | if (data === "") { |
| | | // 新增根节点 |
| | | console.log("新增根节点"); |
| | | const newNode = { |
| | | id: Date.now(), |
| | | name: "新节点", |
| | |
| | | const node = treeRef.value?.getNode(nodeKey); |
| | | const isExpanded = node?.expanded; // 如果有子级且未展开,先展开节点 |
| | | if (hasChildren && !isExpanded) { |
| | | console.log(treeRef.value, "展开节点", nodeKey); |
| | | if ( |
| | | treeRef.value && |
| | | treeRef.value.store && |
| | |
| | | treeRef.value.store.nodesMap[nodeKey].expanded = true; |
| | | } |
| | | } |
| | | |
| | | const newNode = { |
| | | id: Date.now(), |
| | | name: "新子节点", |
| | |
| | | } |
| | | }; |
| | | |
| | | const handleEdit = () => {}; |
| | | const handleEdit = (rows) => { |
| | | row.value = rows; |
| | | dialogVisible.value = true; |
| | | archiveDialogs.value.editForm(rows); // 调用编辑方法 |
| | | }; |
| | | |
| | | // 移除懒加载,直接获取数据 |
| | | const getList = async () => { |
| | |
| | | if (res.code === 200) { |
| | | treeData.value = res.data?.records || res.data || []; |
| | | } else { |
| | | console.error("Failed to fetch tree data:", res.message); |
| | | treeData.value = []; |
| | | } |
| | | } catch (error) { |
| | | console.error("获取树形数据失败:", error); |
| | | treeData.value = []; |
| | | } |
| | | }; |
| | |
| | | float: left; |
| | | } |
| | | } |
| | | .archive-management-card{ |
| | | .archive-management-card { |
| | | margin: 0; |
| | | } |
| | | </style> |