|
@@ -1,21 +1,26 @@
|
|
import React, { useCallback, useMemo } from "react";
|
|
import React, { useCallback, useMemo } from "react";
|
|
-import styles from "./index.module.scss";
|
|
|
|
import { Button, Popconfirm, Table } from "antd";
|
|
import { Button, Popconfirm, Table } from "antd";
|
|
import { useSelector } from "react-redux";
|
|
import { useSelector } from "react-redux";
|
|
import { RootState } from "@/store";
|
|
import { RootState } from "@/store";
|
|
import { A2_APIdel, A2_APIsort } from "@/store/action/A2Dict";
|
|
import { A2_APIdel, A2_APIsort } from "@/store/action/A2Dict";
|
|
import { MessageFu } from "@/utils/message";
|
|
import { MessageFu } from "@/utils/message";
|
|
import { A5TableType } from "@/types";
|
|
import { A5TableType } from "@/types";
|
|
|
|
+import { A5_APIdel, A5_APIsort } from "@/store/action/A5Section";
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
editFu: (item: A5TableType) => void;
|
|
editFu: (item: A5TableType) => void;
|
|
upTaleFu: () => void;
|
|
upTaleFu: () => void;
|
|
- type: "job" | "status";
|
|
|
|
|
|
+ myType: "字典" | "部门";
|
|
};
|
|
};
|
|
|
|
|
|
-function A2Table3({ editFu, upTaleFu, type }: Props) {
|
|
|
|
|
|
+function A2Table3({ editFu, upTaleFu, myType }: Props) {
|
|
// 获取表格数据
|
|
// 获取表格数据
|
|
- const tableList = useSelector((state: RootState) => state.A2Dict.A2Tab1_2Arr);
|
|
|
|
|
|
+ const arr1 = useSelector((state: RootState) => state.A2Dict.A2Tab1_2Arr);
|
|
|
|
+ const arr2 = useSelector((state: RootState) => state.A5Section.tableList);
|
|
|
|
+ const tableList = useMemo(() => {
|
|
|
|
+ if (myType === "字典") return arr1;
|
|
|
|
+ else return arr2;
|
|
|
|
+ }, [arr1, arr2, myType]);
|
|
|
|
|
|
// 树型数组扁平化
|
|
// 树型数组扁平化
|
|
const arrAllArr = useMemo(() => {
|
|
const arrAllArr = useMemo(() => {
|
|
@@ -53,38 +58,41 @@ function A2Table3({ editFu, upTaleFu, type }: Props) {
|
|
[arrAllArr]
|
|
[arrAllArr]
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ // 点击删除
|
|
|
|
+ const delById = useCallback(
|
|
|
|
+ async (id: string) => {
|
|
|
|
+ const res = myType === "字典" ? await A2_APIdel(id) : await A5_APIdel(id);
|
|
|
|
+ if (res.code === 0) {
|
|
|
|
+ MessageFu.success("删除成功!");
|
|
|
|
+ upTaleFu();
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ [myType, upTaleFu]
|
|
|
|
+ );
|
|
|
|
+
|
|
// 点击 上移 和下移
|
|
// 点击 上移 和下移
|
|
const sortMoveFu = useCallback(
|
|
const sortMoveFu = useCallback(
|
|
async (flag: 1 | -1, index: number, oldId: string, fId: string) => {
|
|
async (flag: 1 | -1, index: number, oldId: string, fId: string) => {
|
|
const arr = sonArrFu(fId);
|
|
const arr = sonArrFu(fId);
|
|
const newId = arr[index + flag].id;
|
|
const newId = arr[index + flag].id;
|
|
|
|
|
|
- const res = await A2_APIsort(oldId, newId);
|
|
|
|
|
|
+ const res =
|
|
|
|
+ myType === "字典"
|
|
|
|
+ ? await A2_APIsort(oldId, newId)
|
|
|
|
+ : await A5_APIsort(oldId, newId);
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
upTaleFu();
|
|
upTaleFu();
|
|
MessageFu.success("排序修改成功!");
|
|
MessageFu.success("排序修改成功!");
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- [upTaleFu, sonArrFu]
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // 点击删除
|
|
|
|
- const delById = useCallback(
|
|
|
|
- async (id: string) => {
|
|
|
|
- const res = await A2_APIdel(id);
|
|
|
|
- if (res.code === 0) {
|
|
|
|
- MessageFu.success("删除成功!");
|
|
|
|
- upTaleFu();
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- [upTaleFu]
|
|
|
|
|
|
+ [sonArrFu, myType, upTaleFu]
|
|
);
|
|
);
|
|
|
|
|
|
const columns = useMemo(() => {
|
|
const columns = useMemo(() => {
|
|
return [
|
|
return [
|
|
{
|
|
{
|
|
- title: <>  部门名称</>,
|
|
|
|
|
|
+ title: <>  {myType === "字典" ? "字典值" : "部门名称"}</>,
|
|
dataIndex: "name",
|
|
dataIndex: "name",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
@@ -104,8 +112,8 @@ function A2Table3({ editFu, upTaleFu, type }: Props) {
|
|
},
|
|
},
|
|
{
|
|
{
|
|
title: "同级排序",
|
|
title: "同级排序",
|
|
- render: (item: A5TableType) =>
|
|
|
|
- item.name === "未分类" ? "-" : item.level + "级 - " + item.sort,
|
|
|
|
|
|
+ render: (item: A5TableType, _: any, index: number) =>
|
|
|
|
+ item.name === "未分类" ? "-" : item.level + "级 - " + (index + 1),
|
|
},
|
|
},
|
|
{
|
|
{
|
|
title: "操作",
|
|
title: "操作",
|
|
@@ -169,12 +177,14 @@ function A2Table3({ editFu, upTaleFu, type }: Props) {
|
|
),
|
|
),
|
|
},
|
|
},
|
|
];
|
|
];
|
|
- }, [delById, editFu, sonArrFu, sortMoveFu]);
|
|
|
|
|
|
+ }, [delById, editFu, myType, sonArrFu, sortMoveFu]);
|
|
|
|
|
|
return (
|
|
return (
|
|
- <div className={styles.A2Table3}>
|
|
|
|
|
|
+ <div id="A2Table3">
|
|
{tableList.length ? (
|
|
{tableList.length ? (
|
|
<Table
|
|
<Table
|
|
|
|
+ size={myType === "字典" ? "small" : "large"}
|
|
|
|
+ scroll={{ y: myType === "字典" ? 750 : "null" }}
|
|
dataSource={tableList}
|
|
dataSource={tableList}
|
|
columns={columns}
|
|
columns={columns}
|
|
rowKey="id"
|
|
rowKey="id"
|