|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useEffect, useRef, useState } from "react";
|
|
|
+import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
|
import { ProTable, PageContainer } from "@ant-design/pro-components";
|
|
|
import {
|
|
|
Card,
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
Tree,
|
|
|
Dropdown,
|
|
|
message,
|
|
|
+ TreeDataNode,
|
|
|
+ Tag,
|
|
|
} from "antd";
|
|
|
import type { MenuProps } from "antd";
|
|
|
import { Icon, useRequest } from "umi";
|
|
@@ -27,13 +29,14 @@ import {
|
|
|
EditFolder,
|
|
|
DeleteFolder,
|
|
|
Move,
|
|
|
+ GetAllFolders,
|
|
|
} from "@/api/systemDesigner";
|
|
|
import ProjectCard from "./ProjectCard";
|
|
|
import { graphOptions } from "./data";
|
|
|
import { GraphType } from "@/enum";
|
|
|
import DragItem from "./DragItem";
|
|
|
import DropItem from "./DropItem";
|
|
|
-import { createNew } from "@/utils";
|
|
|
+import { createNew, listToTree } from "@/utils";
|
|
|
|
|
|
type BreadcrumbItem = {
|
|
|
title: React.ReactNode;
|
|
@@ -43,20 +46,25 @@ type BreadcrumbItem = {
|
|
|
};
|
|
|
export default function All({
|
|
|
onChangeCurrentFolder,
|
|
|
+ updateKey,
|
|
|
}: {
|
|
|
onChangeCurrentFolder: (id: string) => void;
|
|
|
+ updateKey: number;
|
|
|
}) {
|
|
|
const [display, setDisplay] = useState("card");
|
|
|
const [folderData, setFolderData] = useState<any[]>([]);
|
|
|
const [dataSource, setDataSource] = useState<any[]>([]);
|
|
|
const [total, setTotal] = useState(0);
|
|
|
const [searchName, setSearchName] = useState("");
|
|
|
+ const [graphType, setGraphType] = useState<GraphType | ''>('');
|
|
|
const [currentPage, setCurrentPage] = useState(1);
|
|
|
const [pageSize, setPageSize] = useState(12);
|
|
|
const [open, setOpen] = useState(false);
|
|
|
const currentFolder = useRef("root");
|
|
|
const { confirm } = Modal;
|
|
|
const moveSource = useRef<{ id: string; type: "folder" | "chart" }>();
|
|
|
+ const [folderList, setFolderList] = useState<any[]>([]);
|
|
|
+ const [selectFolder, setSelectFolder] = useState("");
|
|
|
|
|
|
const { loading, run, refresh } = useRequest(FlowchartMindMapList, {
|
|
|
defaultParams: [
|
|
@@ -83,6 +91,16 @@ export default function All({
|
|
|
},
|
|
|
});
|
|
|
|
|
|
+ useRequest(GetAllFolders, {
|
|
|
+ onSuccess: (res) => {
|
|
|
+ setFolderList(res?.result || []);
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ updateKey && getData(1, pageSize);
|
|
|
+ }, [updateKey]);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
onChangeCurrentFolder(currentFolder.current);
|
|
|
}, [currentFolder.current]);
|
|
@@ -118,7 +136,7 @@ export default function All({
|
|
|
useState<BreadcrumbItem[]>(defultData);
|
|
|
const breadcrumbDataRef = useRef<BreadcrumbItem[]>(breadcrumbData);
|
|
|
|
|
|
- const getData = (page: number, pageSize: number) => {
|
|
|
+ const getData = (page: number, pageSize: number, type?: GraphType | '') => {
|
|
|
setCurrentPage(page);
|
|
|
setPageSize(pageSize);
|
|
|
run({
|
|
@@ -133,6 +151,10 @@ export default function All({
|
|
|
name: "folderId",
|
|
|
value: currentFolder.current,
|
|
|
},
|
|
|
+ {
|
|
|
+ name: "type",
|
|
|
+ value: type !== undefined ? type : graphType,
|
|
|
+ },
|
|
|
],
|
|
|
});
|
|
|
};
|
|
@@ -145,24 +167,46 @@ export default function All({
|
|
|
);
|
|
|
};
|
|
|
|
|
|
- const folderTreeData = [
|
|
|
- {
|
|
|
- key: "1",
|
|
|
- title: (
|
|
|
- <span>
|
|
|
- 我的文件<span className="text-12px color-#999">(当前)</span>
|
|
|
- </span>
|
|
|
+ const root = {
|
|
|
+ id: "root",
|
|
|
+ name: "我的文件",
|
|
|
+ key: "root",
|
|
|
+ title: (
|
|
|
+ <span>
|
|
|
+ 我的文件
|
|
|
+ {currentFolder.current === "root" ? (
|
|
|
+ <span className="text-12px color-#999">(当前)</span>
|
|
|
+ ) : null}
|
|
|
+ </span>
|
|
|
+ ),
|
|
|
+ icon: <FolderIcon />,
|
|
|
+ parentId: "",
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+
|
|
|
+ // 构建文件夹树
|
|
|
+ const folderTreeData = useMemo((): TreeDataNode[] => {
|
|
|
+ return [
|
|
|
+ listToTree(
|
|
|
+ folderList.map((item) => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ key: item.id,
|
|
|
+ title: (
|
|
|
+ <span>
|
|
|
+ {item.name}
|
|
|
+ {currentFolder.current === item.id ? (
|
|
|
+ <span className="text-12px color-#999">(当前)</span>
|
|
|
+ ) : null}
|
|
|
+ </span>
|
|
|
+ ),
|
|
|
+ icon: <FolderIcon />,
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ root
|
|
|
),
|
|
|
- icon: <FolderIcon />,
|
|
|
- children: [
|
|
|
- {
|
|
|
- key: "1-1",
|
|
|
- title: "文件夹1",
|
|
|
- icon: <FolderIcon />,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- ];
|
|
|
+ ] as unknown as TreeDataNode[];
|
|
|
+ }, [folderList, currentFolder.current]);
|
|
|
|
|
|
const contextMenu: MenuProps["items"] = [
|
|
|
{
|
|
@@ -201,7 +245,7 @@ export default function All({
|
|
|
icon: <Icon icon="local:flow" width="22px" />,
|
|
|
onClick: () => {
|
|
|
createNew(GraphType.flowchart, currentFolder.current);
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
key: "3",
|
|
@@ -209,7 +253,7 @@ export default function All({
|
|
|
icon: <Icon icon="local:mind" width="22px" />,
|
|
|
onClick: () => {
|
|
|
createNew(GraphType.mindmap, currentFolder.current);
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
];
|
|
|
|
|
@@ -248,7 +292,10 @@ export default function All({
|
|
|
};
|
|
|
|
|
|
// 搜索图形类型
|
|
|
- const setSearchGraphType = (type: GraphType) => {};
|
|
|
+ const setSearchGraphType = (type: GraphType | '') => {
|
|
|
+ setGraphType(type);
|
|
|
+ getData(1, pageSize, type);
|
|
|
+ };
|
|
|
|
|
|
const handleOpenFolderModal = (id: string, type: "folder" | "chart") => {
|
|
|
moveSource.current = {
|
|
@@ -263,10 +310,12 @@ export default function All({
|
|
|
id,
|
|
|
type,
|
|
|
};
|
|
|
+ setOpen(false);
|
|
|
};
|
|
|
|
|
|
const handleMove = (targetFolderId: string) => {
|
|
|
- if (!moveSource.current || targetFolderId === moveSource.current?.id) return;
|
|
|
+ if (!moveSource.current || targetFolderId === moveSource.current?.id)
|
|
|
+ return;
|
|
|
Move({
|
|
|
fileType: moveSource.current.type,
|
|
|
fileId: moveSource.current.id,
|
|
@@ -277,6 +326,10 @@ export default function All({
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const handleCopy = (targetFolderId: string) => {
|
|
|
+ // TODO: 复制
|
|
|
+ };
|
|
|
+
|
|
|
const clearMoveSource = () => {
|
|
|
moveSource.current = undefined;
|
|
|
};
|
|
@@ -285,23 +338,38 @@ export default function All({
|
|
|
<>
|
|
|
<PageContainer
|
|
|
extra={[
|
|
|
- <Dropdown
|
|
|
- key="1"
|
|
|
- menu={{
|
|
|
- items: graphOptions.map((item) => {
|
|
|
- return {
|
|
|
- key: item.key,
|
|
|
- label: item.label,
|
|
|
- value: item.value,
|
|
|
- onClick: () => {
|
|
|
- setSearchGraphType(item.value);
|
|
|
- },
|
|
|
- };
|
|
|
- }),
|
|
|
- }}
|
|
|
- >
|
|
|
- <Button key="1" icon={<i className="iconfont icon-shaixuan" />} />
|
|
|
- </Dropdown>,
|
|
|
+ <span key="1">
|
|
|
+ {graphType ? (
|
|
|
+ <Tag
|
|
|
+ color="#108ee9"
|
|
|
+ closable
|
|
|
+ onClose={() => setSearchGraphType('')}
|
|
|
+ >
|
|
|
+ { graphOptions.find(item => item.value === graphType)?.label}
|
|
|
+ </Tag>
|
|
|
+ ) : (
|
|
|
+ <Dropdown
|
|
|
+ key="1"
|
|
|
+ menu={{
|
|
|
+ items: graphOptions.map((item) => {
|
|
|
+ return {
|
|
|
+ key: item.key,
|
|
|
+ label: item.label,
|
|
|
+ value: item.value,
|
|
|
+ onClick: () => {
|
|
|
+ setSearchGraphType(item.value);
|
|
|
+ },
|
|
|
+ };
|
|
|
+ }),
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Button
|
|
|
+ key="1"
|
|
|
+ icon={<i className="iconfont icon-shaixuan" />}
|
|
|
+ />
|
|
|
+ </Dropdown>
|
|
|
+ )}
|
|
|
+ </span>,
|
|
|
<Button
|
|
|
key="2"
|
|
|
onClick={() => {
|
|
@@ -412,7 +480,10 @@ export default function All({
|
|
|
key: "2",
|
|
|
label: "移动或复制",
|
|
|
onClick: () => {
|
|
|
- handleOpenFolderModal(item.id, 'folder');
|
|
|
+ handleOpenFolderModal(
|
|
|
+ item.id,
|
|
|
+ "folder"
|
|
|
+ );
|
|
|
},
|
|
|
},
|
|
|
{
|
|
@@ -438,7 +509,10 @@ export default function All({
|
|
|
},
|
|
|
}}
|
|
|
>
|
|
|
- <MoreOutlined className="hidden group-hover/item:inline-block" onClick={(e) => e.stopPropagation()} />
|
|
|
+ <MoreOutlined
|
|
|
+ className="hidden group-hover/item:inline-block"
|
|
|
+ onClick={(e) => e.stopPropagation()}
|
|
|
+ />
|
|
|
</Dropdown>
|
|
|
</span>
|
|
|
}
|
|
@@ -477,7 +551,9 @@ export default function All({
|
|
|
record={item}
|
|
|
onFresh={refresh}
|
|
|
onDelete={refresh}
|
|
|
- onChangeLocation={() => handleOpenFolderModal(item.id, 'chart')}
|
|
|
+ onChangeLocation={() =>
|
|
|
+ handleOpenFolderModal(item.id, "chart")
|
|
|
+ }
|
|
|
/>
|
|
|
</DragItem>
|
|
|
</Col>
|
|
@@ -540,7 +616,10 @@ export default function All({
|
|
|
title="移动/复制到"
|
|
|
width={440}
|
|
|
open={open}
|
|
|
- onCancel={() => setOpen(false)}
|
|
|
+ onCancel={() => {
|
|
|
+ setOpen(false);
|
|
|
+ setSelectFolder("");
|
|
|
+ }}
|
|
|
centered
|
|
|
footer={
|
|
|
<div>
|
|
@@ -550,18 +629,26 @@ export default function All({
|
|
|
<Button
|
|
|
className="m-r-8px"
|
|
|
type="primary"
|
|
|
- onClick={() => setOpen(false)}
|
|
|
+ onClick={() => handleMove(selectFolder)}
|
|
|
+ disabled={selectFolder === currentFolder.current}
|
|
|
>
|
|
|
移动
|
|
|
</Button>
|
|
|
- <Button type="primary" onClick={() => setOpen(false)}>
|
|
|
+ {/* <Button type="primary" onClick={() => handleCopy(selectFolder)}>
|
|
|
复制
|
|
|
- </Button>
|
|
|
+ </Button> */}
|
|
|
</div>
|
|
|
}
|
|
|
>
|
|
|
<div className="min-h-300px">
|
|
|
- <Tree treeData={folderTreeData} showIcon blockNode />
|
|
|
+ <Tree
|
|
|
+ treeData={folderTreeData}
|
|
|
+ selectedKeys={[selectFolder]}
|
|
|
+ onSelect={(keys) => setSelectFolder(keys[0] as string)}
|
|
|
+ showIcon
|
|
|
+ blockNode
|
|
|
+ autoExpandParent
|
|
|
+ />
|
|
|
</div>
|
|
|
</Modal>
|
|
|
</>
|