TableView.jsx 27.3 KB
Newer Older
1
import React, { useEffect, useState, useRef, useContext, useMemo } from 'react';
2 3 4 5
import {
  CreateTablePost,
  getTableInfo,
  updateTablePost,
皮倩雯's avatar
皮倩雯 committed
6
  GetDefaultTableFields,
7 8
  reloadTableFields,
  removeFields,
9 10 11 12 13 14 15 16 17 18 19 20 21 22
} from '@/services/tablemanager/tablemanager';
import {
  Form,
  Modal,
  Button,
  Input,
  Select,
  Checkbox,
  Table,
  notification,
  InputNumber,
  Tooltip,
  Switch,
  Spin,
23
  Empty,
24
} from 'antd';
皮倩雯's avatar
皮倩雯 committed
25 26 27 28 29 30 31
import {
  DeleteOutlined,
  PlusOutlined,
  MinusOutlined,
  DeleteFilled,
  KeyOutlined,
} from '@ant-design/icons';
32
import styles from './TableView.less';
33 34
import primaryKey from '../../../../../assets/images/icons/主键.svg';
import index from '../../../../../assets/images/icons/索引.svg';
35
import clearImg from '@/assets/font/omsfont/clear.svg';
皮倩雯's avatar
皮倩雯 committed
36
// import { defaultFields } from './defaultFields';
37 38
const EditableContext = React.createContext(null);

39 40 41 42 43 44 45 46
const tableMap = {
  事件表: '事件',
  事件工单表: '事件',
  工单表: '工单',
  台账表: '台账',
  设备表: '设备',
  反馈表: '反馈',
};
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
const EditableRow = ({ index, ...props }) => {
  const [form] = Form.useForm();
  return (
    <Form form={form} component={false}>
      <EditableContext.Provider value={form}>
        <tr {...props} />
      </EditableContext.Provider>
    </Form>
  );
};
const EditableCell = ({
  index,
  title,
  editable,
  children,
  dataIndex,
  record,
  handleSave,
  ellipsis,
  width,
  dataSource,
  tableDataCount,
69
  defaultData,
70
  setDefaultData,
71 72 73 74 75 76 77 78 79 80 81 82 83
  ...restProps
}) => {
  const [editing, setEditing] = useState(false);
  const inputRef = useRef(null);
  const form = useContext(EditableContext);

  // 复选框回显
  useEffect(() => {
    if (record && dataIndex === 'IsNullable') {
      form.setFieldsValue({
        [dataIndex]: record[dataIndex],
      });
    }
84 85 86 87 88
    if (record && dataIndex === 'IsAddFieldConfig') {
      form.setFieldsValue({
        [dataIndex]: record[dataIndex],
      });
    }
89
  }, [dataSource]);
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

  useEffect(() => {
    if (editing && inputRef.current) {
      inputRef.current.focus();
    }
  }, [editing]);

  const toggleEdit = () => {
    setEditing(!editing);
    form.setFieldsValue({
      [dataIndex]: record[dataIndex],
    });
  };

  const save = async () => {
    try {
      const values = await form.validateFields();
      toggleEdit();
      handleSave({ ...record, [dataIndex]: values[dataIndex], index, errors: [] }, dataIndex);
    } catch (errInfo) {
      toggleEdit();
      handleSave({ ...record, index, errors: errInfo.errorFields[0].errors }, dataIndex);
      console.log('Save failed:', errInfo);
    }
  };
  const saveCheckBox = async () => {
    const values = await form.validateFields();
    form.setFieldsValue({
      [dataIndex]: values.IsNullable,
    });
    handleSave({ ...record, ...values, index });
  };
122 123 124 125 126 127 128

  const saveAddCheckBox = async e => {
    const values = await form.validateFields();
    form.setFieldsValue({
      [dataIndex]: values.IsAddFieldConfig,
    });
    handleSave({ ...record, ...values, index });
129 130 131 132 133 134 135
    let defaultArr = JSON.parse(JSON.stringify(defaultData));
    defaultArr.forEach(item => {
      if (item.Name === record.Name) {
        item.IsAddFieldConfig = values.IsAddFieldConfig;
      }
    });
    setDefaultData(defaultArr);
136 137
  };

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  const rendeFrom = val => {
    let lengthMin = 0;
    let lengthMax = 0;
    let decimalPlaceMin = 0;
    let decimalPlaceMax = 0;
    // 字段类型为精确数值型(decimal),字段长度1-38小数点位数0-38
    if (record.FieldType === 8) {
      lengthMin = 1;
      lengthMax = 38;
      decimalPlaceMin = 0;
      decimalPlaceMax = 38;
    }
    // 字段类型为字符串型(nvarchar)、二进制(varbinary),字段长度为0-4000
    if (record.FieldType === 2 || record.FieldType === 10) {
      lengthMin = 1;
      lengthMax = 4000;
    }
    // 字段类型为字符串型(varchar)、,字段长度为0-8000
    if (record.FieldType === 0 || record.FieldType === 1) {
      lengthMin = 1;
      lengthMax = 8000;
    }
    if (val === '字段名称') {
      return <Input ref={inputRef} onPressEnter={save} onBlur={save} />;
    }
    if (val === '字段类型') {
      return (
        <Select
          ref={inputRef}
          onPressEnter={save}
          onBlur={save}
          showSearch
          filterOption={(input, option) =>
            option.children.toLowerCase().includes(input.toLowerCase())
          }
        >
          <Select.Option value={0}>字符串型(varchar)</Select.Option>
          <Select.Option value={12}>字符串型(varchar(max))</Select.Option>
          <Select.Option value={1}>字符型(nchar)</Select.Option>
          <Select.Option value={2}>字符串型(nvarchar)</Select.Option>
          <Select.Option value={3}>字符串型(nvarchar(max))</Select.Option>
          <Select.Option value={4}>布尔型(bit)</Select.Option>
          <Select.Option value={5}>整数型(int)</Select.Option>
          <Select.Option value={6}>浮点型(float)</Select.Option>
邓超's avatar
邓超 committed
182
          <Select.Option value={7}>长整型(bigint)</Select.Option>
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
          <Select.Option value={8}>精确数值型(decimal)</Select.Option>
          <Select.Option value={9}>时间(datetime)</Select.Option>
          <Select.Option value={10}>二进制(varbinary)</Select.Option>
          <Select.Option value={11}>二进制(varbinary(max))</Select.Option>
        </Select>
      );
    }
    if (val === '字段长度') {
      return (
        <InputNumber
          ref={inputRef}
          min={lengthMin}
          max={lengthMax}
          onPressEnter={save}
          onBlur={save}
        />
      );
    }
    if (val === '小数点位') {
      return (
        <InputNumber
          ref={inputRef}
          min={decimalPlaceMin}
          max={decimalPlaceMax}
          onPressEnter={save}
          onBlur={save}
        />
      );
    }

    return <Input ref={inputRef} onPressEnter={save} onBlur={save} />;
  };

  let childNode = children;

  if (editable) {
    // 字段类型为 字符串型(varchar)、二进制(varbinary)、字符型(nchar)、字符串型(nvarchar)、精确数值型(decimal)让修改
    if (
      title === '字段长度' &&
      (record.FieldType !== 0 &&
        record.FieldType !== 10 &&
        record.FieldType !== 1 &&
        record.FieldType !== 2 &&
        record.FieldType !== 8)
    ) {
      return <td {...restProps}>--</td>;
    }
    // 字段类型为 精确数值型(decimal)让修改
    if (title === '小数点位' && record.FieldType !== 8) {
      return <td {...restProps}>--</td>;
    }
    // 只读
235
    if (record.ReadOnly && title !== '允许空值' && title !== '是否附加') {
236 237 238 239 240 241 242 243 244 245 246 247
      return <td {...restProps}>{childNode}</td>;
    }
    // 表单规则
    let rules = [];
    if (title === '字段名称') {
      rules = [
        {
          required: true,
          message: '字段名称不能为空',
        },
        {
          validator: (rule, value) => {
248 249
            let list = JSON.parse(JSON.stringify(dataSource));
            // 合并内置字段
250 251
            if (
              value &&
252 253 254
              [...defaultData, ...list].some(
                (item, i) => item.Name === value && item.keyIndex !== record.keyIndex,
              )
255
            ) {
256
              return Promise.reject(new Error('字段名称重复,请重新输入'));
257 258 259 260
            }
            return Promise.resolve();
          },
        },
261
        {
邓超's avatar
邓超 committed
262
          pattern: /^[^\d][\u4e00-\u9fffA-Za-z0-9_]+$/,
263 264
          message: '不能输入特殊符号或者纯数字',
        },
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
      ];
    }
    childNode = editing ? (
      <Form.Item
        style={{
          width: `${width - 20}px`,
          height: '32px',
          margin: 0,
          marginLeft: '50%',
          transform: 'translateX(-50%)',
        }}
        rules={rules}
        name={dataIndex}
      >
        {rendeFrom(title)}
      </Form.Item>
    ) : (
      <div
        className="editable-cell-value-wrap"
284
        // title={children[1]}
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
        style={{
          width: `${width - 20}px`,
          height: '32px',
          overflow: 'hidden',
          whiteSpace: 'nowrap',
          textOverflow: 'ellipsis',
          margin: 'auto',
        }}
        onClick={toggleEdit}
      >
        {children}
      </div>
    );
    if (title === '允许空值') {
      childNode = (
        <Form.Item
          style={{
            margin: 0,
          }}
          name={dataIndex}
          valuePropName="checked"
        >
          <Checkbox onChange={saveCheckBox} disabled={record.ReadOnly || tableDataCount} />
        </Form.Item>
      );
    }
311 312 313 314 315 316 317
    if (title === '是否附加') {
      childNode = (
        <Form.Item
          style={{
            margin: 0,
          }}
          name={dataIndex}
涂伟's avatar
涂伟 committed
318
          valuePropName="checked"
319
        >
320 321 322 323
          <Checkbox
            disabled={record.ReadOnly && record.groupName === '物联设备表'}
            onChange={saveAddCheckBox}
          />
324 325 326
        </Form.Item>
      );
    }
327 328 329 330 331
  }

  return <td {...restProps}>{childNode}</td>;
};
const TableView = props => {
332
  const { callBackSubmit, onCancel, visible, type, formObj, tableType, defaultFieldsList } = props;
333 334 335 336 337 338 339 340
  const [dataSource, setDataSource] = useState([]);
  const [count, setCount] = useState(0);
  const [loading, setLoading] = useState(false);
  const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  const [tableMsg, setTableMsg] = useState({});
  const [tableDataCount, setTableDataCount] = useState(false);
  const [defaultData, setDefaultData] = useState([]);
  const [showDefault, setShowDefault] = useState(true);
341
  const [exceptionArr, setExceptionArr] = useState([]);
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
  const [form] = Form.useForm();

  useEffect(() => {
    if (visible) {
      if (type === 'tableEdit') {
        setLoading(true);
        form.setFieldsValue({
          tableName: formObj.tableName,
          alias: formObj.tableAlias,
        });
        getTableInfo({ tableName: formObj.tableName, isIncludeField: true })
          .then(res => {
            setLoading(false);
            if (res.code === 0) {
              setTableDataCount(res.data.root[0].TableDataCount);
              setTableMsg({
                tableStyle: res.data.root[0].tableStyle ? res.data.root[0].tableStyle : '大',
                officeTmpl: res.data.root[0].officeTmpl,
                interfaceName: res.data.root[0].interfaceText,
                tableID: res.data.root[0].tableID,
              });
              const defaultList = [];
              const fieldList = res.data.root[0].TableFields.map((item, index) => {
365
                item.groupName = formObj.groupName;
366 367 368 369 370 371 372 373 374 375 376
                const obj = {
                  ...item,
                  keyIndex: index,
                };
                if (item.ReadOnly) {
                  defaultList.push(obj);
                }
                return obj;
              });
              setDefaultData(defaultList);
              setCount(fieldList.length);
377 378 379 380 381

              setShowDefault(false);
              let list = JSON.parse(JSON.stringify(fieldList));
              list = list.filter(item => !item.ReadOnly);
              setDataSource(list);
382 383 384 385 386 387 388 389 390
            } else {
              notification.error({ message: '提示', duration: 3, description: res.msg });
            }
          })
          .catch(() => {
            setLoading(false);
            notification.error({ message: '提示', duration: 3, description: '网络异常' });
          });
      } else {
391 392 393 394 395 396 397 398 399 400
        let list = defaultFieldsList
          .find(item => item.value === tableType)
          .list.map((item, i) => ({ ...item, keyIndex: i }));
        console.log(list);
        setDefaultData(list);
        setCount(list.length);
        setShowDefault(false);
        let listitem = JSON.parse(JSON.stringify(list));
        listitem = listitem.filter(item => !item.ReadOnly);
        setDataSource(listitem);
401
      }
402
      reloadTableFieldsArr();
403
    } else {
404
      setShowDefault(false);
405 406 407
      setDataSource([]);
      setDefaultData([]);
      setSelectedRowKeys([]);
408
      setExceptionArr([]);
409 410 411 412
      form.resetFields();
    }
  }, [visible]);

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
  const removeMissingFields = () => {
    let ids = exceptionArr.map(item => item.ID).join(',');
    removeFields({
      fieldIDs: ids,
    }).then(res => {
      if (res.code === 0) {
        notification.success({
          message: '提示',
          duration: 3,
          description: '清除成功',
        });
        reloadTableFieldsArr();
      }
    });
  };
  const reloadTableFieldsArr = () => {
    reloadTableFields({
      tableName: formObj.tableName,
    }).then(res => {
      if (res.msg === 'Ok') {
        setExceptionArr(res.data.root.filter(item => item.group === '(缺少字段)'));
      }
    });
  };

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
  // 提交表单
  const onFinish = () => {
    // 校验提示
    let checkMsg = '';
    let TableFields = JSON.parse(JSON.stringify(dataSource));

    TableFields.forEach((item, index) => {
      item.Order = index;
      if (!item.Name) {
        item.errors = ['字段名称不能为空'];
      }
      if (item.errors?.length > 0) {
        item.errors.forEach(ele => {
          checkMsg = `${checkMsg}${index + 1}行 校验错误:${ele}\n`;
        });
      }
    });
    if (!showDefault) {
      // 默认字段不显示时要拼接上默认字段
      TableFields = [...defaultData, ...TableFields];
    }
459 460 461 462 463 464 465 466 467
    // if (checkMsg) {
    //   notification.error({
    //     message: '提示',
    //     duration: 3,
    //     description: checkMsg,
    //     style: { whiteSpace: 'pre-wrap' },
    //   });
    //   return;
    // }
468 469 470 471 472 473 474 475 476 477 478
    form.validateFields().then(validate => {
      if (validate) {
        if (!validate.tableName) {
          notification.error({ message: '提示', duration: 3, description: '请填写表名' });
          return;
        }

        if (type === 'add') {
          // 新建表
          CreateTablePost({
            ...validate,
邓超's avatar
邓超 committed
479
            tableName: `${tableType.substr(0, tableType.length - 1)}_${validate.tableName}`,
480 481
            TableFields,
            tableType,
482
            tableStyle: '大',
483 484 485 486 487
          }).then(res => {
            if (res.code === 0) {
              notification.success({
                message: '提示',
                duration: 3,
488
                description: '新增成功',
489 490 491 492 493 494 495 496 497 498 499 500 501
              });
              callBackSubmit();
            } else {
              notification.error({ message: '提示', duration: 3, description: res.msg });
            }
          });
        } else {
          // 编辑表
          updateTablePost({ ...validate, TableFields, ...tableMsg }).then(res => {
            if (res.code === 0) {
              notification.success({
                message: '提示',
                duration: 3,
502
                description: '编辑成功',
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
              });
              callBackSubmit();
            } else {
              notification.error({ message: '提示', duration: 3, description: res.msg });
            }
          });
        }
      }
    });
  };
  // 添加字段
  const handleAdd = () => {
    const newData = {
      keyIndex: count,
      Name: '',
      FieldType: 0,
519
      FieldLength: 255,
520 521
      DecimalPlace: 0,
      IsNullable: true,
522
      IsAddFieldConfig: true,
523 524 525
    };
    setDataSource([...dataSource, newData]);
    setCount(count + 1);
526 527 528 529
    setTimeout(() => {
      let tableEl = document.querySelector(`.${styles.content} .ant-table-body`);
      tableEl.scrollTop = tableEl.scrollHeight;
    }, 10);
530
  };
皮倩雯's avatar
皮倩雯 committed
531

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
  // 批量删除字段
  const deleteFilleds = () => {
    if (selectedRowKeys.length === 0) {
      notification.error({ message: '提示', duration: 3, description: '请选择字段' });
      return;
    }
    const list = [];
    dataSource.forEach(item => {
      const isDelete = selectedRowKeys.some(value => value === item.keyIndex);
      if (!isDelete) {
        list.push(item);
      }
    });
    setDataSource(list);
  };
  // 删除字段
  const handleDelete = (record, keyIndex) => {
    if (record.ReadOnly) {
      notification.error({ message: '提示', duration: 3, description: '内置字段不允许删除' });
      return;
    }
    const newData = dataSource.filter((item, index) => index !== keyIndex);
    setDataSource(newData);
  };
556 557 558 559 560 561 562
  const addArr = useMemo(() => {
    let arr = JSON.parse(JSON.stringify(dataSource));
    if (showDefault) {
      return arr;
    }
    return [...defaultData, ...arr];
  }, [showDefault, defaultData, dataSource]);
563 564 565
  // 修改后存值
  const handleSave = (row, key) => {
    if (key === 'FieldType') {
566 567 568 569
      if (row.FieldType === 0 || row.FieldType === 2) {
        row.FieldLength = 255;
        row.DecimalPlace = 0;
      } else if (row.FieldType === 10) {
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
        row.FieldLength = 50;
        row.DecimalPlace = 0;
      } else if (row.FieldType === 1) {
        row.FieldLength = 10;
        row.DecimalPlace = 0;
      } else if (row.FieldType === 8) {
        row.FieldLength = 18;
        row.DecimalPlace = 3;
      } else {
        row.FieldLength = 0;
        row.DecimalPlace = 0;
      }
    }
    const { index } = row;
    const newData = [...dataSource];
    const item = newData[index];
    newData.splice(index, 1, { ...item, ...row });
587
    // 内置字段同步更改
涂伟's avatar
涂伟 committed
588 589 590 591 592
    // if (index < defaultData.length) {
    //   const newDefaultData = [...defaultData];
    //   newDefaultData.splice(index, 1, { ...item, ...row });
    //   setDefaultData(newDefaultData);
    // }
593 594 595 596 597 598 599 600 601 602 603 604 605 606
    setDataSource(newData);
  };
  // 是否显示默认字段
  const showDefaultFields = e => {
    setShowDefault(e);
    let list = JSON.parse(JSON.stringify(dataSource));
    if (e) {
      // 显示内置字段
      list = [...defaultData, ...list];
    } else {
      list = list.filter(item => !item.ReadOnly);
    }
    setDataSource(list);
  };
607
  const deleteAddField = (row, index) => {
608 609
    let arr = JSON.parse(JSON.stringify(dataSource));
    arr.forEach(item => {
610
      if (item.Name === row.Name) {
611 612 613
        item.IsAddFieldConfig = false;
      }
    });
614 615 616 617 618 619 620 621 622
    if (!showDefault) {
      let defaultArr = JSON.parse(JSON.stringify(defaultData));
      defaultArr.forEach(item => {
        if (item.Name === row.Name) {
          item.IsAddFieldConfig = false;
        }
      });
      setDefaultData(defaultArr);
    }
623
    setDataSource(arr);
624
    // }
625
  };
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
  // 表格设置
  const components = {
    body: {
      row: EditableRow,
      cell: EditableCell,
    },
  };
  const defaultColumns = [
    {
      title: '序号',
      align: 'center',
      width: 50,
      render: (text, record, index) => <span>{index + 1}</span>,
    },
    {
      title: '字段名称',
      dataIndex: 'Name',
      width: 200,
644
      // ellipsis: true,
645 646
      editable: true,
      align: 'center',
皮倩雯's avatar
皮倩雯 committed
647 648 649 650
      render: (text, record) => (
        <>
          <span>{text}</span>
          {record.IsIndex && (
651 652 653 654
            <img src={index} style={{ height: '25px', marginLeft: '5px' }} alt="" />
          )}
          {record.IsPrimaryKey && (
            <img src={primaryKey} style={{ height: '25px', marginLeft: '5px' }} alt="" />
皮倩雯's avatar
皮倩雯 committed
655 656 657
          )}
        </>
      ),
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
    },
    {
      title: '字段类型',
      dataIndex: 'FieldType',
      width: 220,
      ellipsis: true,
      editable: true,
      align: 'center',
      render: text => {
        switch (text) {
          case 0:
            return '字符串型(varchar)';
          case 1:
            return '字符型(nchar)';
          case 2:
            return '字符串型(nvarchar)';
          case 3:
            return '字符串型(nvarchar(max))';
          case 4:
            return '布尔型(bit)';
          case 5:
            return '整数型(int)';
          case 6:
            return '浮点型(float)';
          case 7:
邓超's avatar
邓超 committed
683
            return '长整型(bigint)';
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
          case 8:
            return '精确数值型(decimal)';
          case 9:
            return '时间(datetime)';
          case 10:
            return '二进制(varbinary)';
          case 11:
            return '二进制(varbinary(max))';
          case 12:
            return '字符串型(varchar(max))';

          default:
            return null;
        }
      },
    },
    {
      title: '字段长度',
      dataIndex: 'FieldLength',
      width: 100,
      ellipsis: true,
      editable: true,
      align: 'center',
    },
    {
      title: '小数点位',
      dataIndex: 'DecimalPlace',
      width: 100,
      ellipsis: true,
      editable: true,
      align: 'center',
    },
716 717 718 719 720 721 722
    // {
    //   title: '允许空值',
    //   dataIndex: 'IsNullable',
    //   width: 100,
    //   editable: true,
    //   align: 'center',
    // },
723 724 725 726 727 728 729
    {
      title: '是否附加',
      dataIndex: 'IsAddFieldConfig',
      width: 100,
      editable: true,
      align: 'center',
    },
730 731
    {
      title: '操作',
732
      width: 50,
733 734 735 736
      align: 'center',
      render: (_, record, index) =>
        dataSource.length >= 1 ? (
          <Tooltip title="删除">
737 738
            <Button
              style={{ border: 'none', padding: '4px 5px', background: 'none' }}
739
              onClick={() => handleDelete(record, index)}
740 741 742 743 744 745 746
              disabled={record.ReadOnly}
            >
              <DeleteOutlined
                style={{ fontSize: '16px', color: `${record.ReadOnly ? '#ccc' : '#e86060'}` }}
                disabled={record.ReadOnly}
              />
            </Button>
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
          </Tooltip>
        ) : null,
    },
  ];
  const columns = defaultColumns.map(col => {
    if (!col.editable) {
      return col;
    }
    return {
      ...col,
      onCell: (record, index) => ({
        index,
        record,
        editable: col.editable,
        dataIndex: col.dataIndex,
        width: col.width,
        title: col.title,
        ellipsis: col.ellipsis,
        align: col.align,
        dataSource,
        tableDataCount,
768
        defaultData,
769
        setDefaultData,
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796
        handleSave,
      }),
    };
  });
  // 表格复选框
  const onSelectChange = newSelectedRowKeys => {
    setSelectedRowKeys(newSelectedRowKeys);
  };
  const rowSelection = {
    selectedRowKeys,
    onChange: onSelectChange,
    getCheckboxProps: record => ({
      disabled: record.ReadOnly,
    }),
  };
  return (
    <Modal
      title={type === 'add' ? `建表【${tableType}】` : `表编辑`}
      visible={visible}
      width="1300px"
      onOk={onFinish}
      onCancel={onCancel}
      maskClosable={false}
      destroyOnClose
      centered
    >
      <div className={styles.content}>
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
        <div>
          <Form form={form}>
            <div style={{ display: 'flex', justifyContent: 'space-between' }}>
              <div style={{ display: 'flex' }}>
                <Form.Item
                  label="表名"
                  rules={[
                    {
                      required: true,
                      message: '表名称不能为空',
                    },
                    {
                      pattern: /^[\u4e00-\u9fffa-zA-Z0-9_]+$/,
                      message: '不能输入特殊符号',
                    },
                  ]}
                  name="tableName"
                  required
                  style={{ marginBottom: '0' }}
                >
                  <Input
                    addonBefore={
                      type === 'add' ? `${tableType.substr(0, tableType.length - 1)}_` : null
                    }
                    placeholder="请填写表名"
                  />
                </Form.Item>
                <Form.Item
825
                  label="展示名称"
826 827 828
                  name="alias"
                  style={{ marginBottom: '0', marginLeft: '10px' }}
                >
829
                  <Input placeholder="请填写展示名称" />
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
                </Form.Item>
              </div>
              <div style={{ display: 'flex' }}>
                <Form.Item label="内置字段" style={{ marginBottom: '0', marginRight: '10px' }}>
                  <Switch
                    checkedChildren="显示"
                    unCheckedChildren="隐藏"
                    onChange={showDefaultFields}
                  />
                </Form.Item>
                <Form.Item style={{ marginBottom: '0', marginRight: '10px' }}>
                  <Button type="primary" onClick={() => handleAdd()}>
                    <div style={{ display: 'flex', alignItems: 'center' }}>
                      <PlusOutlined style={{ marginRight: '5px' }} />
                      <span> 新增</span>
                    </div>
                  </Button>
                </Form.Item>
                <Form.Item style={{ marginBottom: '0' }}>
                  <Button onClick={() => deleteFilleds()}>
                    <div style={{ display: 'flex', alignItems: 'center' }}>
                      <MinusOutlined style={{ marginRight: '5px' }} />
                      <span> 批量删除</span>
                    </div>
                  </Button>
                </Form.Item>
              </div>
857
            </div>
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
          </Form>
          <Spin spinning={loading}>
            <Table
              rowKey="keyIndex"
              rowSelection={rowSelection}
              size="small"
              style={{ marginTop: '10PX' }}
              components={components}
              rowClassName={() => 'editable-row'}
              bordered
              dataSource={dataSource}
              columns={columns}
              scroll={{ y: '540px' }}
              pagination={false}
              id="box"
            />
            <div id="page-bottom" />
          </Spin>
        </div>
        <div className={styles.subContent}>
878 879 880 881 882 883
          <div className={styles.subArea} style={{ height: exceptionArr.length ? '70%' : '100%' }}>
            <div className={styles.subTitle}>已附加字段集</div>
            <div className={styles.subItems}>
              {addArr.map((item, index) =>
                item.IsAddFieldConfig ? (
                  <div className={styles.subItem}>
884
                    <span>{item.Name}</span>{' '}
885
                    <span className={styles.deleteItem} onClick={() => deleteAddField(item, index)}>
886 887 888 889 890 891 892 893 894 895 896 897 898
                      X
                    </span>
                  </div>
                ) : null,
              )}
              {/* {dataSource.some(item => {
                item.IsAddFieldConfig;
              })?:<Empty
              image={Empty.PRESENTED_IMAGE_SIMPLE}
              description="暂无数据"
              style={{ margin: '20px auto 0px auto', paddingTop: '50px' }}
            />} */}
            </div>
899
          </div>
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
          {exceptionArr.length ? (
            <div className={styles.exceptionArea}>
              <div className={styles.subTitle}>
                异常字段集{' '}
                <Button
                  danger
                  style={{
                    borderRadius: '4px',
                    display: 'flex',
                    alignItems: 'center',
                    justifyContent: 'space-around',
                  }}
                  onClick={() => removeMissingFields()}
                  size="small"
                >
                  <img src={clearImg} alt="" style={{ width: '14px' }} />
                  一键清除
                </Button>
              </div>
              <div className={styles.subItems}>
                {exceptionArr.map((item, index) => (
                  <div className={styles.subItem}>
                    <span style={{ color: 'red' }}>{item.alias || item.name}</span>{' '}
                  </div>
                ))}
              </div>
            </div>
          ) : null}
928
        </div>
929 930 931 932 933
      </div>
    </Modal>
  );
};
export default TableView;