|
@@ -1,4 +1,4 @@
|
|
|
-import React from "react";
|
|
|
+import React, { useEffect } from "react";
|
|
|
import { EditableProTable, ProColumns } from "@ant-design/pro-components";
|
|
|
import type { ColumnItem } from "@/type";
|
|
|
import { createColumn } from "@/utils";
|
|
@@ -8,13 +8,22 @@ 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[] }) {
|
|
|
+import { FormInstance } from "antd/lib";
|
|
|
+export default function TableEdit(props: {
|
|
|
+ tableId?: string;
|
|
|
+ data: any[];
|
|
|
+ modelId?: string;
|
|
|
+ onChange?: (data: readonly ColumnItem[]) => void;
|
|
|
+}) {
|
|
|
const [editableKeys, setEditableRowKeys] = React.useState<React.Key[]>([]);
|
|
|
const [dataSource, setDataSource] = React.useState<readonly ColumnItem[]>(
|
|
|
props.data
|
|
|
);
|
|
|
const boxRef = React.useRef<HTMLDivElement>(null);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ props.onChange?.(dataSource);
|
|
|
+ }, [dataSource]);
|
|
|
const DefaultValueComp = ({
|
|
|
value,
|
|
|
onChange,
|
|
@@ -32,23 +41,61 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
}}
|
|
|
/>
|
|
|
<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>
|
|
|
+ <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 LengthComp = ({
|
|
|
+ value,
|
|
|
+ onChange,
|
|
|
+ model,
|
|
|
+ form,
|
|
|
+ rowKey,
|
|
|
+ }: {
|
|
|
+ value?: string;
|
|
|
+ onChange?: (value: string) => void;
|
|
|
+ model: ColumnItem;
|
|
|
+ form: FormInstance;
|
|
|
+ rowKey?: React.Key | React.Key[];
|
|
|
+ }) => {
|
|
|
+ return (
|
|
|
+ <span className="flex gap-2px">
|
|
|
+ <InputNumber
|
|
|
+ min={0}
|
|
|
+ placeholder="总长度"
|
|
|
+ defaultValue={model.precision}
|
|
|
+ onChange={(value) =>
|
|
|
+ form.setFieldValue([rowKey || "", "precision"], value)
|
|
|
+ }
|
|
|
+ />
|
|
|
+ <InputNumber
|
|
|
+ min={0}
|
|
|
+ placeholder="小数位数"
|
|
|
+ defaultValue={model.scale}
|
|
|
+ onChange={(value) =>
|
|
|
+ form.setFieldValue([rowKey || "", "scale"], value)
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </span>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
const columns: ProColumns[] = [
|
|
|
{
|
|
|
title: "字段代码",
|
|
@@ -71,16 +118,24 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
},
|
|
|
{
|
|
|
title: "字段名称",
|
|
|
- dataIndex: "alignment",
|
|
|
+ dataIndex: "langNameList",
|
|
|
valueType: "text",
|
|
|
width: 80,
|
|
|
+ render: (_dom, entity) => {
|
|
|
+ return (
|
|
|
+ entity.langNameList?.find(
|
|
|
+ (item: Record<string, string>) => item.name === "zh-CN"
|
|
|
+ )?.value || "-"
|
|
|
+ );
|
|
|
+ },
|
|
|
renderFormItem: (_schema, config, form) => {
|
|
|
const model = config.record;
|
|
|
+ const rowKey = config.recordKey;
|
|
|
return (
|
|
|
<LangInput
|
|
|
value={model.langNameList}
|
|
|
onChange={(langValue) =>
|
|
|
- form.setFieldValue("langNameList", langValue)
|
|
|
+ form.setFieldValue([rowKey || "", "langNameList"], langValue)
|
|
|
}
|
|
|
/>
|
|
|
);
|
|
@@ -91,8 +146,15 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
dataIndex: "type",
|
|
|
valueType: "select",
|
|
|
width: 120,
|
|
|
- fieldProps: {
|
|
|
- options: DATA_TYPE_OPTIONS,
|
|
|
+ fieldProps: (form, { rowKey }) => {
|
|
|
+ return {
|
|
|
+ options: DATA_TYPE_OPTIONS,
|
|
|
+ onChange: () => {
|
|
|
+ form.setFieldValue([rowKey || "", "maxLength"], undefined);
|
|
|
+ form.setFieldValue([rowKey || "", "scale"], undefined);
|
|
|
+ form.setFieldValue([rowKey || "", "precision"], undefined);
|
|
|
+ },
|
|
|
+ };
|
|
|
},
|
|
|
formItemProps: {
|
|
|
rules: [
|
|
@@ -101,7 +163,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
message: "请选择类型",
|
|
|
},
|
|
|
],
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
{
|
|
|
title: "长度",
|
|
@@ -111,39 +173,20 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
fieldProps: {
|
|
|
precision: 0,
|
|
|
},
|
|
|
- render: (text, record, index) => {
|
|
|
+ render: (text, record) => {
|
|
|
return record.type === DataType.Decimal
|
|
|
? `${record.precision},${record.scale}`
|
|
|
: text;
|
|
|
},
|
|
|
- renderFormItem: (schema, config, form) => {
|
|
|
+ renderFormItem: (_schema, config, form) => {
|
|
|
const model = config.record;
|
|
|
+ const rowKey = config.recordKey;
|
|
|
return model.type === DataType.Nvarchar ? (
|
|
|
- <InputNumber
|
|
|
- min={0}
|
|
|
- max={255}
|
|
|
- value={model.maxLength}
|
|
|
- onChange={(value) => form.setFieldValue("maxLength", value)}
|
|
|
- />
|
|
|
+ <InputNumber min={0} placeholder="字符长度" />
|
|
|
) : model.type === DataType.Decimal ? (
|
|
|
- <span className="flex gap-2px">
|
|
|
- <InputNumber
|
|
|
- min={0}
|
|
|
- max={20}
|
|
|
- placeholder="总长度"
|
|
|
- value={model.precision}
|
|
|
- onChange={(value) => form.setFieldValue("precision", value)}
|
|
|
- />
|
|
|
- <InputNumber
|
|
|
- min={0}
|
|
|
- max={19}
|
|
|
- placeholder="小数位数"
|
|
|
- value={model.scale}
|
|
|
- onChange={(value) => form.setFieldValue("scale", value)}
|
|
|
- />
|
|
|
- </span>
|
|
|
+ <LengthComp model={model} form={form} rowKey={rowKey} />
|
|
|
) : (
|
|
|
- <>-</>
|
|
|
+ "-"
|
|
|
);
|
|
|
},
|
|
|
},
|
|
@@ -203,7 +246,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
title: "操作",
|
|
|
valueType: "option",
|
|
|
width: 120,
|
|
|
- render: (text, record, _, action) =>
|
|
|
+ render: (_text, record, _, action) =>
|
|
|
record.isPreDefined
|
|
|
? []
|
|
|
: [
|
|
@@ -234,7 +277,7 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
- <div className="w-full h-full overflow-hidden" ref={boxRef}>
|
|
|
+ <div className="w-full h-full overflow-auto" ref={boxRef}>
|
|
|
<EditableProTable
|
|
|
columns={columns}
|
|
|
rowKey="id"
|
|
@@ -243,19 +286,12 @@ export default function TableEdit(props: { tableId?: string; data: any[] }) {
|
|
|
recordCreatorProps={{
|
|
|
record: handleAdd,
|
|
|
}}
|
|
|
- pagination={{
|
|
|
- total: 10,
|
|
|
- pageSize: 10,
|
|
|
- onChange: (page, pageSize) => {
|
|
|
- console.log(page, pageSize);
|
|
|
- },
|
|
|
- }}
|
|
|
editable={{
|
|
|
type: "multiple",
|
|
|
editableKeys,
|
|
|
- onSave: async (rowKey, data, row) => {
|
|
|
- console.log(rowKey, data, row);
|
|
|
- },
|
|
|
+ // onSave: async (rowKey, data, row) => {
|
|
|
+ // console.log(rowKey, data, row, dataSource);
|
|
|
+ // },
|
|
|
onChange: setEditableRowKeys,
|
|
|
}}
|
|
|
/>
|