|
@@ -1,14 +1,22 @@
|
|
|
-import React, { useState } from "react";
|
|
|
-import { Layout, Menu, Button, Descriptions, Input, Tooltip } from "antd";
|
|
|
+import React, { useMemo, useRef, useState } from "react";
|
|
|
+import { Layout, Menu, Button, Descriptions, Input, Tooltip, Empty } from "antd";
|
|
|
import type { DescriptionsProps, MenuProps } from "antd";
|
|
|
import { PlusOutlined, SearchOutlined } from "@ant-design/icons";
|
|
|
import TableEdit from "@/components/TableEdit";
|
|
|
import ER from "./components/ER";
|
|
|
+import AddTable from "./components/AddTable";
|
|
|
+import { useModel } from "umi";
|
|
|
+import NoData from "@/assets/no-data.png";
|
|
|
+import { TableItemType } from "@/type";
|
|
|
|
|
|
const { Content, Header } = Layout;
|
|
|
export default function index() {
|
|
|
const [active, setActive] = useState(0);
|
|
|
const [showNavigator, setShowNavigator] = useState(false);
|
|
|
+ const addTableRef = useRef<{open: () => void}>();
|
|
|
+ const { project } = useModel("erModel");
|
|
|
+ const [searchKeyword, setSearchKeyword] = useState("");
|
|
|
+
|
|
|
const descItems: DescriptionsProps["items"] = [
|
|
|
{
|
|
|
key: "1",
|
|
@@ -47,35 +55,37 @@ export default function index() {
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- const tableData: MenuProps["items"] = [
|
|
|
- {
|
|
|
- key: "1",
|
|
|
- label: "user_info(用户信息表)",
|
|
|
- icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
- children: [
|
|
|
- {
|
|
|
- key: "1-1",
|
|
|
- label: "user_xxx(xxx子表)",
|
|
|
- icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
- },
|
|
|
- {
|
|
|
- key: "1-2",
|
|
|
- label: "user_xxx(xxx子表)",
|
|
|
- icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
- {
|
|
|
- key: "2",
|
|
|
- label: "xxxx主表2",
|
|
|
- icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
- },
|
|
|
- {
|
|
|
- key: "3",
|
|
|
- label: "xxxx主表2",
|
|
|
- icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
- },
|
|
|
- ];
|
|
|
+ const tableData: MenuProps["items"] = useMemo(() => {
|
|
|
+ const { tables } = project;
|
|
|
+ const treeList: {
|
|
|
+ key: string;
|
|
|
+ label: string | React.ReactNode;
|
|
|
+ icon: React.ReactNode;
|
|
|
+ children: MenuProps["items"];
|
|
|
+ }[] = [];
|
|
|
+
|
|
|
+ tables.forEach((item) => {
|
|
|
+ const newItem = {
|
|
|
+ key: item.table.id,
|
|
|
+ label: item.table.langNameList?.find((item) => item.label === "zh-CN")?.value,
|
|
|
+ icon: <i className="iconfont icon-biaogebeifen" />,
|
|
|
+ children: []
|
|
|
+ };
|
|
|
+ if(!item.table.parentBusinessTableId) {
|
|
|
+ treeList.push(newItem);
|
|
|
+ } else {
|
|
|
+ const parent = treeList.find(tableItem => tableItem?.key === item.table.parentBusinessTableId);
|
|
|
+ if(parent) {
|
|
|
+ parent.children?.push(newItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return treeList;
|
|
|
+ }, [project]);
|
|
|
+
|
|
|
+ const handleAddTable = (tableItem: TableItemType) => {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
const extra = (
|
|
|
<div className="flex gap-12px">
|
|
@@ -97,6 +107,7 @@ export default function index() {
|
|
|
</a>
|
|
|
</div>
|
|
|
);
|
|
|
+
|
|
|
return (
|
|
|
<Layout className="h-100vh flex flex-col bg-#fafafa p-12px">
|
|
|
<Header
|
|
@@ -114,7 +125,7 @@ export default function index() {
|
|
|
title={
|
|
|
<span>
|
|
|
<svg className="iconfont w-14px h-14px m-r-4px">
|
|
|
- <use xlinkHref="#icon-model" />
|
|
|
+ <use xlinkHref="#icon-shujumoxing" />
|
|
|
</svg>
|
|
|
模型详情
|
|
|
</span>
|
|
@@ -148,21 +159,25 @@ export default function index() {
|
|
|
</div>
|
|
|
<div>
|
|
|
<Input
|
|
|
- size="small"
|
|
|
placeholder="搜索"
|
|
|
className="w-100px m-r-4px"
|
|
|
suffix={<SearchOutlined />}
|
|
|
+ value={searchKeyword}
|
|
|
+ onChange={(e) => setSearchKeyword(e.target.value)}
|
|
|
/>
|
|
|
<Tooltip title="添加数据表">
|
|
|
<Button
|
|
|
- size="small"
|
|
|
type="primary"
|
|
|
icon={<PlusOutlined />}
|
|
|
+ onClick={() => addTableRef.current?.open()}
|
|
|
></Button>
|
|
|
</Tooltip>
|
|
|
</div>
|
|
|
</div>
|
|
|
<Menu mode="inline" items={tableData} />
|
|
|
+ {
|
|
|
+ !tableData.length && <Empty image={NoData} description="点击+添加数据表!" />
|
|
|
+ }
|
|
|
</div>
|
|
|
<div className="right flex-1 h-full shadow-sm bg-#fff rounded-8px p-12px flex flex-col">
|
|
|
<div className="head flex justify-between">
|
|
@@ -216,6 +231,7 @@ export default function index() {
|
|
|
</div>
|
|
|
</div>
|
|
|
</Content>
|
|
|
+ <AddTable ref={addTableRef} onChange={handleAddTable}/>
|
|
|
</Layout>
|
|
|
);
|
|
|
}
|