UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

1,463 lines (1,217 loc) 101 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectSpread from "@babel/runtime/helpers/objectSpread2"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _get from "@babel/runtime/helpers/get"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _createSuper from "@babel/runtime/helpers/createSuper"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { __decorate } from "tslib"; import React from 'react'; import classNames from 'classnames'; import ResizeObserver from 'resize-observer-polyfill'; import raf from 'raf'; import { observer } from 'mobx-react'; import moment from 'moment'; import pick from 'lodash/pick'; import omit from 'lodash/omit'; import isString from 'lodash/isString'; import isNil from 'lodash/isNil'; import isUndefined from 'lodash/isUndefined'; import noop from 'lodash/noop'; import defer from 'lodash/defer'; import attempt from 'lodash/attempt'; import { action, isArrayLike, runInAction, toJS } from 'mobx'; import { DragDropContext } from 'react-beautiful-dnd'; import warning from '../../../es/_util/warning'; import { isCalcSize, isPercentSize, pxToRem, toPx } from '../../../es/_util/UnitConvertor'; import measureScrollbar from '../../../es/_util/measureScrollbar'; import KeyCode from '../../../es/_util/KeyCode'; import ReactResizeObserver from '../../../es/_util/resizeObserver'; import Column from './Column'; import TableRow from './TableRow'; import TableHeaderCell from './TableHeaderCell'; import TableStore, { CUSTOMIZED_KEY, SELECTION_KEY } from './TableStore'; import TableHeader from './TableHeader'; import autobind from '../_util/autobind'; import Pagination from '../pagination/Pagination'; import Spin from '../spin'; import DataSetComponent from '../data-set/DataSetComponent'; import { TableContextProvider } from './TableContext'; import TableWrapper from './TableWrapper'; import Profiler from './Profiler'; import TableTBody from './TableTBody'; import ExpandableTableTBody from './ExpandableTableTBody'; import TableFooter from './TableFooter'; import { ColumnLock, RowBoxPlacement, ScrollPosition, SelectionMode, TableHeightType, TableMode, TablePaginationPosition } from './enum'; import TableQueryBar from './query-bar'; import ToolBar from './query-bar/TableToolBar'; import FilterBar from './query-bar/TableFilterBar'; import AdvancedQueryBar from './query-bar/TableAdvancedQueryBar'; import ProfessionalBar from './query-bar/TableProfessionalBar'; import ComboBar from './query-bar/TableComboBar'; import DynamicFilterBar from './query-bar/TableDynamicFilterBar'; import FilterSelect from './query-bar/FilterSelect'; import { findCell, findIndexedSibling, findRow, getCellVerticalSize, getDateByISOWeek, getHeight, getPaginationPosition, isCanEdictingRow, isDropresult, isStickySupport, onlyCustomizedColumn, isJsonString, copyToClipboard, pasteFromClipboard } from './utils'; import TableBody from './TableBody'; import VirtualWrapper from './VirtualWrapper'; import SelectionTips from './SelectionTips'; import { DataSetEvents, DataSetSelection, DataSetStatus, FieldType, RecordStatus } from '../data-set/enum'; import { Size } from '../core/enum'; import StickyShadow from './StickyShadow'; import { getUniqueFieldNames } from '../data-set/utils'; import mergeProps from '../_util/mergeProps'; import ErrorBar from './ErrorBar'; import TableSibling from './TableSibling'; import message from '../message'; import ClipboardBar from './ClipboardBar'; import { $l } from '../locale-context'; var _instance; // 构造一个单例table来防止body下不能有table元素的报错 export var instance = function instance(wrapperClassName, prefixCls) { // Using a table as the portal so that we do not get react // warnings when mounting a tr element var _tableContain = function _tableContain() { var table = document.createElement('table'); if (wrapperClassName) { table.className = wrapperClassName; } var thead = document.createElement('thead'); thead.className = "".concat(prefixCls, "-thead"); table.appendChild(thead); var headtr = document.createElement('tr'); thead.appendChild(headtr); var tbody = document.createElement('tbody'); tbody.className = "".concat(prefixCls, "-tbody"); table.appendChild(tbody); if (!document.body) { throw new Error('document.body required a body to append'); } document.body.appendChild(table); return { tbody: tbody, headtr: headtr }; }; if (_instance) { return _instance; } return _instance = _tableContain(); }; var Table = /*#__PURE__*/function (_DataSetComponent) { _inherits(Table, _DataSetComponent); var _super = _createSuper(Table); function Table() { var _this; _classCallCheck(this, Table); _this = _super.apply(this, arguments); _this.tableStore = new TableStore(_assertThisInitialized(_this)); _this.wrapperWidth = []; return _this; } _createClass(Table, [{ key: "currentRow", get: function get() { var prefixCls = this.prefixCls, element = this.element; return element ? element.querySelector(".".concat(prefixCls, "-row-current")) : null; } }, { key: "firstRow", get: function get() { var prefixCls = this.prefixCls, element = this.element; return element ? element.querySelector(".".concat(prefixCls, "-row:first-child")) : null; } }, { key: "lastRow", get: function get() { var prefixCls = this.prefixCls, element = this.element; return element ? element.querySelector(".".concat(prefixCls, "-row:last-child")) : null; } }, { key: "saveResizeRef", value: function saveResizeRef(node) { this.resizeLine = node; } }, { key: "saveContentRef", value: function saveContentRef(node) { this.tableContentWrap = node; } }, { key: "saveRangeBorderRef", value: function saveRangeBorderRef(node) { this.rangeBorder = node; } }, { key: "useFocusedClassName", value: function useFocusedClassName() { return false; } }, { key: "setCode", value: function setCode(props) { var customizedCode = props.customizedCode; if (customizedCode) { this.code = customizedCode; } else { _get(_getPrototypeOf(Table.prototype), "setCode", this).call(this, props); } } }, { key: "handleResize", value: function handleResize(width) { var element = this.element, tableStore = this.tableStore, wrapperWidth = this.wrapperWidth; if (width !== undefined) { var duplicate = wrapperWidth.includes(width); wrapperWidth.unshift(width); window.clearTimeout(this.wrapperWidthTimer); this.wrapperWidthTimer = window.setTimeout(function () { wrapperWidth.pop(); }, 500); if (wrapperWidth.length > 2) { wrapperWidth.pop(); } if (duplicate) { return; } } if (element && !element.offsetParent) { tableStore.styledHidden = true; } else if (!tableStore.hidden) { this.syncSizeInFrame(width); } else { tableStore.styledHidden = false; } } }, { key: "handleWindowResize", value: function handleWindowResize() { this.handleResize(); } }, { key: "clearClipboard", value: function clearClipboard() { var tableStore = this.tableStore; if (tableStore.startChooseCell && tableStore.endChooseCell && this.rangeBorder) { this.rangeBorder.style.display = 'none'; runInAction(function () { tableStore.startChooseCell = null; tableStore.endChooseCell = null; }); } } }, { key: "handleDataSetLoad", value: function handleDataSetLoad() { var tableStore = this.tableStore; if (tableStore.performanceEnabled) { tableStore.performanceOn = true; } this.setScrollTop(0); this.initDefaultExpandedRows(); this.clearClipboard(); } }, { key: "handleDataSetCreate", value: function handleDataSetCreate(_ref) { var record = _ref.record, dataSet = _ref.dataSet; var tableStore = this.tableStore; if (tableStore.inlineEdit) { if (tableStore.currentEditRecord) { tableStore.currentEditRecord.reset(); dataSet.remove(record); } else { tableStore.currentEditRecord = record; } } this.clearClipboard(); } }, { key: "handleDataSetReset", value: function handleDataSetReset(_ref2) { var record = _ref2.record, dataSet = _ref2.dataSet; if (record) { var errors = dataSet.getAllValidationErrors(); this.bubbleValidationReport(errors.dataSet.length > 0 || errors.records.length > 0); } else { this.bubbleValidationReport(false); } this.clearClipboard(); } }, { key: "handleDataSetRemove", value: function handleDataSetRemove(_ref3) { var records = _ref3.records, dataSet = _ref3.dataSet; if (records) { var errors = dataSet.getAllValidationErrors(); this.bubbleValidationReport(errors.dataSet.length > 0 || errors.records.length > 0); } this.clearClipboard(); } }, { key: "handleDataSetValidateSelf", value: function handleDataSetValidateSelf(props) { var dataSet = props.dataSet; var errors = dataSet.getAllValidationErrors(); this.bubbleValidationReport(errors.dataSet.length > 0 || errors.records.length > 0); } }, { key: "handleDataSetValidate", value: function handleDataSetValidate(props) { var valid = props.valid, dataSet = props.dataSet, validationErrors = props.errors, noLocate = props.noLocate; var autoValidationLocate = this.props.autoValidationLocate; var errors = dataSet.getAllValidationErrors(); this.bubbleValidationReport(errors.dataSet.length > 0 || errors.records.length > 0); if (autoValidationLocate !== false && !noLocate && !valid) { var tableStore = this.tableStore; var _validationErrors = _slicedToArray(validationErrors, 1), firstInvalidRecord = _validationErrors[0]; if (firstInvalidRecord) { var _errors = firstInvalidRecord.errors, record = firstInvalidRecord.record; if (_errors.length) { if (!tableStore.showCachedSelection) { if (dataSet.cachedRecords.includes(record)) { runInAction(function () { tableStore.showCachedSelection = true; }); } } var _errors2 = _slicedToArray(_errors, 1), name = _errors2[0].field.name; if (tableStore.virtual && !findRow(tableStore, record)) { var tableBodyWrap = this.tableBodyWrap; if (tableBodyWrap) { var rowMetaData = tableStore.rowMetaData; if (rowMetaData) { var metaData = rowMetaData.find(function (m) { return m.record === record; }); if (metaData) { tableBodyWrap.scrollTop = metaData.offset; } } else { tableBodyWrap.scrollTop = record.index * tableStore.virtualRowHeight; } } } raf(function () { var cell = findCell(tableStore, name, undefined, record); if (cell) { cell.focus(); } }); } } } } }, { key: "handleKeyDown", value: function handleKeyDown(e) { var tableStore = this.tableStore, clipboard = this.props.clipboard; var keyboard = tableStore.keyboard; var ctrlKey = e.ctrlKey || e.metaKey; if (!tableStore.editing) { try { var dataSet = this.props.dataSet; var altKey = e.altKey; var shiftKey = e.shiftKey; switch (e.keyCode) { case KeyCode.UP: if (shiftKey && keyboard) { this.handleKeyDownUpShift(e); } else { this.handleKeyDownUp(e); } break; case KeyCode.DOWN: if (shiftKey && keyboard) { this.handleKeyDownDownShift(e); } else { this.handleKeyDownDown(e); } break; case KeyCode.RIGHT: this.handleKeyDownRight(e); break; case KeyCode.LEFT: this.handleKeyDownLeft(e); break; case KeyCode.PAGE_UP: e.preventDefault(); dataSet.prePage(); break; case KeyCode.PAGE_DOWN: e.preventDefault(); dataSet.nextPage(); break; case KeyCode.HOME: this.handleKeyDownHome(e); break; case KeyCode.END: this.handleKeyDownEnd(e); break; case KeyCode.S: if (ctrlKey === true && keyboard) this.handleKeyDownCTRLS(e); break; case KeyCode.N: if (altKey === true && keyboard) this.handleKeyDownCTRLN(e); break; case KeyCode.D: if (ctrlKey === true && keyboard) this.handleKeyDownCTRLD(e); break; case KeyCode.DELETE: if (altKey === true && keyboard) this.handleKeyDownCTRLDELETE(e); break; default: } } catch (error) { warning(false, error.message); } } if (clipboard && clipboard.copy && ctrlKey && e.keyCode === KeyCode.C) { this.handleCopyChoose(); } if (clipboard && clipboard.paste && ctrlKey && e.keyCode === KeyCode.V) { this.handlePasteChoose(); } var _this$props$onKeyDown = this.props.onKeyDown, onKeyDown = _this$props$onKeyDown === void 0 ? noop : _this$props$onKeyDown; onKeyDown(e); } }, { key: "focusRow", value: function focusRow(row) { if (row) { var index = row.dataset.index; if (index) { var dataSet = this.props.dataSet; var record = dataSet.findRecordById(index); if (record) { dataSet.current = record; return record; } } } } }, { key: "handleKeyDownHome", value: function () { var _handleKeyDownHome = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(e) { var dataSet; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: e.preventDefault(); dataSet = this.props.dataSet; if (this.tableStore.isTree) { _context.next = 5; break; } _context.next = 5; return dataSet.first(); case 5: this.focusRow(this.firstRow); case 6: case "end": return _context.stop(); } } }, _callee, this); })); function handleKeyDownHome(_x) { return _handleKeyDownHome.apply(this, arguments); } return handleKeyDownHome; }() }, { key: "handleKeyDownEnd", value: function () { var _handleKeyDownEnd = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(e) { var dataSet; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: e.preventDefault(); dataSet = this.props.dataSet; if (this.tableStore.isTree) { _context2.next = 5; break; } _context2.next = 5; return dataSet.last(); case 5: this.focusRow(this.lastRow); case 6: case "end": return _context2.stop(); } } }, _callee2, this); })); function handleKeyDownEnd(_x2) { return _handleKeyDownEnd.apply(this, arguments); } return handleKeyDownEnd; }() }, { key: "handleKeyDownCTRLS", value: function () { var _handleKeyDownCTRLS = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(e) { var dataSet; return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: e.preventDefault(); dataSet = this.tableStore.dataSet; dataSet.submit(); case 3: case "end": return _context3.stop(); } } }, _callee3, this); })); function handleKeyDownCTRLS(_x3) { return _handleKeyDownCTRLS.apply(this, arguments); } return handleKeyDownCTRLS; }() }, { key: "handleKeyDownCTRLN", value: function () { var _handleKeyDownCTRLN = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(e) { var _this$tableStore, dataSet, editors; return _regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _this$tableStore = this.tableStore, dataSet = _this$tableStore.dataSet, editors = _this$tableStore.editors; if (editors.size) { e.preventDefault(); dataSet.create({}, 0); } case 2: case "end": return _context4.stop(); } } }, _callee4, this); })); function handleKeyDownCTRLN(_x4) { return _handleKeyDownCTRLN.apply(this, arguments); } return handleKeyDownCTRLN; }() // TODO: To be optimized }, { key: "handleKeyDownCTRLD", value: function () { var _handleKeyDownCTRLD = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(e) { var currentRow, tableStore, dataSet, currentElementSibling, previousElementSibling, index, currentIndex, record, currentRecord, cloneRecodData, dealCloneRecodData, editeColumn, uniqueFieldNames; return _regeneratorRuntime.wrap(function _callee5$(_context5) { while (1) { switch (_context5.prev = _context5.next) { case 0: e.preventDefault(); currentRow = this.currentRow, tableStore = this.tableStore; dataSet = tableStore.dataSet; currentElementSibling = null; // to justice it can be change or standards compliant if (isCanEdictingRow(currentRow)) { currentElementSibling = currentRow; } if (currentElementSibling && tableStore && dataSet) { previousElementSibling = findIndexedSibling(currentElementSibling, -1); if (previousElementSibling) { index = previousElementSibling.dataset.index; currentIndex = currentElementSibling.dataset.index; if (index && currentIndex) { record = dataSet.findRecordById(index); currentRecord = dataSet.findRecordById(currentIndex); // exculde the primery key and merge has columns which has edictor if (record && currentRecord && tableStore) { cloneRecodData = record.clone().toData() || {}; dealCloneRecodData = {}; editeColumn = tableStore.columns.filter(function (column) { return !!column.editor; }).reduce(function (accumulator, nowValue) { return [].concat(_toConsumableArray(accumulator), [nowValue.name]); }, []).filter(function (v) { return !(v === null || v === undefined || v === ''); }); if (editeColumn && editeColumn.length > 0) { editeColumn.forEach(function (element) { if (element) { dealCloneRecodData[element] = cloneRecodData[element]; } }); } // remove the unique name of fields uniqueFieldNames = getUniqueFieldNames(dataSet); if (uniqueFieldNames && uniqueFieldNames.length > 0) { uniqueFieldNames.forEach(function (element) { if (element) { delete dealCloneRecodData[element]; } }); } currentRecord.set(dealCloneRecodData); } } } } case 6: case "end": return _context5.stop(); } } }, _callee5, this); })); function handleKeyDownCTRLD(_x5) { return _handleKeyDownCTRLD.apply(this, arguments); } return handleKeyDownCTRLD; }() }, { key: "handleKeyDownCTRLDELETE", value: function () { var _handleKeyDownCTRLDELETE = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(e) { var dataSet; return _regeneratorRuntime.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: e.preventDefault(); dataSet = this.tableStore.dataSet; dataSet["delete"](dataSet.selected); case 3: case "end": return _context6.stop(); } } }, _callee6, this); })); function handleKeyDownCTRLDELETE(_x6) { return _handleKeyDownCTRLDELETE.apply(this, arguments); } return handleKeyDownCTRLDELETE; }() }, { key: "handleKeyDownUp", value: function () { var _handleKeyDownUp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(e) { var currentRow, returnRecod, previousElementSibling, dataSet; return _regeneratorRuntime.wrap(function _callee7$(_context7) { while (1) { switch (_context7.prev = _context7.next) { case 0: e.preventDefault(); currentRow = this.currentRow; if (!currentRow) { _context7.next = 14; break; } previousElementSibling = findIndexedSibling(currentRow, -1); if (!previousElementSibling) { _context7.next = 8; break; } returnRecod = this.focusRow(previousElementSibling); _context7.next = 12; break; case 8: dataSet = this.props.dataSet; _context7.next = 11; return dataSet.prePage(); case 11: returnRecod = this.focusRow(this.lastRow); case 12: if (!returnRecod) { _context7.next = 14; break; } return _context7.abrupt("return", Promise.resolve(returnRecod)); case 14: return _context7.abrupt("return", Promise.reject()); case 15: case "end": return _context7.stop(); } } }, _callee7, this); })); function handleKeyDownUp(_x7) { return _handleKeyDownUp.apply(this, arguments); } return handleKeyDownUp; }() }, { key: "handleKeyDownDown", value: function () { var _handleKeyDownDown = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(e) { var currentRow, returnRecod, nextElementSibling, dataSet; return _regeneratorRuntime.wrap(function _callee8$(_context8) { while (1) { switch (_context8.prev = _context8.next) { case 0: e.preventDefault(); currentRow = this.currentRow; if (!currentRow) { _context8.next = 14; break; } nextElementSibling = findIndexedSibling(currentRow, 1); if (!nextElementSibling) { _context8.next = 8; break; } returnRecod = this.focusRow(nextElementSibling); _context8.next = 12; break; case 8: dataSet = this.props.dataSet; _context8.next = 11; return dataSet.nextPage(); case 11: returnRecod = this.focusRow(this.firstRow); case 12: if (!returnRecod) { _context8.next = 14; break; } return _context8.abrupt("return", Promise.resolve(returnRecod)); case 14: return _context8.abrupt("return", Promise.reject()); case 15: case "end": return _context8.stop(); } } }, _callee8, this); })); function handleKeyDownDown(_x8) { return _handleKeyDownDown.apply(this, arguments); } return handleKeyDownDown; }() }, { key: "handleKeyDownDownShift", value: function () { var _handleKeyDownDownShift = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(e) { var dataSet, currentRow, index, record, currentRecord; return _regeneratorRuntime.wrap(function _callee9$(_context9) { while (1) { switch (_context9.prev = _context9.next) { case 0: e.preventDefault(); dataSet = this.tableStore.dataSet; currentRow = this.currentRow; if (!(currentRow && isCanEdictingRow(currentRow))) { _context9.next = 22; break; } index = currentRow.dataset.index; if (!index) { _context9.next = 20; break; } record = dataSet.findRecordById(index); if (!record) { _context9.next = 20; break; } if (record.selectable) { _context9.next = 12; break; } this.handleKeyDownDown(e); _context9.next = 20; break; case 12: if (record.isSelected) { _context9.next = 16; break; } dataSet.select(record); _context9.next = 20; break; case 16: _context9.next = 18; return this.handleKeyDownDown(e); case 18: currentRecord = _context9.sent; if (currentRecord && dataSet) { dataSet.select(currentRecord); } case 20: _context9.next = 23; break; case 22: this.handleKeyDownDown(e); case 23: case "end": return _context9.stop(); } } }, _callee9, this); })); function handleKeyDownDownShift(_x9) { return _handleKeyDownDownShift.apply(this, arguments); } return handleKeyDownDownShift; }() }, { key: "handleKeyDownUpShift", value: function () { var _handleKeyDownUpShift = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(e) { var dataSet, currentRow, index, record, currentRecord; return _regeneratorRuntime.wrap(function _callee10$(_context10) { while (1) { switch (_context10.prev = _context10.next) { case 0: e.preventDefault(); dataSet = this.tableStore.dataSet; currentRow = this.currentRow; if (!(currentRow && isCanEdictingRow(currentRow))) { _context10.next = 22; break; } index = currentRow.dataset.index; if (!index) { _context10.next = 20; break; } record = dataSet.findRecordById(index); if (!record) { _context10.next = 20; break; } if (record.selectable) { _context10.next = 12; break; } this.handleKeyDownUp(e); _context10.next = 20; break; case 12: if (record.isSelected) { _context10.next = 16; break; } dataSet.select(record); _context10.next = 20; break; case 16: _context10.next = 18; return this.handleKeyDownUp(e); case 18: currentRecord = _context10.sent; if (currentRecord) { dataSet.select(currentRecord); } case 20: _context10.next = 23; break; case 22: this.handleKeyDownUp(e); case 23: case "end": return _context10.stop(); } } }, _callee10, this); })); function handleKeyDownUpShift(_x10) { return _handleKeyDownUpShift.apply(this, arguments); } return handleKeyDownUpShift; }() }, { key: "handleKeyDownRight", value: function handleKeyDownRight(e) { var tableStore = this.tableStore, _this$props = this.props, expandedRowRenderer = _this$props.expandedRowRenderer, dataSet = _this$props.dataSet; if (tableStore.isTree || expandedRowRenderer) { var current = dataSet.current; if (current) { e.preventDefault(); tableStore.setRowExpanded(current, true); } } } }, { key: "handleKeyDownLeft", value: function handleKeyDownLeft(e) { var tableStore = this.tableStore, _this$props2 = this.props, expandedRowRenderer = _this$props2.expandedRowRenderer, dataSet = _this$props2.dataSet; if (tableStore.isTree || expandedRowRenderer) { var current = dataSet.current; if (current) { e.preventDefault(); tableStore.setRowExpanded(current, false); } } } }, { key: "handleCopyChoose", value: function handleCopyChoose() { var _this2 = this; var _this$tableStore2 = this.tableStore, columnGroups = _this$tableStore2.columnGroups, startChooseCell = _this$tableStore2.startChooseCell, endChooseCell = _this$tableStore2.endChooseCell, clipboard = _this$tableStore2.clipboard, isCopyPristine = _this$tableStore2.isCopyPristine; var columns = columnGroups.leafs; if (startChooseCell && endChooseCell) { if (this.dataSet) { var minRowIndex = Math.min(startChooseCell.rowIndex, endChooseCell.rowIndex); var maxRowIndex = Math.max(startChooseCell.rowIndex, endChooseCell.rowIndex); var minColIndex = Math.min(startChooseCell.colIndex, endChooseCell.colIndex); var maxColIndex = Math.max(startChooseCell.colIndex, endChooseCell.colIndex); var copyData = []; var _loop = function _loop(i) { var record = _this2.dataSet.records[i]; for (var j = minColIndex; j <= maxColIndex; j++) { var recordData = void 0; var fieldName = columns[j].column.name || String(columns[j].column.key || ''); if (fieldName === SELECTION_KEY) { recordData = String(record.isSelected); } else { (function () { var field = _this2.dataSet.getField(fieldName); if (field) { var fieldType = field && field.get('type', record); recordData = record.get(fieldName); if (clipboard && !isCopyPristine) { if (field.getLookup(record) || field.get('options', record) || field.get('lovCode', record)) { // 处理 lookup、lov recordData = isArrayLike(recordData) ? recordData.map(function (x) { return field.getText(x, undefined, record); }).join(',') : field.getText(recordData); } if (field && fieldType === FieldType["boolean"]) { var text = field.getText(recordData); recordData = isString(text) ? text : text ? $l('Table', 'query_option_yes') : $l('Table', 'query_option_no'); } if (columns[j] && columns[j].column.renderer) { var getTBodyElement = startChooseCell.target.parentElement.parentElement; var td = getTBodyElement === null || getTBodyElement === void 0 ? void 0 : getTBodyElement.querySelectorAll('tr')[i].querySelectorAll('td')[j]; recordData = td ? td.innerText : null; } } else if (fieldType === FieldType.object) { recordData = JSON.stringify(recordData); } // 去掉换行符 if (isString(recordData)) { recordData = recordData.replace(/[\r\n]/g, ""); } } })(); } recordData = isNil(recordData) ? '' : recordData; copyData.push(j === maxColIndex ? "".concat(recordData, " \t\n") : "".concat(recordData, " \t")); } }; for (var i = minRowIndex; i < maxRowIndex + 1; i++) { _loop(i); } copyToClipboard().writeText(copyData.join('')).then(function () { message.success($l('Table', isCopyPristine ? 'copy_pristine_success' : 'copy_display_success')); }); } } } }, { key: "handlePasteChoose", value: function () { var _handlePasteChoose = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() { var _this3 = this; var _this$tableStore3, node, columnGroups, currentEditorName, currentEditRecord, editors, inlineEdit, colIndex, columns, keys, _loop2, i, _ret, clipText, _this$dataSet, currentIndex, length, batchRecord, rows, _i, editorRowIndex, cols, _loop3, j, _ret2; return _regeneratorRuntime.wrap(function _callee12$(_context13) { while (1) { switch (_context13.prev = _context13.next) { case 0: _this$tableStore3 = this.tableStore, node = _this$tableStore3.node, columnGroups = _this$tableStore3.columnGroups, currentEditorName = _this$tableStore3.currentEditorName, currentEditRecord = _this$tableStore3.currentEditRecord, editors = _this$tableStore3.editors, inlineEdit = _this$tableStore3.inlineEdit; if (!(!currentEditorName && !currentEditRecord)) { _context13.next = 3; break; } return _context13.abrupt("return"); case 3: columns = columnGroups.leafs; if (!currentEditorName) { _context13.next = 8; break; } colIndex = columns.findIndex(function (x) { return x.column.name === currentEditorName; }); _context13.next = 19; break; case 8: if (!currentEditRecord) { _context13.next = 19; break; } keys = Array.from(editors.keys()); _loop2 = function _loop2(i) { var key = keys[i]; var editorItem = editors.get(key); if (editors.get(key)) { var cellIsFocus = editorItem && editorItem.editor && editorItem.editor.isFocus; if (cellIsFocus) { colIndex = columns.findIndex(function (x) { return x.column.name === key; }); return "break"; } } }; i = 0; case 12: if (!(i < keys.length)) { _context13.next = 19; break; } _ret = _loop2(i); if (!(_ret === "break")) { _context13.next = 16; break; } return _context13.abrupt("break", 19); case 16: i++; _context13.next = 12; break; case 19: // 先失焦 this.tableStore.blurEditor(); if (this.dataSet) { this.dataSet.status = DataSetStatus.loading; } _context13.next = 23; return pasteFromClipboard(node.element); case 23: clipText = _context13.sent; if (!this.dataSet) { _context13.next = 57; break; } _this$dataSet = this.dataSet, currentIndex = _this$dataSet.currentIndex, length = _this$dataSet.length; batchRecord = []; rows = clipText.split('\n').filter(function (line) { return line.trim() !== ''; }); _context13.prev = 28; _i = 0; case 30: if (!(_i < rows.length)) { _context13.next = 49; break; } if (!(currentEditRecord && _i > 0)) { _context13.next = 33; break; } return _context13.abrupt("break", 49); case 33: editorRowIndex = !currentEditRecord ? _i + currentIndex : currentEditRecord.index; if (editorRowIndex >= length) { this.dataSet.create({}, editorRowIndex + 1); } cols = rows[_i].split('\t').filter(function (x) { return !!x; }); _loop3 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop3(j) { var text, record, column, fieldName, field, fieldType, optionDs, jsonText, textField, promises, results, obj, data, current, optionData, _textField, valueField, option, columnRenderer; return _regeneratorRuntime.wrap(function _loop3$(_context12) { while (1) { switch (_context12.prev = _context12.next) { case 0: text = cols[j]; record = _this3.dataSet.get(editorRowIndex); column = columns[colIndex + j].column; fieldName = column.name; field = _this3.dataSet.getField(fieldName); // 非编辑项则跳过赋值 if (!(!column.editor || !field || field.disabled || field.readOnly || !_this3.dataSet)) { _context12.next = 7; break; } return _context12.abrupt("return", "break"); case 7: fieldType = field.type; optionDs = field.getOptions(); jsonText = isJsonString(text); if (fieldType !== FieldType.object || !jsonText) { text = String(text).trim(); if (text.includes(',')) { // 默认以英文逗号分割 text = text.split(','); } else if (text.includes(',')) { // 兼容中文逗号 text = text.split(','); } } _context12.t0 = fieldType; _context12.next = _context12.t0 === FieldType["boolean"] ? 14 : _context12.t0 === FieldType.number ? 16 : _context12.t0 === FieldType.date ? 18 : _context12.t0 === FieldType.dateTime ? 18 : _context12.t0 === FieldType.month ? 18 : _context12.t0 === FieldType.year ? 18 : _context12.t0 === FieldType.week ? 20 : _context12.t0 === FieldType.time ? 22 : _context12.t0 === FieldType.object ? 24 : 45; break; case 14: text = String(text).toLowerCase() === 'true' || String(text) === "1" || String(text) === "是"; return _context12.abrupt("break", 47); case 16: if (isArrayLike(text)) { text = text.map(function (item) { return Number(item); }); } else { text = Number(text); } return _context12.abrupt("break", 47); case 18: if (isArrayLike(text)) { text = text.map(function (item) { return moment(item); }); } else { text = moment(text); } return _context12.abrupt("break", 47); case 20: if (isArrayLike(text)) { text = text.map(function (item) { return moment(getDateByISOWeek(item)); }); } else { text = moment(getDateByISOWeek(text)); } return _context12.abrupt("break", 47); case 22: if (isArrayLike(text)) { text = text.map(function (item) { return moment("".concat(moment().format('YYYY-MM-DD'), " ").concat(item)); }); } else { text = moment("".concat(moment().format('YYYY-MM-DD'), " ").concat(text)); } return _context12.abrupt("break", 47); case 24: if (!jsonText) { _context12.next = 28; break; } text = attempt(JSON.parse, text); _context12.next = 44; break; case 28: if (!optionDs) { _context12.next = 44; break; } textField = field.get('textField'); if (!isArrayLike(text)) { _context12.next = 38; break; } promises = text.map( /*#__PURE__*/function () { var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(t) { var obj, data, current; return _regeneratorRuntime.wrap(function _callee11$(_context11) { while (1) { switch (_context11.prev = _context11.next) { case 0: obj = _defineProperty({}, textField, t.trim()); _context11.next = 3; return optionDs.query(1, obj); case 3: data = _context11.sent; if (_this3.dataSet && data) { current = data[_this3.dataSet.dataKey][0]; text = current || null; } return _context11.abrupt("return", text); case 6: case "end": return _context11.stop(); } } }, _callee11); })); return function (_x11) { return _ref4.apply(this, arguments); }; }()); // eslint-disable-next-line no-await-in-loop _context12.next = 34; return Promise.all(promises); case 34: results = _context12.sent; text = results; _context12.next = 44; break; case 38: if (!isString(text)) { _context12.next = 44; break; } obj = _defineProperty({}, textField, text.trim()); // eslint-disable-next-line no-await-in-loop _context12.next = 42; return optionDs.query(1, obj); case 42: data = _context12.sent; if (_this3.dataSet && data) { current = data[_this3.dataSet.dataKey][0]; text = current || null; } case 44: return _context12.abrupt("break", 47); case 45: if (optionDs) { optionData = optionDs.toData(); _textField = field.get('textField'); valueField = field.get('valueField'); if (isArrayLike(text)) { text = text.map(function (v) { var option = optionData.find(function (x) { return x[_textField] === v.trim() || x[valueField] === v.trim(); }); return option ? option[valueField] : null; }); } else { option = optionData.find(function (x) { return x[_textField] === text || x[valueField] === text; }); text = option ? option[valueField] : null; } } return _context12.abrupt("break", 47); case 47: columnRenderer = columns[colIndex + j].column.renderer; if (columnRenderer) { columnRenderer({ record: record, text: text, value: text, name: fieldName, dataSet: _this3.dataSet }); }