index.jsx 30.5 KB
Newer Older
1
/* eslint-disable object-shorthand */
邓超's avatar
邓超 committed
2
import React, { useEffect, useState, useRef } from 'react';
shaoan123's avatar
shaoan123 committed
3
import classnames from 'classnames';
mayongxin's avatar
mayongxin committed
4
import {
5 6 7 8 9 10 11 12 13 14 15 16
  // Tree,
  Table,
  Space,
  Input,
  Button,
  Select,
  Popconfirm,
  notification,
  Spin,
  Tooltip,
  Badge,
  Spac,
邓超's avatar
邓超 committed
17
  Card,
18 19
  Dropdown,
  Menu,
20
  Modal,
21
  message,
22
  Tag,
mayongxin's avatar
mayongxin committed
23
} from 'antd';
24 25 26 27 28 29 30 31
import {
  EditOutlined,
  DeleteOutlined,
  FontColorsOutlined,
  PlusSquareOutlined,
  SortDescendingOutlined,
  PlusOutlined,
  BorderInnerOutlined,
邓超's avatar
邓超 committed
32 33
  DoubleLeftOutlined,
  DoubleRightOutlined,
34 35
  MenuOutlined,
  DatabaseOutlined,
36 37 38
  FunnelPlotOutlined,
  BranchesOutlined,
  ToolOutlined,
39
  QuestionCircleTwoTone,
40
} from '@ant-design/icons';
41

mayongxin's avatar
mayongxin committed
42
import PageContainer from '@/components/BasePageContainer';
43 44 45 46
import {
  CM_Table_LoadTable,
  removeTable,
  loadUnattachedTables,
47 48
  checkTableType,
  regroupTableType,
49
  GetDefaultTableFields,
50 51
  CheckUpgradeTable,
  UpgradeTable,
邓超's avatar
邓超 committed
52
} from '@/services/tablemanager/tablemanager';
53
import { useHistory } from 'react-router-dom';
54
import { Ellipse } from 'bizcharts/lib/g-components';
55

涂伟's avatar
涂伟 committed
56
import { number } from 'prop-types';
57
import Editor from './components/Field/editor';
58 59
// import AddTablelList from './components/Field/addTable';
import AddTablelList from './components/TableView';
60 61
import AffiliateAdd from './components/Field/affiliateAdd';
import LoadGroup from './components/Field/loadGroup';
62
import LoadGroupNew from './components/Field/loadGroupNew';
邓超's avatar
邓超 committed
63
import ChooseTableType from './components/ChooseTableType';
涂伟's avatar
涂伟 committed
64
import AddModal from './filedConfig/filedConfig';
65
// import { defaultFields } from './components/defaultFields';
66
import styles from './index.less';
涂伟's avatar
涂伟 committed
67 68 69
import formDesign from '@/assets/font/omsfont/formDesign.svg';
import tableDesign from '@/assets/font/omsfont/tableDesign.svg';
import deleteSvg from '@/assets/font/omsfont/delete.svg';
70
import update from '@/assets/font/omsfont/update.png';
mayongxin's avatar
mayongxin committed
71 72
const { Search } = Input;
const { Option } = Select;
73
const placeholder = '请输入表名';
74

75 76 77 78 79 80
const TableManager = props => {
  const history = useHistory();
  const [visible, setVisible] = useState(false); // 弹窗
  const [type, setType] = useState(''); // 弹窗类型
  const [formObj, setFormObj] = useState({});
  const [flag, setFlag] = useState(0); // 弹窗类型
邓超's avatar
邓超 committed
81
  // const [initNum, setIntNum] = useState(0);
82 83 84 85 86 87
  const [searchValue, setSearchValue] = useState('');
  const [treeLoading, setTreeLoading] = useState(true);
  const [tableList, setTableList] = useState([]);
  const [groupArr, setGroupArr] = useState([]);
  const [allData, setAllData] = useState([]);
  const [tableData, setTableData] = useState([]);
邓超's avatar
邓超 committed
88
  const [select, setSelect] = useState();
89
  const [selectTableName, setSelectTableName] = useState('');
皮倩雯's avatar
皮倩雯 committed
90
  const [showSearchStyle, setShowSearchStyle] = useState(false); // 是否显示模糊查询样式
91 92
  const [chooseLine, setChooseLine] = useState([0]);
  const [keepValue, setKeepValue] = useState([0]);
93
  const [keepTreeSelect, setKeepTreeSelect] = useState([]);
皮倩雯's avatar
皮倩雯 committed
94
  const [keepData, setKeepData] = useState([]);
95
  const [keepTreeFirst, setKeepTreeFirst] = useState([]);
邓超's avatar
邓超 committed
96 97 98
  const [treeVisible, setTreeVisible] = useState(true); // 是否显示左侧树
  const [hoverItemIndex, setHoverItemIndex] = useState(0); // hover流程索引
  const [pickIndex, setPickIndex] = useState(0);
99 100 101
  const [defaultFields, setDefaultFields] = useState([]);
  const [defaultFieldsList, setDefaultFieldsList] = useState([]);
  const [tableType, setTableType] = useState(defaultFields[0]);
102 103
  const [groupPopVisible, setgGroupPopVisible] = useState(false);
  const [checkMsg, setCheckMsg] = useState();
涂伟's avatar
涂伟 committed
104 105
  const [fieldConfigShow, setFieldConfigShow] = useState(false);
  const [tableInfo, setTableInfo] = useState({});
邓超's avatar
邓超 committed
106
  const initNum = useRef(0);
107 108 109 110
  useEffect(() => {
    GetDefaultTableFields().then(res => {
      if (res.code === 0) {
        let list = [];
111 112 113 114
        // 过滤掉事件表
        let resList = res.data.filter(item => item.value !== '事件表');
        setDefaultFieldsList(resList);
        resList.forEach(item => {
115 116 117 118 119 120 121 122 123
          list.push(item.value);
        });
        setDefaultFields(list);
      } else {
        message.error(res.msg);
      }
    });
  }, []);

124 125
  useEffect(
    record => {
涂伟's avatar
涂伟 committed
126 127 128
      if (props.location.query && initNum.current == 0) {
        loadTable(props.location.query.searchV);
        setSearchValue(props.location.query.searchV);
邓超's avatar
邓超 committed
129 130 131 132
      } else {
        loadTable(searchValue);
      }

133 134 135 136 137 138 139 140 141 142 143
      getField();
      //   if (props.history.location.query && selectTableName !== {}) {
      //     let { template } = props.history.location.query;
      //     setSelectTableName(template);
      //   }
    },
    [flag],
  );
  // 重字段配置返回后需要返回到原来的位置
  useEffect(() => {
    let arr = Object.keys(allData);
邓超's avatar
邓超 committed
144

邓超's avatar
邓超 committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
    if (
      arr.length > 0 &&
      props.history.location.query &&
      selectTableName == '' &&
      initNum.current == 0
    ) {
      let {
        tableScroll,
        template,
        keepValue,
        group,
        backIndex,
        selectValue,
      } = props.history.location.query;
      setSelectTableName(template);
160
      const i = group.findIndex(item => item.type == selectValue);
161
      setTimeout(() => {
邓超's avatar
邓超 committed
162 163
        setSelect(selectValue);
        setPickIndex(i);
164
        console.log(group);
邓超's avatar
邓超 committed
165
        setGroupArr(group);
166 167
        document.querySelector('.ant-table-body').scrollTop = tableScroll;
      }, 0);
168 169
      setChooseLine(keepValue);
      setKeepValue(keepValue);
170
    }
171
  }, [allData]);
邓超's avatar
邓超 committed
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
  // 附加
  const add = record => {
    setFormObj(record);
    setType('affiliateAdd');
    setVisible(true);
  };
  // 修改表名
  const changeDesc = record => {
    setType('edit');
    setVisible(true);
    setFormObj(record);
  };
  // 删除表
  const deleteChart = record => {
    removeTable({ tableID: record.tableID, removeFields: true }).then(res => {
      if (res.msg === 'Ok' || res.msg === '') {
        notification.success({
          message: '提示',
          duration: 3,
          description: '删除成功',
        });
        setFlag(flag + 1);
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: res.msg,
        });
      }
    });
  };
204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
  const onSubmit = prop => {
    setVisible(false);
    setFlag(flag + 1);
  };
  // 建表
  const AddTable = () => {
    setType('add');
    setVisible(true);
  };
  // 附加表
  const AffiliateAddTable = () => {
    setType('affiliateAdd');
    setFormObj({});
    setVisible(true);
  };
  // 字段配置
  const fieldsConfig = (record, e) => {
    e.stopPropagation();
    setFormObj(record);
涂伟's avatar
涂伟 committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
    pushFieldConfig(record);
    // history.push({
    //   pathname: `/biz/account/fieldConfig`,
    //   state: {
    //     name: record.tableAlias || record.tableName,
    //     id: record.tableName,
    //     template: record,
    //     tableScroll: document.querySelector('.ant-table-body').scrollTop,
    //     groupArr: groupArr,
    //     pickIndex: pickIndex,
    //     searchValue: searchValue,
    //     select: select,
    //     keepValue: keepValue,
    //     keepTreeSelect: keepTreeSelect,
    //     keepTreeFirst: keepTreeFirst,
    //     keepData: keepData,
    //   },
    // });
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
    // setType('config');
    // setVisible(true);
  };
  // 分组与排序
  const sort = record => {
    setFormObj(record);
    setType('sort');
    setVisible(true);
  };
  // 搜索框改变时存储输入的值
  const handleChange = e => {
    setSearchValue(e.target.value);
  };
  // 搜索
  const handleSearch = text => {
邓超's avatar
邓超 committed
257
    loadTable(text, 'search');
258
    setSearchValue(text);
邓超's avatar
邓超 committed
259
    setSelectTableName('');
邓超's avatar
邓超 committed
260 261
    setPickIndex(0);
    setSelect(groupArr[0].type);
262 263 264 265 266
    if (!text) {
      setShowSearchStyle(false);
    } else {
      setShowSearchStyle(true);
    }
267 268 269 270
  };
  const getField = () => {
    loadUnattachedTables().then(res => {
      if (res.data.root && res.data.root.length) {
271
        setTableList(res.data.root.reverse());
272 273 274 275
      }
    });
  };
  // 加载表
邓超's avatar
邓超 committed
276
  const loadTable = (keyword, isSearch) => {
277 278 279 280 281 282 283 284
    setTreeLoading(true);
    CM_Table_LoadTable({
      _version: 9999,
      filter: keyword || '',
    })
      .then(res => {
        setTreeLoading(false);
        if (res.msg === 'Ok') {
邓超's avatar
邓超 committed
285
          // setTableData(res.data.root);
涂伟's avatar
涂伟 committed
286 287 288 289 290 291
          let arr = res.data.root;
          arr.forEach(item => {
            item.tableStyle =
              item.tableStyle === '大'
                ? `一行三列/${item.labelStyle ? `${item.labelStyle}布局` : '左右布局'}`
                : item.tableStyle;
292
            let fieldCount = Number(item.fieldCount === '(无)' ? 0 : item.fieldCount);
涂伟's avatar
涂伟 committed
293 294 295 296 297 298
            let extraFieldCount = Number(
              item.extraFieldCount === '(无)' ? 0 : item.extraFieldCount,
            );
            // item.fieldCount extraFieldCount
            item.fieldRatio = `${fieldCount}/${fieldCount + extraFieldCount}`;
          });
299 300
          let groupData = formateArrDataA(res.data.root, 'groupName');
          let newArr = [];
301 302
          let aa = [];
          let bb = [];
303
          // 对分组进行排序
304
          const sortNameArr = res.data.groupNames;
305 306 307 308 309 310 311 312 313
          const sortList = [];
          sortNameArr.forEach(ele => {
            Object.keys(groupData).map((item, index) => {
              if (item === ele) {
                newArr.push({ type: item, key: index, page: 1, pageSize: 20 });
                aa.push({ name: item, key: index, ID: index, children: groupData[item] });
                bb.push(item);
              }
            });
314
          });
邓超's avatar
邓超 committed
315
          setAllData(groupData);
邓超's avatar
邓超 committed
316 317 318 319
          if (!props.history.location.query || initNum.current > 0) {
            if (newArr.length > 0 && (!select || isSearch)) {
              setSelect(newArr[0].type);
            }
320
            setGroupArr(newArr);
邓超's avatar
邓超 committed
321
          }
322 323
          setKeepTreeFirst(bb);
          setKeepTreeSelect(aa);
皮倩雯's avatar
皮倩雯 committed
324 325 326
          if (keyword === '') {
            setKeepData(aa);
          }
邓超's avatar
邓超 committed
327
          initNum.current += 1;
328 329 330
        }
      })
      .catch(e => {
邓超's avatar
邓超 committed
331
        setTreeLoading(false);
332 333 334 335 336 337
      });
  };
  const formateArrDataA = (initialArr, name) => {
    // 判定传参是否符合规则
    if (!(initialArr instanceof Array)) {
      return '请传入正确格式的数组';
338
    }
339 340
    if (!name) {
      return '请传入对象属性';
mayongxin's avatar
mayongxin committed
341
    }
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    // 先获取一下这个数组中有多少个"name"
    let nameArr = [];
    for (let i in initialArr) {
      if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
        nameArr.push(initialArr[i][`${name}`]);
      }
    }
    // 新建一个包含多个list的结果对象
    let tempObj = {};
    // 根据不同的"name"生成多个数组
    for (let k in nameArr) {
      for (let j in initialArr) {
        if (initialArr[j][`${name}`] == nameArr[k]) {
          // 每次外循环时新建一个对应"name"的数组, 内循环时当前数组不变
          tempObj[nameArr[k]] = tempObj[nameArr[k]] || [];
          tempObj[nameArr[k]].push(initialArr[j]);
358
        }
359
      }
360
    }
361 362 363 364 365 366 367 368 369 370 371
    for (let keys in tempObj) {
      let arr = [];
      tempObj[keys].map((item, index) => {
        tempObj[keys] = arr;
        item.key = index;
        arr.push(item);
      });
    }
    return tempObj;
  };
  const setRowClassName = record =>
372
    Object.entries(record).toString() === Object.entries(selectTableName).toString()
373 374
      ? styles.clickRowStyle
      : '';
邓超's avatar
邓超 committed
375 376 377 378 379 380 381 382 383 384 385 386
  // 模糊查询匹配的样式
  const searchStyle = val => {
    let n;
    if (showSearchStyle) {
      n = val.replace(
        new RegExp(searchValue, 'g'),
        `<span style='color:red'>${searchValue}</span>`,
      );
    } else {
      n = val;
    }
    return <div dangerouslySetInnerHTML={{ __html: n }} />;
387
  };
388

涂伟's avatar
涂伟 committed
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
  const pushFieldConfig = record => {
    // history.push({
    //   pathname: `/biz/account/fieldConfig`,
    //   state: {
    //     name: record.tableAlias || record.tableName,
    //     id: record.tableName,
    //     template: record,
    //     tableScroll: document.querySelector('.ant-table-body').scrollTop,
    //     groupArr: groupArr,
    //     pickIndex: pickIndex,
    //     searchValue: searchValue,
    //     select: select,
    //     keepValue: keepValue,
    //     keepTreeSelect: keepTreeSelect,
    //     keepTreeFirst: keepTreeFirst,
    //     keepData: keepData,
    //   },
    // });
    setTableInfo({
      name: record.tableAlias || record.tableName,
      id: record.tableName,
      template: record,
      tableScroll: document.querySelector('.ant-table-body').scrollTop,
      groupArr: groupArr,
      pickIndex: pickIndex,
      searchValue: searchValue,
      select: select,
      keepValue: keepValue,
      keepTreeSelect: keepTreeSelect,
      keepTreeFirst: keepTreeFirst,
      keepData: keepData,
    });
    setFieldConfigShow(true);
  };

424 425 426 427 428 429 430 431 432 433 434 435
  const updateForm = (record, e) => {
    e.stopPropagation();
    let params = {
      tableName: record.tableName,
      toTableType:
        record.groupName === '事件表' || record.groupName === '工单表'
          ? '事件工单表'
          : record.groupName,
    };
    CheckUpgradeTable(params).then(res => {
      if (res.code === 0) {
        return Modal.confirm({
436 437 438
          // icon: <QuestionCircleTwoTone />,
          icon: null,
          content: <div style={{ whiteSpace: 'pre-line', textAlign: 'justify' }}>{res.data}</div>,
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
          okText: '确认',
          cancelText: '取消',
          onOk: () => {
            UpgradeTable(params).then(ress => {
              if (ress.code === 0) {
                message.success('升级成功!');
                loadTable(showSearchStyle ? searchValue : '');
              } else {
                notification.error({
                  message: '提示',
                  duration: 3,
                  description: ress.msg,
                });
              }
            });
          },
        });
      }
      notification.error({
        message: '提示',
        duration: 3,
        description: res.msg,
      });
    });
  };

465 466 467
  const columns = [
    {
      title: '名称',
邓超's avatar
邓超 committed
468 469
      dataIndex: 'tableName',
      key: 'tableName',
470
      width: 200,
邓超's avatar
邓超 committed
471
      render: (text, record) => (
472 473 474 475 476 477 478 479 480
        <div
          onClick={e => fieldsConfig(record, e)}
          style={{ display: 'flex', alignItems: 'center' }}
        >
          {searchStyle(text)}
          {record.IsCanUpgrade ? (
            <img
              className={styles.btnImg}
              alt=""
481 482 483 484 485
              title={`升级到${
                record.groupName === '事件表' || record.groupName === '工单表'
                  ? '事件工单表'
                  : record.groupName
              }`}
486 487 488 489 490 491
              style={{ marginLeft: '6px' }}
              src={update}
              onClick={e => updateForm(record, e)}
            />
          ) : null}
        </div>
492
      ),
493 494
    },
    {
涂伟's avatar
涂伟 committed
495
      title: '展示名称',
496 497 498
      dataIndex: 'tableAlias',
      key: 'tableAlias',
      align: 'center',
499
      width: 200,
涂伟's avatar
涂伟 committed
500
      render: text => <div>{text || <span style={{ color: 'grey' }}>(无)</span>}</div>,
501 502
    },
    {
涂伟's avatar
涂伟 committed
503
      title: '表单布局',
504 505 506
      dataIndex: 'tableStyle',
      key: 'tableStyle',
      align: 'center',
507
      width: 100,
涂伟's avatar
涂伟 committed
508
      render: text => <div>{!text ? <span style={{ color: 'grey' }}>(无)</span> : text}</div>,
509
    },
涂伟's avatar
涂伟 committed
510 511 512 513 514 515 516
    // {
    //   title: '附加字段',
    //   dataIndex: 'fieldCount',
    //   key: 'fieldCount',
    //   align: 'center',
    //   width: 80,
    // },
517
    {
涂伟's avatar
涂伟 committed
518 519 520
      title: '已附加/全部字段',
      dataIndex: 'fieldRatio',
      key: 'fieldRatio',
521
      align: 'center',
涂伟's avatar
涂伟 committed
522 523 524 525 526 527 528
      width: 240,
      render: (text, record) => {
        if (record.missingFieldCount === '(无)') {
          return <Tag color="processing">{text}</Tag>;
        }
        return <Tag color="error">{text}</Tag>;
      },
529 530
    },
    {
涂伟's avatar
涂伟 committed
531
      title: '异常字段',
532 533
      dataIndex: 'missingFieldCount',
      key: 'missingFieldCount',
534 535
      align: 'center',
      width: 80,
涂伟's avatar
涂伟 committed
536 537 538 539 540 541
      render: record => {
        if (record === '(无)') {
          return <div style={{ color: 'grey' }}>{record}</div>;
        }
        return <div style={{ color: 'red' }}>{record}</div>;
      },
542
    },
涂伟's avatar
涂伟 committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
    // {
    //   title: '缺少字段',
    //   dataIndex: 'missingFieldCount',
    //   key: 'missingFieldCount',
    //   align: 'center',
    //   width: 80,
    //   render: text => (
    //     <div
    //       className={classnames({
    //         [styles.lack]: text !== '(无)',
    //       })}
    //     >
    //       {text}
    //     </div>
    //   ),
    // },
    // {
    //   title: '未附加',
    //   dataIndex: 'extraFieldCount',
    //   key: 'extraFieldCount',
    //   align: 'center',
    //   width: 80,
    // },
566 567 568 569 570
    {
      title: '分组数量',
      dataIndex: 'groupCount',
      key: 'groupCount',
      align: 'center',
571
      width: 80,
572
    },
573 574 575 576 577 578 579 580 581 582
    {
      title: '接口',
      dataIndex: 'interfaceText',
      key: 'interfaceText',
      align: 'center',
      width: 80,
      render: record => {
        if (record) {
          return (
            <Tooltip title={record}>
583
              <Tag color="success"></Tag>
584 585 586
            </Tooltip>
          );
        }
587
        return <Tag color="processing"></Tag>;
588 589
      },
    },
590 591
    {
      title: '操作',
邓超's avatar
邓超 committed
592 593
      ellipsis: true,
      key: 'tableID',
594
      align: 'center',
涂伟's avatar
涂伟 committed
595
      width: 120,
邓超's avatar
邓超 committed
596 597
      render: (text, record) => (
        <Space>
涂伟's avatar
涂伟 committed
598 599
          <Tooltip title="表结构设计">
            {/* <EditOutlined
邓超's avatar
邓超 committed
600 601
              onClick={() => changeDesc(record)}
              style={{ fontSize: '20px', color: '#1890FF' }}
涂伟's avatar
涂伟 committed
602 603 604 605 606 607 608 609 610 611 612 613
            /> */}
            <img
              className={styles.btnImg}
              src={formDesign}
              alt=""
              // onClick={() => changeDesc(record)}
              onClick={() => {
                setType('tableEdit');
                setVisible(true);
                setFormObj(record);
              }}
              style={{ width: '16px', color: '#1890FF' }}
614
            />
邓超's avatar
邓超 committed
615
          </Tooltip>
涂伟's avatar
涂伟 committed
616 617
          <Tooltip title="表单设计">
            {/* <MenuOutlined
618 619 620 621 622 623
              onClick={() => {
                setType('tableEdit');
                setVisible(true);
                setFormObj(record);
              }}
              style={{ fontSize: '20px', color: '#1890FF' }}
涂伟's avatar
涂伟 committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
            /> */}
            <img
              className={styles.btnImg}
              src={tableDesign}
              alt=""
              // onClick={() => {
              //   setType('tableEdit');
              //   setVisible(true);
              //   setFormObj(record);
              // }}
              onClick={e => {
                e.stopPropagation();
                pushFieldConfig(record);
              }}
              style={{ width: '16px', color: '#1890FF' }}
639
            />
640
          </Tooltip>
邓超's avatar
邓超 committed
641
          {/* <Tooltip title="字段配置">
邓超's avatar
邓超 committed
642 643 644 645
            <FontColorsOutlined
              onClick={e => fieldsConfig(record, e)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
邓超's avatar
邓超 committed
646 647
          </Tooltip> */}
          {/* <Tooltip title="附加">
邓超's avatar
邓超 committed
648 649 650 651
            <PlusSquareOutlined
              onClick={() => add(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
邓超's avatar
邓超 committed
652 653
          </Tooltip> */}
          {/* <Tooltip title="分组与排序">
邓超's avatar
邓超 committed
654 655 656 657
            <SortDescendingOutlined
              onClick={() => sort(record)}
              style={{ fontSize: '16px', color: '#1890FF' }}
            />
邓超's avatar
邓超 committed
658
          </Tooltip> */}
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
          {record.groupName !== '物联设备表' ? (
            <div onClick={e => e.stopPropagation()}>
              <Popconfirm
                title="是否删除该表?"
                okText="确认"
                cancelText="取消"
                onConfirm={() => {
                  deleteChart(record);
                }}
              >
                <Tooltip title="删除">
                  {/* <DeleteOutlined style={{ fontSize: '16px', color: '#e86060' }} /> */}
                  <img
                    className={styles.btnImg}
                    src={deleteSvg}
                    alt=""
                    style={{ width: '16px', color: '#1890FF' }}
                  />
                </Tooltip>
              </Popconfirm>
            </div>
          ) : null}
邓超's avatar
邓超 committed
681 682
        </Space>
      ),
683 684
    },
  ];
涂伟's avatar
涂伟 committed
685 686 687 688

  const tableListCancel = () => {
    setVisible(false);
  };
邓超's avatar
邓超 committed
689 690 691 692 693
  const pageChage = (page, pageSize) => {
    const list = JSON.parse(JSON.stringify(groupArr));
    list[pickIndex].page = page;
    list[pickIndex].pageSize = pageSize;
    setGroupArr(list);
694
  };
695 696 697 698 699
  const onMenuClick = e => {
    console.log('click', e);
    setTableType(e.key);
    AddTable();
  };
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
  // 检查表类型重分组
  const checkGroup = () => {
    checkTableType().then(res => {
      console.log(res);
      if (res.data === '检查完成,一切正常!') {
        notification.success({ message: '提示', duration: 3, description: res.data });
      } else {
        setCheckMsg(res.data);
        setgGroupPopVisible(true);
      }
    });
  };
  const getNewGroup = () => {
    regroupTableType().then(res => {
      if (res.code === 0) {
715
        // setFlag(flag + 1);
716
        setgGroupPopVisible(false);
717 718 719 720
        loadTable(searchValue, 'search');
        setSelectTableName('');
        setPickIndex(0);
        setSelect(groupArr[0].type);
721 722 723 724
        notification.success({ message: '提示', duration: 3, description: '执行成功' });
      }
    });
  };
725
  const menu = (
726
    <Menu onClick={onMenuClick} items={defaultFields.map(item => ({ key: item, label: item }))} />
727
  );
728 729 730
  return (
    <Spin tip="loading..." spinning={treeLoading}>
      <PageContainer>
邓超's avatar
邓超 committed
731 732 733 734 735 736 737 738 739 740
        <div className={styles.content}>
          {/* 左侧树 */}
          <Spin spinning={treeLoading} tip="loading...">
            <Card
              className={classnames({
                [styles.orgContainer]: true,
                [styles.orgContainerHide]: !treeVisible,
              })}
            >
              <div style={{ display: `${treeVisible ? 'block' : 'none'}` }}>
741 742
                <span className={styles.processTitle}>
                  表分组
743
                  <Tooltip title="表类型重新分组检查">
744 745 746 747 748 749
                    <ToolOutlined
                      onClick={() => checkGroup()}
                      style={{
                        fontSize: '20px',
                        color: '#1890FF',
                        cursor: 'pointer',
750
                        marginLeft: '150px',
751 752 753 754
                      }}
                    />
                  </Tooltip>
                </span>
邓超's avatar
邓超 committed
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
                <hr className={styles.splitLine} />

                <div
                  style={{
                    overflowY: 'scroll',
                    height: 'calc(100vh - 150px)',
                    overflowX: 'hidden',
                  }}
                >
                  {groupArr.length > 0 &&
                    groupArr.map((item, index) => (
                      <div
                        key={index}
                        className={classnames({
                          [styles.listItem]: true,
                          [styles.pickItem]: item.type === select,
                          [styles.listHover]: item.type !== select && item.type === hoverItemIndex,
                        })}
                        onMouseEnter={() => {
                          setHoverItemIndex(item.type);
                        }}
                        onMouseLeave={() => {
                          setHoverItemIndex('');
                        }}
                        onClick={() => {
                          setPickIndex(index);
                          setSelect(item.type);
                          setTableData(item.root);
                        }}
                      >
                        {item.type}{allData[item.type]?.length}
                      </div>
                    ))}
                </div>
              </div>
              <div className={styles.switcher}>
                {treeVisible && (
                  <Tooltip title="隐藏分组列表">
                    <DoubleLeftOutlined onClick={() => setTreeVisible(false)} />
                  </Tooltip>
                )}
                {!treeVisible && (
                  <Tooltip title="显示分组列表">
                    <DoubleRightOutlined onClick={() => setTreeVisible(true)} />
                  </Tooltip>
                )}
              </div>
            </Card>
          </Spin>
          <div className={styles.tablemanager_container}>
            <div className={styles.operate_bar}>
              <div className={styles.fast_search}>
                <div className={styles.title}>快速检索</div>
                <Search
                  allowClear
                  placeholder={placeholder}
                  onSearch={handleSearch}
                  onChange={handleChange}
                  value={searchValue}
                  enterButton
                  style={{ width: '300px' }}
                />
              </div>
邓超's avatar
邓超 committed
818
              {/* <Dropdown overlay={menu} arrow>
819 820 821 822 823 824 825
                <Button
                  type="primary"
                  icon={<BorderInnerOutlined />}
                  style={{ marginLeft: '10px' }}
                >
                  建表
                </Button>
邓超's avatar
邓超 committed
826 827 828 829 830 831 832 833 834 835 836 837
              </Dropdown> */}
              <Button
                type="primary"
                icon={<BorderInnerOutlined />}
                style={{ marginLeft: '10px' }}
                onClick={() => {
                  setType('chooseType');
                  setVisible(true);
                }}
              >
                建表
              </Button>
邓超's avatar
邓超 committed
838 839 840 841 842 843 844 845 846
              <Button
                type="primary"
                style={{ marginLeft: '10px' }}
                icon={<PlusOutlined />}
                onClick={AffiliateAddTable}
              >
                附加表
              </Button>
            </div>
847
            <div style={{ flex: 1, position: 'relative', width: '100%', background: '#fff' }}>
邓超's avatar
邓超 committed
848 849 850 851 852 853 854
              <Table
                rowKey={record => record.key}
                size="small"
                bordered
                style={{ position: 'absolute' }}
                columns={columns}
                dataSource={allData[select]}
855
                scroll={{ x: 'max-content', y: 'calc(100% - 50px)' }}
邓超's avatar
邓超 committed
856 857 858 859
                rowClassName={setRowClassName}
                onRow={record => ({
                  onDoubleClick: event => {
                    event.stopPropagation();
涂伟's avatar
涂伟 committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876
                    // history.push({
                    //   pathname: `/biz/account/fieldConfig`,
                    //   state: {
                    //     id: record.tableName,
                    //     template: record,
                    //     tableScroll: document.querySelector('.ant-table-body').scrollTop,
                    //     groupArr: groupArr,
                    //     pickIndex: pickIndex,
                    //     searchValue: searchValue,
                    //     select: select,
                    //     keepValue: keepValue,
                    //     keepTreeSelect: keepTreeSelect,
                    //     keepTreeFirst: keepTreeFirst,
                    //     keepData: keepData,
                    //   },
                    // });
                    pushFieldConfig(record);
邓超's avatar
邓超 committed
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
                  },
                  onClick: event => {
                    event.stopPropagation();
                    setSelectTableName(record);
                  }, // 点击行
                })}
                pagination={{
                  showTotal: (total, range) => `第${range[0]}-${range[1]} 条/共 ${total} 条`,
                  pageSizeOptions: [10, 20, 50, 100],
                  defaultPageSize: 20,
                  showQuickJumper: true,
                  showSizeChanger: true,
                  current: groupArr[pickIndex] ? groupArr[pickIndex].page : 1,
                  pageSize: groupArr[pickIndex] ? groupArr[pickIndex].pageSize : 20,
                  onChange: (page, pageSize) => pageChage(page, pageSize),
                }}
893 894 895 896 897 898 899 900 901 902 903 904 905
              />
            </div>
          </div>
        </div>
        {visible && type == 'edit' && (
          <Editor
            visible={visible}
            onCancel={() => setVisible(false)}
            callBackSubmit={onSubmit}
            type={type}
            formObj={formObj}
          />
        )}
906
        {/* {visible && type === 'add' && (
907
          <AddTablelList type={type} onCancel={() => setVisible(false)} callBackSubmit={onSubmit} />
908 909 910 911
        )} */}
        <AddTablelList
          visible={visible && (type === 'add' || type === 'tableEdit')}
          type={type}
涂伟's avatar
涂伟 committed
912
          onCancel={() => tableListCancel()}
913 914
          formObj={formObj}
          callBackSubmit={onSubmit}
915
          defaultFieldsList={defaultFieldsList}
916 917
          tableType={tableType}
        />
邓超's avatar
邓超 committed
918 919 920 921 922 923 924 925 926
        <ChooseTableType
          visible={visible && type === 'chooseType'}
          defalutFields={defaultFieldsList}
          onCancel={() => setVisible(false)}
          onTableClick={val => {
            setTableType(val);
            AddTable();
          }}
        />
927 928 929 930 931 932 933 934 935 936
        {visible && type === 'affiliateAdd' && (
          <AffiliateAdd
            visible={visible}
            tableList={tableList}
            type={type}
            onCancel={() => setVisible(false)}
            callBackSubmit={onSubmit}
            formObj={formObj}
          />
        )}
mayongxin's avatar
mayongxin committed
937

938
        {/* {visible && type === 'sort' && (
939 940 941 942 943 944 945
          <LoadGroup
            visible={visible}
            type={type}
            formObj={formObj}
            onCancel={() => setVisible(false)}
            callBackSubmit={onSubmit}
          />
946 947 948 949 950 951 952 953 954
        )} */}
        {visible && type === 'sort' && (
          <LoadGroupNew
            visible={visible}
            type={type}
            formObj={formObj}
            onCancel={() => setVisible(false)}
            callBackSubmit={onSubmit}
          />
955
        )}
956
        <Modal
957
          title="确定要进行表类型重新分组吗?"
958 959 960 961 962 963
          visible={groupPopVisible}
          onOk={getNewGroup}
          onCancel={() => setgGroupPopVisible(false)}
        >
          <div style={{ whiteSpace: 'pre-line', textAlign: 'justify' }}>{checkMsg}</div>
        </Modal>
964
        {/* <Modal
涂伟's avatar
涂伟 committed
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979
          title="表单设计"
          visible={fieldConfigShow}
          // onOk={getNewGroup}
          onCancel={() => setFieldConfigShow(false)}
          footer={null}
          width="100vw"
          style={{
            maxWidth: '100vw',
            top: 0,
            paddingBottom: 0,
          }}
          bodyStyle={{
            height: 'calc(100vh - 55px)',
          }}
          getContainer={false}
980 981 982 983 984 985 986 987
        > */}
        <AddModal
          tableInfo={tableInfo}
          show={fieldConfigShow}
          fieldConfigShow={fieldConfigShow}
          setFieldConfigShow={flags => setFieldConfigShow(flags)}
        />
        {/* </Modal> */}
988 989 990 991 992
      </PageContainer>
    </Spin>
  );
};
export default TableManager;