UNPKG

vxe-table-select-area

Version:

一个基于 vxe-table 的可区域选中复制、粘贴的组件

1,351 lines (1,335 loc) 80.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _vue = require("vue"); var _xeUtils = _interopRequireDefault(require("xe-utils")); var _mouseEvent = require("../utils/mouse-event"); var _scrollBar = require("../utils/scroll-bar"); var _index = require("../utils/index"); var _constant = require("../utils/constant"); var _common = require("../common"); var _clipboard = require("../common/clipboard"); var _constant2 = require("../common/constant"); var _eventKeyCodes = require("../utils/event-key-codes"); var _methods; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable no-unreachable */ /* eslint-disable brace-style */ // import Vue from 'vue' // const { render } = require('nprogress') // const vm = new Vue() // console.log(vm.$createElement); // console.log(createElement) // const h = vm.$createElement // const h = createElement var _default = { name: 'VxeSelection', data: function data() { return { currentCellEl: null, isBodyCellMousedown: false, cellSelectionData: { currentCell: { rowKey: '', colKey: '', rowIndex: -1 }, normalEndCell: { rowKey: '', colKey: '', rowIndex: -1 }, autoFillEndCell: { rowKey: '', colKey: '' } }, cellSelectionRangeData: { leftColKey: '', rightColKey: '', topRowKey: '', bottomRowKey: '' }, // body indicator rowKeys bodyIndicatorRowKeys: { startRowKey: '', startRowKeyIndex: -1, endRowKey: '', endRowKeyIndex: -1 }, tableContainerRef: '$el', tableContentWrapperRef: 'tableBody', colgroups: [], cellSelectionRect: { // current cell element rect currentCellRect: { left: 0, top: 0, width: 0, height: 0 }, // normal end cell element rect normalEndCellRect: { left: 0, top: 0, width: 0, height: 0 }, // auto fill end cell element rect autoFillEndCellRect: { left: 0, top: 0, width: 0, height: 0 } }, domRect: {}, currentCellSelectionType: '', isAutofillStarting: false, isColumnResizing: false, enableStopEditing: true }; }, computed: { // return row keys allRowKeys: function allRowKeys() { var result = []; var keyField = this.rowOpts.keyField; this.rowKeyFieldName = keyField; var tableData = this.tableData, rowKeyFieldName = this.rowKeyFieldName; if (rowKeyFieldName) { result = tableData.map(function (x) { return x[rowKeyFieldName]; }); } // // console.log(480,tableData,rowKeyFieldName,result) return result; }, /* enable cell selection 单元格编辑、剪贴板都依赖单元格选择 */ enableCellSelection: function enableCellSelection() { var result = true; var cellSelectionOption = this.cellSelectionOption, rowKeyFieldName = this.rowKeyFieldName; if ((0, _index.isEmptyValue)(rowKeyFieldName)) { result = false; } else if (cellSelectionOption && (0, _index.isBoolean)(cellSelectionOption.enable) && cellSelectionOption.enable === false) { result = false; } return result; }, // show corner showCorner: function showCorner() { var result = true; // this.cellAutofillOption = true var cellAutofillOption = this.cellAutofillOption; if (cellAutofillOption) { var _this$cellAutofillOpt = this.cellAutofillOption, directionX = _this$cellAutofillOpt.directionX, directionY = _this$cellAutofillOpt.directionY; if ((0, _index.isBoolean)(directionY) && !directionY && (0, _index.isBoolean)(directionX) && !directionX) { result = false; } } else { result = false; } // // console.log(163333,cellAutofillOption) return result; } }, watch: { tableColumn: { handler: function handler(newVal) { var _this = this; this.$nextTick(function () { // // console.log(105,newVal) _this.tableEl = _this.$refs[_this.tableContentWrapperRef].$refs.table; _this.tableColumn.forEach(function (e) { var obj = { field: e.field || e.id, edit: true, key: e.id, title: e.title || e.type, width: e.minWidth, _colspan: e.colSpan, _keys: e.id, _level: e.level, _realTimeWidth: e.renderWidth, _rowspan: e.rowSpan }; _this.colgroups.push(obj); }); }); }, immediate: false }, allRowKeys: { handler: function handler(newVal) { if (Array.isArray(newVal)) { var currentCell = this.cellSelectionData.currentCell; // 行被移除,清空单元格选中 if (currentCell.rowIndex > -1) { if (newVal.indexOf(currentCell.rowKey) === -1) { this.clearCellSelectionCurrentCell(); } } } }, immediate: false }, 'cellSelectionData.currentCell': { handler: function handler(val) { this.setCurrentCellSelectionType(); var rowKey = val.rowKey, colKey = val.colKey; if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { // // console.log(138) this.setCurrentCellEl(); this.setSelectionPositions({ type: 'currentCell' }); } else { this[_constant2.INSTANCE_METHODS.CLEAR_CURRENT_CELL_RECT](); } this.setCellSelectionRangeData(); }, deep: true, immediate: true }, 'cellSelectionData.normalEndCell': { handler: function handler(val) { this.setCurrentCellSelectionType(); var rowKey = val.rowKey, colKey = val.colKey; if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { // set normal end cell el this.setNormalEndCellEl(); this.setSelectionPositions({ type: 'normalEndCell' }); } else { this[_constant2.INSTANCE_METHODS.CLEAR_NORMAL_END_CELL_RECT](); } this.setCellSelectionRangeData(); }, deep: true, immediate: true }, 'cellSelectionData.autoFillEndCell': { handler: function handler(val) { var rowKey = val.rowKey, colKey = val.colKey; if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { this.setAutofillEndCellEl(); this.setSelectionPositions({ type: 'autoFillEndCell' }); } else { this.clearAutofillEndCellRect(); } }, deep: true, immediate: true }, isAutofillStarting: { handler: function handler(val) { if (!val) { this.setCellSelectionByAutofill(); this.clearCellSelectionAutofillEndCell(); } } } }, methods: (_methods = { setCurrentCellSelectionType: function setCurrentCellSelectionType() { var _this$cellSelectionDa = this.cellSelectionData, currentCell = _this$cellSelectionDa.currentCell, normalEndCell = _this$cellSelectionDa.normalEndCell; var result; if ((0, _index.isEmptyValue)(currentCell.rowKey) || (0, _index.isEmptyValue)(currentCell.colKey)) { result = ''; } else { if (!(0, _index.isEmptyValue)(normalEndCell.rowKey) && !(0, _index.isEmptyValue)(normalEndCell.colKey)) { result = _constant2.CURRENT_CELL_SELECTION_TYPES.RANGE; } else { result = _constant2.CURRENT_CELL_SELECTION_TYPES.SINGLE; } } // // console.log(261,result) this.currentCellSelectionType = result; }, resetCellPositions: function resetCellPositions() { // // // console.log(350) var _this$cellSelectionDa2 = this.cellSelectionData, currentCell = _this$cellSelectionDa2.currentCell, normalEndCell = _this$cellSelectionDa2.normalEndCell; if (!(0, _index.isEmptyValue)(currentCell.rowKey) && !(0, _index.isEmptyValue)(currentCell.colKey)) { this.setSelectionPositions({ type: 'currentCell' }); } if (!(0, _index.isEmptyValue)(normalEndCell.rowKey) && !(0, _index.isEmptyValue)(normalEndCell.colKey)) { this.setSelectionPositions({ type: 'normalEndCell' }); } }, cellSelectionRangeDataChange: function cellSelectionRangeDataChange(newData) { this.cellSelectionRangeData = Object.assign(this.cellSelectionRangeData, newData); }, cellSelectionCornerMousedown: function cellSelectionCornerMousedown(_ref) { var event = _ref.event; this.isAutofillStarting = true; }, autofillingDirectionChange: function autofillingDirectionChange(direction) { this.autofillingDirection = direction; }, cellSelectionCornerMouseup: function cellSelectionCornerMouseup(_ref2) { var event = _ref2.event; this.isAutofillStarting = false; }, handleCellAreaEvent: function handleCellAreaEvent(evnt, params) { // // // console.log(17,evnt,params) var shiftKey = evnt.shiftKey; var row = params.row, column = params.column; var rowData = row; var getRowid = this.getRowid, cellSelectionData = this.cellSelectionData, cellSelectionRangeData = this.cellSelectionRangeData, colgroups = this.colgroups, allRowKeys = this.allRowKeys; var rowKey = getRowid(rowData); var colKey = column.id; // // console.log(24,this,rowKey) var currentCell = cellSelectionData.currentCell; var mouseEventClickType = (0, _mouseEvent.getMouseEventClickType)(evnt); // // console.log(47,mouseEventClickType) this.isBodyCellMousedown = true; var isClearByRightClick = (0, _common.isClearSelectionByBodyCellRightClick)({ mouseEventClickType: mouseEventClickType, cellData: { rowKey: rowKey, colKey: colKey }, cellSelectionData: cellSelectionData, cellSelectionRangeData: cellSelectionRangeData, colgroups: colgroups, allRowKeys: allRowKeys }); // // // console.log(70,cellSelectionData,cellSelectionRangeData,colgroups,allRowKeys) // const isClearByRightClick = true if (isClearByRightClick) { // clear header indicator colKeys // this.clearHeaderIndicatorColKeys(); // clear body indicator colKeys this.clearBodyIndicatorRowKeys(); if (shiftKey && currentCell.rowIndex > -1) { this.cellSelectionNormalEndCellChange({ rowKey: rowKey, colKey: colKey }); } else { // cell selection by click this.cellSelectionByClick({ rowData: rowData, column: column }); this.clearCellSelectionNormalEndCell(); } } }, // table click outside tableClickOutside: function tableClickOutside(e) { // exclude contextmenu panel clicked if ((0, _common.isContextmenuPanelClicked)(e)) { return false; } this.isHeaderCellMousedown = false; this.isBodyCellMousedown = false; this.isBodyOperationColumnMousedown = false; this.isAutofillStarting = false; this.setIsColumnResizing(false); // clear cell selection this.clearCellSelectionCurrentCell(); this.clearCellSelectionNormalEndCell(); // clear indicators // this.clearHeaderIndicatorColKeys(); this.clearBodyIndicatorRowKeys(); // stop editing cell // this[INSTANCE_METHODS.STOP_EDITING_CELL](); }, // clear header indicator colKeys clearHeaderIndicatorColKeys: function clearHeaderIndicatorColKeys() { this.headerIndicatorColKeys.startColKey = ''; this.headerIndicatorColKeys.startColKeyIndex = -1; this.headerIndicatorColKeys.endColKey = ''; this.headerIndicatorColKeys.endColKeyIndex = -1; }, clearCellSelectionCurrentCell: function clearCellSelectionCurrentCell() { this.cellSelectionCurrentCellChange({ rowKey: '', colKey: '', rowIndex: -1 }); }, setIsColumnResizing: function setIsColumnResizing(val) { this.isColumnResizing = val; }, setCellSelectionRangeData: function setCellSelectionRangeData() { var currentCellSelectionType = this.currentCellSelectionType; var _this$cellSelectionDa3 = this.cellSelectionData, currentCell = _this$cellSelectionDa3.currentCell, normalEndCell = _this$cellSelectionDa3.normalEndCell; var result = {}; if (currentCellSelectionType === _constant2.CURRENT_CELL_SELECTION_TYPES.SINGLE) { result = { leftColKey: currentCell.colKey, rightColKey: currentCell.colKey, topRowKey: currentCell.rowKey, bottomRowKey: currentCell.rowKey }; } else if (currentCellSelectionType === _constant2.CURRENT_CELL_SELECTION_TYPES.RANGE) { var leftmostColKey = (0, _common.getLeftmostColKey)({ colgroups: this.colgroups, colKeys: [currentCell.colKey, normalEndCell.colKey] }); /* current cell col key is leftmost colKey 需要用 colKey 的位置进行判断,不能根据当前单元格 left 值判断(固定列时) */ if (leftmostColKey === currentCell.colKey) { result.leftColKey = currentCell.colKey; result.rightColKey = normalEndCell.colKey; } else { result.leftColKey = normalEndCell.colKey; result.rightColKey = currentCell.colKey; } if (currentCell.rowIndex < normalEndCell.rowIndex) { result.topRowKey = currentCell.rowKey; result.bottomRowKey = normalEndCell.rowKey; } else { result.topRowKey = normalEndCell.rowKey; result.bottomRowKey = currentCell.rowKey; } } else { // clear result = { leftColKey: '', rightColKey: '', topRowKey: '', bottomRowKey: '' }; } // // console.log(3888888,result) this.$emit(_constant2.EMIT_EVENTS.CELL_SELECTION_RANGE_DATA_CHANGE, result); }, // cell selection by click cellSelectionByClick: function cellSelectionByClick(_ref3) { var rowData = _ref3.rowData, column = _ref3.column; // const { rowKeyFieldName } = this; var getRowid = this.getRowid; // const rowKey = getRowKey(rowData, rowKeyFieldName); var rowKey = getRowid(rowData); // set cell selection and column to visible this[_constant2.INSTANCE_METHODS.SET_CELL_SELECTION]({ rowKey: rowKey, colKey: column.id, isScrollToRow: false }); // row to visible this.rowToVisible(_constant.KEY_CODES.ARROW_UP, rowKey); this.rowToVisible(_constant.KEY_CODES.ARROW_DOWN, rowKey); }, // cell selection end cell change // cellSelectionNormalEndCellChange({ rowKey, colKey }) { // this.cellSelectionData.normalEndCell.colKey = colKey; // this.cellSelectionData.normalEndCell.rowKey = rowKey; // this.cellSelectionData.normalEndCell.rowIndex = // this.allRowKeys.indexOf(rowKey); // }, setAutofillEndCellEl: function setAutofillEndCellEl() { var cellSelectionData = this.cellSelectionData, tableEl = this.tableEl; var _cellSelectionData$au = cellSelectionData.autoFillEndCell, rowKey = _cellSelectionData$au.rowKey, colKey = _cellSelectionData$au.colKey; if (tableEl) { var autoFillEndCellEl = tableEl.querySelector("tbody tr[rowid=\"".concat(rowKey, "\"] td[colid=\"").concat(colKey, "\"]")); if (autoFillEndCellEl) { this.autoFillEndCellEl = autoFillEndCellEl; } } } }, _defineProperty(_methods, _constant2.INSTANCE_METHODS.SET_CELL_SELECTION, function (_ref4) { var rowKey = _ref4.rowKey, colKey = _ref4.colKey, _ref4$isScrollToRow = _ref4.isScrollToRow, isScrollToRow = _ref4$isScrollToRow === void 0 ? true : _ref4$isScrollToRow; var enableCellSelection = this.enableCellSelection; // // console.log(165,this) // if (!enableCellSelection) { // return false; // } if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { // // console.log(171) this.cellSelectionCurrentCellChange({ rowKey: rowKey, colKey: colKey }); var column = (0, _common.getColumnByColkey)(colKey, this.colgroups); // // console.log(219,this.colgroups,column) // column to visible // this.columnToVisible(column); // row to visible if (isScrollToRow) { this[_constant2.INSTANCE_METHODS.SCROLL_TO_ROW_KEY]({ rowKey: rowKey }); } } }), _defineProperty(_methods, _constant2.INSTANCE_METHODS.SCROLL_TO_ROW_KEY, function (_ref5) { var rowKey = _ref5.rowKey; // // console.log('550滚动') if ((0, _index.isEmptyValue)(rowKey)) { // console.warn("Row key can't be empty!"); return false; } var scrollTop = 0; var isVirtualScroll = this.isVirtualScroll, headerTotalHeight = this.headerTotalHeight; var tableContainerRef = this.$refs[this.tableContainerRef]; if (isVirtualScroll) { var position = this.virtualScrollPositions.find(function (x) { return x.rowKey === rowKey; }); if (position) { scrollTop = position.top; } // fix bug #470 setTimeout(function () { scrollTo(tableContainerRef, { top: scrollTop, behavior: 'auto' }); }, 200); } else { var rowEl = this.$el.querySelector("tbody tr[".concat(_constant2.COMPS_CUSTOM_ATTRS.BODY_ROW_KEY, "=\"").concat(rowKey, "\"]")); scrollTop = rowEl.offsetTop - headerTotalHeight; } scrollTo(tableContainerRef, { top: scrollTop, behavior: isVirtualScroll ? 'auto' : 'smooth' }); }), _defineProperty(_methods, _constant2.INSTANCE_METHODS.CLEAR_CURRENT_CELL_RECT, function () { this.currentCellEl = null; this.cellSelectionRect.currentCellRect = { left: 0, top: 0, width: 0, height: 0 }; }), _defineProperty(_methods, "rowToVisible", function rowToVisible(keyCode, nextRowKey) { // const tableContainerRef = this.$refs[this.tableContainerRef]; var tableContainerRef = this[this.tableContainerRef]; var tableContentWrapperRef = this.$refs[this.tableContentWrapperRef].$refs.table; var isVirtualScroll = this.isVirtualScroll, headerTotalHeight = this.headerTotalHeight, footerTotalHeight = this.footerTotalHeight; var containerClientHeight = tableContainerRef.clientHeight, containerScrollTop = tableContainerRef.scrollTop; var nextRowEl = this.$el.querySelector("tbody tr[".concat(_constant2.COMPS_CUSTOM_ATTRS.BODY_ROW_KEY, "=\"").concat(nextRowKey, "\"]")); // // console.log(208,nextRowEl) if (nextRowEl) { var trOffsetTop = nextRowEl.offsetTop, trClientHeight = nextRowEl.clientHeight; var parentOffsetTop = tableContentWrapperRef.offsetTop; // arrow up if (keyCode === _constant.KEY_CODES.ARROW_UP) { var diff = 0; if (isVirtualScroll) { diff = headerTotalHeight - (trOffsetTop - (containerScrollTop - parentOffsetTop)); } else { diff = containerScrollTop + headerTotalHeight - trOffsetTop; } if (diff > 0) { tableContainerRef.scrollTop = containerScrollTop - diff; } } // arrow down else if (keyCode === _constant.KEY_CODES.ARROW_DOWN) { // console.log(652) var _diff = 0; if (isVirtualScroll) { _diff = trOffsetTop - (containerScrollTop - parentOffsetTop) + trClientHeight + footerTotalHeight - containerClientHeight; } else { _diff = trOffsetTop + trClientHeight + footerTotalHeight - (containerClientHeight + containerScrollTop); } if (_diff >= 0) { tableContainerRef.scrollTop = containerScrollTop + _diff; } } var currentCell = this.cellSelectionData.currentCell; // // console.log(258,currentCell) this.cellSelectionCurrentCellChange({ rowKey: nextRowKey, colKey: currentCell.colKey }); } }), _defineProperty(_methods, "cellSelectionCurrentCellChange", function cellSelectionCurrentCellChange(_ref6) { var rowKey = _ref6.rowKey, colKey = _ref6.colKey; // // console.log(266,this.cellSelectionData) this.cellSelectionData.currentCell.colKey = colKey; this.cellSelectionData.currentCell.rowKey = rowKey; this.cellSelectionData.currentCell.rowIndex = this.allRowKeys.indexOf(rowKey); }), _defineProperty(_methods, "clearCellSelectionNormalEndCell", function clearCellSelectionNormalEndCell() { this.cellSelectionNormalEndCellChange({ rowKey: '', colKey: '', rowIndex: -1 }); }), _defineProperty(_methods, "cellSelectionNormalEndCellChange", function cellSelectionNormalEndCellChange(_ref7) { var rowKey = _ref7.rowKey, colKey = _ref7.colKey; this.cellSelectionData.normalEndCell.colKey = colKey; this.cellSelectionData.normalEndCell.rowKey = rowKey; this.cellSelectionData.normalEndCell.rowIndex = this.allRowKeys.indexOf(rowKey); }), _defineProperty(_methods, "cellSelectionAutofillCellChange", function cellSelectionAutofillCellChange(_ref8) { var rowKey = _ref8.rowKey, colKey = _ref8.colKey; this.cellSelectionData.autoFillEndCell.colKey = colKey; this.cellSelectionData.autoFillEndCell.rowKey = rowKey; }), _defineProperty(_methods, "clearBodyIndicatorRowKeys", function clearBodyIndicatorRowKeys() { this.bodyIndicatorRowKeys.startRowKey = ''; this.bodyIndicatorRowKeys.startRowKeyIndex = -1; this.bodyIndicatorRowKeys.endRowKey = ''; this.bodyIndicatorRowKeys.endRowKeyIndex = -1; }), _defineProperty(_methods, "setCurrentCellEl", function setCurrentCellEl() { var cellSelectionData = this.cellSelectionData; var _cellSelectionData$cu = cellSelectionData.currentCell, rowKey = _cellSelectionData$cu.rowKey, colKey = _cellSelectionData$cu.colKey; if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { var cellEl = this.getTableCellEl({ rowKey: rowKey, colKey: colKey }); if (cellEl) { this.currentCellEl = cellEl; } // // console.log(448,cellEl) } }), _defineProperty(_methods, "setNormalEndCellEl", function setNormalEndCellEl() { var cellSelectionData = this.cellSelectionData; var _cellSelectionData$no = cellSelectionData.normalEndCell, rowKey = _cellSelectionData$no.rowKey, colKey = _cellSelectionData$no.colKey; if (!(0, _index.isEmptyValue)(rowKey) && !(0, _index.isEmptyValue)(colKey)) { var cellEl = this.getTableCellEl({ rowKey: rowKey, colKey: colKey }); if (cellEl) { this.normalEndCellEl = cellEl; } } }), _defineProperty(_methods, "setSelectionPositions", function setSelectionPositions(_ref9) { var type = _ref9.type; var allRowKeys = this.allRowKeys, tableEl = this.tableEl, currentCellEl = this.currentCellEl, normalEndCellEl = this.normalEndCellEl, autoFillEndCellEl = this.autoFillEndCellEl, cellSelectionData = this.cellSelectionData, virtualScrollVisibleIndexs = this.virtualScrollVisibleIndexs; // table empty if (allRowKeys.length === 0) { return false; } if (!tableEl) { return false; } var _tableEl$getBoundingC = tableEl.getBoundingClientRect(), tableLeft = _tableEl$getBoundingC.left, tableTop = _tableEl$getBoundingC.top; var isCurrentCellOverflow = false; var isNormalEndCellOverflow = false; // set current cell position if (type === 'currentCell') { isCurrentCellOverflow = true; if (currentCellEl) { var rect = this.getCellPosition({ cellEl: currentCellEl, tableLeft: tableLeft, tableTop: tableTop }); this.domRect = rect; if (rect) { isCurrentCellOverflow = false; this.cellSelectionRect.currentCellRect = rect; } } } // set nromal end cell position` if (type === 'normalEndCell') { isNormalEndCellOverflow = true; if (normalEndCellEl) { var _rect = this.getCellPosition({ cellEl: normalEndCellEl, tableLeft: tableLeft, tableTop: tableTop }); // // console.log('区域>>>',this.cellSelectionRect,rect) if (_rect) { isNormalEndCellOverflow = false; this.cellSelectionRect.normalEndCellRect = _rect; } } } // current cell overflow or normal end cell overflow && is virtual scroll if ((isCurrentCellOverflow || isNormalEndCellOverflow) && this.isVirtualScroll) { var currentCell = cellSelectionData.currentCell, normalEndCell = cellSelectionData.normalEndCell; // 弥补的 var mackUpColKey; var mackUpRowIndex; if (isCurrentCellOverflow) { mackUpColKey = currentCell.colKey; mackUpRowIndex = currentCell.rowIndex; } else { mackUpColKey = normalEndCell.colKey; mackUpRowIndex = normalEndCell.rowIndex; } var mackUpRect; /* 当没有 currentCellRect 或 normalCellRect 时 进行纠正,否则只更新top值 */ if (isCurrentCellOverflow && !this.cellSelectionRect.currentCellRect.height || isNormalEndCellOverflow && !this.cellSelectionRect.normalEndCellRect.height) { var mackUpRectParams = { tableLeft: tableLeft, tableTop: tableTop, colKey: mackUpColKey }; // 上方超出 if (mackUpRowIndex < virtualScrollVisibleIndexs.start) { mackUpRect = this.getCellPositionByColKey(_objectSpread(_objectSpread({}, mackUpRectParams), {}, { isFirstRow: true })); } // 下方超出 else if (mackUpRowIndex > virtualScrollVisibleIndexs.end) { mackUpRect = this.getCellPositionByColKey(_objectSpread(_objectSpread({}, mackUpRectParams), {}, { isLastRow: true })); } } // 仅更新 top 值 else { // 上方超出 if (mackUpRowIndex < virtualScrollVisibleIndexs.start) { mackUpRect = { top: 0 }; } // 下方超出 else if (mackUpRowIndex > virtualScrollVisibleIndexs.end) { mackUpRect = { top: tableEl.clientHeight }; } } if (isCurrentCellOverflow) { Object.assign(this.cellSelectionRect.currentCellRect, mackUpRect); } else { Object.assign(this.cellSelectionRect.normalEndCellRect, mackUpRect); } } if (autoFillEndCellEl && type === 'autoFillEndCell') { var _rect2 = this.getCellPosition({ cellEl: autoFillEndCellEl, tableLeft: tableLeft, tableTop: tableTop }); if (_rect2) { this.cellSelectionRect.autoFillEndCellRect = _rect2; } } }), _defineProperty(_methods, "getCellPosition", function getCellPosition(_ref10) { var cellEl = _ref10.cellEl, tableLeft = _ref10.tableLeft, tableTop = _ref10.tableTop; // // console.log('点击单元格',cellEl,tableLeft,tableTop) // if (!this.selectionBordersVisibility) { // return false; // } var _cellEl$getBoundingCl = cellEl.getBoundingClientRect(), cellLeft = _cellEl$getBoundingCl.left, cellTop = _cellEl$getBoundingCl.top, cellHeight = _cellEl$getBoundingCl.height, cellWidth = _cellEl$getBoundingCl.width; // // console.log(605,cellEl.getBoundingClientRect(),this) if (cellHeight && cellWidth) { return { left: cellLeft - tableLeft, top: cellTop - tableTop, width: cellWidth, height: cellHeight }; } }), _defineProperty(_methods, "getTableCellEl", function getTableCellEl(_ref11) { var rowKey = _ref11.rowKey, colKey = _ref11.colKey; var result = null; // const { tableEl } = this; var tableEl = this.$refs[this.tableContentWrapperRef].$refs.table; // // console.log(566,tableEl) if (tableEl) { result = tableEl.querySelector("tbody tr[rowid=\"".concat(rowKey, "\"] td[colid=\"").concat(colKey, "\"]")); } return result; }), _defineProperty(_methods, "getSelectionCurrent", function getSelectionCurrent(_ref12) { var fixedType = _ref12.fixedType; var result = { selectionCurrent: null, autoFillArea: null }; var cellSelectionRect = this.cellSelectionRect, colgroups = this.colgroups, cellSelectionData = this.cellSelectionData; var currentCellRect = cellSelectionRect.currentCellRect, normalEndCellRect = cellSelectionRect.normalEndCellRect; if (!currentCellRect.width) { return result; } var borders = { borderWidth: currentCellRect.width + 1, borderHeight: currentCellRect.height, topBorder: { show: true, width: 0, height: 2, top: currentCellRect.top - 1, left: currentCellRect.left - 1 }, rightBorder: { show: true, width: 2, height: 0, top: currentCellRect.top, left: currentCellRect.left + currentCellRect.width - 2 }, bottomBorder: { show: true, width: 0, height: 2, top: currentCellRect.top + currentCellRect.height - 2, left: currentCellRect.left - 1 }, leftBorder: { show: true, width: 2, height: 0, top: currentCellRect.top, left: currentCellRect.left - 1 }, corner: { show: !normalEndCellRect.width, top: 0, left: 0 } }; borders.corner.top = borders.bottomBorder.top - 3; borders.corner.left = borders.rightBorder.left - 3; // cell selection single autofill if (!normalEndCellRect.width) { result.autoFillArea = this.getSelectionAutofillArea({ areaPostions: borders, fixedType: fixedType }); } var totalColKeys = [cellSelectionData.currentCell.colKey]; var fixedColKeys = (0, _common.getColKeysByFixedTypeWithinColKeys)({ colKeys: totalColKeys, fixedType: fixedType, colgroups: colgroups }); result.selectionCurrent = this.getBorders(_objectSpread(_objectSpread({}, borders), {}, { showCorner: !normalEndCellRect.width, className: 'selection-current', fixedType: fixedType, totalColKeys: totalColKeys, fixedColKeys: fixedColKeys })); // // console.log(727,result.selectionCurrent) return result; }), _defineProperty(_methods, "getSelectionAutofillArea", function getSelectionAutofillArea(_ref13) { var areaPostions = _ref13.areaPostions, fixedType = _ref13.fixedType; var result = null; // // console.log(903) var cellAutofillOption = this.cellAutofillOption, cellSelectionRangeData = this.cellSelectionRangeData, cellSelectionRect = this.cellSelectionRect, cellSelectionData = this.cellSelectionData, isAutofillStarting = this.isAutofillStarting, currentCellSelectionType = this.currentCellSelectionType, colgroups = this.colgroups; if (!isAutofillStarting) { return result; } var currentCellRect = cellSelectionRect.currentCellRect, autoFillEndCellRect = cellSelectionRect.autoFillEndCellRect; if (!currentCellRect.width || !autoFillEndCellRect.width) { return result; } if (!areaPostions) { return result; } var borders = { borderWidth: 0, borderHeight: 0, topBorder: { show: true, width: 0, height: 1, top: 0, left: 0 }, rightBorder: { show: true, width: 1, height: 0, top: 0, left: 0 }, bottomBorder: { show: true, width: 0, height: 1, top: 0, left: 0 }, leftBorder: { show: true, width: 1, height: 0, top: 0, left: 0 }, corner: { show: false, top: 0, left: 0 } }; var currentCell = cellSelectionData.currentCell, autoFillEndCell = cellSelectionData.autoFillEndCell; var leftColKey = cellSelectionRangeData.leftColKey, rightColKey = cellSelectionRangeData.rightColKey; if (currentCellSelectionType === _constant2.CURRENT_CELL_SELECTION_TYPES.SINGLE) { leftColKey = currentCell.colKey; rightColKey = currentCell.colKey; } var leftmostColKey; if (leftColKey !== autoFillEndCell.colKey) { leftmostColKey = (0, _common.getLeftmostColKey)({ colgroups: colgroups, colKeys: [leftColKey, autoFillEndCell.colKey] }); } var rightmostColKey; if (rightColKey !== autoFillEndCell.colKey) { rightmostColKey = (0, _common.getRightmostColKey)({ colgroups: colgroups, colKeys: [rightColKey, autoFillEndCell.colKey] }); } // autofilling direction var autofillingDirection; var rangeColKey1; var rangeColKey2; // auto fill end cell below if (autoFillEndCellRect.top > areaPostions.bottomBorder.top) { autofillingDirection = _constant2.AUTOFILLING_DIRECTION.DOWN; rangeColKey1 = leftColKey; rangeColKey2 = rightColKey; borders.topBorder.show = false; borders.borderWidth = areaPostions.borderWidth; borders.borderHeight = autoFillEndCellRect.top - areaPostions.bottomBorder.top + autoFillEndCellRect.height; borders.rightBorder.top = areaPostions.bottomBorder.top; borders.rightBorder.left = areaPostions.rightBorder.left; if (currentCellSelectionType === _constant2.CURRENT_CELL_SELECTION_TYPES.SINGLE) { borders.rightBorder.left++; } borders.leftBorder.top = areaPostions.bottomBorder.top; borders.leftBorder.left = areaPostions.leftBorder.left; borders.bottomBorder.top = autoFillEndCellRect.top + autoFillEndCellRect.height - 1; borders.bottomBorder.left = areaPostions.bottomBorder.left; } // end cell above else if (autoFillEndCellRect.top < areaPostions.topBorder.top) { autofillingDirection = _constant2.AUTOFILLING_DIRECTION.UP; rangeColKey1 = leftColKey; rangeColKey2 = rightColKey; borders.bottomBorder.show = false; borders.borderWidth = areaPostions.borderWidth; borders.borderHeight = areaPostions.topBorder.top - autoFillEndCellRect.top; borders.topBorder.top = autoFillEndCellRect.top - 1; borders.topBorder.left = areaPostions.topBorder.left; borders.rightBorder.top = autoFillEndCellRect.top; borders.rightBorder.left = areaPostions.rightBorder.left; if (currentCellSelectionType === _constant2.CURRENT_CELL_SELECTION_TYPES.SINGLE) { borders.rightBorder.left++; } borders.leftBorder.top = autoFillEndCellRect.top; borders.leftBorder.left = areaPostions.leftBorder.left; } // auto fill end cell right else if (rightmostColKey === autoFillEndCell.colKey && !(0, _index.isEmptyValue)(rightmostColKey)) { autofillingDirection = _constant2.AUTOFILLING_DIRECTION.RIGHT; rangeColKey1 = (0, _common.getNextColKey)({ colgroups: colgroups, currentColKey: rightColKey }); rangeColKey2 = autoFillEndCell.colKey; borders.leftBorder.show = false; borders.borderWidth = autoFillEndCellRect.left - areaPostions.rightBorder.left + autoFillEndCellRect.width + 1; borders.borderHeight = areaPostions.borderHeight; borders.topBorder.top = areaPostions.topBorder.top; borders.topBorder.left = areaPostions.rightBorder.left - 1; borders.rightBorder.top = areaPostions.topBorder.top; borders.rightBorder.left = autoFillEndCellRect.left + autoFillEndCellRect.width - 1; borders.bottomBorder.top = areaPostions.bottomBorder.top; borders.bottomBorder.left = areaPostions.rightBorder.left - 1; } // auto fill end cell left else if (leftmostColKey === autoFillEndCell.colKey && !(0, _index.isEmptyValue)(leftmostColKey)) { autofillingDirection = _constant2.AUTOFILLING_DIRECTION.LEFT; rangeColKey1 = (0, _common.getPreviewColKey)({ colgroups: colgroups, currentColKey: leftColKey }); rangeColKey2 = autoFillEndCell.colKey; borders.rightBorder.show = false; borders.borderWidth = areaPostions.leftBorder.left - autoFillEndCellRect.left + 1; borders.borderHeight = areaPostions.borderHeight; borders.topBorder.top = areaPostions.topBorder.top; borders.topBorder.left = autoFillEndCellRect.left; borders.rightBorder.left = areaPostions.topBorder.left; borders.bottomBorder.top = areaPostions.bottomBorder.top; borders.bottomBorder.left = autoFillEndCellRect.left; borders.leftBorder.top = areaPostions.topBorder.top; borders.leftBorder.left = autoFillEndCellRect.left; } else { return result; } var directionX = cellAutofillOption.directionX, directionY = cellAutofillOption.directionY; if ((0, _index.isBoolean)(directionX) && !directionX) { if (autofillingDirection === _constant2.AUTOFILLING_DIRECTION.LEFT || autofillingDirection === _constant2.AUTOFILLING_DIRECTION.RIGHT) { return false; } } if ((0, _index.isBoolean)(directionY) && !directionY) { if (autofillingDirection === _constant2.AUTOFILLING_DIRECTION.UP || autofillingDirection === _constant2.AUTOFILLING_DIRECTION.DOWN) { return false; } } var totalColKeys = (0, _common.getColKeysByRangeColKeys)({ colKey1: rangeColKey1, colKey2: rangeColKey2, colgroups: colgroups }); var fixedColKeys = (0, _common.getColKeysByFixedTypeWithinColKeys)({ colKeys: totalColKeys, fixedType: fixedType, colgroups: colgroups }); result = this.getBorders(_objectSpread(_objectSpread({ className: 'selection-autofill-area' }, borders), {}, { fixedType: fixedType, totalColKeys: totalColKeys, fixedColKeys: fixedColKeys })); if (result) { this.$emit(_constant2.EMIT_EVENTS.AUTOFILLING_DIRECTION_CHANGE, autofillingDirection); // this.dispatch( // COMPS_NAME.VE_TABLE, // EMIT_EVENTS.AUTOFILLING_DIRECTION_CHANGE, // autofillingDirection, // ); } // // console.log(1095,result) return result; }), _defineProperty(_methods, "cornerCellInfo", function cornerCellInfo() { var allRowKeys = this.allRowKeys, colgroups = this.colgroups, cellSelectionRangeData = this.cellSelectionRangeData; var rightColKey = cellSelectionRangeData.rightColKey, bottomRowKey = cellSelectionRangeData.bottomRowKey; var isLastColumn = false; if ((0, _common.isLastColumnByColKey)(rightColKey, colgroups)) { isLastColumn = true; } else { var index = colgroups.findIndex(function (x) { return x.key === rightColKey; }); // right col is right fixed and current col is not right fixed if (colgroups[index + 1].fixed === _constant2.COLUMN_FIXED_TYPE.RIGHT && colgroups[index].fixed !== _constant2.COLUMN_FIXED_TYPE.RIGHT) { isLastColumn = true; } } var isLastRow = false; if ((0, _common.isLastRowByRowKey)(bottomRowKey, allRowKeys)) { isLastRow = true; } return { isLastColumn: isLastColumn, isLastRow: isLastRow }; }), _defineProperty(_methods, "getBorders", function getBorders(_ref14) { var _this2 = this; var borderWidth = _ref14.borderWidth, borderHeight = _ref14.borderHeight, topBorder = _ref14.topBorder, rightBorder = _ref14.rightBorder, bottomBorder = _ref14.bottomBorder, leftBorder = _ref14.leftBorder, corner = _ref14.corner, className = _ref14.className, fixedType = _ref14.fixedType, totalColKeys = _ref14.totalColKeys, fixedColKeys = _ref14.fixedColKeys; var cornerCellInfo = this.cornerCellInfo, colgroups = this.colgroups, isFirstSelectionRow = this.isFirstSelectionRow, isFirstSelectionCol = this.isFirstSelectionCol, isFirstNotFixedSelectionCol = this.isFirstNotFixedSelectionCol, showCorner = this.showCorner; var scrollYStore = this.scrollYStore; var startIndex = scrollYStore.startIndex; var rowHeight = scrollYStore.rowHeight; var topSpaceHeight = Math.max(0, startIndex * rowHeight); var isRender = true; if (fixedType) { isRender = (0, _common.isExistGivenFixedColKey)({ fixedType: fixedType, colKeys: totalColKeys, colgroups: colgroups }); } // middle normal area else { isRender = (0, _common.isExistNotFixedColKey)({ colKeys: totalColKeys, colgroups: colgroups }); } if (!isRender) { return null; } // fixed columns total width var fixedColsTotalWidth = 0; if (fixedColKeys.length) { fixedColsTotalWidth = (0, _common.getTotalWidthByColKeys)({ colKeys: fixedColKeys, colgroups: colgroups }); } if (fixedType) { borderWidth = fixedColsTotalWidth; if (fixedType === _constant2.COLUMN_FIXED_TYPE.LEFT) { borderWidth += 1; } } if (fixedType === _constant2.COLUMN_FIXED_TYPE.LEFT) { if (totalColKeys.length !== fixedColKeys.length) { rightBorder.show = false; corner.show = false; } } if (fixedType === _constant2.COLUMN_FIXED_TYPE.RIGHT) { if (totalColKeys.length !== fixedColKeys.length) { leftBorder.show = false; } topBorder.left = rightBorder.left - borderWidth + 1; bottomBorder.left = rightBorder.left - borderWidth + 1; } // solved first row、first column、first not fixed column selection border hidden if (isFirstSelectionRow) { topBorder.top += 1; } if (isFirstSelectionCol) { leftBorder.left += 1; } if (isFirstNotFixedSelectionCol) { leftBorder.left += 1; } var cornerTop = corner.top; var cornerLeft = corner.left; var cornerBorderRightWidth = '1px'; var cornerBorderBottomtWidth = '1px'; if (cornerCellInfo.isLastRow) { cornerTop -= 3; cornerBorderBottomtWidth = '0px'; } if (cornerCellInfo.isLastColumn) { cornerLeft -= 3; cornerBorderRightWidth = '0px'; } if (!showCorner) { corner.show = false; } // corner props var cornerProps = { "class": (0, _common.clsName)('selection-corner'), style: { display: corner.show ? 'block' : 'none', top: topSpaceHeight ? cornerTop + topSpaceHeight + 'px' : cornerTop + 'px', left: cornerLeft + 'px', borderWidth: "1px ".concat(cornerBorderRightWidth, " ").concat(cornerBorderBottomtWidth, " 1px") }, on: { mousedown: function mousedown(e) { _this2.$emit(_constant2.EMIT_EVENTS.SELECTION_CORNER_MOUSEDOWN, { event: e }); // this.dispatch( // 'VxeSelecteAreaDom', // EMIT_EVENTS.SELECTION_CORNER_MOUSEDOWN, // { // event: e, // }, // ); }, mouseup: function mouseup(e) { _this2.$emit(_constant2.EMIT_EVENTS.SELECTION_CORNER_MOUSEUP, { event: e }); // this.dispatch( // 'VxeSelecteAreaDom', // EMIT_EVENTS.SELECTION_CORNER_MOUSEUP, // { // event: e, // }, // ); } } }; // // console.log(1169,topBorder,corner) return (0, _vue.h)('div', { "class": (0, _common.clsName)(className) }, [(0, _vue.h)('div', { "class": (0, _common.clsName)('selection-border'), style: { display: topBorder.show ? 'block' : 'none', width: borderWidth + 'px', height: topBorder.height + 'px', top: topSpaceHeight ? topBorder.top + topSpaceHeight + 'px' : topBorder.top + 'px', left: topBorder.left + 'px' } }), (0, _vue.h)('div', { "class": (0, _common.clsName)('selection-border'), style: { display: rightBorder.show ? 'block' : 'none', width: rightBorder.width + 'px', height: borderHeight + 'px', top: topSpaceHeight ? rightBorder.top + topSpaceHeight + 'px' : rightBorder.top + 'px', left: rightBorder.left + 'px' } }), (0, _vue.h)('div', { "class": (0, _common.clsName)('selection-border'), style: { display: bottomBorder.show ? 'block' : 'none', width: borderWidth + 'px', height: bottomBorder.height + 'px', top: topSpaceHeight ? bottomBorder.top + topSpaceHeight + 'px' : bottomBorder.top + 'px', left: bottomBorder.left + 'px' } }), (0, _vue.h)('div', { "class": (0, _common.clsName)('selection-border'), style: { display: leftBorder.show ? 'block' : 'none', width: leftBorder.width + 'px', height: borderHeight + 'px', top: topSpaceHeight ? leftBorder.top + topSpaceHeight + 'px' : leftBorder.top + 'px', left: leftBorder.left + 'px' } }), (0, _vue.h)('div', _objectSpread({}, cornerProps))]); }), _defineProperty(_methods, "getSelectionAreas", function getSelectionAreas(_ref15) { var fixedType = _ref15.fixedType; // // console.log('1234选中区域',fixedType) var result = { normalArea: null, autoFillArea: null }; var _this$cellSelectionDa4 = this.cellSelectionData, currentCell = _this$cellSelectionDa4.currentCell, normalEndCell = _this$cellSelectionDa4.normalEndCell; var cellSelectionRect = this.cellSelectionRect, cellSelectionRangeData = this.cellSelectionRangeData, colgroups = this.colgroups; var currentCellRect = cellSelectionRect.currentCellRect, normalEndCellRect = cellSelectionRect.normalEndCellRect; if (!currentCellRect.width || !normalEndCellRect.width) { // // console.log(1248,cellSelectionRect) return result; } var borders = { borderWidth: 0, borderHeight: 0, topBorder: { show: true, width: 0, height: 1, top: 0, left: 0 }, rightBorder: { show: true, width: 1, height: 0, top: 0, left: 0 }, bottomBorder: { show: true, width: 0, height: 1, top: 0, left: 0 }, leftBorder: { show: true, width: 1, height: 0, top: 0, left: 0 }, corner: { show: true, top: 0, left: 0 } }; var leftmostColKey = (0, _common.getLeftmostColKey)({ colgroups: this.colgroups, colKeys: [currentCell.colKey, normalEndCell.colKey] }); // end cell column key right if (leftmostColKey === currentCell.colKey) { borders.borderWidth = normalEndCellRect.left - currentCellRect.left + normalEndCellRect.width + 1; borders.topBorder.left = currentCellRect.left - 1; borders.bottomBorder.left = currentCellRect.left - 1; borders.leftBorder.left = curr