index.tsx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import React, { useEffect } from "react";
  2. import { Input, Layout, Tabs, ConfigProvider, Spin } from "antd";
  3. import type { TabsProps } from "antd/lib";
  4. import Toolbar from "./components/Toolbar";
  5. import TablePanel from "./components/TablePanel";
  6. import RelationPanel from "./components/RelationPanel";
  7. import ThemePanel from "./components/ThemePanel";
  8. import RemarkPanel from "./components/RemarkPanel";
  9. import Navigator from "./components/Navigator";
  10. import Menu from "./components/Menu";
  11. import { useModel, useRequest, useParams } from "umi";
  12. import "./index.less";
  13. import { useSessionStorageState } from "ahooks";
  14. import { EnvironmentOutlined, FullscreenExitOutlined, UnorderedListOutlined } from "@ant-design/icons";
  15. import { GetDataModelDetail } from "@/api";
  16. const { Header, Content, Sider } = Layout;
  17. const App: React.FC = () => {
  18. const containerRef = React.useRef(null);
  19. const { initGraph, project, playModeEnable, exitPlayMode, setProject } =
  20. useModel("erModel");
  21. const [tabActiveKey, setTabActiveKey] = useSessionStorageState(
  22. "tabs-active-key",
  23. {
  24. defaultValue: "1",
  25. listenStorageChange: true,
  26. }
  27. );
  28. const [show, setShow] = useSessionStorageState('show-navigator');
  29. const params = useParams();
  30. const { run, loading } = useRequest(GetDataModelDetail, {
  31. manual: true,
  32. onSuccess: (res) => {
  33. console.log("模型详情:", res);
  34. const result = res?.result;
  35. if (result) {
  36. setProject(
  37. result,
  38. false,
  39. true
  40. );
  41. }
  42. },
  43. });
  44. useEffect(() => {
  45. if (containerRef.current) {
  46. initGraph(containerRef.current);
  47. }
  48. if(!project.id && params?.id) {
  49. run({
  50. id: params.id
  51. });
  52. }
  53. }, []);
  54. const tabItems: TabsProps["items"] = [
  55. {
  56. key: "1",
  57. label: "表",
  58. children: <TablePanel />,
  59. },
  60. {
  61. key: "2",
  62. label: "关系",
  63. children: <RelationPanel />,
  64. },
  65. {
  66. key: "3",
  67. label: "主题区域",
  68. children: <ThemePanel />,
  69. },
  70. {
  71. key: "4",
  72. label: "注释",
  73. children: <RemarkPanel />,
  74. },
  75. ];
  76. return (
  77. <Spin spinning={loading}>
  78. <Layout className="h-100vh">
  79. {!playModeEnable && (
  80. <Header
  81. className="bg-white h-100px border-b-1px border-b-solid border-b-gray-200 p-x-0 flex flex-col"
  82. style={{
  83. height: project.setting.showMenu ? "100px" : "32px",
  84. transition: "all 0.3s ease-in-out",
  85. }}
  86. >
  87. <div
  88. className="grid"
  89. style={{
  90. gridTemplateRows: project.setting.showMenu ? "1fr" : "0fr",
  91. transition: "all 0.3s",
  92. }}
  93. >
  94. <div className="overflow-hidden">
  95. <Menu />
  96. </div>
  97. </div>
  98. <Toolbar />
  99. </Header>
  100. )}
  101. <Layout>
  102. {!playModeEnable && (
  103. <Sider
  104. width={project.setting.showSidebar ? 360 : 0}
  105. style={{ background: "#fff", borderRight: "1px solid #eee" }}
  106. >
  107. <ConfigProvider
  108. theme={{
  109. components: {
  110. Tabs: {
  111. colorPrimary: "#000",
  112. },
  113. },
  114. }}
  115. >
  116. <Tabs
  117. animated
  118. activeKey={tabActiveKey}
  119. onChange={setTabActiveKey}
  120. items={tabItems}
  121. centered
  122. />
  123. </ConfigProvider>
  124. </Sider>
  125. )}
  126. <Layout>
  127. <Content>
  128. <div id="graph-container" ref={containerRef}></div>
  129. <Navigator key="editor"/>
  130. {
  131. playModeEnable && <div className="absolute top-32px right-32px z-2">
  132. <div className="left bg-#fff shadow-md p-x-4px p-y-4px flex items-center gap-8px">
  133. <div
  134. className="
  135. rounded-4px
  136. cus-btn
  137. w-32px
  138. h-32px
  139. bg-#eee
  140. flex-none
  141. text-center
  142. leading-32px
  143. cursor-pointer
  144. hover:bg-#ddd"
  145. >
  146. <UnorderedListOutlined />
  147. </div>
  148. <div
  149. className="
  150. rounded-4px
  151. cus-btn
  152. w-32px
  153. h-32px
  154. bg-#eee
  155. flex-none
  156. text-center
  157. leading-32px
  158. cursor-pointer
  159. hover:bg-#ddd"
  160. >
  161. <EnvironmentOutlined onClick={() => setShow(!show)}/>
  162. </div>
  163. <div
  164. className="
  165. rounded-4px
  166. cus-btn
  167. w-32px
  168. h-32px
  169. bg-#eee
  170. flex-none
  171. text-center
  172. leading-32px
  173. cursor-pointer
  174. hover:bg-#ddd"
  175. onClick={() => exitPlayMode()}
  176. >
  177. <FullscreenExitOutlined />
  178. </div>
  179. </div>
  180. </div>
  181. }
  182. </Content>
  183. </Layout>
  184. </Layout>
  185. </Layout>
  186. </Spin>
  187. );
  188. };
  189. export default App;