ReportsSetting.js 75.5 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 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
 * * 报表设置列表 * 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';
import style from './ReportsSetting.less';
import classname from 'classnames';
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';

55
const { Option, OptGroup } = Select;
陈龙's avatar
陈龙 committed
56 57
const { TextArea } = Input;
const { Search } = Input;
58 59 60 61 62 63
const typeArray = {
  '文本': ['文本', '多行文本', '标签', '链接', '功能', '附件'],
  '数值': ['数值', '数值标签'],
  '日期': ['日期', '日期时间'],
};
const filterRule = ['文本', '下拉', '多选', '日期', '复选框'];
陈龙's avatar
陈龙 committed
64 65 66
const publicSplit = '&split;';
const USER_ID = window.globalConfig.userInfo.OID;
const ReportsSetting = () => {
67 68 69 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
    // 报表列表
    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 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}>
陈龙's avatar
陈龙 committed
109 110
          {/* 自动折叠内容时,如果使用Tooltip,Tooltip会无法正确定位;建议手动设置内容折叠 */}
          <span className={style.reportFiled}>{text}</span>
111 112 113 114 115 116 117 118 119 120 121
        </Tooltip>,
      }, {
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
        width: 200,
      }, {
        title: '创建人',
        dataIndex: 'creator',
        key: 'creator',
        width: 100,
陈龙's avatar
陈龙 committed
122
      },
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
      {
        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);
            }}/>
            <ExportOutlined title={'导出配置'} onClick={() => exportConfigs(record)}/>
            <DeleteOutlined title={'删除报表'} style={{ color: 'red' }} onClick={() => deleteReport(record)}/>
          </div>;
陈龙's avatar
陈龙 committed
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 182 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
      },
    ];
    // 详情表
    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: () => {
      },
      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',
      },
      withCredentials: true,
      customRequest({ action, file, headers, withCredentials }) {
        const formData = new FormData();
        formData.append('file', file);
        const _data = { userId: USER_ID };
        importReportConfig(
          {
            headers: {
              'Content-Type': 'multipart/form-data',
            },
          },
          { ..._data },
          formData,
        ).then(res => {
          if (res.code === 0) {
            message.success('导入成功!');
            getData();
          } else {
            message.info(res.msg);
          }
        });
      },
    };
    const onSortEnd = ({ oldIndex, newIndex }) => {
      if (oldIndex !== newIndex) {
        const newData = arrayMoveImmutable(detailData.slice(), oldIndex, newIndex).filter(
          (el) => !!el,
陈龙's avatar
陈龙 committed
221
        );
222 223 224 225 226 227 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
        console.log('Sorted items: ', newData);
        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 !== tempDetailData || detailData[index] !== tempDetailData[index] || (detailData[index] && tempDetailData[index] && detailData[index][key] !== tempDetailData[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/>,
      },
      {
        title: '表名',
        dataIndex: 'tableName',
        className: 'drag-visible',
        key: 'tableName',
        // colSpan: currentDataSourceType === 'webapi' ? 0 : 1,
陈龙's avatar
陈龙 committed
260
      },
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 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
      {
        title: '字段名',
        dataIndex: 'fieldName',
        key: 'fieldName',
      },
      {
        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') ? style.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') ? style.boxShadowOfSelect : ''}>
陈龙's avatar
陈龙 committed
302 303 304 305
              <Option value={text ? 'left' : ''}></Option>
              <Option value={'center'}></Option>
              <Option value={'right'}></Option>
            </Select>
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
          </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') ? style.boxShadowOfSelect : ''}>
陈龙's avatar
陈龙 committed
321 322 323 324
              <Option value={''}>不固定</Option>
              <Option value={'left'}></Option>
              <Option value={'right'}></Option>
            </Select>
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
          </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') ? style.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') ? style.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') ? style.boxShadowOfSelect : ''}>
陈龙's avatar
陈龙 committed
361
              <Option value={''}>不过滤</Option>
362 363 364
              {
                filterRule.map(item => <Option value={item}>{item}</Option>)
              }
陈龙's avatar
陈龙 committed
365
            </Select>
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
          </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') ? style.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') ? style.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') ? style.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>;
        },
陈龙's avatar
陈龙 committed
420
      },
421 422 423 424 425
    ];
    const rowSelection = {
      onChange: (selectedRowKeys, selectedRows) => {
        setSelectedRowKeys(selectedRowKeys);
        setSelectedRows(selectedRows);
陈龙's avatar
陈龙 committed
426
      },
427 428 429 430 431 432 433 434
    };
    const wordInputWidth = 300;
    const numberInputWidth = 120;
    const rangeWidth = 500;
    const tagWidth = 400;
    const getData = () => {
      setTableLoading(true);
      reportService.getReportConfigList().then(res => {
陈龙's avatar
陈龙 committed
435 436
        if (res.code === 0) {
          // 增加visible属性,后续搜索时需要
437
          let _data = res.data.map(item => {
陈龙's avatar
陈龙 committed
438 439 440 441 442 443 444 445 446
            let _item = { ...item };
            _item.visible = true;
            return _item;
          });
          setTableData(_data);
        } else {
          message.error(res.msg);
        }
        setTableLoading(false);
447
      }).catch(err => {
陈龙's avatar
陈龙 committed
448 449
        setTableLoading(false);
      });
450 451 452 453
    };
    const clickReport = (reportId) => {
      setTableLoading(true);
      reportService.getReportDetailsInfo({ reportId }).then(res => {
陈龙's avatar
陈龙 committed
454 455 456 457
        if (res.code === 0) {
          setTableLoading(false);
          setDetailTableVisible(true);
          // 增加visible属性,方便后续检索的属性变更
458
          let _final = res.data.details.map(item => {
陈龙's avatar
陈龙 committed
459 460 461 462
            let _item = { ...item };
            _item.visible = true;
            return _item;
          });
463
          _final.sort((a, b) => b.isShow - a.isShow);  // 将显示项放在前边 edit by zhangzhiwei 2023-07-04
陈龙's avatar
陈龙 committed
464 465 466 467 468 469
          editDetailForm.setFieldsValue(_final);
          setDetailData(_final);
          setTempDetailData(_final);
          // 存储关联关系
          setRelationship(res.data.child);
        }
470
      }).catch(err => {
陈龙's avatar
陈龙 committed
471 472
        setTableLoading(false);
      });
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
    };
    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),
          };
          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 }, () => {
陈龙's avatar
陈龙 committed
502 503 504 505 506
            setCreateBtnLoading(false);
            setCreateModalVisible(false);
            getData();
            restCreateReportForm();
          });
507 508
        },
      ).catch(err => {
陈龙's avatar
陈龙 committed
509 510
        setCreateBtnLoading(false);
      });
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
    };
    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(','),
      });
      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;
        }, {});
陈龙's avatar
陈龙 committed
595
      }
596 597 598 599
      if (!_record.filterRule) _record.filterRule = '下拉';
      if (!_record.statisticsRule) _record.statisticsRule = '求和';
      // 统计规则变更
      if (isString(_record.statisticsData)) _record.statisticsData = {
陈龙's avatar
陈龙 committed
600 601 602
        单页: _record.statisticsData.includes('单页'),
        全部: _record.statisticsData.includes('全部'),
      };
603 604 605 606 607 608 609 610 611 612 613 614 615 616
      // 对齐方式设置默认值
      if (!_record.alignType) _record.alignType = 'left';
      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
617
          let _item = { ...item };
618
          Object.keys(_item).forEach(key => {
陈龙's avatar
陈龙 committed
619 620 621 622 623 624
            if (_item[key] === '') _item[key] = null;
          });
          _item.configId = _value.id;
          _item.id = 0;
          return _item;
        });
625
        if (labelColorPickerArray.length) _value.labelConfigs = labelColorPickerArray.map(item => {
陈龙's avatar
陈龙 committed
626 627 628 629 630
          let _item = { ...item };
          _item.configId = _value.id;
          _item.id = 0;
          return _item;
        });
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 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
        // 文字的颜色
        if (backgroundColor) {
          _value.color = backgroundColor;
        }
        // 过滤规则的设置,需要确保日期类型的过滤规则字段是唯一的
        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 => {
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          setSubmitFieldLoading(false);
          if (!type) {
            setDetailVisible(false);
          }
          clickReport(currentReport.id);
        });
      });
    };
    const searchReportList = (e) => {
      let _data = [...tableData];
      let final = _data.map(item => {
        let _item = { ...item };
        if (!e) {
          _item.visible = true;
        } else {
          _item.visible = _item.reportName.includes(e);
        }
        return _item;
      });
      setTableData(final);
    };
    const openCreateModal = (callback) => {
      if (callback) callback();
      getTableFromDB((data) => {
        setAllTableList(data);
        createMainTableForm.setFieldsValue({
          sourcesId: 0,
        });
        setCreateModalVisible(true);
      });
    };
    const getTableFromDB = (callback, sourcesId) => {
      reportService.getTables({ sourcesId }).then(res => {
陈龙's avatar
陈龙 committed
682
        if (res.code === 0) {
683
          callback(res.data);
陈龙's avatar
陈龙 committed
684 685 686 687
        } else {
          message.error(res.msg);
        }
      });
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
    };
    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);
          }
陈龙's avatar
陈龙 committed
709 710
        }
      });
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 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
    };
    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 => {
陈龙's avatar
陈龙 committed
777 778 779 780 781 782 783 784 785
          if (res.code === 0) {
            message.success('提交成功!');
          } else {
            message.error(res.msg);
          }
          setDetailTableLoading(false);
          setSubmitFieldLoading(false);
          setDetailVisible(false);
          clickReport(currentReport.id);
786
        }).catch(err => {
陈龙's avatar
陈龙 committed
787 788 789
          setDetailTableLoading(false);
        });
      });
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
    };
    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`],
          };
        });
        // debugger
        // return false
        await reportService.addReportInfo({
陈龙's avatar
陈龙 committed
821
          rM_ReportInfo,
822 823 824
          sourcesId: currentReport.sourcesId,
          isAdd: false,
        }).then(res => {
陈龙's avatar
陈龙 committed
825 826 827 828 829 830
          if (res.code === 0) {
            message.success('保存成功!');
            setPatchFieldVisible(false);
          } else {
            message.error(res.msg);
          }
831
        }).catch(err => {
陈龙's avatar
陈龙 committed
832 833 834
          message.error('保存失败!');
          setPatchSubTableBtnLoading(false);
        });
835
        setPatchSubTableBtnLoading(false);
陈龙's avatar
陈龙 committed
836
        clickReport(currentReport.id);
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 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 885 886 887 888 889 890 891 892 893 894 895 896 897 898
      });
    };
    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保证显示效果
      }
      setColorCardPosition({
        left: _cardLeft,
        top: _cardTop,
      });
      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;
陈龙's avatar
陈龙 committed
899
      }
900 901 902 903
      let { data, callback, index, key } = currentColorPicker;
      let _data = [...data];
      if (['tagColor', 'textColor'].includes(currentColorPicker.key)) {
        _data[index].color = e;
陈龙's avatar
陈龙 committed
904
      } else {
905
        _data[index][key] = `rgba(${_rgb.r},${_rgb.g},${_rgb.b},${_rgb.a})`;
陈龙's avatar
陈龙 committed
906
      }
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
      callback(_data);
    };
    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;
        return _item;
      });
      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 => {
        if (res.code === 0) {
          message.success('提交成功!');
        } else {
          message.error(res.msg);
        }
        setSubmitFieldLoading(false);
        clickReport(currentReport.id);
      });
    };
    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 };
陈龙's avatar
陈龙 committed
961

962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
        if (selectedRowKeys.includes(_item.id)) {
          _item[key] = value;
        }
        return _item;
      });
      setDetailData(_detailData);
      editDetailForm.setFieldsValue(_detailData);
    };
    const exportConfigs = (record) => {
      setTableLoading(true);
      exportReportConfig({ responseType: 'blob' }, {
        reportId: record.id,
      }).then(res => {
        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 => {
        if (res.code === 0) {
          setDataSourcesList(res.data);
        } else {
          setDataSourcesList([]);
        }
      });
    };
    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 });
      } else {
        getTableFromDB(..._arr);
陈龙's avatar
陈龙 committed
1013
      }
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
    };
    useEffect(() => {
      getData();
      getDataSourcesList();
    }, []);
    useEffect(() => {
      let numericalConfigs = currentField ? currentField.numericalConfigs : [];
      let labelConfigs = currentField ? currentField.labelConfigs : [];
      setNumberColorPickerArray(numericalConfigs);
      setLabelColorPickerArray(labelConfigs);
    }, [watchType]);
    return <div className={style.reportSettings}>
陈龙's avatar
陈龙 committed
1026
      {
1027
        detailTableVisible ? <div ref={reportDetails} className={style.reportDetails}>
陈龙's avatar
陈龙 committed
1028
          {/* 色板容器 */}
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
          <div onClick={(e) => {
            if (e.target.className.includes('colorSketch')) {
              setShowSketchPicker(false);
            }
          }} style={{
            visibility: showSketchPicker ? 'visible' : 'hidden',
          }}
               className={style.colorSketch}>
            <div ref={colorPicker} style={{
              position: 'absolute',
              left: colorCardPosition.left,
              top: colorCardPosition.top,
            }}>
              {
                ['textColor', 'tagColor'].includes(currentColorPicker.key) ?
                  <CustomerColorPicker clickColorPicker={(backgroundColor) => {
陈龙's avatar
陈龙 committed
1045
                    changeBackgroundColor(backgroundColor);
1046 1047
                  }}/> :
                  <SketchPicker width={240} presetColors={[
陈龙's avatar
陈龙 committed
1048 1049 1050 1051 1052 1053 1054 1055 1056
                    '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)',
1057 1058 1059
                  ]} color={currentColorPicker.key === 'wordColor' ? backgroundColor : returnCurrentColor()}
                                onChange={(e) => changeBackgroundColor(e)}/>
              }
陈龙's avatar
陈龙 committed
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
            </div>
          </div>
          <Modal
            title={'附加子表'}
            width={600}
            visible={patchFieldVisible}
            onCancel={() => {
              setPatchFieldVisible(false);
              setAllFields([]);
              setAllSubFields([]);
            }}
            onOk={patchSubTable2MainTable}
            okButtonProps={{
              loading: patchSubTableBtnLoading,
            }}
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
            footer={[
              <Button onClick={() => clearRelation(currentReport.id)}>清空挂接关系</Button>,
              <Button onClick={() => {
                setPatchFieldVisible(false);
                setAllFields([]);
                setAllSubFields([]);
                patchSubTableForm.resetFields();
              }}>取消</Button>,
              <Button type="primary" htmlType={'submit'} onClick={patchSubTable2MainTable}>确定</Button>,
            ]}
陈龙's avatar
陈龙 committed
1085 1086
          >
            <Form form={patchSubTableForm} {...layout}>
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
              <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');
                          }
                        }}>
陈龙's avatar
陈龙 committed
1098
                  {
1099 1100
                    subTableList.map(item => <Option value={item.name}>{item.name}</Option>)
                  }
陈龙's avatar
陈龙 committed
1101 1102
                </Select>
              </Form.Item>
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
              {
                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>;
                        })
                      }
                    </Checkbox.Group>
                  </Form.Item> : ''
              }
陈龙's avatar
陈龙 committed
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
            </Form>
          </Modal>
          <Modal
            title={'编辑字段属性'}
            width={920}
            visible={detailVisible}
            onCancel={() => setDetailVisible(false)}
            destroyOnClose
            footer={null}
            onClick={() => setShowSketchPicker(false)}
          >
            <div style={{ display: 'flex' }}>
              <div style={{ width: 200 }}>
1167 1168 1169 1170
                {
                  detailData ? <ul>
                    {
                      detailData.map((item, index) => <li
陈龙's avatar
陈龙 committed
1171
                        onClick={() => changeField(item)}
1172 1173 1174 1175 1176
                        className={classname(style.fieldList, activeID === item.id ? style.active : '')}
                        key={item.id}>{item.fieldAlias}</li>)
                    }
                  </ul> : ''
                }
陈龙's avatar
陈龙 committed
1177
              </div>
1178 1179 1180
              <div style={{
                flex: 1,
              }}>
陈龙's avatar
陈龙 committed
1181
                {/*<Form {...layout} form={form} initialValues={setDefaultValue(currentField)}*/}
1182 1183
                <Form {...layout} form={form}
                      onFinish={submitReportDetails}>
陈龙's avatar
陈龙 committed
1184
                  <div style={{ height: 500, overflowY: 'scroll' }}>
1185 1186 1187 1188 1189 1190
                    <Form.Item disabled label={'字段'} name={'fieldName'} rules={[
                      {
                        required: true, message: '编码名称必填',
                      },
                    ]}>
                      <Input disabled style={{ width: wordInputWidth }}/>
陈龙's avatar
陈龙 committed
1191
                    </Form.Item>
1192 1193 1194 1195 1196 1197
                    <Form.Item label={'别名'} name={'fieldAlias'} rules={[
                      {
                        required: true, message: '别名必填且不可重复',
                      },
                    ]}>
                      <Input style={{ width: wordInputWidth }}/>
陈龙's avatar
陈龙 committed
1198
                    </Form.Item>
1199 1200 1201 1202 1203 1204
                    <Form.Item label={'表头级数'} name={'level'} rules={[
                      {
                        required: true, message: '别名必填且不可重复',
                      },
                    ]}>
                      <InputNumber min={1}/>
陈龙's avatar
陈龙 committed
1205
                    </Form.Item>
1206 1207
                    {
                      fieldGroupLevel ? <Form.Item style={{ marginBottom: 0 }} label={'分组'}>
陈龙's avatar
陈龙 committed
1208
                        <Input.Group compact>
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
                          {
                            (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>;
                              }
                            })
                          }
陈龙's avatar
陈龙 committed
1224
                        </Input.Group>
1225 1226
                      </Form.Item> : ''
                    }
陈龙's avatar
陈龙 committed
1227 1228
                    <Form.Item label={'形态'} name={'type'}>
                      <Select style={{ width: wordInputWidth }}>
1229 1230 1231 1232 1233 1234 1235 1236 1237
                        {
                          Object.keys(typeArray).map(key => {
                            return <OptGroup label={key}>
                              {
                                typeArray[key].map(item => <Option value={item}>{item}</Option>)
                              }
                            </OptGroup>;
                          })
                        }
陈龙's avatar
陈龙 committed
1238 1239 1240
                      </Select>
                    </Form.Item>
                    <Form.Item label={'字体颜色'} name={'color'}>
1241 1242 1243 1244 1245 1246 1247 1248 1249
                      <div style={{
                        padding: 4,
                        display: 'inline-flex',
                        borderRadius: '2px',
                        border: '1px solid rgba(0,0,0,.35)',
                      }}>
                        <div style={{
                          width: '36px',
                          height: '14px',
陈龙's avatar
陈龙 committed
1250 1251
                          borderRadius: '2px',
                          border: '1px solid rgba(0,0,0,.35)',
1252 1253 1254 1255 1256 1257 1258
                          backgroundColor: backgroundColor,
                        }} onClick={(e) => {
                          clickColorCard(e);
                          setCurrentColorPicker({
                            key: 'wordColor',
                          });
                        }}/>
陈龙's avatar
陈龙 committed
1259 1260
                      </div>
                    </Form.Item>
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
                    {
                      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={{
陈龙's avatar
陈龙 committed
1289 1290 1291 1292
                                    padding: 4,
                                    display: 'inline-flex',
                                    borderRadius: '2px',
                                    border: '1px solid rgba(0,0,0,.35)',
1293 1294
                                  }}>
                                    <div style={{
陈龙's avatar
陈龙 committed
1295 1296 1297 1298 1299
                                      width: '36px',
                                      height: '14px',
                                      borderRadius: '2px',
                                      border: '1px solid rgba(0,0,0,.35)',
                                      backgroundColor: item.color,
1300
                                    }} onClick={(e) => {
陈龙's avatar
陈龙 committed
1301 1302 1303 1304 1305 1306 1307
                                      clickColorCard(e);
                                      setCurrentColorPicker({
                                        data: numberColorPickerArray,
                                        callback: setNumberColorPickerArray,
                                        index,
                                        key: 'color',
                                      });
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
                                    }}/>
                                  </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>
陈龙's avatar
陈龙 committed
1326
                          </Form.Item>
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
                        </Form.Item> : ''
                    }
                    {
                      ['文本'].includes(watchType) ?
                        <Form.Item label={'文本设置'}>
                          {
                            labelColorPickerArray.map((item, index) => {
                              return <Space
                                key={item.key}
                                style={{
                                  display: 'flex',
                                  marginBottom: 8,
                                }}
                                align="baseline"
陈龙's avatar
陈龙 committed
1341
                              >
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
                                <Form.Item
                                  label={'文本'}
                                >
                                  <Input value={item.labelValue}
                                         onChange={(e) => changeColorLabel(e, labelColorPickerArray, setLabelColorPickerArray, 'labelValue', index)}/>
                                </Form.Item>
                                <Form.Item
                                  label={'颜色'}
                                >
                                  <div style={{
陈龙's avatar
陈龙 committed
1352 1353 1354 1355
                                    padding: 4,
                                    display: 'inline-flex',
                                    borderRadius: '2px',
                                    border: '1px solid rgba(0,0,0,.35)',
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 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
                                  }}>
                                    <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>;
                            })
                          }
                          <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={'标签设置'}>
                          {
                            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={'颜色'}
陈龙's avatar
陈龙 committed
1412
                                >
1413 1414 1415 1416 1417 1418 1419
                                  <div style={{
                                    padding: 4,
                                    display: 'inline-flex',
                                    borderRadius: '2px',
                                    border: '1px solid rgba(0,0,0,.35)',
                                  }}>
                                    <div style={{
陈龙's avatar
陈龙 committed
1420 1421 1422 1423 1424
                                      width: '36px',
                                      height: '14px',
                                      borderRadius: '2px',
                                      border: '1px solid rgba(0,0,0,.35)',
                                      backgroundColor: item.color,
1425
                                    }} onClick={(e) => {
陈龙's avatar
陈龙 committed
1426 1427 1428 1429 1430 1431 1432
                                      clickColorCard(e);
                                      setCurrentColorPicker({
                                        data: labelColorPickerArray,
                                        callback: setLabelColorPickerArray,
                                        index,
                                        key: 'tagColor',
                                      });
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 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
                                    }}/>
                                  </div>
                                </Form.Item>
                                <MinusCircleOutlined
                                  onClick={() => removeColorPicker(labelColorPickerArray, setLabelColorPickerArray, index)}/>
                              </Space>;
                            })
                          }
                          <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={'统计规则'} style={{ display: 'flex' }}>
                          <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: 120 }}>
                                      <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>
                                </> : ''
陈龙's avatar
陈龙 committed
1484
                            }
1485 1486 1487
                          </Space>
                        </Form.Item> : ''
                    }
陈龙's avatar
陈龙 committed
1488
                    <Form.Item label={'配置'} name={'configItems'}>
1489
                      <TextArea rows={6}/>
陈龙's avatar
陈龙 committed
1490 1491 1492 1493
                    </Form.Item>
                  </div>
                  <Form.Item label={' '} colon={false} style={{ marginTop: 10 }}>
                    <Button onClick={() => setDetailVisible(false)}>取消</Button>
1494 1495
                    <Button loading={submitFieldLoading} style={{ marginLeft: 8 }} type="primary"
                            htmlType="submit">提交</Button>
陈龙's avatar
陈龙 committed
1496 1497 1498 1499 1500 1501 1502
                  </Form.Item>
                </Form>
              </div>
            </div>
          </Modal>
          <div className={style.tableWrapper}>
            <Row className={style.controlRow}>
1503 1504 1505 1506
              <LeftOutlined className={style.leftBtn} onClick={() => {
                setDetailTableVisible(false);
              }}/>
              <Form layout={'inline'} style={{ display: 'flex', flex: 1, justifyContent: 'space-between' }}>
陈龙's avatar
陈龙 committed
1507 1508
                <div style={{ display: 'flex' }}>
                  <Form.Item label={'快速索引'}>
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
                    <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);
                    }}/>
陈龙's avatar
陈龙 committed
1522 1523
                  </Form.Item>
                  <Form.Item>
1524 1525
                    <Button style={{ marginRight: 8 }}
                            onClick={() => showPatchSubModal(currentReport.sourcesId)}>附加子表</Button>
陈龙's avatar
陈龙 committed
1526 1527 1528 1529
                    <Button onClick={addVirtualColumn}>添加虚拟字段</Button>
                  </Form.Item>
                </div>
                <Form.Item style={{ marginRight: 0 }}>
1530 1531 1532 1533
                  {
                    isEditing ?
                      <>
                        <Button style={{ marginRight: 8 }} onClick={() => {
陈龙's avatar
陈龙 committed
1534 1535
                          setDetailData(tempDetailData);
                          editDetailForm.setFieldsValue(tempDetailData);
1536 1537 1538 1539 1540 1541 1542 1543 1544
                        }}>重置</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>
                  }
陈龙's avatar
陈龙 committed
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555
                </Form.Item>
              </Form>
            </Row>
            <div className={style.tableContent}>
              <Form className={style.tableForm} form={editDetailForm}>
                <BasicTable
                  loading={detailTableLoading}
                  pagination={false}
                  bordered
                  scroll={{ y: `calc(100% - ${selectedRowKeys.length ? 90 : 40}px)` }} // 需要考虑总结栏的高度
                  rowKey={'id'}
1556 1557 1558 1559 1560 1561
                  columns={currentDataSourceType === 'webapi' ? detailColumns.filter(item => item.title !== '表名') : detailColumns}
                  rowSelection={isEditing ? {
                    type: 'checkbox',
                    ...rowSelection,
                  } : null}
                  dataSource={detailData.filter(item => item.visible)}
陈龙's avatar
陈龙 committed
1562 1563
                  summary={(pageData) => {
                    if (detailData && detailData.length > 1 && isEditing && selectedRows.length) {
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 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
                      return <Table.Summary fixed>
                        <Table.Summary.Row>
                          <Table.Summary.Cell colSpan={7}>批量操作</Table.Summary.Cell>
                          <Table.Summary.Cell>
                            <Form.Item>
                              <InputNumber onChange={(e) => batchModify('columnWidth', e)}/>
                            </Form.Item>
                          </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>
                            </Form.Item>
                          </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>
                            </Form.Item>
                          </Table.Summary.Cell>
                          <Table.Summary.Cell>
                            <Form.Item>
                              <Switch checkedChildren="显示"
                                      unCheckedChildren="不显示"
                                      defaultChecked={false}
                                      onChange={(e) => batchModify('isShow', e)}/>
                            </Form.Item>
                          </Table.Summary.Cell>
                          <Table.Summary.Cell>
                            <Form.Item>
                              <Switch checkedChildren="开启"
                                      unCheckedChildren="关闭"
                                      defaultChecked={false}
                                      onChange={(e) => batchModify('isFilter', e)}/>
                            </Form.Item>
                          </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>
                            </Form.Item>
                          </Table.Summary.Cell>
                          <Table.Summary.Cell>
                            <Form.Item>
                              <Switch checkedChildren="开启"
                                      unCheckedChildren="关闭"
                                      defaultChecked={false}
                                      onChange={(e) => batchModify('isMerge', 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>;
陈龙's avatar
陈龙 committed
1634 1635
                    }
                  }}
1636 1637 1638 1639 1640 1641 1642
                  components={isEditing ? '' : {
                    body: {
                      wrapper: DraggableContainer,
                      row: DraggableBodyRow,
                    },
                  }}
                  onRow={record => {
陈龙's avatar
陈龙 committed
1643 1644 1645
                    return {
                      onDoubleClick: (e) => {
                        return false;
1646
                        if (e.target.cellIndex === detailColumns.length - 1 || e.target.cellIndex === void 0) return false;
陈龙's avatar
陈龙 committed
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
                        setActiveID(record.id);
                        if (record.color) setBackgroundColor(record.color);
                        form.setFieldsValue(setDefaultValue(record));
                        setCurrentField(setDefaultValue(record));
                        setDetailVisible(true);
                      },
                    };
                  }}
                />
              </Form>
            </div>
          </div>
1659
        </div> : <div className={style.reportDetails}>
陈龙's avatar
陈龙 committed
1660
          <Modal
1661 1662 1663 1664 1665 1666
            onCancel={() => {
              setCreateModalVisible(false);
              setIsCreatingMainTable(false);
              setCurrentDataSource('');
              createMainTableForm.resetFields();
            }}
陈龙's avatar
陈龙 committed
1667 1668 1669 1670 1671
            closable={false}
            visible={createModalVisible}
            footer={null}
            destroyOnClose
          >
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 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
            <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
1712
              </Form.Item>
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
              {
                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> : ''
              }
陈龙's avatar
陈龙 committed
1724
              <Form.Item label={' '} colon={false}>
1725 1726 1727 1728 1729 1730 1731
                <Button onClick={() => {
                  setCreateModalVisible(false);
                  setCurrentDataSource('');
                  createMainTableForm.resetFields();
                }}>取消</Button>
                <Button loading={createBtnLoading} style={{ marginLeft: 8 }} type={'primary'}
                        htmlType={'submit'}>提交</Button>
陈龙's avatar
陈龙 committed
1732 1733 1734 1735 1736 1737 1738
              </Form.Item>
            </Form>
          </Modal>
          <div className={style.tableWrapper}>
            <Row className={style.controlRow}>
              <Form layout={'inline'}>
                <Form.Item label={'快速索引'}>
1739
                  <Search onSearch={(e) => searchReportList(e)}/>
陈龙's avatar
陈龙 committed
1740 1741
                </Form.Item>
                <Form.Item>
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751
                  <Button type={'primary'} style={{ marginRight: 8 }} onClick={() => openCreateModal(() => {
                    setCurrentReport({});
                    setAllFields([]);
                    setIsCreatingMainTable(true);
                    createMainTableForm.setFieldsValue({
                      tableName: '',
                      reportName: '',
                      reportFields: [],
                    });
                  })}>新增</Button>
陈龙's avatar
陈龙 committed
1752
                  <Upload {...uploadProps}>
1753
                    <Button size="middle" icon={<ImportOutlined/>}>
陈龙's avatar
陈龙 committed
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
                      导入
                    </Button>
                  </Upload>
                </Form.Item>
              </Form>
            </Row>
            <div className={style.tableContent}>
              <BasicTable
                pagination={false}
                bordered
                loading={tableLoading}
                rowKey={'id'}
                columns={columns}
1767
                dataSource={tableData.filter(item => item.visible)}
陈龙's avatar
陈龙 committed
1768 1769 1770 1771
              />
            </div>
          </div>
        </div>
1772 1773 1774 1775
      }
    </div>;
  }
;
陈龙's avatar
陈龙 committed
1776
export default ReportsSetting;