|
@@ -3,8 +3,12 @@ import { message, Modal, Table, Tooltip } from "antd";
|
|
|
import { ColumnItem } from "@/type";
|
|
|
import { TableProps } from "antd/lib";
|
|
|
import { createColumn } from "@/utils";
|
|
|
+import { DataType } from "@/enum";
|
|
|
|
|
|
-export default forwardRef(function ImportResultModal(props: { tableId?: string}, ref) {
|
|
|
+export default forwardRef(function ImportResultModal(
|
|
|
+ props: { tableId?: string; onChange: (list: ColumnItem[]) => void },
|
|
|
+ ref
|
|
|
+) {
|
|
|
const [open, setOpen] = useState(false);
|
|
|
const [dataSource, setDataSource] = useState<any[]>([]);
|
|
|
const originData = useRef<ColumnItem[]>([]);
|
|
@@ -33,6 +37,10 @@ export default forwardRef(function ImportResultModal(props: { tableId?: string},
|
|
|
msg += "!编码长度不能超过50";
|
|
|
}
|
|
|
|
|
|
+ if (["id", ""].includes(val)) {
|
|
|
+ msg += "编码不能是预定义字段!";
|
|
|
+ }
|
|
|
+
|
|
|
return msg;
|
|
|
};
|
|
|
|
|
@@ -58,6 +66,12 @@ export default forwardRef(function ImportResultModal(props: { tableId?: string},
|
|
|
msg = "长度不能超过4000!";
|
|
|
}
|
|
|
}
|
|
|
+ if (type !== "Decimal" && val.toString().includes(",")) {
|
|
|
+ msg = "非Decimal类型不能包含逗号!";
|
|
|
+ }
|
|
|
+ if (!/^\d+(,\d+)?$/.test(val.toString())) {
|
|
|
+ msg = "长度必须是数字逗号组成!";
|
|
|
+ }
|
|
|
return msg;
|
|
|
};
|
|
|
|
|
@@ -72,7 +86,7 @@ export default forwardRef(function ImportResultModal(props: { tableId?: string},
|
|
|
valid = false;
|
|
|
}
|
|
|
});
|
|
|
- if(!valid) {
|
|
|
+ if (!valid) {
|
|
|
message.error("数据校验失败,请检查数据修改后重新导入!");
|
|
|
return;
|
|
|
}
|
|
@@ -83,11 +97,51 @@ export default forwardRef(function ImportResultModal(props: { tableId?: string},
|
|
|
okText: "确认",
|
|
|
cancelText: "取消",
|
|
|
onOk: () => {
|
|
|
- const addList = dataSource.map((item, i) => {
|
|
|
- const old = originData.current.find((obj) => obj.schemaName === item?.['字段名']);
|
|
|
- const newColumn = createColumn(props?.tableId, old?.displayOrder || originData.current.length + i + 1);
|
|
|
- return newColumn;
|
|
|
+ const list = [...originData.current];
|
|
|
+ dataSource.forEach((item, i) => {
|
|
|
+ const data = {
|
|
|
+ schemaName: item["字段名"],
|
|
|
+ type: DataType[item["类型"]] as unknown as DataType,
|
|
|
+ langNameList: [
|
|
|
+ { name: "en", value: item["英文名"] },
|
|
|
+ { name: "zh-CN", value: item["中文名"] },
|
|
|
+ ],
|
|
|
+ isRequired: item["是否必填"] === "是",
|
|
|
+ defaultValue: item["默认值"],
|
|
|
+ memo: item["描述"],
|
|
|
+ maxLength: 0,
|
|
|
+ precision: 0,
|
|
|
+ scale: 0,
|
|
|
+ };
|
|
|
+ if (item["类型"] === "Nvarchar") {
|
|
|
+ data.maxLength = item["长度"];
|
|
|
+ }
|
|
|
+ if (item["类型"] === "Decimal") {
|
|
|
+ const arr = item["长度"].toString().split(",");
|
|
|
+ data.precision = arr?.[0];
|
|
|
+ data.scale = item.arr?.[1];
|
|
|
+ }
|
|
|
+ const index = list.findIndex(
|
|
|
+ (obj) => obj.schemaName === item?.["字段名"]
|
|
|
+ );
|
|
|
+ if (index >= 0) {
|
|
|
+ list[index] = {
|
|
|
+ ...list[index],
|
|
|
+ ...data,
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ const newColumn = createColumn(
|
|
|
+ props?.tableId,
|
|
|
+ list.length + i + 1
|
|
|
+ );
|
|
|
+ list.push({
|
|
|
+ ...newColumn,
|
|
|
+ ...data,
|
|
|
+ });
|
|
|
+ }
|
|
|
});
|
|
|
+
|
|
|
+ props.onChange(list);
|
|
|
setOpen(false);
|
|
|
},
|
|
|
onCancel: () => {
|
|
@@ -153,7 +207,7 @@ export default forwardRef(function ImportResultModal(props: { tableId?: string},
|
|
|
>
|
|
|
{contextHolder}
|
|
|
<Table
|
|
|
- key={"字段名"}
|
|
|
+ rowKey={"字段名"}
|
|
|
scroll={{ y: 400 }}
|
|
|
columns={columns}
|
|
|
dataSource={dataSource}
|