|
@@ -1,11 +1,9 @@
|
|
|
-import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
+import React, { useCallback, useEffect, useState } from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
-import { Button, Popconfirm, Table } from "antd";
|
|
|
-import { useDispatch, useSelector } from "react-redux";
|
|
|
-import { A5_APIdel, A5_APIgetList, A5_APIsort } from "@/store/action/A5Section";
|
|
|
-import { RootState } from "@/store";
|
|
|
+import { Button } from "antd";
|
|
|
+import { useDispatch } from "react-redux";
|
|
|
+import { A5_APIgetList } from "@/store/action/A5Section";
|
|
|
import { A5TableType } from "@/types";
|
|
|
-import { MessageFu } from "@/utils/message";
|
|
|
import A5Add from "./A5Add";
|
|
|
import A2Table3 from "../A2Dict/A2Tab1/A2Table3";
|
|
|
|
|
@@ -20,165 +18,6 @@ function A5Section() {
|
|
|
getListFu();
|
|
|
}, [getListFu]);
|
|
|
|
|
|
- // 获取表格数据
|
|
|
- const tableList = useSelector(
|
|
|
- (state: RootState) => state.A5Section.tableList
|
|
|
- );
|
|
|
-
|
|
|
- // 树型数组扁平化
|
|
|
- const arrAllArr = useMemo(() => {
|
|
|
- const arr: A5TableType[] = [...tableList];
|
|
|
- const arr1: A5TableType[] = [];
|
|
|
- arr.forEach((v) => {
|
|
|
- arr1.push(v);
|
|
|
- if (v.children && v.children.length) {
|
|
|
- v.children.forEach((v2) => {
|
|
|
- arr1.push(v2);
|
|
|
- if (v2.children && v2.children.length) {
|
|
|
- v2.children.forEach((v3) => {
|
|
|
- arr1.push(v3);
|
|
|
- if (v3.children && v3.children.length) {
|
|
|
- v3.children.forEach((v4) => {
|
|
|
- arr1.push(v4);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- return arr1;
|
|
|
- }, [tableList]);
|
|
|
-
|
|
|
- // 拿到当前点击 级别的 数组
|
|
|
- const sonArrFu = useCallback(
|
|
|
- (fId: string) => {
|
|
|
- const arr: A5TableType[] = arrAllArr.filter(
|
|
|
- (v) => v.parentId === fId && v.name !== "未分类"
|
|
|
- );
|
|
|
- return arr;
|
|
|
- },
|
|
|
- [arrAllArr]
|
|
|
- );
|
|
|
-
|
|
|
- // 点击删除
|
|
|
- const delById = useCallback(
|
|
|
- async (id: string) => {
|
|
|
- const res = await A5_APIdel(id);
|
|
|
- if (res.code === 0) {
|
|
|
- MessageFu.success("删除成功!");
|
|
|
- getListFu();
|
|
|
- }
|
|
|
- },
|
|
|
- [getListFu]
|
|
|
- );
|
|
|
-
|
|
|
- // 点击 上移 和下移
|
|
|
- const sortMoveFu = useCallback(
|
|
|
- async (flag: 1 | -1, index: number, oldId: string, fId: string) => {
|
|
|
- const arr = sonArrFu(fId);
|
|
|
- const newId = arr[index + flag].id;
|
|
|
-
|
|
|
- const res = await A5_APIsort(oldId, newId);
|
|
|
-
|
|
|
- if (res.code === 0) {
|
|
|
- getListFu();
|
|
|
- MessageFu.success("排序修改成功!");
|
|
|
- }
|
|
|
- },
|
|
|
- [getListFu, sonArrFu]
|
|
|
- );
|
|
|
-
|
|
|
- const columns = useMemo(() => {
|
|
|
- return [
|
|
|
- {
|
|
|
- title: <>  部门名称</>,
|
|
|
- dataIndex: "name",
|
|
|
- },
|
|
|
- {
|
|
|
- title: "说明",
|
|
|
- render: (item: A5TableType) =>
|
|
|
- item.description ? (
|
|
|
- item.description.length >= 30 ? (
|
|
|
- <span style={{ cursor: "pointer" }} title={item.description}>
|
|
|
- {item.description.substring(0, 30) + "..."}
|
|
|
- </span>
|
|
|
- ) : (
|
|
|
- item.description
|
|
|
- )
|
|
|
- ) : (
|
|
|
- "(空)"
|
|
|
- ),
|
|
|
- },
|
|
|
- {
|
|
|
- title: "同级排序",
|
|
|
- render: (item: A5TableType, _: any, index: number) =>
|
|
|
- item.name === "未分类" ? "-" : item.level + "级 - " + (index + 1),
|
|
|
- },
|
|
|
- {
|
|
|
- title: "操作",
|
|
|
- render: (item: A5TableType, _: any, index: number) => (
|
|
|
- <>
|
|
|
- {item.level < 4 && item.name !== "未分类" ? (
|
|
|
- <Button
|
|
|
- size="small"
|
|
|
- type="text"
|
|
|
- onClick={() =>
|
|
|
- setAddInfo({
|
|
|
- id: "-1",
|
|
|
- parentId: item.id,
|
|
|
- name: item.name,
|
|
|
- level: item.level,
|
|
|
- } as A5TableType)
|
|
|
- }
|
|
|
- >
|
|
|
- 新增子部门
|
|
|
- </Button>
|
|
|
- ) : null}
|
|
|
-
|
|
|
- <Button size="small" type="text" onClick={() => setAddInfo(item)}>
|
|
|
- 编辑
|
|
|
- </Button>
|
|
|
- {index !== 0 && item.name !== "未分类" ? (
|
|
|
- <Button
|
|
|
- size="small"
|
|
|
- type="text"
|
|
|
- onClick={() => sortMoveFu(-1, index, item.id, item.parentId)}
|
|
|
- >
|
|
|
- 上移
|
|
|
- </Button>
|
|
|
- ) : null}
|
|
|
-
|
|
|
- {sonArrFu(item.parentId).length - 1 !== index &&
|
|
|
- item.name !== "未分类" ? (
|
|
|
- <Button
|
|
|
- size="small"
|
|
|
- type="text"
|
|
|
- onClick={() => sortMoveFu(1, index, item.id, item.parentId)}
|
|
|
- >
|
|
|
- 下移
|
|
|
- </Button>
|
|
|
- ) : null}
|
|
|
-
|
|
|
- {item.name !== "未分类" ? (
|
|
|
- <Popconfirm
|
|
|
- title="删除后无法恢复,是否删除?"
|
|
|
- okText="删除"
|
|
|
- cancelText="取消"
|
|
|
- onConfirm={() => delById(item.id)}
|
|
|
- okButtonProps={{ loading: false }}
|
|
|
- >
|
|
|
- <Button size="small" type="text" danger>
|
|
|
- 删除
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- ) : null}
|
|
|
- </>
|
|
|
- ),
|
|
|
- },
|
|
|
- ];
|
|
|
- }, [delById, sonArrFu, sortMoveFu]);
|
|
|
-
|
|
|
// 新增和编辑
|
|
|
const [addInfo, setAddInfo] = useState({} as A5TableType);
|
|
|
|
|
@@ -199,21 +38,11 @@ function A5Section() {
|
|
|
|
|
|
{/* 表格主体 */}
|
|
|
<div className="A5tableBox">
|
|
|
- <A2Table3
|
|
|
- editFu={(item) => setAddInfo2(item)}
|
|
|
- upTaleFu={() => getListFu2()}
|
|
|
- myType='字典'
|
|
|
- />
|
|
|
- {tableList.length ? (
|
|
|
- <Table
|
|
|
- scroll={{ y: 750 }}
|
|
|
- dataSource={tableList}
|
|
|
- columns={columns}
|
|
|
- rowKey="id"
|
|
|
- pagination={false}
|
|
|
- expandable={{ defaultExpandAllRows: true }}
|
|
|
- />
|
|
|
- ) : null}
|
|
|
+ <A2Table3
|
|
|
+ editFu={(item) => setAddInfo(item)}
|
|
|
+ upTaleFu={() => getListFu()}
|
|
|
+ myType="部门"
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
|