|
@@ -8,6 +8,10 @@ import { Export } from "@antv/x6-plugin-export";
|
|
import { Selection } from "@antv/x6-plugin-selection";
|
|
import { Selection } from "@antv/x6-plugin-selection";
|
|
import { GetAllDesignTables } from "@/api";
|
|
import { GetAllDesignTables } from "@/api";
|
|
import { useRequest } from "umi";
|
|
import { useRequest } from "umi";
|
|
|
|
+import { useFullscreen } from "ahooks";
|
|
|
|
+import { throttle } from "lodash-es";
|
|
|
|
+import { createTable } from "@/utils";
|
|
|
|
+
|
|
import type {
|
|
import type {
|
|
ColumnItem,
|
|
ColumnItem,
|
|
ColumnRelation,
|
|
ColumnRelation,
|
|
@@ -16,7 +20,7 @@ import type {
|
|
TableItemType,
|
|
TableItemType,
|
|
TopicAreaInfo,
|
|
TopicAreaInfo,
|
|
} from "@/type";
|
|
} from "@/type";
|
|
-import { uuid } from "@/utils";
|
|
|
|
|
|
+import { createColumn, uuid } from "@/utils";
|
|
import { DataType, RelationLineType, RelationType } from "@/enum";
|
|
import { DataType, RelationLineType, RelationType } from "@/enum";
|
|
import { render } from "./renderer";
|
|
import { render } from "./renderer";
|
|
import { useSessionStorageState } from "ahooks";
|
|
import { useSessionStorageState } from "ahooks";
|
|
@@ -31,6 +35,8 @@ export default function erModel() {
|
|
const [graph, setGraph] = useState<Graph>();
|
|
const [graph, setGraph] = useState<Graph>();
|
|
const historyRef = useRef<ProjectInfo[]>([]);
|
|
const historyRef = useRef<ProjectInfo[]>([]);
|
|
const activeIndex = useRef(0);
|
|
const activeIndex = useRef(0);
|
|
|
|
+ const [_isFullscreen, { enterFullscreen, exitFullscreen }] = useFullscreen(document.body);
|
|
|
|
+ const [playModeEnable, setPlayModeEnable] = useState(false);
|
|
const [project, setProjectInfo] = useState<ProjectInfo>({
|
|
const [project, setProjectInfo] = useState<ProjectInfo>({
|
|
id: "1",
|
|
id: "1",
|
|
name: "项目1",
|
|
name: "项目1",
|
|
@@ -44,7 +50,6 @@ export default function erModel() {
|
|
relations: [],
|
|
relations: [],
|
|
topicAreas: [],
|
|
topicAreas: [],
|
|
remarkInfos: [],
|
|
remarkInfos: [],
|
|
- history: [],
|
|
|
|
todos: [],
|
|
todos: [],
|
|
setting: {
|
|
setting: {
|
|
showMenu: true,
|
|
showMenu: true,
|
|
@@ -121,7 +126,6 @@ export default function erModel() {
|
|
* @param container
|
|
* @param container
|
|
*/
|
|
*/
|
|
const initGraph = (container: HTMLElement, width?: number, height?: number) => {
|
|
const initGraph = (container: HTMLElement, width?: number, height?: number) => {
|
|
- console.log(container.clientWidth, container.clientHeight);
|
|
|
|
const instance = new Graph({
|
|
const instance = new Graph({
|
|
container,
|
|
container,
|
|
width: width || document.documentElement.clientWidth,
|
|
width: width || document.documentElement.clientWidth,
|
|
@@ -238,6 +242,45 @@ export default function erModel() {
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
|
|
+ instance.on("node:change:position", throttle((args) => {
|
|
|
|
+ console.log(args);
|
|
|
|
+ const data = args.node.data;
|
|
|
|
+ const current = args.current;
|
|
|
|
+ if(data.isTable) {
|
|
|
|
+ updateTable({
|
|
|
|
+ ...data,
|
|
|
|
+ table: {
|
|
|
|
+ ...data.table,
|
|
|
|
+ style: {
|
|
|
|
+ ...data.table.style,
|
|
|
|
+ x: current.x,
|
|
|
|
+ y: current.y,
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ if(data.isTopicArea) {
|
|
|
|
+ updateTopicArea({
|
|
|
|
+ ...data,
|
|
|
|
+ style: {
|
|
|
|
+ ...data.style,
|
|
|
|
+ x: current.x,
|
|
|
|
+ y: current.y,
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ if(data.isRemark) {
|
|
|
|
+ updateRemark({
|
|
|
|
+ ...data,
|
|
|
|
+ style: {
|
|
|
|
+ ...data.style,
|
|
|
|
+ x: current.x,
|
|
|
|
+ y: current.y,
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }, 500));
|
|
|
|
+
|
|
instance.bindKey("ctrl+z", onUndo);
|
|
instance.bindKey("ctrl+z", onUndo);
|
|
instance.bindKey("ctrl+y", onRedo);
|
|
instance.bindKey("ctrl+y", onRedo);
|
|
instance.bindKey("ctrl+c", onCopy);
|
|
instance.bindKey("ctrl+c", onCopy);
|
|
@@ -291,62 +334,13 @@ export default function erModel() {
|
|
* 添加表
|
|
* 添加表
|
|
*/
|
|
*/
|
|
const addTable = (parentId?: string) => {
|
|
const addTable = (parentId?: string) => {
|
|
- const tableId = uuid();
|
|
|
|
- const columnId = uuid();
|
|
|
|
- const newTable: TableItemType = {
|
|
|
|
- isTable: true,
|
|
|
|
- table: {
|
|
|
|
- aliasName: "newtable",
|
|
|
|
- creationTime: "",
|
|
|
|
- creatorUserId: "",
|
|
|
|
- displayOrder: true,
|
|
|
|
- id: tableId,
|
|
|
|
- isDeleted: false,
|
|
|
|
- langDescription: "",
|
|
|
|
- langName: "",
|
|
|
|
- parentBusinessTableId: parentId || "",
|
|
|
|
- schemaName: "new_table",
|
|
|
|
- type: 1,
|
|
|
|
- updateTime: "",
|
|
|
|
- openSync: false,
|
|
|
|
- style: {
|
|
|
|
- // 随机颜色
|
|
|
|
- color: "#" + Math.floor(Math.random() * 0x666666).toString(16),
|
|
|
|
- x: 300,
|
|
|
|
- y: 300,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- tableColumnList: [
|
|
|
|
- {
|
|
|
|
- id: columnId,
|
|
|
|
- schemaName: "",
|
|
|
|
- type: DataType.Nvarchar,
|
|
|
|
- maxLength: 100,
|
|
|
|
- precision: 0,
|
|
|
|
- scale: 0,
|
|
|
|
- isRequired: false,
|
|
|
|
- isUnique: false,
|
|
|
|
- isPreDefined: false,
|
|
|
|
- defaultValue: "",
|
|
|
|
- displayOrder: false,
|
|
|
|
- businessTableId: tableId,
|
|
|
|
- memo: '',
|
|
|
|
- alignment: '',
|
|
|
|
- isDisplayEnable: true,
|
|
|
|
- isLinkEnable: false,
|
|
|
|
- isWhereEnable: false,
|
|
|
|
- isOrderByEnable: false,
|
|
|
|
- isGroupByEnable: false,
|
|
|
|
- isAggregateEnable: false,
|
|
|
|
- whereInputType: '',
|
|
|
|
- whereInputContent: '',
|
|
|
|
- alterId: '',
|
|
|
|
- temp_rename: '',
|
|
|
|
- charset: '',
|
|
|
|
- orderChar: ''
|
|
|
|
- },
|
|
|
|
- ],
|
|
|
|
- };
|
|
|
|
|
|
+ const area = graphRef.current?.getGraphArea();
|
|
|
|
+ const x = area?.center.x || 300;
|
|
|
|
+ const y = area?.center.y || 300;
|
|
|
|
+ // todo 获取表类型
|
|
|
|
+ const newTable = createTable(3, parentId);
|
|
|
|
+ newTable.table.style.x = x;
|
|
|
|
+ newTable.table.style.y = y;
|
|
|
|
|
|
// 子表插入到父表后面
|
|
// 子表插入到父表后面
|
|
const list = [...project.tables];
|
|
const list = [...project.tables];
|
|
@@ -367,14 +361,16 @@ export default function erModel() {
|
|
* @param table
|
|
* @param table
|
|
*/
|
|
*/
|
|
const updateTable = (table: TableItemType) => {
|
|
const updateTable = (table: TableItemType) => {
|
|
- setProject({
|
|
|
|
- ...project,
|
|
|
|
- tables: project.tables.map((item) => {
|
|
|
|
- if (item.table.id === table.table.id) {
|
|
|
|
- return table;
|
|
|
|
- }
|
|
|
|
- return item;
|
|
|
|
- }),
|
|
|
|
|
|
+ setProject((project) => {
|
|
|
|
+ return {
|
|
|
|
+ ...project,
|
|
|
|
+ tables: project.tables.map((item) => {
|
|
|
|
+ if (item.table.id === table.table.id) {
|
|
|
|
+ return table;
|
|
|
|
+ }
|
|
|
|
+ return item;
|
|
|
|
+ }),
|
|
|
|
+ }
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -429,14 +425,16 @@ export default function erModel() {
|
|
* 修改主题域
|
|
* 修改主题域
|
|
*/
|
|
*/
|
|
const updateTopicArea = (topicArea: TopicAreaInfo) => {
|
|
const updateTopicArea = (topicArea: TopicAreaInfo) => {
|
|
- setProject({
|
|
|
|
- ...project,
|
|
|
|
- topicAreas: project.topicAreas.map((item) => {
|
|
|
|
- if (item.id === topicArea.id) {
|
|
|
|
- return topicArea;
|
|
|
|
- }
|
|
|
|
- return item;
|
|
|
|
- }),
|
|
|
|
|
|
+ setProject((project) => {
|
|
|
|
+ return {
|
|
|
|
+ ...project,
|
|
|
|
+ topicAreas: project.topicAreas.map((item) => {
|
|
|
|
+ if (item.id === topicArea.id) {
|
|
|
|
+ return topicArea;
|
|
|
|
+ }
|
|
|
|
+ return item;
|
|
|
|
+ }),
|
|
|
|
+ }
|
|
});
|
|
});
|
|
};
|
|
};
|
|
|
|
|
|
@@ -479,14 +477,10 @@ export default function erModel() {
|
|
* 修改备注
|
|
* 修改备注
|
|
*/
|
|
*/
|
|
const updateRemark = (remark: RemarkInfo) => {
|
|
const updateRemark = (remark: RemarkInfo) => {
|
|
|
|
+ console.log(remark)
|
|
setProject((state) => ({
|
|
setProject((state) => ({
|
|
...(state || {}),
|
|
...(state || {}),
|
|
- remarks: state.remarkInfos.map((item) => {
|
|
|
|
- if (item.id === remark.id) {
|
|
|
|
- return remark;
|
|
|
|
- }
|
|
|
|
- return item;
|
|
|
|
- }),
|
|
|
|
|
|
+ remarkInfos: state.remarkInfos.map((item) => item.id === remark.id ? remark : item),
|
|
}));
|
|
}));
|
|
};
|
|
};
|
|
|
|
|
|
@@ -640,10 +634,11 @@ export default function erModel() {
|
|
*/
|
|
*/
|
|
const onCut = () => {
|
|
const onCut = () => {
|
|
const cells = graphRef.current?.getSelectedCells();
|
|
const cells = graphRef.current?.getSelectedCells();
|
|
- if (cells?.[0]?.isNode) {
|
|
|
|
|
|
+ if (cells?.[0]?.isNode()) {
|
|
const cell = cells[0];
|
|
const cell = cells[0];
|
|
const data = cell.data;
|
|
const data = cell.data;
|
|
setClipboardCache(data);
|
|
setClipboardCache(data);
|
|
|
|
+ // 表
|
|
if (data?.isTable) {
|
|
if (data?.isTable) {
|
|
const childTableIds = project.tables
|
|
const childTableIds = project.tables
|
|
.filter((item) => item.table.parentBusinessTableId === cell.id)
|
|
.filter((item) => item.table.parentBusinessTableId === cell.id)
|
|
@@ -664,12 +659,14 @@ export default function erModel() {
|
|
),
|
|
),
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ // 主题区域
|
|
if (data?.isTopicArea) {
|
|
if (data?.isTopicArea) {
|
|
setProject({
|
|
setProject({
|
|
...project,
|
|
...project,
|
|
topicAreas: project.topicAreas.filter((item) => item.id !== cell.id),
|
|
topicAreas: project.topicAreas.filter((item) => item.id !== cell.id),
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
+ // 备注
|
|
if (data?.isRemark) {
|
|
if (data?.isRemark) {
|
|
setProject({
|
|
setProject({
|
|
...project,
|
|
...project,
|
|
@@ -684,7 +681,7 @@ export default function erModel() {
|
|
*/
|
|
*/
|
|
const onCopy = () => {
|
|
const onCopy = () => {
|
|
const cells = graphRef.current?.getSelectedCells();
|
|
const cells = graphRef.current?.getSelectedCells();
|
|
- if (cells?.[0]?.isNode) {
|
|
|
|
|
|
+ if (cells?.[0]?.isNode()) {
|
|
const cell = cells[0];
|
|
const cell = cells[0];
|
|
const data = cell.data;
|
|
const data = cell.data;
|
|
setClipboardCache(data);
|
|
setClipboardCache(data);
|
|
@@ -766,7 +763,7 @@ export default function erModel() {
|
|
*/
|
|
*/
|
|
const onDelete = () => {
|
|
const onDelete = () => {
|
|
const cell = graphRef.current?.getSelectedCells();
|
|
const cell = graphRef.current?.getSelectedCells();
|
|
- if (cell?.[0]?.isNode) {
|
|
|
|
|
|
+ if (cell?.[0]?.isNode()) {
|
|
const data = cell[0].data;
|
|
const data = cell[0].data;
|
|
if (data?.isTable) {
|
|
if (data?.isTable) {
|
|
setProject({
|
|
setProject({
|
|
@@ -791,6 +788,25 @@ export default function erModel() {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 演示模式
|
|
|
|
+ */
|
|
|
|
+ const enterPlayMode = () => {
|
|
|
|
+ enterFullscreen();
|
|
|
|
+ setPlayModeEnable(true);
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ graphRef.current?.centerContent();
|
|
|
|
+ }, 100);
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 退出演示模式
|
|
|
|
+ */
|
|
|
|
+ const exitPlayMode = () => {
|
|
|
|
+ exitFullscreen();
|
|
|
|
+ setPlayModeEnable(false);
|
|
|
|
+ };
|
|
|
|
+
|
|
return {
|
|
return {
|
|
initGraph,
|
|
initGraph,
|
|
graph,
|
|
graph,
|
|
@@ -818,5 +834,9 @@ export default function erModel() {
|
|
onCopy,
|
|
onCopy,
|
|
onPaste,
|
|
onPaste,
|
|
onDelete,
|
|
onDelete,
|
|
|
|
+ enterPlayMode,
|
|
|
|
+ playModeEnable,
|
|
|
|
+ setPlayModeEnable,
|
|
|
|
+ exitPlayMode
|
|
};
|
|
};
|
|
}
|
|
}
|