|
@@ -1,22 +1,73 @@
|
|
|
import React from "react";
|
|
|
import { EditableProTable, ProColumns } from "@ant-design/pro-components";
|
|
|
import type { ColumnItem } from "@/type";
|
|
|
-import { createColumn, uuid } from "@/utils";
|
|
|
+import { createColumn } from "@/utils";
|
|
|
import { DataType } from "@/enum";
|
|
|
import { DATA_TYPE_OPTIONS } from "@/constants";
|
|
|
-import { Input, InputNumber } from "antd";
|
|
|
+import { Button, Input, InputNumber } from "antd";
|
|
|
import LangInput from "./LangInput";
|
|
|
+import { validateColumnCode } from "@/utils/validator";
|
|
|
+import VariableModal from "./VariableModal";
|
|
|
export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
const [editableKeys, setEditableRowKeys] = React.useState<React.Key[]>([]);
|
|
|
const [dataSource, setDataSource] = React.useState<readonly ColumnItem[]>(
|
|
|
props.data
|
|
|
);
|
|
|
+ const boxRef = React.useRef<HTMLDivElement>(null);
|
|
|
+
|
|
|
+ const DefaultValueComp = ({
|
|
|
+ value,
|
|
|
+ onChange,
|
|
|
+ }: {
|
|
|
+ value?: string;
|
|
|
+ onChange?: (value: string) => void;
|
|
|
+ }) => {
|
|
|
+ return (
|
|
|
+ <div className="flex gap-2px">
|
|
|
+ <Input
|
|
|
+ placeholder="默认值"
|
|
|
+ value={value}
|
|
|
+ onChange={(e) => {
|
|
|
+ onChange?.(e.target.value);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <div>
|
|
|
+ <VariableModal
|
|
|
+ trigger={
|
|
|
+ <Button size="small" style={{ width: 40, fontSize: 12 }} type="text">
|
|
|
+ +变量
|
|
|
+ </Button>
|
|
|
+ }
|
|
|
+ onOk={(val) => onChange?.(val)}
|
|
|
+ />
|
|
|
+ <Button size="small" style={{ width: 40, fontSize: 12 }} type="text">
|
|
|
+ +字段
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
const columns: ProColumns[] = [
|
|
|
{
|
|
|
title: "字段代码",
|
|
|
dataIndex: "schemaName",
|
|
|
valueType: "text",
|
|
|
width: 80,
|
|
|
+ formItemProps: {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请输入字段名称",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ max: 50,
|
|
|
+ message: "字段名称不能超过50个字符",
|
|
|
+ },
|
|
|
+ validateColumnCode,
|
|
|
+ ],
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: "字段名称",
|
|
@@ -43,6 +94,14 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
fieldProps: {
|
|
|
options: DATA_TYPE_OPTIONS,
|
|
|
},
|
|
|
+ formItemProps: {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: "请选择类型",
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: "长度",
|
|
@@ -104,7 +163,10 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
title: "默认值",
|
|
|
dataIndex: "defaultValue",
|
|
|
valueType: "text",
|
|
|
- width: 120,
|
|
|
+ width: 150,
|
|
|
+ renderFormItem() {
|
|
|
+ return <DefaultValueComp />;
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: "字符集",
|
|
@@ -113,7 +175,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
width: 120,
|
|
|
renderFormItem: (_schema, config) => {
|
|
|
return config.record.type === DataType.Nvarchar ? (
|
|
|
- <Input placeholder="请输入" />
|
|
|
+ <Input placeholder="字符集" />
|
|
|
) : null;
|
|
|
},
|
|
|
},
|
|
@@ -124,7 +186,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
width: 120,
|
|
|
renderFormItem: (_schema, config) => {
|
|
|
return config.record.type === DataType.Nvarchar ? (
|
|
|
- <Input.TextArea placeholder="请输入" />
|
|
|
+ <Input.TextArea placeholder="内容..." />
|
|
|
) : null;
|
|
|
},
|
|
|
},
|
|
@@ -134,7 +196,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
valueType: "textarea",
|
|
|
width: 120,
|
|
|
renderFormItem: () => {
|
|
|
- return <Input.TextArea placeholder="请输入" />;
|
|
|
+ return <Input.TextArea placeholder="描述..." />;
|
|
|
},
|
|
|
},
|
|
|
{
|
|
@@ -170,17 +232,24 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
const handleAdd = () => {
|
|
|
return createColumn(props?.tableId);
|
|
|
};
|
|
|
+
|
|
|
return (
|
|
|
- <div className="w-full h-full">
|
|
|
+ <div className="w-full h-full overflow-hidden" ref={boxRef}>
|
|
|
<EditableProTable
|
|
|
columns={columns}
|
|
|
rowKey="id"
|
|
|
- scroll={{ x: 960 }}
|
|
|
value={dataSource}
|
|
|
onChange={setDataSource}
|
|
|
recordCreatorProps={{
|
|
|
record: handleAdd,
|
|
|
}}
|
|
|
+ pagination={{
|
|
|
+ total: 10,
|
|
|
+ pageSize: 10,
|
|
|
+ onChange: (page, pageSize) => {
|
|
|
+ console.log(page, pageSize);
|
|
|
+ },
|
|
|
+ }}
|
|
|
editable={{
|
|
|
type: "multiple",
|
|
|
editableKeys,
|