ReportsSetting.js 82.4 KB
Newer Older
陈龙's avatar
陈龙 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/**
 * * 报表设置列表 * create by ChenLong on 2022/6/28 *
 * 功能路径:src\pages\product\ReportsManage\Components\ReportsSetting.js *
 * 菜单参数列表:*变量名*(变量说明,数据类型,是否必填,取值范围) * @changelog: edit by ChenLong 2022年7月7日
 * 增加日期类型的过滤,可以配置日期选择器,只允许存在一个日期类型的过滤;在表单提交时做校验 edit by ChenLong 2022年7月8日 表单的使用方式需要变更,需求为:1.
 * 动态表单控件需要封装成组件; 2. 动态列表需要使用Form.List替换】 待执行 edit by ChenLong 2022年7月8日 变更单页、全部统计的规则
 */

import React, { useEffect, useRef, useState } from 'react';
import {
  DeleteOutlined,
  FormOutlined,
  MinusCircleOutlined,
  PlusOutlined,
  MenuOutlined,
  SettingOutlined,
  LeftOutlined,
  ExportOutlined,
  ImportOutlined,
} from '@ant-design/icons';
import {
  Button,
  Checkbox,
  Divider,
  Form,
  Input,
  InputNumber,
  message,
  Modal,
  Row,
  Select,
  Space,
  Switch,
  Tooltip,
  Table,
  Upload,
} from 'antd';
import { SketchPicker } from 'react-color';
import { arrayMoveImmutable } from 'array-move';
import BasicTable from '@wisdom-components/basictable';
import { reportService } from '../api';
陈龙's avatar
陈龙 committed
42
import styles from './ReportsSetting.less';
陈龙's avatar
陈龙 committed
43 44 45 46 47 48 49 50 51 52 53
import { SortableContainer, SortableElement, SortableHandle } from 'react-sortable-hoc';
import {
  addReportDetailInfoIndex,
  API,
  exportReportConfig,
  importReportConfig,
} from '../api/service/report';
import { isNumber, isString } from './utils/utils';
import moment from 'moment';
import CustomerColorPicker from './Components/customerColorPicker/CustomerColorPicker';

陈龙's avatar
陈龙 committed
54 55 56 57
import ChartConfig from '../ReportsManage/Components/ChartConfig';
import classnames from 'classnames';
import NumberConfig from '../ReportsManage/Components/NumberConfig';

58
const { Option, OptGroup } = Select;
陈龙's avatar
陈龙 committed
59 60
const { TextArea } = Input;
const { Search } = Input;
61 62 63 64 65 66
const typeArray = {
  '文本': ['文本', '多行文本', '标签', '链接', '功能', '附件'],
  '数值': ['数值', '数值标签'],
  '日期': ['日期', '日期时间'],
};
const filterRule = ['文本', '下拉', '多选', '日期', '复选框'];
陈龙's avatar
陈龙 committed
67 68 69
const publicSplit = '&split;';
const USER_ID = window.globalConfig.userInfo.OID;
const ReportsSetting = () => {
陈龙's avatar
陈龙 committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 122 123 124 125
      // 报表列表
      const layout = {
        labelCol: { span: 4 },
        wrapperCol: { span: 20 },
      };
      const [form] = Form.useForm();
      const [createMainTableForm] = Form.useForm();
      const [patchSubTableForm] = Form.useForm();
      const [editDetailForm] = Form.useForm();
      const watchType = Form.useWatch('type', form);
      const showFilter = Form.useWatch('isFilter', form);
      const fieldGroupLevel = Form.useWatch('level', form);
      const isStatistics = Form.useWatch('isStatistics', form);
      const [isCreatingMainTable, setIsCreatingMainTable] = useState(false);
      const colorPicker = useRef();
      const reportDetails = useRef();
      const [tableData, setTableData] = useState([]); // 常规使用的数据
      const [tableLoading, setTableLoading] = useState(false);
      const [detailTableVisible, setDetailTableVisible] = useState(false);
      const [currentPage, setCurrentPage] = useState('报表列表'); // 报表列表 报表设置 图表设置
      const columns = [
        {
          title: '报表名称',
          dataIndex: 'reportName',
          key: 'reportName',
          width: 260,
        }, {
          title: '数据源',
          dataIndex: 'db_sourcesname',
          key: 'db_sourcesname',
          width: 200,
          render: text => !text ? '本地' : text,
        }, {
          title: '主表名称',
          dataIndex: 'tableName',
          key: 'tableName',
          width: 300,
        }, {
          title: '报表字段',
          dataIndex: 'reportFields',
          key: 'reportFields',
          // ellipsis:true,
          render: (text) => <Tooltip title={text}>
            {/* 自动折叠内容时,如果使用Tooltip,Tooltip会无法正确定位;建议手动设置内容折叠 */}
            <span className={styles.reportFiled}>{text}</span>
          </Tooltip>,
        }, {
          title: '创建时间',
          dataIndex: 'createTime',
          key: 'createTime',
          width: 200,
        }, {
          title: '创建人',
          dataIndex: 'creator',
          key: 'creator',
          width: 100,
陈龙's avatar
陈龙 committed
126
        },
陈龙's avatar
陈龙 committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        {
          title: '操作',
          width: 120,
          render: (text, record) => {
            return <div style={{ display: 'flex', justifyContent: 'space-around' }}>
              <FormOutlined title={'编辑字段'} onClick={() => {
                setCurrentDataSourceType(
                    dataSourcesList.find(item => item.id === record.sourcesId)?.db_type || '',
                );
                editReport(record);
              }} style={{ color: '#1685FF' }}/>
              <SettingOutlined title={'设置'} style={{ color: 'rgba(0,0,0,.55)' }} onClick={() => {
                setCurrentReport(record);
                setCurrentDataSourceType(
                    dataSourcesList.find(item => item.id === record.sourcesId)?.db_type || '',
                );
                clickReport(record.id);
              }}/>
              <LineChartOutlined title={'图表配置'} onClick={() => {
                setCurrentReport(record);
                setCurrentPage('图表配置');
                setCurrentDataSourceType(
                    dataSourcesList.find(item => item.id === record.sourcesId)?.db_type || '',
                );
              }
              }/>
              <ExportOutlined title={'导出配置'} onClick={() => exportConfigs(record)}/>
              <DeleteOutlined title={'删除报表'} style={{ color: 'red' }} onClick={() => deleteReport(record)}/>
            </div>;
156 157
          },
        },
陈龙's avatar
陈龙 committed
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 [detailData, setDetailData] = useState([]); // 详情表的数据
      const [tempDetailData, setTempDetailData] = useState([]); // 备份数据
      const [detailVisible, setDetailVisible] = useState(false);
      const [backgroundColor, setBackgroundColor] = useState('rgba(0,0,0,.85)');
      const [showSketchPicker, setShowSketchPicker] = useState(false);
      const [createModalVisible, setCreateModalVisible] = useState(false);
      const [activeID, setActiveID] = useState(null);
      const [currentField, setCurrentField] = useState(null);
      const [patchFieldVisible, setPatchFieldVisible] = useState(false);
      const [subTableList, setSubTableList] = useState([]);
      const [allTableList, setAllTableList] = useState([]); // 数据库表
      const [allFields, setAllFields] = useState([]); // 新增主表时的选择的表字段
      const [allSubFields, setAllSubFields] = useState([]);// 新增子表字段
      const [createBtnLoading, setCreateBtnLoading] = useState(false);
      const [currentReport, setCurrentReport] = useState({});
      const [colorCardPosition, setColorCardPosition] = useState({});
      const [labelColorPickerArray, setLabelColorPickerArray] = useState([]); // 标签色板
      const [textColorPickerArray, setTextColorPickerArray] = useState([]); // 文本色板
      const [numberColorPickerArray, setNumberColorPickerArray] = useState([]); // 数值色板
      const [currentColorPicker, setCurrentColorPicker] = useState({ // 因为使用单例,需要记录是哪一个色板触发了
        data: [],
        callback: () => {
182
        },
陈龙's avatar
陈龙 committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
        index: 0,
        key: 'init', // init 初始化时的key,用来解决初始化报错的问题;wordColor 用来区分是那部分的色板
      }); // 记录需要修改的对象
      const [submitFieldLoading, setSubmitFieldLoading] = useState(false);
      const [relationship, setRelationship] = useState([]);
      const [patchSubTableBtnLoading, setPatchSubTableBtnLoading] = useState(false);
      const [isEditing, setIsEditing] = useState(true);
      const [detailTableLoading, setDetailTableLoading] = useState(false);
      const [selectedRowKeys, setSelectedRowKeys] = useState([]);
      const [selectedRows, setSelectedRows] = useState([]);
      const [dataSourcesList, setDataSourcesList] = useState([]);
      const [currentDataSource, setCurrentDataSource] = useState('');
      const [currentDataSourceType, setCurrentDataSourceType] = useState('');
      const SortableItem = SortableElement((props) => <tr {...props} />);
      const SortableBody = SortableContainer((props) => <tbody {...props} />);
      // 导入配置
      const uploadProps = {
        action: `${window.location.origin}${API.IMPORT_REPORT_DATA}`,
        multiple: false,
        showUploadList: false,
        headers: {
          'Content-Type': 'multipart/form-data',
205
        },
陈龙's avatar
陈龙 committed
206 207 208 209 210 211
        withCredentials: true,
        customRequest({ action, file, headers, withCredentials }) {
          const formData = new FormData();
          formData.append('file', file);
          const _data = { userId: USER_ID };
          importReportConfig(
212
              {
陈龙's avatar
陈龙 committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226
                headers: {
                  'Content-Type': 'multipart/form-data',
                },
              },
              { ..._data },
              formData,
          ).then(res => {
            if (res.code === 0) {
              message.success('导入成功!');
              getData();
            } else {
              message.info(res.msg);
            }
          });
227
        },
陈龙's avatar
陈龙 committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
      };
      const onSortEnd = ({ oldIndex, newIndex }) => {
        if (oldIndex !== newIndex) {
          const newData = arrayMoveImmutable(detailData.slice(), oldIndex, newIndex).filter(
              (el) => !!el,
          );
          setDetailData(newData);
          setTempDetailData(newData);
          editDetailForm.setFieldsValue(newData);
          saveOrder(newData);
        }
      };
      const DraggableContainer = (props) => (
          <SortableBody
              useDragHandle
              disableAutoscroll
              helperClass="row-dragging"
              onSortEnd={onSortEnd}
              {...props}
          />
      );
      const DraggableBodyRow = ({ className, style, ...restProps }) => {
        const index = detailData.findIndex((x) => x.id === restProps['data-row-key']);
        return <SortableItem index={index} {...restProps} />;
      };
      const returnEqual = (index, key) => {
        return (detailData[index] && !tempDetailData[index]) || (detailData[index] && tempDetailData[index] && detailData[index][key] !== tempDetailData[index][key]);
      };
      const detailColumns = [
        {
          title: '',
          dataIndex: 'sort',
          width: isEditing ? 0 : 30,
          className: 'drag-visible',
          render: () => <DragHandle/>,
263
        },
陈龙's avatar
陈龙 committed
264 265 266 267 268 269
        {
          title: '表名',
          dataIndex: 'tableName',
          className: 'drag-visible',
          key: 'tableName',
          // colSpan: currentDataSourceType === 'webapi' ? 0 : 1,
270
        },
陈龙's avatar
陈龙 committed
271 272 273 274
        {
          title: '字段名',
          dataIndex: 'fieldName',
          key: 'fieldName',
275
        },
陈龙's avatar
陈龙 committed
276 277 278 279 280 281 282 283 284 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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
        {
          title: '字段组',
          dataIndex: 'fieldGroup',
          key: 'fieldGroup',
        }, {
          title: '形态',
          dataIndex: 'type',
          key: 'type',
          width: 80,
        }, {
          title: '列宽',
          dataIndex: 'columnWidth',
          key: 'columnWidth',
          width: 120,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'columnWidth']} rules={[{
              required: true,
              message: '列宽不能为空',
            }]}><InputNumber value={record?.columnWidth}
                             className={returnEqual(index, 'columnWidth') ? styles.boxShadow : ''}
                             onChange={(e) => modifyDetailData('columnWidth', e, record, index)}/></Form.Item> : `${text}px`;
          },
        }, {
          title: '对齐方式',
          dataIndex: 'alignType',
          key: 'alignType',
          width: 80,
          render: (text, record, index) => {
            const _map = {
              left: '左',
              right: '右',
              center: '中',
            };
            return isEditing ? <Form.Item name={[index, 'alignType']}>
              <Select onChange={(e) => modifyDetailData('alignType', e, record, index)}
                      className={returnEqual(index, 'alignType') ? styles.boxShadowOfSelect : ''}>
                <Option value={text ? 'left' : ''}></Option>
                <Option value={'center'}></Option>
                <Option value={'right'}></Option>
              </Select>
            </Form.Item> : (_map[text] || '左');
          },
        }, {
          title: '是否固定',
          dataIndex: 'fixedColumn',
          key: 'fixedColumn',
          width: 120,
          render: (text, record, index) => {
            const _map = {
              left: '左',
              right: '右',
            };
            return isEditing ? <Form.Item name={[index, 'fixedColumn']}>
              <Select onChange={(e) => modifyDetailData('fixedColumn', e, record, index)}
                      className={returnEqual(index, 'fixedColumn') ? styles.boxShadowOfSelect : ''}>
                <Option value={''}>不固定</Option>
                <Option value={'left'}></Option>
                <Option value={'right'}></Option>
              </Select>
            </Form.Item> : (_map[text] || '不固定');
          },
        }, {
          title: '是否显示',
          dataIndex: 'isShow',
          key: 'isShow',
          width: 100,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'isShow']} valuePropName="checked">
              <Switch onChange={(e) => modifyDetailData('isShow', e, record, index)} checkedChildren="显示"
                      unCheckedChildren="不显示" defaultChecked={false}
                      className={returnEqual(index, 'isShow') ? styles.boxShadowOfSwitch : ''}/>
            </Form.Item> : (text ? '是' : '否');
          },
        }, {
          title: '是否过滤',
          dataIndex: 'isFilter',
          key: 'isFilter',
          width: 120,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'isFilter']} valuePropName="checked">
              <Switch onChange={(e) => modifyDetailData('isFilter', e, record, index)} checkedChildren="开启"
                      unCheckedChildren="关闭" defaultChecked={false}
                      className={returnEqual(index, 'isFilter') ? styles.boxShadowOfSwitch : ''}/>
            </Form.Item> : (text ? '是' : '否');
          },
        }, {
          title: '过滤类型',
          dataIndex: 'filterRule',
          key: 'filterRule',
          width: 120,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'filterRule']}>
              <Select disabled={!record.isFilter}
                      onChange={(e) => modifyDetailData('filterRule', e, record, index)}
                      className={returnEqual(index, 'filterRule') ? styles.boxShadowOfSelect : ''}>
                <Option value={''}>不过滤</Option>
                {
                  filterRule.map(item => <Option value={item}>{item}</Option>)
                }
              </Select>
            </Form.Item> : text;
          },
        }, {
          title: '向下合并',
          dataIndex: 'isMerge',
          key: 'isMerge',
          width: 120,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'isMerge']} valuePropName="checked">
              <Switch onChange={(e) => modifyDetailData('isMerge', e, record, index)} checkedChildren="开启"
                      unCheckedChildren="关闭" defaultChecked={false}
                      className={returnEqual(index, 'isMerge') ? styles.boxShadowOfSwitch : ''}/>
            </Form.Item> : (text ? '合并' : '不合并');
          },
        }, {
          title: '是否必填',
          dataIndex: 'isRequired',
          key: 'isRequired',
          width: 100,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'isRequired']} valuePropName="checked">
              <Switch onChange={(e) => modifyDetailData('isRequired', e, record, index)} checkedChildren="是"
                      unCheckedChildren="否" defaultChecked={false}
                      className={returnEqual(index, 'isRequired') ? styles.boxShadowOfSwitch : ''}/>
            </Form.Item> : (text ? '是' : '否');
          },
        }, {
          title: '是否只读',
          dataIndex: 'isReadOnly',
          key: 'isReadOnly',
          width: 100,
          render: (text, record, index) => {
            return isEditing ? <Form.Item name={[index, 'isReadOnly']} valuePropName="checked">
              <Switch onChange={(e) => modifyDetailData('isReadOnly', e, record, index)} checkedChildren="是"
                      unCheckedChildren="否" defaultChecked={false}
                      className={returnEqual(index, 'isReadOnly') ? styles.boxShadowOfSwitch : ''}/>
            </Form.Item> : (text ? '是' : '否');
          },
        }, {
          title: '操作',
          width: 80,
          render: (text, record) => {
            return <div style={{ display: 'flex', justifyContent: 'space-around' }}>
              <FormOutlined onClick={() => {
                setActiveID(record.id);
                if (record.color) setBackgroundColor(record.color);
                form.setFieldsValue(setDefaultValue(record));
                setCurrentField(setDefaultValue(record));
                setDetailVisible(true);
              }
              }/>
              <DeleteOutlined onClick={() => deleteReportDetail(record.id)} style={{ color: 'red' }}/>
            </div>;
          },
430
        },
陈龙's avatar
陈龙 committed
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
      ];
      const rowSelection = {
        onChange: (selectedRowKeys, selectedRows) => {
          setSelectedRowKeys(selectedRowKeys);
          setSelectedRows(selectedRows);
        },
      };
      const wordInputWidth = 300;
      const numberInputWidth = 120;
      const rangeWidth = 500;
      const tagWidth = 400;
      const getData = () => {
        setTableLoading(true);
        reportService.getReportConfigList().then(res => {
          if (res.code === 0) {
            // 增加visible属性,后续搜索时需要
            let _data = res.data.map(item => {
              let _item = { ...item };
              _item.visible = true;
              return _item;
            });
            setTableData(_data);
          } else {
            message.error(res.msg);
          }
          setTableLoading(false);
        }).catch(err => {
          setTableLoading(false);
        });
      };
      const clickReport = (reportId) => {
        setTableLoading(true);
        reportService.getReportDetailsInfo({ reportId }).then(res => {
          if (res.code === 0) {
            setTableLoading(false);
            setCurrentPage('报表配置');
            // 增加visible属性,方便后续检索的属性变更
            let _final = res.data.details.map(item => {
              let _item = { ...item };
              _item.visible = true;
              return _item;
            });
            _final.sort((a, b) => b.isShow - a.isShow);  // 将显示项放在前边 edit by zhangzhiwei 2023-07-04
            editDetailForm.setFieldsValue(_final);
            setDetailData(_final);
            setTempDetailData(_final);
            // 存储关联关系
            setRelationship(res.data.child);
          }
        }).catch(err => {
          setTableLoading(false);
        });
      };
      const restCreateReportForm = () => {
        createMainTableForm.resetFields();
        setAllFields([]);
      };
      const createReport = () => {
        setCreateBtnLoading(true);
        createMainTableForm.validateFields().then(
            values => {
              let _data = {
                reportName: values.reportName,
                tableName: values.tableName,
                reportFields: values.reportFields.join(','),
                creator: String(globalConfig.userInfo.OID),
                interfaceConfig: values.interfaceConfig,
              };
              if (currentReport && currentReport.id) {
                _data.id = currentReport.id;
                return editReportOrSubTable({
                  rM_ReportInfo: [_data],
                  sourcesId: currentReport.sourcesId,
                  isAdd: false,
                }, () => {
                  setCreateBtnLoading(false);
                  setCreateModalVisible(false);
                  getData();
                  restCreateReportForm();
                });
              }
              addReportOrPatchSubTable({ rM_ReportInfo: [_data], sourcesId: values.sourcesId, isAdd: true }, () => {
                setCreateBtnLoading(false);
                setCreateModalVisible(false);
                getData();
                restCreateReportForm();
              });
            },
        ).catch(err => {
          setCreateBtnLoading(false);
        });
      };
      const deleteReport = (report) => {
        Modal.confirm({
          title: '请确认',
          content: `是否删除【${report.reportName}】报表?`,
          onOk: () => {
            reportService.deleteReportInfo({ reportId: report.id }).then(res => {
              if (res.code === 0) {
                message.success('删除成功!');
                getData();
              }
            });
          },
        });
      };
      const deleteReportDetail = (reportDetailId) => {
        Modal.confirm({
          title: '请确认',
          content: '是否删除该参数?',
          onOk: () => {
            reportService.deleteReportDetailInfo({ reportDetailId }).then(res => {
              if (res.code === 0) {
                clickReport(currentReport.id);
                message.success('删除成功!');
              } else {
                message.error(res.code);
              }
            });
          },
        });
      };
      const editReport = (record) => {
        openCreateModal();
        setCurrentReport(record);
        setIsCreatingMainTable(false);
        createMainTableForm.setFieldsValue({
          tableName: record.tableName,
          reportName: record.reportName,
          reportFields: record.reportFields.split(','),
          interfaceConfig: record.interfaceConfig,
        });
        getFieldsFromTable(record.tableName, 'mainTable', record);
      };
      const addReportOrPatchSubTable = (data, callback) => {
        reportService.addReportInfo(data).then(res => {
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          if (callback) callback();
        });
      };
      const editReportOrSubTable = (data, callback) => {
        reportService.editReportInfo(data).then(res => {
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          if (callback) callback();
        });
      };
      // 切换字段的同时,如果数据有修改,那需要保存之前的数据 edit by ChenLong 2022年8月29日
      const changeField = (record) => {
        // submitReportDetails('changeField').then(res => {
        setActiveID(record.id);
        form.setFieldsValue(setDefaultValue(record));
        // 手动设置文字的颜色
        setBackgroundColor(record.color);
        // 手动设置labelConfig和number的设置
        setNumberColorPickerArray(record.numericalConfigs);
        setLabelColorPickerArray(record.labelConfigs);
        setCurrentField(setDefaultValue(record)); // 为了确保前后数据统一
        // });
      };
      const setDefaultValue = (record) => {
        if (!record) return {};
        let _record = { ...record };
        if (!_record.type) _record.type = '文本';
        if (isString(_record.fieldGroup)) {
          _record.fieldGroup = _record.fieldGroup.split('-').reduce((final, curr, index) => {
            final[`fieldGroup_${record.fieldAlias}_${index}`] = curr;
            return final;
          }, {});
        }
        if (!_record.filterRule) _record.filterRule = '下拉';
        if (!_record.statisticsRule) _record.statisticsRule = '求和';
        // 统计规则变更
        if (isString(_record.statisticsData)) _record.statisticsData = {
          单页: _record.statisticsData.includes('单页'),
          全部: _record.statisticsData.includes('全部'),
        };
        // 对齐方式设置默认值
        if (!_record.alignType) _record.alignType = 'left';
        /**
         *  @Date 2023年12月22日
         * 拆分现有的configItems
         * defaultDate/defaultValue/defaultMo
         * */
        return _record;
      };
      // @params: {type:String} 不传入type,默认提交表单、关闭表单;传入type时
      const submitReportDetails = (type) => {
        // 1.表单内的值;2.标签值
        return form.validateFields().then(value => {
          // 需要将表单内带索引的fieldGroup_[number]处理成后端需要的fieldGroups: a-b-c-d;
          value.fieldGroup = Object.values(value.fieldGroup).join('-');
          let _value = Object.assign(currentField, value);
          // 处理数值颜色和标签颜色
          // 后端需求:labelConfig和numberConfig里面都需要设置默认configId并且id设置为0;
          if (numberColorPickerArray.length) _value.numericalConfigs = numberColorPickerArray.map(item => {
陈龙's avatar
陈龙 committed
634
            let _item = { ...item };
陈龙's avatar
陈龙 committed
635 636 637 638 639
            Object.keys(_item).forEach(key => {
              if (_item[key] === '') _item[key] = null;
            });
            _item.configId = _value.id;
            _item.id = 0;
陈龙's avatar
陈龙 committed
640 641
            return _item;
          });
陈龙's avatar
陈龙 committed
642
          if (labelColorPickerArray.length) _value.labelConfigs = labelColorPickerArray.map(item => {
陈龙's avatar
陈龙 committed
643
            let _item = { ...item };
陈龙's avatar
陈龙 committed
644 645
            _item.configId = _value.id;
            _item.id = 0;
陈龙's avatar
陈龙 committed
646 647
            return _item;
          });
陈龙's avatar
陈龙 committed
648 649 650
          // 文字的颜色
          if (backgroundColor) {
            _value.color = backgroundColor;
651
          }
陈龙's avatar
陈龙 committed
652 653 654 655 656 657 658 659 660
          // 过滤规则的设置,需要确保日期类型的过滤规则字段是唯一的
          let _isDateArray = detailData.filter(item => item.filterRule === '日期');
          if (_isDateArray.length > 1 || (_isDateArray.length === 1 && _value.filterRule === '日期' && _isDateArray[0].fieldName !== _value.fieldName)) return message.error('已存在日期类型的过滤,请确保日期类型的过滤规则只存在一个!');
          // 统计规则的提交变更
          let _statisticsData = _value.statisticsData;
          _value.statisticsData = Object.keys(_statisticsData).filter(key => _statisticsData[key]).join(',');
          // 提交请求
          setSubmitFieldLoading(true);
          reportService.addReportDetailInfo({ reportDetails: [_value] }).then(res => {
661
            if (res.code === 0) {
陈龙's avatar
陈龙 committed
662
              message.success('提交成功!');
663
            } else {
陈龙's avatar
陈龙 committed
664 665 666 667 668
              message.error(res.msg);
            }
            setSubmitFieldLoading(false);
            if (!type) {
              setDetailVisible(false);
669
            }
陈龙's avatar
陈龙 committed
670
            clickReport(currentReport.id);
671
          });
陈龙's avatar
陈龙 committed
672
        });
陈龙's avatar
陈龙 committed
673
      };
陈龙's avatar
陈龙 committed
674 675 676
      const searchReportList = (e) => {
        let _data = [...tableData];
        let final = _data.map(item => {
陈龙's avatar
陈龙 committed
677
          let _item = { ...item };
陈龙's avatar
陈龙 committed
678 679 680 681 682
          if (!e) {
            _item.visible = true;
          } else {
            _item.visible = _item.reportName.includes(e);
          }
陈龙's avatar
陈龙 committed
683 684
          return _item;
        });
陈龙's avatar
陈龙 committed
685 686 687 688 689 690 691 692 693 694
        setTableData(final);
      };
      const openCreateModal = (callback) => {
        if (callback) callback();
        getTableFromDB((data) => {
          setAllTableList(data);
          createMainTableForm.setFieldsValue({
            sourcesId: 0,
          });
          setCreateModalVisible(true);
陈龙's avatar
陈龙 committed
695
        });
陈龙's avatar
陈龙 committed
696 697 698
      };
      const getTableFromDB = (callback, sourcesId) => {
        reportService.getTables({ sourcesId }).then(res => {
699
          if (res.code === 0) {
陈龙's avatar
陈龙 committed
700
            callback(res.data);
701 702 703
          } else {
            message.error(res.msg);
          }
陈龙's avatar
陈龙 committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
        });
      };
      const getFieldsFromTable = (tableName, type, record) => {
        //webapi的tableName传null
        let _data = tableName ? tableName.split(',').map(name => ({ name: name })) : null;
        // webapi类型的,不需要传tableName
        let _tempData = tableName ? {
          tableName: _data,
          sourcesId: (record ? record.sourcesId : currentReport.sourcesId) || 0,
        } : {
          tableName: [{ 'name': '', 'type': '' }],
          sourcesId: (record ? record.sourcesId : currentReport.sourcesId) || 0,
        };
        reportService.getTableFields(_tempData).then(res => {
          if (res.code === 0) {
            if (type === 'mainTable') {
              setAllFields(res.data[0]?.fieldName || []);
            }
            if (type === 'subTable') {
              // setTable
              setAllSubFields(res.data);
            }
726
          }
陈龙's avatar
陈龙 committed
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 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 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 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
        });
      };
      const showPatchSubModal = (sourceId) => {
        getTableFromDB((data) => {
          setSubTableList(data.filter(item => item.name !== currentReport.tableName));
        }, sourceId);
        setPatchFieldVisible(true);
        getFieldsFromTable(currentReport.tableName, 'mainTable');
        let subTableName = relationship.map(item => item.tableName);
        if (subTableName && subTableName.length) getFieldsFromTable(subTableName.join(','), 'subTable');
        let _relationshipObject = {};
        relationship.forEach(item => {
          let _arr = item.relation.split('=');
          _relationshipObject[(item.tableName + publicSplit + 'mainTable')] = _arr[0];
          _relationshipObject[(item.tableName + publicSplit + 'subTable')] = _arr[1];
          _relationshipObject[(item.tableName + publicSplit + 'isMasterDetail')] = item.isMasterDetail;
        });
        patchSubTableForm.setFieldsValue({
          subTableName,
          subTableFields: detailData.map(item => item.tableName + publicSplit + item.fieldName),
          ..._relationshipObject,
        });
      };
      const addVirtualColumn = () => {
        // 添加虚拟列;1. 增加字段;2.保存
        const _detailData = [...detailData];
        const _temp = { ..._detailData[0] };
        delete _temp.id;
        _temp.filterRule = '';// 确保filterRule不是日期
        _temp.alignType = 'left';
        _temp.fixedColumn = '';
        _temp.isFilter = false;
        // delete _temp.tableName;
        _temp.index = _detailData.length - 1;
        _temp.isVirtualColumn = true;
        //fieldAlias: "软件开票"
        // fieldGroup: "软件开票"
        // fieldName: "软件开票"
        _temp.fieldAlias = _temp.fieldGroup = _temp.fieldName = `虚拟字段${moment().format('YYYY-MM-DD-HH-mm-ss').replace(/-/g, '')}`;
        _detailData.push(_temp);
        setDetailData(_detailData);
        // setTempDetailData(_detailData);
        editDetailForm.setFieldsValue(_detailData);
        // submitDetailFromTable();
      };
      const editDetailInTable = () => {
        // setIsEditing(true);
      };
      const submitDetailFromTable = () => {
        setDetailTableLoading(true);
        editDetailForm.validateFields().then(res => {
          // 去除掉标签、数字区间内的id
          let _detailData = detailData.map(item => {
            let _item = { ...item };
            _item.numericalConfigs = _item.numericalConfigs.map(obj => {
              let _obj = { ...obj };
              _obj.id = 0;
              return _obj;
            });
            _item.labelConfigs = _item.labelConfigs.map(obj => {
              let _obj = { ...obj };
              _obj.id = 0;
              return _obj;
            });
            return _item;
          });
          reportService.addReportDetailInfo({ reportDetails: _detailData }).then(res => {
            if (res.code === 0) {
              message.success('提交成功!');
            } else {
              message.error(res.msg);
            }
            setDetailTableLoading(false);
            setSubmitFieldLoading(false);
            setDetailVisible(false);
            clickReport(currentReport.id);
          }).catch(err => {
            setDetailTableLoading(false);
          });
        });
      };
      const patchSubTable2MainTable = () => {
        let _subTable = patchSubTableForm.getFieldValue('subTableName');
        if (_subTable && _subTable.length === 0) {
          return clearRelation(currentReport.id);
        }
        patchSubTableForm.validateFields().then(async value => {
          setPatchSubTableBtnLoading(true);
          // 由于是动态表单数据,导致表单对象无法正常监听数据,要过滤掉未能监听的数据。
          let _tempArray = value.subTableFields.filter(item => value.subTableName.includes(item.split(publicSplit)[0])).map(item => item.split(publicSplit));
          if (!_tempArray || _tempArray.length === 0) return message.error('请勾选子表字段'); // 因为数据结构的问题,导致暂时无法正确获取表单数据,只能这样提示
          let _tempObject = {};
          _tempArray.forEach(item => {
            if (_tempObject[item[0]]) {
              _tempObject[item[0]].push(item[1]);
            } else {
              _tempObject[item[0]] = [item[1]];
            }
          });
          let rM_ReportInfo = Object.keys(_tempObject).map(key => {
            return {
              parentId: currentReport.id,
              tableName: key,
              reportFields: _tempObject[key].join(','),
              relation: `${value[key + `${publicSplit}mainTable`]}=${value[key + `${publicSplit}subTable`]}`,
              isMasterDetail: value[key + `${publicSplit}isMasterDetail`],
            };
          });
          await reportService.addReportInfo({
            rM_ReportInfo,
            sourcesId: currentReport.sourcesId,
            isAdd: false,
          }).then(res => {
            if (res.code === 0) {
              message.success('保存成功!');
              setPatchFieldVisible(false);
            } else {
              message.error(res.msg);
            }
          }).catch(err => {
            message.error('保存失败!');
            setPatchSubTableBtnLoading(false);
          });
          setPatchSubTableBtnLoading(false);
851 852
          clickReport(currentReport.id);
        });
陈龙's avatar
陈龙 committed
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
      };
      const clearRelation = (reportId) => {
        Modal.confirm({
          title: '请确认',
          content: '是否需要清空关联关系?',
          onOk: () => {
            reportService.delReportChild({ reportId }).then(res => {
              if (res.code === 0) {
                message.success('删除成功!');
                patchSubTableForm.resetFields();
                setAllSubFields([]);
                getFieldsFromTable(currentReport.tableName, 'mainTable');
              } else {
                message.error(res.msg);
              }
            });
          },
        });
      };
      const clickColorCard = (e) => {
        let _cardPosition = e.target.getBoundingClientRect();
        let _wrapperPosition = reportDetails.current.getBoundingClientRect();
        let _colorPicker = colorPicker.current.getBoundingClientRect();
        // 减去最外层的边距之后,还需要减去色块的高度+外边白边的高度+1px的边框+1px间隙 + 8px的最外层容器的padding
        let _cardLeft = _cardPosition.left - _wrapperPosition.left - 4 - 8;
        let _cardTop = _cardPosition.top - _wrapperPosition.top + 14 + 4 + 1 + 1 - 8;
        // 需要考虑超出边距的问题,如果超出边界,则向上,向左平移
        let isOuterOfBottom = (_cardTop + _colorPicker.height) - _wrapperPosition.height;
        // let isOuterOfRight = (_colorPicker.left + _colorPicker.width) - (_wrapperPosition.top + _wrapperPosition.height);
        if (isOuterOfBottom > 0) {
          _cardTop -= (isOuterOfBottom + 10); // 向上平移,10px保证显示效果
          _cardLeft -= (_colorPicker.width + 5); // 向左平移,5px保证显示效果
885
        }
陈龙's avatar
陈龙 committed
886 887 888
        setColorCardPosition({
          left: _cardLeft,
          top: _cardTop,
889
        });
陈龙's avatar
陈龙 committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
        setShowSketchPicker(true);
      };
      const addColorPicker = (data, callback, init) => {
        let _labels = [...data];
        _labels.push(init);
        callback(_labels);
      };
      const removeColorPicker = (data, callback, index) => {
        let _labels = [...data];
        _labels.splice(index, 1);
        callback(_labels);
      };
      const changeColorLabel = (e, data, callback, key, index) => {
        // 接口需要id全部为 0
        let _labels = [...data];
        _labels[index][key] = e !== null ? isNumber(e) ? e : e.target.value : null; // e为数值时是InputNumber,e为对象时是Input
        callback(_labels);
      };
      const changeBackgroundColor = (e) => {
        // 改变当前的
        let _rgb = e.rgb;
        if (currentColorPicker.key === 'wordColor') {
          setBackgroundColor(`rgba(${_rgb.r},${_rgb.g},${_rgb.b},${_rgb.a})`);
          return;
        }
        let { data, callback, index, key } = currentColorPicker;
        let _data = [...data];
        if (['tagColor', 'textColor'].includes(currentColorPicker.key)) {
          _data[index].color = e;
陈龙's avatar
陈龙 committed
919
        } else {
陈龙's avatar
陈龙 committed
920
          _data[index][key] = `rgba(${_rgb.r},${_rgb.g},${_rgb.b},${_rgb.a})`;
陈龙's avatar
陈龙 committed
921
        }
陈龙's avatar
陈龙 committed
922
        callback(_data);
923
      };
陈龙's avatar
陈龙 committed
924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
      const returnCurrentColor = () => {
        let { data, index, key } = currentColorPicker;
        if (key === 'init') return 'rgba(0,0,0,.65)';
        return data[index][key];
      };
      // 拖拽
      const DragHandle = SortableHandle(() => (
          <MenuOutlined
              style={{
                cursor: 'grab',
                color: '#999',
              }}
          />
      ));
      const saveOrder = (data) => {
        let _data = data.map((item, index) => {
          let _item = {};
          _item.index = index;
          _item.id = item.id;
943 944
          return _item;
        });
陈龙's avatar
陈龙 committed
945 946 947 948 949 950 951 952 953 954
        addReportDetailInfoIndex(_data).then(res => {
          if (res.code !== 0) {
            message.error(res.msg);
          } else {
            clickReport(currentReport.id);
          }
        });
      };
      const submitDetail = (data) => {
        reportService.addReportDetailInfo({ reportDetails: data }).then(res => {
陈龙's avatar
陈龙 committed
955 956 957 958 959 960 961 962
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          setSubmitFieldLoading(false);
          clickReport(currentReport.id);
        });
陈龙's avatar
陈龙 committed
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
      };
      const modifyDetailData = (key, value, record, index, data = detailData) => {
        let _data = [...data];
        let _record = { ...record };
        _record[key] = value;
        _data.splice(index, 1, _record);
        setDetailData(_data);
      };
      const batchModify = (key, value) => {
        // 1.取出勾选的字段;2.批量修改值
        if (selectedRowKeys.length === 0) return message.info('未勾选任何字段');
        let _detailData = detailData.map(item => {
          let _item = { ...item };

          if (selectedRowKeys.includes(_item.id)) {
            _item[key] = value;
979
          }
陈龙's avatar
陈龙 committed
980
          return _item;
981
        });
陈龙's avatar
陈龙 committed
982 983 984 985 986 987 988
        setDetailData(_detailData);
        editDetailForm.setFieldsValue(_detailData);
      };
      const exportConfigs = (record) => {
        setTableLoading(true);
        exportReportConfig({ responseType: 'blob' }, {
          reportId: record.id,
989
        }).then(res => {
陈龙's avatar
陈龙 committed
990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004
          setTableLoading(false);
          if (res && res.code === -1) return message.error(res.msg);
          const url = window.URL.createObjectURL(
              new Blob([res], { type: 'application/json;charset=UTF-8' }),
          );
          const a = document.createElement('a');
          a.href = url;
          a.target = '_blank';
          a.download = `${record.reportName}.json`;
          a.click();
          a.remove();
        });
      };
      const getDataSourcesList = () => {
        reportService.getDataSources().then(res => {
陈龙's avatar
陈龙 committed
1005
          if (res.code === 0) {
陈龙's avatar
陈龙 committed
1006
            setDataSourcesList(res.data);
陈龙's avatar
陈龙 committed
1007
          } else {
陈龙's avatar
陈龙 committed
1008
            setDataSourcesList([]);
陈龙's avatar
陈龙 committed
1009 1010
          }
        });
陈龙's avatar
陈龙 committed
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
      };
      const selectDataSource = (e) => {
        setCurrentDataSource(e);
        createMainTableForm.setFieldsValue({ tableName: '', reportFields: [] });
        let type = dataSourcesList.find(item => item.id === e)?.db_type || '';
        setCurrentDataSourceType(type);
        setAllFields([]);
        let _arr = e ? [(data) => {
          setAllTableList(data);
        }, e] : [(data) => {
          setAllTableList(data);
        }];
        if (type === 'webapi') {
          // webapi不取表,接收接口返回的数据
          getFieldsFromTable(null, 'mainTable', { sourcesId: e });
1026
        } else {
陈龙's avatar
陈龙 committed
1027
          getTableFromDB(..._arr);
1028
        }
陈龙's avatar
陈龙 committed
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
      };
      useEffect(() => {
        getData();
        getDataSourcesList();
      }, []);
      useEffect(() => {
        let numericalConfigs = currentField ? currentField.numericalConfigs : [];
        let labelConfigs = currentField ? currentField.labelConfigs : [];
        setNumberColorPickerArray(numericalConfigs);
        setLabelColorPickerArray(labelConfigs);
      }, [watchType]);
      return <div className={styles.reportSettings}>
        {
          currentPage === '报表配置' ? <div ref={reportDetails} className={styles.reportDetails}>
            {/* 色板容器 */}
            <div onClick={(e) => {
              if (e.target.className.includes('colorSketch')) {
                setShowSketchPicker(false);
1047
              }
陈龙's avatar
陈龙 committed
1048 1049
            }} style={{
              visibility: showSketchPicker ? 'visible' : 'hidden',
陈龙's avatar
陈龙 committed
1050
            }}
陈龙's avatar
陈龙 committed
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
                 className={styles.colorSketch}>
              <div ref={colorPicker} style={{
                position: 'absolute',
                left: colorCardPosition.left,
                top: colorCardPosition.top,
              }}>
                {
                  ['textColor', 'tagColor'].includes(currentColorPicker.key) ?
                      <CustomerColorPicker clickColorPicker={(backgroundColor) => {
                        changeBackgroundColor(backgroundColor);
                      }}/> :
                      <SketchPicker width={240} presetColors={[
                        'rgb(129, 134, 143)',
                        'rgb(41, 114, 244)',
                        'rgb(0, 163, 245)',
                        'rgb(69, 176, 118)',
                        'rgb(222, 60, 54)',
                        'rgb(248, 136, 37)',
                        'rgb(216,180,255)',
                        'rgb(154, 56, 215)',
                        'rgb(221, 64, 151)',
                      ]} color={currentColorPicker.key === 'wordColor' ? backgroundColor : returnCurrentColor()}
                                    onChange={(e) => changeBackgroundColor(e)}/>
                }
              </div>
            </div>
            <Modal
                title={'附加子表'}
                width={600}
                visible={patchFieldVisible}
                onCancel={() => {
                  setPatchFieldVisible(false);
                  setAllFields([]);
                  setAllSubFields([]);
                }}
                onOk={patchSubTable2MainTable}
                okButtonProps={{
                  loading: patchSubTableBtnLoading,
                }}
                footer={[
                  <Button onClick={() => clearRelation(currentReport.id)}>清空挂接关系</Button>,
                  <Button onClick={() => {
                    setPatchFieldVisible(false);
                    setAllFields([]);
                    setAllSubFields([]);
                    patchSubTableForm.resetFields();
                  }}>取消</Button>,
                  <Button type="primary" htmlType={'submit'} onClick={patchSubTable2MainTable}>确定</Button>,
                ]}
            >
              <Form form={patchSubTableForm} {...layout}>
                <Form.Item label={'子表'} rules={[{
                  required: true, message: '请选择需要附加的子表,若清空子表后提交,则会清空该报表关联关系',
                }]} name={'subTableName'}>
                  <Select placeholder={'请选择子表'} maxTagCount={2} style={{ width: '100%' }} mode={'multiple'}
                          onChange={(value) => {
                            if (value && value.length === 0) {
                              setAllSubFields([]);
                            } else {
                              getFieldsFromTable(value.join(','), 'subTable');
                            }
                          }}>
                    {
                      subTableList.map(item => <Option value={item.name}>{item.name}</Option>)
                    }
                  </Select>
                </Form.Item>
                {
                  allSubFields && allSubFields.length ?
                      <Form.Item label={'子表字段'} rules={[{
                        required: true, message: '请选择字段',
                      }]} name={'subTableFields'}>
                        <Checkbox.Group style={{ height: 400, overflowY: 'scroll' }}>
                          {
                            allSubFields.map((item, index) => {
                              return <div>
                                <Divider orientation="left">{item.tableName}</Divider>
                                <Row style={{ display: 'flex' }}>
                                  <Form.Item label={'主表'} name={`${item.tableName}${publicSplit}mainTable`} rules={[{
                                    required: true, message: '请选择对应字段',
                                  }]}>
                                    <Select style={{ width: 150 }} placeholder={'主表对应字段'}>
                                      {
                                        allFields.map(field => <Option
                                            value={`${currentReport.tableName}.${field.name}`}>{field.name}</Option>)
                                      }
                                    </Select>
                                  </Form.Item>
                                  <Form.Item label={'子表'} name={`${item.tableName}${publicSplit}subTable`} rules={[{
                                    required: true, message: '请选择对应字段',
                                  }]}>
                                    <Select style={{ width: 150 }} placeholder={'子表关联字段'}>
                                      {
                                        item.fieldName.map(field => <Option
                                            value={`${item.tableName}.${field.name}`}>{field.name}</Option>)
                                      }
                                    </Select>
                                  </Form.Item>
                                </Row>
                                <Row>
                                  {/*<Form.Item label={'是否主从表'} name={`${item.tableName}${publicSplit}isMasterDetail`}*/}
                                  <Form.Item label={'是否关联关系'} name={`${item.tableName}${publicSplit}isMasterDetail`}
                                             valuePropName={'checked'}>
                                    <Switch checkedChildren="是" unCheckedChildren="否"/>
                                  </Form.Item>
                                </Row>
                                {
                                  item.fieldName.map(field => {
                                    return <Row><Checkbox
                                        value={`${item.tableName}${publicSplit}${field.name}`}>{field.name}</Checkbox></Row>;
                                  })
                                }
                              </div>;
                            })
1165
                          }
陈龙's avatar
陈龙 committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
                        </Checkbox.Group>
                      </Form.Item> : ''
                }
              </Form>
            </Modal>
            <Modal
                title={'编辑字段属性'}
                width={920}
                visible={detailVisible}
                onCancel={() => setDetailVisible(false)}
                destroyOnClose
                footer={null}
                onClick={() => setShowSketchPicker(false)}
            >
              <div className={classnames(styles.configForm)}>
                <div className={classnames(styles.list, 'wkt-scroll-light')}>
陈龙's avatar
陈龙 committed
1182
                  {
陈龙's avatar
陈龙 committed
1183 1184 1185 1186 1187 1188 1189 1190
                    detailData ? <ul>
                      {
                        detailData.map((item, index) => <li
                            onClick={() => changeField(item)}
                            className={classnames(styles.fieldItem, activeID === item.id ? styles.active : '')}
                            key={item.id}>{item.fieldAlias}</li>)
                      }
                    </ul> : ''
1191
                  }
陈龙's avatar
陈龙 committed
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
                </div>
                <div style={{
                  flex: 1,
                }}>
                  {/*<Form {...layout} form={form} initialValues={setDefaultValue(currentField)}*/}
                  <Form {...layout} form={form}
                        onFinish={submitReportDetails}>
                    <div style={{ height: 500, overflowY: 'scroll' }}>
                      <Form.Item disabled label={'字段'} name={'fieldName'} rules={[
                        {
                          required: true, message: '编码名称必填',
                        },
                      ]}>
                        <Input disabled style={{ width: wordInputWidth }}/>
                      </Form.Item>
                      <Form.Item label={'别名'} name={'fieldAlias'} rules={[
                        {
                          required: true, message: '别名必填且不可重复',
                        },
                      ]}>
                        <Input style={{ width: wordInputWidth }}/>
                      </Form.Item>
                      <Form.Item label={'表头级数'} name={'level'} rules={[
                        {
                          required: true, message: '别名必填且不可重复',
                        },
                      ]}>
                        <InputNumber min={1}/>
                      </Form.Item>
1221
                      {
陈龙's avatar
陈龙 committed
1222 1223
                        fieldGroupLevel ? <Form.Item style={{ marginBottom: 0 }} label={'分组'}>
                          <Input.Group compact>
1224
                            {
陈龙's avatar
陈龙 committed
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
                              (new Array((Number(fieldGroupLevel) * 2 - 1)).fill(1)).map((item, index) => {
                                if (index % 2 === 0) {
                                  return <Form.Item key={`fieldGroup_${index / 2}`} style={{ width: 160 }}
                                                    name={['fieldGroup', `fieldGroup_${currentField.fieldAlias}_${index / 2}`]}
                                                    rules={[{
                                                      required: true, message: '分组名称必填',
                                                    }]}>
                                    <Input/>
                                  </Form.Item>;
                                } else {
                                  return <span style={{ color: 'rgba(0,0,0,.25)' }}> &nbsp; _ &nbsp;</span>;
                                }
1237 1238
                              })
                            }
陈龙's avatar
陈龙 committed
1239 1240
                          </Input.Group>
                        </Form.Item> : ''
1241
                      }
陈龙's avatar
陈龙 committed
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
                      <Form.Item label={'形态'} name={'type'}>
                        <Select style={{ width: wordInputWidth }}>
                          {
                            Object.keys(typeArray).map(key => {
                              return <OptGroup label={key}>
                                {
                                  typeArray[key].map(item => <Option value={item}>{item}</Option>)
                                }
                              </OptGroup>;
                            })
                          }
                        </Select>
                      </Form.Item>
1255
                      {
陈龙's avatar
陈龙 committed
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
                        ['数值', '数值标签'].includes(watchType) ?
                            <Form.Item label={'数值配置'} name={'numberConfig'}>
                              <NumberConfig/>
                            </Form.Item> : ''
                      }
                      <Form.Item label={'字体颜色'} name={'color'}>
                        <div style={{
                          padding: 4,
                          display: 'inline-flex',
                          borderRadius: '2px',
                          border: '1px solid rgba(0,0,0,.35)',
                        }}>
                          <div style={{
                            width: '36px',
                            height: '14px',
                            borderRadius: '2px',
                            border: '1px solid rgba(0,0,0,.35)',
                            backgroundColor: backgroundColor,
                          }} onClick={(e) => {
                            clickColorCard(e);
                            setCurrentColorPicker({
                              key: 'wordColor',
                            });
                          }}/>
                        </div>
                      </Form.Item>
1282
                      {
陈龙's avatar
陈龙 committed
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349
                        watchType === '数值' ?
                            <Form.Item label={'区间设置'}>
                              {
                                numberColorPickerArray.map((item, index) => {
                                  return <Space
                                      key={item.key}
                                      style={{
                                        display: 'flex',
                                        marginBottom: 8,
                                        width: rangeWidth,
                                      }}
                                      align="baseline"
                                  >
                                    <Form.Item
                                        label={'最小值'}
                                    >
                                      <InputNumber value={item.minValue}
                                                   onChange={(e) => changeColorLabel(e, numberColorPickerArray, setNumberColorPickerArray, 'minValue', index)}/>
                                    </Form.Item>
                                    <Form.Item
                                        label={'最大值'}
                                    >
                                      <InputNumber value={item.maxValue}
                                                   onChange={(e) => changeColorLabel(e, numberColorPickerArray, setNumberColorPickerArray, 'maxValue', index)}/>
                                    </Form.Item>
                                    <Form.Item label={'颜色'}>
                                      <div style={{
                                        padding: 4,
                                        display: 'inline-flex',
                                        borderRadius: '2px',
                                        border: '1px solid rgba(0,0,0,.35)',
                                      }}>
                                        <div style={{
                                          width: '36px',
                                          height: '14px',
                                          borderRadius: '2px',
                                          border: '1px solid rgba(0,0,0,.35)',
                                          backgroundColor: item.color,
                                        }} onClick={(e) => {
                                          clickColorCard(e);
                                          setCurrentColorPicker({
                                            data: numberColorPickerArray,
                                            callback: setNumberColorPickerArray,
                                            index,
                                            key: 'color',
                                          });
                                        }}/>
                                      </div>
                                    </Form.Item>
                                    <MinusCircleOutlined
                                        onClick={() => removeColorPicker(numberColorPickerArray, setNumberColorPickerArray, index)}/>
                                  </Space>;
                                })
                              }
                              <Form.Item>
                                <Button type="dashed"
                                        onClick={() => addColorPicker(numberColorPickerArray, setNumberColorPickerArray, {
                                          maxValue: '',
                                          minValue: '',
                                          color: 'rgba(0,0,0,.65)',
                                        })}
                                        block icon={<PlusOutlined/>}>
                                  增加区间
                                </Button>
                              </Form.Item>
                            </Form.Item> : ''
                      }
1350
                      {
陈龙's avatar
陈龙 committed
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
                        ['文本'].includes(watchType) ?
                            <Form.Item label={'文本设置'}>
                              {
                                labelColorPickerArray.map((item, index) => {
                                  return <Space
                                      key={item.key}
                                      style={{
                                        display: 'flex',
                                        marginBottom: 8,
                                      }}
                                      align="baseline"
                                  >
                                    <Form.Item
                                        label={'文本'}
                                    >
                                      <Input value={item.labelValue}
                                             onChange={(e) => changeColorLabel(e, labelColorPickerArray, setLabelColorPickerArray, 'labelValue', index)}/>
                                    </Form.Item>
                                    <Form.Item
                                        label={'颜色'}
                                    >
                                      <div style={{
                                        padding: 4,
                                        display: 'inline-flex',
                                        borderRadius: '2px',
                                        border: '1px solid rgba(0,0,0,.35)',
                                      }}>
                                        <div style={{
                                          width: '36px',
                                          height: '14px',
                                          borderRadius: '2px',
                                          border: '1px solid rgba(0,0,0,.35)',
                                          backgroundColor: item.color,
                                        }} onClick={(e) => {
                                          clickColorCard(e);
                                          setCurrentColorPicker({
                                            data: labelColorPickerArray,
                                            callback: setLabelColorPickerArray,
                                            index,
                                            key: 'color',
                                          });
                                        }}/>
                                      </div>
                                    </Form.Item>
                                    <MinusCircleOutlined
                                        onClick={() => removeColorPicker(labelColorPickerArray, setLabelColorPickerArray, index)}/>
                                  </Space>;
                                })
1399
                              }
陈龙's avatar
陈龙 committed
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414
                              <Form.Item>
                                <Button type="dashed"
                                        onClick={() => addColorPicker(labelColorPickerArray, setLabelColorPickerArray, {
                                          color: 'rgba(0,0,0,.65)',
                                          labelValue: '',
                                        })}
                                        block icon={<PlusOutlined/>}>
                                  增加区间
                                </Button>
                              </Form.Item>
                            </Form.Item> : ''
                      }
                      {
                        ['标签', '数值标签'].includes(watchType) ?
                            <Form.Item label={'标签设置'}>
1415
                              {
陈龙's avatar
陈龙 committed
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
                                labelColorPickerArray.map((item, index) => {
                                  return <Space
                                      key={item.key}
                                      style={{
                                        display: 'flex',
                                        marginBottom: 8,
                                      }}
                                      align="baseline"
                                  >
                                    <Form.Item
                                        label={'标签'}
                                    >
                                      <Input value={item.labelValue}
                                             onChange={(e) => changeColorLabel(e, labelColorPickerArray, setLabelColorPickerArray, 'labelValue', index)}/>
                                    </Form.Item>
                                    <Form.Item
                                        label={'颜色'}
                                    >
                                      <div style={{
                                        padding: 4,
                                        display: 'inline-flex',
                                        borderRadius: '2px',
                                        border: '1px solid rgba(0,0,0,.35)',
                                      }}>
                                        <div style={{
                                          width: '36px',
                                          height: '14px',
                                          borderRadius: '2px',
                                          border: '1px solid rgba(0,0,0,.35)',
                                          backgroundColor: item.color,
                                        }} onClick={(e) => {
                                          clickColorCard(e);
                                          setCurrentColorPicker({
                                            data: labelColorPickerArray,
                                            callback: setLabelColorPickerArray,
                                            index,
                                            key: 'tagColor',
                                          });
                                        }}/>
                                      </div>
                                    </Form.Item>
                                    <MinusCircleOutlined
                                        onClick={() => removeColorPicker(labelColorPickerArray, setLabelColorPickerArray, index)}/>
                                  </Space>;
                                })
1461
                              }
陈龙's avatar
陈龙 committed
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522
                              <Form.Item>
                                <Button type="dashed"
                                        onClick={() => addColorPicker(labelColorPickerArray, setLabelColorPickerArray, {
                                          color: 'rgba(0,0,0,.65)',
                                          labelValue: '',
                                        })}
                                        block icon={<PlusOutlined/>}>
                                  增加区间
                                </Button>
                              </Form.Item>
                            </Form.Item> : ''
                      }
                      {
                        ['数值', '数值标签'].includes(watchType) ?
                            <Form.Item label={'统计规则'}>
                              <Space style={{
                                display: 'flex',
                                marginBottom: 8,
                              }}>
                                <Form.Item style={{ marginBottom: 0 }} name={'isStatistics'} valuePropName={'checked'}>
                                  <Switch checkedChildren="开启" unCheckedChildren="关闭" defaultChecked={false}/>
                                </Form.Item>
                                {
                                  isStatistics ?
                                      <>
                                        <Form.Item label={'统计规则'} rules={[{
                                          required: true, message: '请选择统计规则',
                                        }]} style={{ marginBottom: 0 }} name={'statisticsRule'}>
                                          <Select style={{ width: 100 }}>
                                            <Option value={'求和'}>求和</Option>
                                            <Option value={'求平均'}>求平均</Option>
                                            <Option value={'求方差'}>求方差</Option>
                                          </Select>
                                        </Form.Item>
                                        <Form.Item name={['statisticsData', '单页']} style={{ marginBottom: 0 }}
                                                   label={'单页统计'} valuePropName={'checked'}>
                                          <Switch checkedChildren="开启" unCheckedChildren="关闭"/>
                                        </Form.Item>
                                        <Form.Item name={['statisticsData', '全部']} style={{ marginBottom: 0 }}
                                                   label={'全部统计'} valuePropName={'checked'}>
                                          <Switch checkedChildren="开启" unCheckedChildren="关闭"/>
                                        </Form.Item>
                                      </> : ''
                                }
                              </Space>
                            </Form.Item> : ''
                      }
                      {
                        ['数值', '数值标签'].includes(watchType) && isStatistics ?
                            <Form.Item label={'统计配置'}>
                              <NumberConfig/>
                            </Form.Item> : ''
                      }
                      <Form.Item label={'配置'} name={'configItems'}>
                        <TextArea rows={6}/>
                      </Form.Item>
                    </div>
                    <Form.Item label={' '} colon={false} style={{ marginTop: 10 }}>
                      <Button onClick={() => setDetailVisible(false)}>取消</Button>
                      <Button loading={submitFieldLoading} style={{ marginLeft: 8 }} type="primary"
                              htmlType="submit">提交</Button>
陈龙's avatar
陈龙 committed
1523
                    </Form.Item>
陈龙's avatar
陈龙 committed
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553
                  </Form>
                </div>
              </div>
            </Modal>
            <div className={styles.tableWrapper}>
              <Row className={styles.controlRow}>
                <LeftOutlined className={styles.leftBtn} onClick={() => {
                  setCurrentPage('报表列表');
                }}/>
                <Form layout={'inline'} style={{ display: 'flex', flex: 1, justifyContent: 'space-between' }}>
                  <div style={{ display: 'flex' }}>
                    <Form.Item label={'快速索引'}>
                      <Search onSearch={(e) => {
                        let _detailData = detailData.map(item => {
                          let _item = { ...item };
                          if (e) {
                            _item.visible = item.fieldName.includes(e) || item.fieldAlias.includes(e);
                          } else {
                            _item.visible = true;
                          }
                          return _item;
                        });
                        setDetailData(_detailData);
                        setTempDetailData(_detailData);
                      }}/>
                    </Form.Item>
                    <Form.Item>
                      <Button style={{ marginRight: 8 }}
                              onClick={() => showPatchSubModal(currentReport.sourcesId)}>附加子表</Button>
                      <Button onClick={addVirtualColumn}>添加虚拟字段</Button>
陈龙's avatar
陈龙 committed
1554
                    </Form.Item>
陈龙's avatar
陈龙 committed
1555 1556
                  </div>
                  <Form.Item style={{ marginRight: 0 }}>
1557
                    {
陈龙's avatar
陈龙 committed
1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
                      isEditing ?
                          <>
                            <Button style={{ marginRight: 8 }} onClick={() => {
                              setDetailData(tempDetailData);
                              editDetailForm.setFieldsValue(tempDetailData);
                            }}>重置</Button>
                            <Button type={'primary'} loading={detailTableLoading} style={{ marginRight: 8 }}
                                    onClick={submitDetailFromTable}>保存字段</Button>
                          </> : ''
                    }
                    {
                      isEditing ? <Button type={'primary'} onClick={() => setIsEditing(false)}>拖动排序</Button> :
                          <Button type={'primary'} onClick={() => setIsEditing(true)}>关闭排序</Button>
                    }
                  </Form.Item>
                </Form>
              </Row>
              <div className={styles.tableContent}>
                <Form className={styles.tableForm} form={editDetailForm}>
                  <BasicTable
                      loading={detailTableLoading}
                      pagination={false}
                      bordered
                      scroll={{ y: `calc(100% - ${selectedRowKeys.length ? 90 : 40}px)` }} // 需要考虑总结栏的高度
                      rowKey={'id'}
                      columns={currentDataSourceType === 'webapi' ? detailColumns.filter(item => item.title !== '表名') : detailColumns}
                      rowSelection={isEditing ? {
                        type: 'checkbox',
                        ...rowSelection,
                      } : null}
                      dataSource={detailData.filter(item => item.visible)}
                      summary={(pageData) => {
                        if (detailData && detailData.length > 1 && isEditing && selectedRows.length) {
                          return <Table.Summary fixed>
                            <Table.Summary.Row>
                              <Table.Summary.Cell colSpan={6}>批量操作</Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <InputNumber onChange={(e) => batchModify('columnWidth', e)}/>
1597
                                </Form.Item>
陈龙's avatar
陈龙 committed
1598 1599 1600 1601 1602 1603 1604 1605
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Select onChange={(e) => batchModify('alignType', e)}>
                                    <Option value={'left'}></Option>
                                    <Option value={'center'}></Option>
                                    <Option value={'right'}></Option>
                                  </Select>
1606
                                </Form.Item>
陈龙's avatar
陈龙 committed
1607 1608 1609 1610 1611 1612 1613 1614
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Select onChange={(e) => batchModify('fixedColumn', e)}>
                                    <Option value={''}>不固定</Option>
                                    <Option value={'left'}></Option>
                                    <Option value={'right'}></Option>
                                  </Select>
1615
                                </Form.Item>
陈龙's avatar
陈龙 committed
1616 1617 1618 1619 1620 1621 1622
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Switch checkedChildren="显示"
                                          unCheckedChildren="不显示"
                                          defaultChecked={false}
                                          onChange={(e) => batchModify('isShow', e)}/>
1623
                                </Form.Item>
陈龙's avatar
陈龙 committed
1624 1625 1626 1627 1628 1629 1630
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Switch checkedChildren="开启"
                                          unCheckedChildren="关闭"
                                          defaultChecked={false}
                                          onChange={(e) => batchModify('isFilter', e)}/>
1631
                                </Form.Item>
陈龙's avatar
陈龙 committed
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Select onChange={(e) => batchModify('isFilter', e)}>
                                    <Option value={''}>不过滤</Option>
                                    <Option value={'文本'}>文本</Option>
                                    <Option value={'下拉'}>下拉</Option>
                                    <Option value={'多选'}>多选</Option>
                                    <Option value={'日期'}>日期</Option>
                                    <Option value={'复选框'}>复选框</Option>
                                  </Select>
1643
                                </Form.Item>
陈龙's avatar
陈龙 committed
1644 1645 1646 1647 1648 1649 1650
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Switch checkedChildren="开启"
                                          unCheckedChildren="关闭"
                                          defaultChecked={false}
                                          onChange={(e) => batchModify('isMerge', e)}/>
1651
                                </Form.Item>
陈龙's avatar
陈龙 committed
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Switch checkedChildren="是"
                                          unCheckedChildren="否"
                                          defaultChecked={false}
                                          onChange={(e) => batchModify('isRequired', e)}/>
                                </Form.Item>
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <Switch checkedChildren="是"
                                          unCheckedChildren="否"
                                          defaultChecked={false}
                                          onChange={(e) => batchModify('isReadOnly', e)}/>
                                </Form.Item>
                              </Table.Summary.Cell>
                              <Table.Summary.Cell>
                                <Form.Item>
                                  <DeleteOutlined onClick={() => batchModify('delete')} title={'批量删除'}
                                                  style={{ color: 'red' }}/>
                                </Form.Item>
                              </Table.Summary.Cell>
                            </Table.Summary.Row>
                          </Table.Summary>;
                        }
                      }}
                      components={isEditing ? '' : {
                        body: {
                          wrapper: DraggableContainer,
                          row: DraggableBodyRow,
                        },
                      }}
                      onRow={record => {
                        return {
                          onDoubleClick: (e) => {
                            return false;
                            if (e.target.cellIndex === detailColumns.length - 1 || e.target.cellIndex === void 0) return false;
                            setActiveID(record.id);
                            if (record.color) setBackgroundColor(record.color);
                            form.setFieldsValue(setDefaultValue(record));
                            setCurrentField(setDefaultValue(record));
                            setDetailVisible(true);
                          },
                        };
                      }}
                  />
陈龙's avatar
陈龙 committed
1699 1700 1701
                </Form>
              </div>
            </div>
陈龙's avatar
陈龙 committed
1702 1703 1704 1705 1706 1707
          </div> : ''
        }
        {
          currentPage === '报表列表' ? <div className={styles.reportDetails}>
            <Modal
                onCancel={() => {
1708
                  setCreateModalVisible(false);
陈龙's avatar
陈龙 committed
1709
                  setIsCreatingMainTable(false);
1710 1711
                  setCurrentDataSource('');
                  createMainTableForm.resetFields();
陈龙's avatar
陈龙 committed
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757
                }}
                closable={false}
                visible={createModalVisible}
                footer={null}
                destroyOnClose
            >
              <Form form={createMainTableForm} initialValues={{ sourcesId: 0 }} {...layout} onFinish={createReport}>
                {
                  isCreatingMainTable ? <Form.Item label={'数据源'} name={'sourcesId'}>
                    <Select onChange={selectDataSource}>
                      <Option value={0}>本地</Option>
                      {
                        dataSourcesList.map(item => {
                          return <Option value={item.id}>{item.db_sourcesname} <span
                              style={{ color: 'rgba(0,0,0,.45)' }}>({item.db_type})</span></Option>;
                        })
                      }
                    </Select>
                  </Form.Item> : ''
                }
                {
                  currentDataSourceType !== 'webapi' ? <Form.Item label={'主表'} name={'tableName'} rules={[{
                    required: true, message: '请选择一张主表',
                  }]}>
                    <Select
                        disabled={!isCreatingMainTable}
                        placeholder={'选择一张表作为主表'}
                        showSearch
                        optionFilterProp="children"
                        filterOption={(input, option) => option.children[0].includes(input)}
                        onChange={(e) => {
                          getFieldsFromTable(e, 'mainTable', { sourcesId: currentDataSource });
                          createMainTableForm.setFields([{ 'reportFields': [] }]);
                        }}
                    >
                      {
                        allTableList.map(item => <Option value={item.name}>{item.name} <span
                            style={{ color: 'rgba(0,0,0,.45)' }}>({item.type === 'table' ? '表' : '视图'})</span></Option>)
                      }
                    </Select>
                  </Form.Item> : ''
                }
                <Form.Item label={'报表名称'} name={'reportName'} rules={[{
                  required: true, message: '请输入报表名称',
                }]}>
                  <Input placeholder={'请输入报表名称'}/>
陈龙's avatar
陈龙 committed
1758
                </Form.Item>
陈龙's avatar
陈龙 committed
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780
                {
                  allFields.length ?
                      <Form.Item label={'报表字段'} name={'reportFields'}
                                 rules={[{ required: true, message: '请选择需要绑定的字段!' }]}>
                        <Checkbox.Group style={{ maxHeight: 400, overflowY: 'scroll' }}>
                          {
                            allFields.map(item => <Row><Checkbox value={item.name}>{item.name}</Checkbox></Row>)
                          }
                        </Checkbox.Group>
                      </Form.Item> : ''
                }
                <Form.Item label={'联动接口'} name={'interfaceConfig'}>
                  <Input placeholder={'可填入联动接口名称,非必填'}/>
                </Form.Item>
                <Form.Item label={' '} colon={false}>
                  <Button onClick={() => {
                    setCreateModalVisible(false);
                    setCurrentDataSource('');
                    createMainTableForm.resetFields();
                  }}>取消</Button>
                  <Button loading={createBtnLoading} style={{ marginLeft: 8 }} type={'primary'}
                          htmlType={'submit'}>提交</Button>
陈龙's avatar
陈龙 committed
1781 1782
                </Form.Item>
              </Form>
陈龙's avatar
陈龙 committed
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818
            </Modal>
            <div className={styles.tableWrapper}>
              <Row className={styles.controlRow}>
                <Form layout={'inline'}>
                  <Form.Item label={'快速索引'}>
                    <Search onSearch={(e) => searchReportList(e)}/>
                  </Form.Item>
                  <Form.Item>
                    <Button type={'primary'} style={{ marginRight: 8 }} onClick={() => openCreateModal(() => {
                      setCurrentReport({});
                      setAllFields([]);
                      setIsCreatingMainTable(true);
                      createMainTableForm.setFieldsValue({
                        tableName: '',
                        reportName: '',
                        reportFields: [],
                      });
                    })}>新增</Button>
                    <Upload {...uploadProps}>
                      <Button size="middle" icon={<ImportOutlined/>}>
                        导入
                      </Button>
                    </Upload>
                  </Form.Item>
                </Form>
              </Row>
              <div className={styles.tableContent}>
                <BasicTable
                    pagination={false}
                    bordered
                    loading={tableLoading}
                    rowKey={'id'}
                    columns={columns}
                    dataSource={tableData.filter(item => item.visible)}
                />
              </div>
陈龙's avatar
陈龙 committed
1819
            </div>
陈龙's avatar
陈龙 committed
1820 1821 1822 1823 1824 1825 1826
          </div> : ''
        }
        {
          currentPage === '图表配置' ? <ChartConfig setCurrentPage={setCurrentPage} currentReport={currentReport}/> : ''
        }
      </div>;
    }
1827
;
陈龙's avatar
陈龙 committed
1828
export default ReportsSetting;