|
@@ -4,11 +4,27 @@ import type { ColumnItem } from "@/type";
|
|
|
import { createColumn } from "@/utils";
|
|
|
import { DataType } from "@/enum";
|
|
|
import { DATA_TYPE_OPTIONS } from "@/constants";
|
|
|
-import { Button, Input, InputNumber, Switch } from "antd";
|
|
|
+import {
|
|
|
+ Button,
|
|
|
+ Input,
|
|
|
+ InputNumber,
|
|
|
+ message,
|
|
|
+ Switch,
|
|
|
+ Tooltip,
|
|
|
+ Upload,
|
|
|
+ UploadFile,
|
|
|
+} from "antd";
|
|
|
import LangInput from "./LangInput";
|
|
|
import { validateColumnCode } from "@/utils/validator";
|
|
|
import VariableModal from "./VariableModal";
|
|
|
import { FormInstance } from "antd/lib";
|
|
|
+import {
|
|
|
+ DownloadOutlined,
|
|
|
+ InfoCircleOutlined,
|
|
|
+ UploadOutlined,
|
|
|
+} from "@ant-design/icons";
|
|
|
+import { parseExcel } from "@/utils/parseExcel";
|
|
|
+import ImportResultModal from "./ImportResultModal";
|
|
|
export default function TableEdit(props: {
|
|
|
tableId?: string;
|
|
|
data: any[];
|
|
@@ -20,6 +36,7 @@ export default function TableEdit(props: {
|
|
|
props.data
|
|
|
);
|
|
|
const boxRef = React.useRef<HTMLDivElement>(null);
|
|
|
+ const importResultRef = React.useRef<{open: (data: any[], columns: readonly ColumnItem[]) => void}>();
|
|
|
|
|
|
useEffect(() => {
|
|
|
props.onChange?.(dataSource);
|
|
@@ -131,7 +148,7 @@ export default function TableEdit(props: {
|
|
|
renderFormItem: (_schema, config, form) => {
|
|
|
const model = config.record;
|
|
|
const rowKey = config.recordKey;
|
|
|
- console.log(model)
|
|
|
+ console.log(model);
|
|
|
return (
|
|
|
<span>
|
|
|
<LangInput
|
|
@@ -187,7 +204,7 @@ export default function TableEdit(props: {
|
|
|
const model = config.record;
|
|
|
const rowKey = config.recordKey;
|
|
|
return model.type === DataType.Nvarchar ? (
|
|
|
- <InputNumber min={0} placeholder="字符长度" />
|
|
|
+ <InputNumber min={0} max={4000} placeholder="字符长度" />
|
|
|
) : model.type === DataType.Decimal ? (
|
|
|
<LengthComp model={model} form={form} rowKey={rowKey} />
|
|
|
) : (
|
|
@@ -253,6 +270,13 @@ export default function TableEdit(props: {
|
|
|
return <Input.TextArea placeholder="描述..." />;
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ title: "预定义字段",
|
|
|
+ dataIndex: "isPreDefined",
|
|
|
+ renderText: (text, record) => {
|
|
|
+ return record.isPreDefined ? "是" : "否";
|
|
|
+ },
|
|
|
+ },
|
|
|
{
|
|
|
title: "操作",
|
|
|
valueType: "option",
|
|
@@ -287,8 +311,31 @@ export default function TableEdit(props: {
|
|
|
return createColumn(props?.tableId, dataSource.length + 1);
|
|
|
};
|
|
|
|
|
|
+ // 上传字段模版文件
|
|
|
+ const handleUpload = (file: UploadFile) => {
|
|
|
+ message.loading("正在解析文件...", 0);
|
|
|
+ parseExcel<any>(file)
|
|
|
+ .then((res) => {
|
|
|
+ console.log("加载数据:", res);
|
|
|
+ const list = res?.["表单字段"];
|
|
|
+ if (!list || !list.length) {
|
|
|
+ message.warning("当前文件无字段数据,请检查");
|
|
|
+ } else {
|
|
|
+ importResultRef.current?.open(list, dataSource);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.error("加载数据失败:", err);
|
|
|
+ message.error("文件解析失败");
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ message.destroy();
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<div className="w-full h-full overflow-auto" ref={boxRef}>
|
|
|
+ <ImportResultModal ref={importResultRef} tableId={props?.tableId} />
|
|
|
<EditableProTable
|
|
|
columns={columns}
|
|
|
rowKey="id"
|
|
@@ -300,11 +347,52 @@ export default function TableEdit(props: {
|
|
|
editable={{
|
|
|
type: "multiple",
|
|
|
editableKeys,
|
|
|
- // onSave: async (rowKey, data, row) => {
|
|
|
- // console.log(rowKey, data, row, dataSource);
|
|
|
- // },
|
|
|
onChange: setEditableRowKeys,
|
|
|
}}
|
|
|
+ toolBarRender={() => [
|
|
|
+ <Tooltip
|
|
|
+ key="info"
|
|
|
+ title={
|
|
|
+ <div>
|
|
|
+ <p>填写规范:</p>
|
|
|
+ <p>
|
|
|
+ 1、字段名第一位必须为大写字母,之后的对象可以字母大小写,数字或下划线;
|
|
|
+ </p>
|
|
|
+ <p>2、Nvarchar类型长度最大不可以超过4000;</p>
|
|
|
+ <p>
|
|
|
+ 3、Decimal类型精度的填写方式:总精度,有效小数位,eg: 18,6;
|
|
|
+ </p>
|
|
|
+ <p>4、Int、Datetime等类型长度需填写为0;</p>
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <InfoCircleOutlined />
|
|
|
+ </Tooltip>,
|
|
|
+ <Button key="download" icon={<DownloadOutlined />}>
|
|
|
+ <a
|
|
|
+ download={"BusinessTableColumnsImportTemplate.xlsx"}
|
|
|
+ href="/Content/Template/BusinessTableColumnsImportTemplate.xlsx"
|
|
|
+ >
|
|
|
+ 下载模版
|
|
|
+ </a>
|
|
|
+ </Button>,
|
|
|
+ <Upload
|
|
|
+ key="upload"
|
|
|
+ accept=".xlsx"
|
|
|
+ showUploadList={false}
|
|
|
+ beforeUpload={(file) => handleUpload(file)}
|
|
|
+ >
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ icon={<UploadOutlined />}
|
|
|
+ onClick={() => {
|
|
|
+ handleAdd();
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 导入字段
|
|
|
+ </Button>
|
|
|
+ </Upload>,
|
|
|
+ ]}
|
|
|
/>
|
|
|
</div>
|
|
|
);
|