"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("antd/es/tooltip/style");

var _tooltip = _interopRequireDefault(require("antd/es/tooltip"));

require("antd/es/input/style");

var _input = _interopRequireDefault(require("antd/es/input"));

require("antd/es/form/style");

var _form = _interopRequireDefault(require("antd/es/form"));

var _react = _interopRequireWildcard(require("react"));

var _moment = _interopRequireDefault(require("moment"));

var _classnames = _interopRequireDefault(require("classnames"));

var _hooks = require("@parallel-line/hooks");

var _utils = require("@parallel-line/utils");

var _lodashEs = require("lodash-es");

var _utils2 = require("@parallel-line/common/es/utils");

var _hooks2 = require("@parallel-line/common/es/hooks");

var _icons = require("@parallel-line/icons");

var _ahooks = require("ahooks");

var _table = _interopRequireDefault(require("../table"));

var _button = _interopRequireDefault(require("../button"));

var _FormFilter = _interopRequireDefault(require("./FormFilter"));

var _whiteBoard = _interopRequireDefault(require("../white-board"));

var _QuickSearch = _interopRequireDefault(require("./QuickSearch"));

var _ColumnSetting = _interopRequireDefault(require("./ColumnSetting"));

var _utils3 = require("./utils");

var _useAntdTable2 = _interopRequireDefault(require("./hooks/useAntdTable"));

var _constant = require("../table/constant");

var _excluded = ["key", "sorter", "hideInSearch", "hideInTable", "hideInForm", "children", "ellipsis"],
    _excluded2 = ["name", "key", "sign", "icon", "click"];

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var sortMap = {
  ascend: 'ASC',
  descend: 'DESC'
};

function setValue(isPath, object, path, value) {
  var newValue = value || undefined;
  if (!newValue) return;

  if (isPath) {
    (0, _lodashEs.set)(object, path, newValue);
    return;
  }

  object[path] = newValue;
}

function formatMenuParams(filteredValues, menus, externalSign) {
  var _handleSign;

  return (_handleSign = (0, _utils3.handleSign)(menus, externalSign)) === null || _handleSign === void 0 ? void 0 : _handleSign.reduce(function (pre, cur) {
    if ((0, _lodashEs.isObject)(cur)) {
      var newCur = (0, _lodashEs.omit)(cur, ['sign']);
      var key = Object.keys(newCur)[0];

      if (filteredValues[key]) {
        pre[key] = filteredValues[key];
      } else {
        pre[key] = cur[key].value;
      }
    }

    return pre;
  }, {});
}

function formatColumn(_ref, signData) {
  var key = _ref.key,
      sorter = _ref.sorter,
      hideInSearch = _ref.hideInSearch,
      hideInTable = _ref.hideInTable,
      _ref$hideInForm = _ref.hideInForm,
      hideInForm = _ref$hideInForm === void 0 ? true : _ref$hideInForm,
      children = _ref.children,
      _ref$ellipsis = _ref.ellipsis,
      ellipsis = _ref$ellipsis === void 0 ? {
    showTitle: false
  } : _ref$ellipsis,
      column = _objectWithoutProperties(_ref, _excluded);

  if (hideInForm === false) {
    hideInSearch = true;
  } // if (isObject(hideInForm)) {
  //   const r = handleSign([hideInForm], signData);
  //   if (r.length === 0) return undefined;
  // } else if (!hideInForm) return undefined;


  if ((0, _lodashEs.isObject)(hideInTable)) {
    var r = (0, _utils3.handleSign)([hideInTable], signData);
    if (r.length > 0) return undefined;
  } else if (hideInTable) return undefined;

  var tableColumn = _objectSpread(_objectSpread({}, column), {}, {
    ellipsis: ellipsis,
    sorter: sorter == null ? !!column.defaultSortOrder : sorter,
    key: key ? key + '' : column.dataIndex instanceof Array ? column.dataIndex.join('.') : column.dataIndex
  });

  if ((0, _lodashEs.isObject)(hideInSearch)) {
    var _r = (0, _utils3.handleSign)([hideInSearch], signData);

    if (_r.length > 0) {
      tableColumn.hideInSearch = true;
      return tableColumn;
    }
  } else {
    tableColumn.hideInSearch = hideInSearch;
  }

  if (tableColumn.type === 'Date') {
    tableColumn.width = tableColumn.width || _constant.DateTimeColWidth;
  } else if (tableColumn.type === 'City') {
    tableColumn.width = tableColumn.width || _constant.CityColWidth;
  } else {
    tableColumn.width = tableColumn.width || _constant.DefaultColWidth;
  }

  return tableColumn;
}

function formatColumn2Filter(column, defaultHideInSearch, signData) {
  var _column$hideInSearch = column.hideInSearch,
      hideInSearch = _column$hideInSearch === void 0 ? defaultHideInSearch : _column$hideInSearch;

  if ((0, _lodashEs.isObject)(hideInSearch)) {
    var r = (0, _utils3.handleSign)([hideInSearch], signData);
    if (r.length > 0) return undefined;
  } else if (hideInSearch) return undefined;

  var filter = {
    dicKey: column.dicKey,
    options: column.options,
    type: column.type || 'Text',
    label: column.title,
    name: column.dataIndex instanceof Array ? column.dataIndex.join('.') : column.dataIndex
  };

  if (column.dicKey || column.options) {
    filter.type = 'Enum';
    filter.props = {
      dicKey: column.dicKey,
      options: column.options
    };
  }

  var dataIndex = column.searchKey || column.dataIndex;

  if ((0, _lodashEs.isArray)(dataIndex)) {
    filter.key = dataIndex.join('.');
    filter.isPath = true;
  } else {
    filter.key = dataIndex;
    filter.isPath = false;
  }

  return filter;
}

function formatColumn2FormFilter(column, defaultHideInForm, signData) {
  var _column$hideInForm = column.hideInForm,
      hideInForm = _column$hideInForm === void 0 ? defaultHideInForm : _column$hideInForm;

  if ((0, _lodashEs.isObject)(hideInForm)) {
    var r = (0, _utils3.handleSign)([hideInForm], signData);
    if (r.length > 0) return undefined;
  } else if (hideInForm) return undefined;

  var filter = {
    dicKey: column.dicKey,
    options: column.options,
    type: column.dicKey ? 'Enum' : column.type || 'Text',
    label: column.title,
    name: column.dataIndex instanceof Array ? column.dataIndex.join('.') : column.dataIndex
  };
  var dataIndex = column.searchKey || column.dataIndex;

  if ((0, _lodashEs.isArray)(dataIndex)) {
    filter.key = dataIndex.join('.');
    filter.isPath = true;
  } else {
    filter.key = dataIndex;
    filter.isPath = false;
  }

  return filter;
}

var CommonTable = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var _tableRef$current, _props$tableProps2, _props$tableProps3;

  var _props$Icon = props.Icon,
      Icon = _props$Icon === void 0 ? _utils.global.Icon || function () {
    return null;
  } : _props$Icon,
      style = props.style,
      config = props.config,
      columns = props.columns,
      _props$showFilter = props.showFilter,
      showFilter = _props$showFilter === void 0 ? true : _props$showFilter,
      externalSign = props.externalSign,
      menuBarRender = props.menuBarRender,
      _props$externalQueryD = props.externalQueryDic,
      externalQueryDic = _props$externalQueryD === void 0 ? {} : _props$externalQueryD,
      _props$useEventEmitte = props.useEventEmitter,
      useEventEmitter = _props$useEventEmitte === void 0 ? _utils.global.eventEmitter : _props$useEventEmitte,
      _props$defaultPageSiz = props.defaultPageSize,
      defaultPageSize = _props$defaultPageSiz === void 0 ? 20 : _props$defaultPageSiz,
      defaultColumnConfig = props.defaultColumnConfig,
      _props$tableProps = props.tableProps,
      pTableProps = _props$tableProps === void 0 ? {} : _props$tableProps,
      _props$customParams = props.customParams,
      customParams = _props$customParams === void 0 ? function (d) {
    return d;
  } : _props$customParams,
      renderColumn = props.renderColumn,
      renderTitle = props.renderTitle,
      renderFilter = props.renderFilter,
      _props$onOptionClick = props.onOptionClick,
      onOptionClick = _props$onOptionClick === void 0 ? function () {} : _props$onOptionClick,
      actionRule = props.actionRule,
      onActionClick = props.onActionClick,
      onLinkClick = props.onLinkClick,
      onMenuChange = props.onMenuChange;
  var menus = config.menus,
      actions = config.actions,
      actionConfig = config.actionConfig,
      options = config.options,
      tableRequest = config.tableRequest;

  var _ref2 = options || {},
      reload = _ref2.reload,
      setting = _ref2.setting,
      optionSearch = _ref2.search,
      _ref2$buttons = _ref2.buttons,
      buttons = _ref2$buttons === void 0 ? [] : _ref2$buttons;

  var tableRef = (0, _react.useRef)(null);
  var history = (0, _hooks.useHistory)();

  var _useNamespace = (0, _hooks2.useNamespace)('pro-table', props.prefixCls),
      _useNamespace2 = _slicedToArray(_useNamespace, 1),
      prefixCls = _useNamespace2[0];

  var _useUniqueKey = (0, _hooks.useUniqueKey)({
    key: props.uniqueKey,
    prefix: prefixCls
  }),
      _useUniqueKey2 = _slicedToArray(_useUniqueKey, 1),
      uniqueKey = _useUniqueKey2[0];

  var _useSize = (0, _ahooks.useSize)((tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.container) || null),
      containerWidth = _useSize.width;

  var _useControllableValue = (0, _ahooks.useControllableValue)(props, {
    valuePropName: 'filteredValues',
    defaultValuePropName: 'defaultFilteredValues',
    trigger: 'onFilteredValuesChange'
  }),
      _useControllableValue2 = _slicedToArray(_useControllableValue, 2),
      filteredValues = _useControllableValue2[0],
      setFilteredValues = _useControllableValue2[1]; // ============================ Listen Route =============================
  // 当路由中有参数时，设置到 filteredValues 上


  var formatFilteredValues = function formatFilteredValues() {
    var newFilteredValues = {};

    if (formatFilter instanceof Array) {
      formatFilter.forEach(function (filter) {
        var key = filter.name;
        newFilteredValues[key] = undefined;
      });
    }

    Object.entries(urlState).forEach(function (_ref3) {
      var _ref4 = _slicedToArray(_ref3, 2),
          key = _ref4[0],
          value = _ref4[1];

      if (value instanceof Array) {
        value = value.filter(function (v) {
          return !!v;
        });
      }

      newFilteredValues[key] = value;
    });
    return newFilteredValues;
  };

  var _useUrlState = (0, _hooks.useUrlState)({}, {
    scope: true
  }),
      _useUrlState2 = _slicedToArray(_useUrlState, 2),
      urlState = _useUrlState2[0],
      setUrlState = _useUrlState2[1];

  var listenRoute = function listenRoute() {
    var newFilteredValues = formatFilteredValues();
    setFilteredValues(newFilteredValues, {});
    setState({
      oldFilteredValues: newFilteredValues,
      menuParams: _objectSpread(_objectSpread({}, state.menuParams), formatMenuParams(newFilteredValues, menus, externalSign))
    });
  }; // TODO: 在WEB端不需要了。但是如果其他地方要用需要考虑怎么兼容～
  // useUpdateEffect(listenRoute, [urlState]);


  (0, _ahooks.useMount)(function () {
    if (!props.manual) listenRoute();
  }); // ============================ eventEmitter =============================

  useEventEmitter.useSubscription(function (_ref5) {
    var k = _ref5.uniqueKey,
        action = _ref5.action;
    if (k !== uniqueKey) return;

    switch (action) {
      default:
      case 'reload':
        onSubmit();
        break;

      case 'reset':
        onReset();
        break;
    }
  }); // ============================ Misc =============================

  var _useSetState = (0, _ahooks.useSetState)(function () {
    var newFilteredValues = formatFilteredValues();
    return {
      tableBodyHeight: 900,
      selectedRows: [],
      selectedRowKeys: [],
      oldFilteredValues: newFilteredValues,
      menuParams: formatMenuParams(newFilteredValues, menus, externalSign)
    };
  }()),
      _useSetState2 = _slicedToArray(_useSetState, 2),
      state = _useSetState2[0],
      setState = _useSetState2[1];
  /** 所有标识 */


  var allSign = _objectSpread(_objectSpread({}, props.externalSign), state.menuParams);

  (0, _ahooks.useUpdateEffect)(function () {
    onMenuChange && onMenuChange(state.menuParams);
    setTimeout(function () {
      return onSubmit();
    }, 0);
  }, [state.menuParams]);
  (0, _react.useImperativeHandle)(ref, function () {
    return _objectSpread(_objectSpread({}, search), {}, {
      getDataSource: function getDataSource() {
        return (tableProps === null || tableProps === void 0 ? void 0 : tableProps.dataSource) || [];
      },
      createReal: function createReal() {
        return {
          onReset: onReset,
          onSubmit: onSubmit,
          state: state
        };
      }
    });
  }); // ============================ Filter =============================

  /** 通过筛选标记，重新生成新的Filter */

  var formatFilter = (0, _hooks.useMemoDeep)(function () {
    var newColumns = (0, _utils3.handleSign)(columns, allSign);
    return (0, _utils3.treeToArray)(newColumns).map(function (column) {
      return formatColumn2Filter(column, defaultColumnConfig === null || defaultColumnConfig === void 0 ? void 0 : defaultColumnConfig.hideInSearch, allSign);
    }).filter(function (f) {
      return !!f;
    });
  }, [columns, allSign]);
  (0, _react.useEffect)(function () {
    var newFilteredValues = {};
    formatFilter.forEach(function (filter) {
      var key = filter.name;
      newFilteredValues[key] = state.oldFilteredValues[key] || undefined;
    });
    setFilteredValues(newFilteredValues, {});
  }, [formatFilter]); // ============================ Form =============================

  var _Form$useForm = _form.default.useForm(),
      _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
      form = _Form$useForm2[0];
  /** 通过筛选标记，重新生成新的Filter */


  var formatFormFilter = (0, _hooks.useMemoDeep)(function () {
    var newColumns = (0, _utils3.handleSign)(columns, allSign);
    return (0, _utils3.treeToArray)(newColumns).map(function (column) {
      return formatColumn2FormFilter(column, true, allSign);
    }).filter(function (f) {
      return !!f;
    });
  }, [columns, allSign]); // ============================ Table =============================

  /** 通过筛选标识，重新生成新的 tableRequest */

  var formatTableRequest = (0, _hooks.useMemoDeep)(function () {
    if (tableRequest instanceof Array) return (0, _utils3.handleSign)(tableRequest, allSign)[0];
    return tableRequest;
  }, [allSign]);
  /** 通过筛选标识，重新生成新的 操作类动作点 */

  var formatActions = (0, _hooks.useMemoDeep)(function () {
    return (0, _utils3.handleSign)(actions, allSign);
  }, [allSign]);
  /** 通过筛选标记，重新生成新的 columns */

  var formatColumns = (0, _hooks.useMemoDeep)(function () {
    var newColumns = (0, _utils3.handleSign)(columns, allSign).map(function (column) {
      return formatColumn(column, allSign);
    }).filter(function (f) {
      return !!f;
    });

    if (containerWidth) {
      var columnsWidth = newColumns.reduce(function (prev, cur) {
        return (0, _utils.calc)("".concat(prev, " + ").concat(cur.width));
      }, 100);

      if (columnsWidth < containerWidth) {
        var separWidth = parseInt((0, _utils.calc)("(".concat(containerWidth, " - ").concat(columnsWidth, ") / ").concat(newColumns.length)) + '');
        return newColumns.map(function (column) {
          column.width = (0, _utils.calc)("".concat(column.width, " + ").concat(separWidth));
          return column;
        });
      }
    }

    return newColumns;
  }, [columns, formatFilter, allSign, containerWidth]);
  /** 通过formatColumns，生成 defaultSort */

  var defaultSort = (0, _hooks.useMemoDeep)(function () {
    return formatColumns.reduce(function (prev, cur) {
      if (cur.key != null && cur.defaultSortOrder != null) {
        prev[cur.key] = sortMap[cur.defaultSortOrder];
      }

      return prev;
    }, {});
  }, [config]);

  var getTableData = /*#__PURE__*/function () {
    var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref6, formData) {
      var current, pageSize, sorter, requestAPI, sort, columnKey, order, singleQuery, rangeQuery, runFilter, newMenuParams, data;
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              runFilter = function _runFilter(filter, value) {
                var key = filter.key || filter.name;
                if (value == null) return;

                if (filter.type === 'Date') {
                  if (!(value === null || value === void 0 ? void 0 : value.length)) return;
                  var rangeDate = {};
                  if (value[0]) rangeDate.start = (0, _moment.default)(value[0]).format('YYYY-MM-DDT00:00:00');
                  if (value[1]) rangeDate.end = (0, _moment.default)(value[1]).format('YYYY-MM-DDT23:59:59');
                  setValue(!!filter.isPath, rangeQuery, key, rangeDate);
                  return;
                } // if (isArray(value)) {
                //   // 区间搜索，多选筛选，待后端提供相应的API
                //   setValue(!!filter.isPath, singleQuery, key, value.join(','));
                //   return;
                // }


                setValue(!!filter.isPath, singleQuery, key, value);
              };

              current = _ref6.current, pageSize = _ref6.pageSize, sorter = _ref6.sorter;
              requestAPI = props.request;

              if (!requestAPI) {
                requestAPI = function requestAPI(url, data) {
                  return _utils.request.post(url, {
                    data: data
                  });
                };
              }

              sort = {};

              if (sorter) {
                if (sorter instanceof Array) {
                  sorter.forEach(function (_ref8) {
                    var columnKey = _ref8.columnKey,
                        order = _ref8.order;
                    sort[columnKey] = sortMap[order];
                  });
                } else {
                  columnKey = sorter.columnKey, order = sorter.order;
                  sort[columnKey] = sortMap[order];
                }
              }

              singleQuery = {};
              rangeQuery = {};
              formatFilter.forEach(function (filter) {
                return runFilter(filter, filteredValues[filter.name]);
              });
              formatFormFilter.forEach(function (filter) {
                return runFilter(filter, formData[filter.name]);
              });
              newMenuParams = (0, _lodashEs.pickBy)(state.menuParams, function (m) {
                return m !== '__ALL__';
              });
              data = {
                sort: _objectSpread(_objectSpread({}, defaultSort), sort),
                query: _objectSpread(_objectSpread(_objectSpread({}, singleQuery), newMenuParams), formatTableRequest === null || formatTableRequest === void 0 ? void 0 : formatTableRequest.query),
                rangeQuery: rangeQuery,
                pageSize: pageSize,
                page: current
              };
              return _context.abrupt("return", requestAPI(formatTableRequest.url, customParams(data)));

            case 13:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));

    return function getTableData(_x, _x2) {
      return _ref7.apply(this, arguments);
    };
  }();

  var _useAntdTable = (0, _useAntdTable2.default)(getTableData, {
    form: form,
    manual: true,
    defaultPageSize: defaultPageSize,
    throwOnError: true,
    code: formatTableRequest.code,
    defaultParams: [{
      current: 1,
      pageSize: defaultPageSize
    }],
    formatResult: function formatResult(response) {
      return {
        response: response,
        list: (0, _lodashEs.get)(response, 'data.rows', []),
        total: (0, _lodashEs.get)(response, 'data.rowTotal', 0),
        statistics: (0, _lodashEs.get)(response, 'data.statistics')
      };
    },
    onSuccess: function onSuccess(res) {
      var _props$onSuccess;

      (_props$onSuccess = props.onSuccess) === null || _props$onSuccess === void 0 ? void 0 : _props$onSuccess.call(props, res);
    },
    onError: function onError(error) {
      var _props$onError;

      (_props$onError = props.onError) === null || _props$onError === void 0 ? void 0 : _props$onError.call(props, error);
    }
  }),
      tableProps = _useAntdTable.tableProps,
      loading = _useAntdTable.loading,
      search = _useAntdTable.search,
      data = _useAntdTable.data;

  var rowSelectionChange = function rowSelectionChange() {
    var selectedRowKeys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var selectedRows = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    setState({
      selectedRowKeys: selectedRowKeys,
      selectedRows: selectedRows
    });

    if ((0, _lodashEs.isObject)(pTableProps.rowSelection)) {
      var _pTableProps$rowSelec, _pTableProps$rowSelec2;

      (_pTableProps$rowSelec = pTableProps.rowSelection) === null || _pTableProps$rowSelec === void 0 ? void 0 : (_pTableProps$rowSelec2 = _pTableProps$rowSelec.onChange) === null || _pTableProps$rowSelec2 === void 0 ? void 0 : _pTableProps$rowSelec2.call(_pTableProps$rowSelec, selectedRowKeys, selectedRows);
    }
  };

  var formatTableProps = _objectSpread(_objectSpread(_objectSpread({}, props.tableProps), tableProps), {}, {
    loading: loading,
    actionConfig: actionConfig,
    externalQueryDic: externalQueryDic,
    defaultColumnConfig: defaultColumnConfig,
    actions: formatActions,
    columns: formatColumns,
    showFilter: showFilter,
    filterIsEmpty: formatFilter.length === 0,
    actionRule: actionRule,
    onActionClick: onActionClick,
    onLinkClick: onLinkClick,
    renderTitle: renderTitle,
    renderFilter: renderFilter,
    renderColumn: renderColumn,
    scroll: {
      y: state.tableBodyHeight,
      x: 'max-content',
      scrollToFirstRowOnChange: false
    },
    pagination: ((_props$tableProps2 = props.tableProps) === null || _props$tableProps2 === void 0 ? void 0 : _props$tableProps2.pagination) === false ? false : _objectSpread(_objectSpread(_objectSpread({}, (_props$tableProps3 = props.tableProps) === null || _props$tableProps3 === void 0 ? void 0 : _props$tableProps3.pagination), tableProps === null || tableProps === void 0 ? void 0 : tableProps.pagination), {}, {
      hideOnSinglePage: false,
      showSizeChanger: true,
      pageSizeOptions: Array.from(new Set([defaultPageSize, 20, 50, 100, 200].sort(function (a, b) {
        return a - b;
      }))).map(function (p) {
        return p + '';
      })
    }),
    rowSelection: pTableProps.rowSelection === true ? {
      fixed: true,
      preserveSelectedRowKeys: true,
      onChange: rowSelectionChange,
      selectedRowKeys: state.selectedRowKeys
    } : (0, _lodashEs.isObject)(pTableProps.rowSelection) ? _objectSpread(_objectSpread({
      fixed: true,
      preserveSelectedRowKeys: true,
      selectedRowKeys: state.selectedRowKeys
    }, pTableProps.rowSelection), {}, {
      onChange: rowSelectionChange
    }) : undefined
  }); // ============================ ToolBar =============================

  /** 通过筛选标记，重新生成新的 menus */


  var formatMenus = (0, _hooks.useMemoDeep)(function () {
    return (0, _utils3.handleSign)(menus, allSign);
  }, [menus, allSign]);
  var formatButtons = (0, _hooks.useMemoDeep)(function () {
    return (0, _utils3.handleSign)(buttons, allSign);
  }, [allSign]);

  var renderOption = function renderOption(key, optionConfig, DefaultOption) {
    var node = onOptionClick(key, optionConfig, DefaultOption);
    return /*#__PURE__*/_react.default.isValidElement(node) ? node : DefaultOption;
  };

  var optionClassName = (0, _classnames.default)("".concat(prefixCls, "-option"), "".concat(prefixCls, "-default-option"));

  var renderToolBar = function renderToolBar() {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, optionSearch && /*#__PURE__*/_react.default.createElement(_input.default, {
      style: {
        maxWidth: 165
      },
      placeholder: "\u641C\u7D22",
      prefix: /*#__PURE__*/_react.default.createElement(_icons.SearchOutlined, null)
    }), reload && /*#__PURE__*/_react.default.createElement(_tooltip.default, {
      title: "\u5237\u65B0"
    }, /*#__PURE__*/_react.default.createElement(_button.default, {
      icon: /*#__PURE__*/_react.default.createElement(_icons.RefreshOutlined, null),
      className: optionClassName,
      onClick: onSubmit
    })), setting && /*#__PURE__*/_react.default.createElement(_ColumnSetting.default, {
      className: optionClassName,
      columns: formatColumns,
      checkable: true,
      draggable: true
    }), formatButtons.map(function (item, index) {
      var name = item.name,
          key = item.key,
          sign = item.sign,
          icon = item.icon,
          click = item.click,
          buttonProps = _objectWithoutProperties(item, _excluded2);

      var _item$type = item.type,
          type = _item$type === void 0 ? 'default' : _item$type;
      return renderOption(key || name, item, /*#__PURE__*/_react.default.createElement(_button.default, Object.assign({
        key: index,
        className: (0, _classnames.default)("".concat(prefixCls, "-option"), type === 'default' && "".concat(prefixCls, "-default-option")),
        icon: typeof icon === 'string' ? /*#__PURE__*/_react.default.createElement(Icon, {
          type: icon
        }) : icon
      }, buttonProps, {
        onClick: function onClick() {
          if (click) {
            (0, _utils2.toRoute)(history, externalQueryDic, click);
          } else onOptionClick(key || name, item);
        }
      }), name));
    }));
  };

  var handleMenuChange = function handleMenuChange(key, value) {
    return setState({
      menuParams: _objectSpread(_objectSpread({}, state.menuParams), {}, _defineProperty({}, key, value))
    });
  }; // ============================ Events =============================


  var onReset = function onReset() {
    setState({
      oldFilteredValues: {}
    });
    setFilteredValues({}, {});
    rowSelectionChange();
    setTimeout(function () {
      search.reset();
    }, 0);
  };

  var onFormReset = function onFormReset() {
    search.reset();
  };

  var onSubmit = function onSubmit() {
    rowSelectionChange();
    search.submit();
  };

  var onCleanFiltered = function onCleanFiltered() {
    var newFilteredValues = {};

    if (formatFilter instanceof Array) {
      formatFilter.forEach(function (filter) {
        var key = filter.name;
        newFilteredValues[key] = undefined;
      });
    }

    setUrlState(newFilteredValues);
    setState({
      oldFilteredValues: {}
    });
    setFilteredValues({}, {});
    onSubmit();
  };

  var render = function render(wrapperStyle) {
    return /*#__PURE__*/_react.default.createElement("div", {
      id: uniqueKey,
      className: (0, _classnames.default)("".concat(prefixCls, "-wrapper "), props.className),
      style: wrapperStyle
    }, (menus || options || config.title) && /*#__PURE__*/_react.default.createElement(_QuickSearch.default, {
      menus: formatMenus,
      title: config.title,
      menuParams: state.menuParams,
      statistics: data === null || data === void 0 ? void 0 : data.statistics,
      menuBarRender: menuBarRender === null || menuBarRender === void 0 ? void 0 : menuBarRender(state.menuParams),
      toolBarRender: renderToolBar(),
      onMenuChange: handleMenuChange
    }), /*#__PURE__*/_react.default.createElement(_table.default, Object.assign({
      ref: tableRef
    }, formatTableProps, {
      filteredValues: filteredValues,
      onCleanFiltered: onCleanFiltered,
      onFilteredChange: function onFilteredChange(key, value) {
        var newFilteredValues = _objectSpread(_objectSpread({}, filteredValues), {}, _defineProperty({}, key, value));

        setState({
          oldFilteredValues: newFilteredValues
        });
        setFilteredValues(newFilteredValues, _defineProperty({}, key, value));

        if (!value) {
          setUrlState(_defineProperty({}, key, value));
        } // TODO 临时做处理，查询值变化事件不应该需要手动触发更新


        setTimeout(function () {
          onSubmit();
        }, 0);
      }
    })));
  };

  if (formatFormFilter.length) {
    return /*#__PURE__*/_react.default.createElement(_whiteBoard.default, {
      style: style
    }, /*#__PURE__*/_react.default.createElement(_whiteBoard.default.TopBoard, null, props.children, /*#__PURE__*/_react.default.createElement(_FormFilter.default, {
      form: form,
      loading: loading,
      filter: formatFormFilter,
      onReset: onFormReset,
      onSubmit: onSubmit
    })), /*#__PURE__*/_react.default.createElement(_whiteBoard.default.BottomBoard, null, render()));
  }

  return render(style);
});
CommonTable.defaultProps = {
  antPrefixCls: 'ant',
  defaultPageSize: 20,
  customParams: function customParams(params) {
    return params;
  }
};
var _default = CommonTable;
exports.default = _default;