|
@@ -1,11 +1,12 @@
|
|
|
-import React, { useCallback, useEffect, useMemo } from "react";
|
|
|
+import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
import { Button, Popconfirm, Table } from "antd";
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
-import { A5_APIgetList, A5_APIsort } from "@/store/action/A5Section";
|
|
|
+import { A5_APIdel, A5_APIgetList, A5_APIsort } from "@/store/action/A5Section";
|
|
|
import { RootState } from "@/store";
|
|
|
import { A5TableType } from "@/types";
|
|
|
import { MessageFu } from "@/utils/message";
|
|
|
+import A5Add from "./A5Add";
|
|
|
|
|
|
function A5Section() {
|
|
|
const dispatch = useDispatch();
|
|
@@ -51,19 +52,25 @@ function A5Section() {
|
|
|
// 拿到当前点击 级别的 数组
|
|
|
const sonArrFu = useCallback(
|
|
|
(fId: string) => {
|
|
|
- const arr: A5TableType[] = arrAllArr.filter((v) => v.parentId === fId);
|
|
|
+ const arr: A5TableType[] = arrAllArr.filter(
|
|
|
+ (v) => v.parentId === fId && v.name !== "未分类"
|
|
|
+ );
|
|
|
return arr;
|
|
|
},
|
|
|
[arrAllArr]
|
|
|
);
|
|
|
|
|
|
// 点击删除
|
|
|
- const delById = useCallback((id: string) => {}, []);
|
|
|
-
|
|
|
- // 点击新增子部门
|
|
|
- const addTree = useCallback((item: A5TableType) => {
|
|
|
- console.log("----", item);
|
|
|
- }, []);
|
|
|
+ const delById = useCallback(
|
|
|
+ async (id: string) => {
|
|
|
+ const res = await A5_APIdel(id);
|
|
|
+ if (res.code === 0) {
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
+ getListFu();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [getListFu]
|
|
|
+ );
|
|
|
|
|
|
// 点击 上移 和下移
|
|
|
const sortMoveFu = useCallback(
|
|
@@ -104,19 +111,34 @@ function A5Section() {
|
|
|
},
|
|
|
{
|
|
|
title: "同级排序",
|
|
|
- dataIndex: "sort",
|
|
|
+ render: (item: A5TableType) =>
|
|
|
+ item.name === "未分类" ? "-" : item.level + "级 - " + item.sort,
|
|
|
},
|
|
|
{
|
|
|
title: "操作",
|
|
|
render: (item: A5TableType, _: any, index: number) => (
|
|
|
<>
|
|
|
- <Button size="small" type="text" onClick={() => addTree(item)}>
|
|
|
- 新增子部门
|
|
|
- </Button>
|
|
|
- <Button size="small" type="text">
|
|
|
+ {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 ? null : (
|
|
|
+ {index !== 0 && item.name !== "未分类" ? (
|
|
|
<Button
|
|
|
size="small"
|
|
|
type="text"
|
|
@@ -124,9 +146,10 @@ function A5Section() {
|
|
|
>
|
|
|
上移
|
|
|
</Button>
|
|
|
- )}
|
|
|
+ ) : null}
|
|
|
|
|
|
- {sonArrFu(item.parentId).length - 1 === index ? null : (
|
|
|
+ {sonArrFu(item.parentId).length - 1 !== index &&
|
|
|
+ item.name !== "未分类" ? (
|
|
|
<Button
|
|
|
size="small"
|
|
|
type="text"
|
|
@@ -134,44 +157,67 @@ function A5Section() {
|
|
|
>
|
|
|
下移
|
|
|
</Button>
|
|
|
- )}
|
|
|
-
|
|
|
- <Popconfirm
|
|
|
- title="删除后无法恢复,是否删除?"
|
|
|
- okText="删除"
|
|
|
- cancelText="取消"
|
|
|
- onConfirm={() => delById(item.id)}
|
|
|
- okButtonProps={{ loading: false }}
|
|
|
- >
|
|
|
- <Button size="small" type="text" danger>
|
|
|
- 删除
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
+ ) : null}
|
|
|
+
|
|
|
+ {item.name !== "未分类" ? (
|
|
|
+ <Popconfirm
|
|
|
+ title="删除后无法恢复,是否删除?"
|
|
|
+ okText="删除"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => delById(item.id)}
|
|
|
+ okButtonProps={{ loading: false }}
|
|
|
+ >
|
|
|
+ <Button size="small" type="text" danger>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ ) : null}
|
|
|
</>
|
|
|
),
|
|
|
},
|
|
|
];
|
|
|
- }, [addTree, delById, sonArrFu, sortMoveFu]);
|
|
|
+ }, [delById, sonArrFu, sortMoveFu]);
|
|
|
+
|
|
|
+ // 新增和编辑
|
|
|
+ const [addInfo, setAddInfo] = useState({} as A5TableType);
|
|
|
|
|
|
return (
|
|
|
<div className={styles.A5Section}>
|
|
|
<div className="pageTitle">部门管理</div>
|
|
|
<div className="A5Main">
|
|
|
<div className="A5Top">
|
|
|
- <Button type="primary">新增</Button>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={() =>
|
|
|
+ setAddInfo({ id: "-1", parentId: "0" } as A5TableType)
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 新增
|
|
|
+ </Button>
|
|
|
</div>
|
|
|
|
|
|
{/* 表格主体 */}
|
|
|
<div className="A5tableBox">
|
|
|
- <Table
|
|
|
- scroll={{ y: 575 }}
|
|
|
- dataSource={tableList}
|
|
|
- columns={columns}
|
|
|
- rowKey="id"
|
|
|
- pagination={false}
|
|
|
- />
|
|
|
+ {tableList.length ? (
|
|
|
+ <Table
|
|
|
+ scroll={{ y: 750 }}
|
|
|
+ dataSource={tableList}
|
|
|
+ columns={columns}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={false}
|
|
|
+ expandable={{ defaultExpandAllRows: true }}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
</div>
|
|
|
+
|
|
|
+ {addInfo.id ? (
|
|
|
+ <A5Add
|
|
|
+ info={addInfo}
|
|
|
+ closeFu={() => setAddInfo({} as A5TableType)}
|
|
|
+ addFu={() => getListFu()}
|
|
|
+ />
|
|
|
+ ) : null}
|
|
|
</div>
|
|
|
);
|
|
|
}
|