|
@@ -11,13 +11,16 @@ import {
|
|
|
Popover,
|
|
|
Popconfirm,
|
|
|
} from "antd";
|
|
|
-import React, { useState } from "react";
|
|
|
+import React, { useEffect, useState } from "react";
|
|
|
import CustomColorPicker from "@/components/CustomColorPicker";
|
|
|
import { ColumnItem, TableItemType } from "@/type";
|
|
|
import { TABLE_TYPE_OPTIONS, DATA_TYPE_OPTIONS } from "@/constants";
|
|
|
import { uuid } from "@/utils";
|
|
|
import { DataType } from "@/enum";
|
|
|
import { useModel } from "umi";
|
|
|
+import { DndContext } from "@dnd-kit/core";
|
|
|
+import type { DragEndEvent } from "@dnd-kit/core";
|
|
|
+import { SortableContext, arrayMove, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
|
|
|
|
export default function TableItem({
|
|
|
data,
|
|
@@ -32,9 +35,13 @@ export default function TableItem({
|
|
|
}) {
|
|
|
const { tableColumnList = [] } = data;
|
|
|
const { addTable, deleteTable } = useModel("erModel");
|
|
|
-
|
|
|
+ const [list, setList] = useState(tableColumnList);
|
|
|
const [table, setTable] = React.useState(data?.table);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ setList(tableColumnList);
|
|
|
+ }, [tableColumnList]);
|
|
|
+
|
|
|
const handleTableChange = (key: string, value: any) => {
|
|
|
onChange({
|
|
|
tableColumnList,
|
|
@@ -45,6 +52,9 @@ export default function TableItem({
|
|
|
};
|
|
|
|
|
|
const handleChangeColumn = (index: number, key: string, value: any) => {
|
|
|
+ const data = tableColumnList[index];
|
|
|
+ const newData = { ...data, [key]: value };
|
|
|
+ setList(tableColumnList.map((item, i) => (i === index ? newData : item)));
|
|
|
onChange({
|
|
|
isTable: true,
|
|
|
table,
|
|
@@ -94,6 +104,10 @@ export default function TableItem({
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ const handleDragEnd = (event: DragEndEvent) => {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<div
|
|
|
className="
|
|
@@ -108,7 +122,7 @@ export default function TableItem({
|
|
|
p-l-16px"
|
|
|
style={{
|
|
|
borderLeftColor: table.style?.color || "#eee",
|
|
|
- marginLeft: table.parentBusinessTableId ? 10 : 0
|
|
|
+ marginLeft: table.parentBusinessTableId ? 10 : 0,
|
|
|
}}
|
|
|
>
|
|
|
<div
|
|
@@ -165,10 +179,14 @@ export default function TableItem({
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
/>
|
|
|
</Popover>
|
|
|
- <i className="iconfont icon-open inline-block" style={{
|
|
|
- transform: active === table.id ? "rotate(180deg)" : "rotate(0deg)",
|
|
|
- transition: "all 0.3s",
|
|
|
- }} />
|
|
|
+ <i
|
|
|
+ className="iconfont icon-open inline-block"
|
|
|
+ style={{
|
|
|
+ transform:
|
|
|
+ active === table.id ? "rotate(180deg)" : "rotate(0deg)",
|
|
|
+ transition: "all 0.3s",
|
|
|
+ }}
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
<div
|
|
@@ -256,189 +274,225 @@ export default function TableItem({
|
|
|
|
|
|
<div className="column-content border-solid border-1px border-#e4e4e4 border-x-none p-y-10px">
|
|
|
{/* 字段内容 */}
|
|
|
- {tableColumnList.map((column, index) => {
|
|
|
- return (
|
|
|
- <div
|
|
|
- key={column.id}
|
|
|
- className="column-item flex gap-4px items-center jutify-space-between hover:bg-gray-100 mb-4px"
|
|
|
- >
|
|
|
- <HolderOutlined className="cursor-move" />
|
|
|
- <Tooltip title="字段编码">
|
|
|
- <Input
|
|
|
- placeholder="编码"
|
|
|
- value={column.schemaName}
|
|
|
- className="flex-1"
|
|
|
- onChange={(e) =>
|
|
|
- handleChangeColumn(index, "schemaName", e.target.value)
|
|
|
- }
|
|
|
- />
|
|
|
- </Tooltip>
|
|
|
- <Tooltip title="字段类型">
|
|
|
- <Select
|
|
|
- placeholder="类型"
|
|
|
- className="w-80px"
|
|
|
- options={DATA_TYPE_OPTIONS}
|
|
|
- value={column.type}
|
|
|
- onChange={(value) =>
|
|
|
- handleChangeColumn(index, "type", value)
|
|
|
- }
|
|
|
- dropdownStyle={{ width: 120 }}
|
|
|
- />
|
|
|
- </Tooltip>
|
|
|
- <Tooltip title="非空">
|
|
|
+ <DndContext onDragEnd={handleDragEnd}>
|
|
|
+ <SortableContext items={list.map(item => item.id)} strategy={verticalListSortingStrategy}>
|
|
|
+ {list.map((column, index) => {
|
|
|
+ return (
|
|
|
<div
|
|
|
- className="
|
|
|
- rounded-4px
|
|
|
- cus-btn
|
|
|
- w-32px
|
|
|
- h-32px
|
|
|
- bg-#eee
|
|
|
- flex-none
|
|
|
- text-center
|
|
|
- leading-32px
|
|
|
- cursor-pointer
|
|
|
- hover:bg-#ddd"
|
|
|
- style={
|
|
|
- column.isRequired
|
|
|
- ? { background: "#1677ff", color: "#fff" }
|
|
|
- : {}
|
|
|
- }
|
|
|
- onClick={() =>
|
|
|
- handleChangeColumn(
|
|
|
- index,
|
|
|
- "isRequired",
|
|
|
- !column.isRequired
|
|
|
- )
|
|
|
- }
|
|
|
+ key={column.id}
|
|
|
+ className="column-item flex gap-4px items-center jutify-space-between hover:bg-gray-100 mb-4px"
|
|
|
>
|
|
|
- !
|
|
|
- </div>
|
|
|
- </Tooltip>
|
|
|
- <Tooltip title="唯一">
|
|
|
- <div
|
|
|
- className="
|
|
|
- rounded-4px
|
|
|
- cus-btn
|
|
|
- w-32px
|
|
|
- h-32px
|
|
|
- bg-#eee
|
|
|
- flex-none
|
|
|
- text-center
|
|
|
- leading-32px
|
|
|
- cursor-pointer
|
|
|
- hover:bg-#ddd"
|
|
|
- style={
|
|
|
- column.isUnique
|
|
|
- ? { background: "#1677ff", color: "#fff" }
|
|
|
- : {}
|
|
|
- }
|
|
|
- onClick={() =>
|
|
|
- handleChangeColumn(index, "isUnique", !column.isUnique)
|
|
|
- }
|
|
|
- >
|
|
|
- 1
|
|
|
- </div>
|
|
|
- </Tooltip>
|
|
|
- <Popover
|
|
|
- trigger="click"
|
|
|
- placement="right"
|
|
|
- content={
|
|
|
- <div
|
|
|
- className="w-200px max-h-400px overflow-y-auto"
|
|
|
- onClick={(e) => e.stopPropagation()}
|
|
|
- >
|
|
|
- <Form layout="vertical">
|
|
|
- <Form.Item label="字段名称" name="pkName">
|
|
|
- <Input
|
|
|
- className="w-full"
|
|
|
- placeholder="中文"
|
|
|
- value={column.cn_name}
|
|
|
- onChange={(e) =>
|
|
|
- handleChangeColumn(
|
|
|
- index,
|
|
|
- "cn_name",
|
|
|
- e.target.value
|
|
|
- )
|
|
|
- }
|
|
|
- />
|
|
|
- <Input
|
|
|
- className="w-full"
|
|
|
- placeholder="英文"
|
|
|
- value={column.en_name}
|
|
|
- onChange={(e) =>
|
|
|
- handleChangeColumn(
|
|
|
- index,
|
|
|
- "en_name",
|
|
|
- e.target.value
|
|
|
- )
|
|
|
- }
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="描述" name="pkName">
|
|
|
- <Input.TextArea
|
|
|
- className="w-full"
|
|
|
- placeholder="描述中文..."
|
|
|
- />
|
|
|
- <Input.TextArea
|
|
|
- className="w-full"
|
|
|
- placeholder="描述英文..."
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="长度">
|
|
|
- <InputNumber
|
|
|
- placeholder="请输入"
|
|
|
- min={0}
|
|
|
- className="w-full"
|
|
|
- value={column.maxLength}
|
|
|
- onChange={(num) =>
|
|
|
- handleChangeColumn(index, "maxLength", num)
|
|
|
- }
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="精度">
|
|
|
- <InputNumber
|
|
|
- placeholder="请输入"
|
|
|
- min={0}
|
|
|
- className="w-full"
|
|
|
- value={column.precision}
|
|
|
- onChange={(num) =>
|
|
|
- handleChangeColumn(index, "precision", num)
|
|
|
- }
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- <Form.Item label="默认值" name="pkName">
|
|
|
- <Input
|
|
|
- className="w-full"
|
|
|
- placeholder="默认值"
|
|
|
- value={column.defaultValue}
|
|
|
- onChange={(e) =>
|
|
|
- handleChangeColumn(
|
|
|
- index,
|
|
|
- "defaultValue",
|
|
|
- e.target.value
|
|
|
- )
|
|
|
- }
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
- </Form>
|
|
|
- <Button
|
|
|
- type="default"
|
|
|
- danger
|
|
|
- className="w-full"
|
|
|
- onClick={() => handleDeleteColumn(column.id)}
|
|
|
+ <HolderOutlined className="cursor-move" />
|
|
|
+ <Tooltip title="字段编码">
|
|
|
+ <Input
|
|
|
+ placeholder="编码"
|
|
|
+ defaultValue={column.schemaName}
|
|
|
+ className="flex-1"
|
|
|
+ onChange={(e) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "schemaName",
|
|
|
+ e.target.value
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Tooltip>
|
|
|
+ <Tooltip title="字段类型">
|
|
|
+ <Select
|
|
|
+ placeholder="类型"
|
|
|
+ className="w-80px"
|
|
|
+ options={DATA_TYPE_OPTIONS}
|
|
|
+ value={column.type}
|
|
|
+ onChange={(value) =>
|
|
|
+ handleChangeColumn(index, "type", value)
|
|
|
+ }
|
|
|
+ dropdownStyle={{ width: 120 }}
|
|
|
+ />
|
|
|
+ </Tooltip>
|
|
|
+ <Tooltip title="非空">
|
|
|
+ <div
|
|
|
+ className="
|
|
|
+ rounded-4px
|
|
|
+ cus-btn
|
|
|
+ w-32px
|
|
|
+ h-32px
|
|
|
+ bg-#eee
|
|
|
+ flex-none
|
|
|
+ text-center
|
|
|
+ leading-32px
|
|
|
+ cursor-pointer
|
|
|
+ hover:bg-#ddd"
|
|
|
+ style={
|
|
|
+ column.isRequired
|
|
|
+ ? { background: "#1677ff", color: "#fff" }
|
|
|
+ : {}
|
|
|
+ }
|
|
|
+ onClick={() =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "isRequired",
|
|
|
+ !column.isRequired
|
|
|
+ )
|
|
|
+ }
|
|
|
>
|
|
|
- 删除
|
|
|
- </Button>
|
|
|
- </div>
|
|
|
- }
|
|
|
- >
|
|
|
- <div className="rounded-4px cus-btn w-32px h-32px bg-#eee flex-none text-center leading-32px cursor-pointer hover:bg-#ddd">
|
|
|
- <i className="iconfont icon-gengduo" />
|
|
|
+ !
|
|
|
+ </div>
|
|
|
+ </Tooltip>
|
|
|
+ <Tooltip title="唯一">
|
|
|
+ <div
|
|
|
+ className="
|
|
|
+ rounded-4px
|
|
|
+ cus-btn
|
|
|
+ w-32px
|
|
|
+ h-32px
|
|
|
+ bg-#eee
|
|
|
+ flex-none
|
|
|
+ text-center
|
|
|
+ leading-32px
|
|
|
+ cursor-pointer
|
|
|
+ hover:bg-#ddd"
|
|
|
+ style={
|
|
|
+ column.isUnique
|
|
|
+ ? { background: "#1677ff", color: "#fff" }
|
|
|
+ : {}
|
|
|
+ }
|
|
|
+ onClick={() =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "isUnique",
|
|
|
+ !column.isUnique
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ 1
|
|
|
+ </div>
|
|
|
+ </Tooltip>
|
|
|
+ <Popover
|
|
|
+ trigger="click"
|
|
|
+ placement="right"
|
|
|
+ content={
|
|
|
+ <div
|
|
|
+ className="w-360px max-h-400px overflow-hidden"
|
|
|
+ onClick={(e) => e.stopPropagation()}
|
|
|
+ >
|
|
|
+ <Form layout="vertical">
|
|
|
+ <Row gutter={8}>
|
|
|
+ <Col span={12}>
|
|
|
+ <Form.Item label="字段名称" name="pkName">
|
|
|
+ <Input
|
|
|
+ className="w-full"
|
|
|
+ placeholder="中文"
|
|
|
+ value={column.cn_name}
|
|
|
+ onChange={(e) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "cn_name",
|
|
|
+ e.target.value
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ <Input
|
|
|
+ className="w-full"
|
|
|
+ placeholder="英文"
|
|
|
+ value={column.en_name}
|
|
|
+ onChange={(e) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "en_name",
|
|
|
+ e.target.value
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <Form.Item label="默认值" name="pkName">
|
|
|
+ <Input
|
|
|
+ className="w-full"
|
|
|
+ placeholder="默认值"
|
|
|
+ value={column.defaultValue}
|
|
|
+ onChange={(e) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "defaultValue",
|
|
|
+ e.target.value
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ <Row gutter={8}>
|
|
|
+ <Col span={12}>
|
|
|
+ <Form.Item label="长度">
|
|
|
+ <InputNumber
|
|
|
+ placeholder="请输入"
|
|
|
+ min={0}
|
|
|
+ className="w-full"
|
|
|
+ value={column.maxLength}
|
|
|
+ onChange={(num) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "maxLength",
|
|
|
+ num
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <Form.Item label="精度">
|
|
|
+ <InputNumber
|
|
|
+ placeholder="请输入"
|
|
|
+ min={0}
|
|
|
+ className="w-full"
|
|
|
+ value={column.precision}
|
|
|
+ onChange={(num) =>
|
|
|
+ handleChangeColumn(
|
|
|
+ index,
|
|
|
+ "precision",
|
|
|
+ num
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ <Row>
|
|
|
+ <Col span={24}>
|
|
|
+ <Form.Item label="描述" name="pkName">
|
|
|
+ <Input.TextArea
|
|
|
+ className="w-full"
|
|
|
+ placeholder="描述中文..."
|
|
|
+ />
|
|
|
+ <Input.TextArea
|
|
|
+ className="w-full"
|
|
|
+ placeholder="描述英文..."
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ </Form>
|
|
|
+ <Button
|
|
|
+ type="default"
|
|
|
+ danger
|
|
|
+ className="w-full"
|
|
|
+ onClick={() => handleDeleteColumn(column.id)}
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <div className="rounded-4px cus-btn w-32px h-32px bg-#eee flex-none text-center leading-32px cursor-pointer hover:bg-#ddd">
|
|
|
+ <i className="iconfont icon-gengduo" />
|
|
|
+ </div>
|
|
|
+ </Popover>
|
|
|
</div>
|
|
|
- </Popover>
|
|
|
- </div>
|
|
|
- );
|
|
|
- })}
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </SortableContext>
|
|
|
+ </DndContext>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|