| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343 |
- "use strict";
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _xeUtils = _interopRequireDefault(require("xe-utils"));
- var _ui = require("../../../ui");
- var _utils = require("../../../ui/src/utils");
- var _util = require("../../src/util");
- var _dom = require("../../../ui/src/dom");
- var _log = require("../../../ui/src/log");
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- const {
- getConfig,
- renderer,
- getI18n
- } = _ui.VxeUI;
- const browseObj = _xeUtils.default.browse();
- function getEditColumnModel(row, column) {
- const {
- model,
- editRender
- } = column;
- if (editRender) {
- model.value = (0, _util.getCellValue)(row, column);
- model.update = false;
- }
- }
- function setEditColumnModel(row, column) {
- const {
- model,
- editRender
- } = column;
- if (editRender && model.update) {
- (0, _util.setCellValue)(row, column, model.value);
- model.update = false;
- model.value = null;
- }
- }
- function removeCellSelectedClass($xeTable) {
- const el = $xeTable.$refs.refElem;
- if (el) {
- const cell = el.querySelector('.col--selected');
- if (cell) {
- (0, _dom.removeClass)(cell, 'col--selected');
- }
- }
- }
- function syncActivedCell($xeTable) {
- const reactData = $xeTable;
- const {
- editStore,
- tableColumn
- } = reactData;
- const editOpts = $xeTable.computeEditOpts;
- const {
- actived
- } = editStore;
- const {
- row,
- column
- } = actived;
- if (row || column) {
- if (editOpts.mode === 'row') {
- tableColumn.forEach(column => setEditColumnModel(row, column));
- } else {
- setEditColumnModel(row, column);
- }
- }
- }
- function insertTreeRow($xeTable, newRecords, isAppend) {
- const internalData = $xeTable;
- const {
- tableFullTreeData,
- afterFullData,
- fullDataRowIdData,
- fullAllDataRowIdData
- } = internalData;
- const treeOpts = $xeTable.computeTreeOpts;
- const {
- rowField,
- parentField,
- mapChildrenField
- } = treeOpts;
- const childrenField = treeOpts.children || treeOpts.childrenField;
- const funcName = isAppend ? 'push' : 'unshift';
- newRecords.forEach(item => {
- const parentRowId = item[parentField];
- const rowid = (0, _util.getRowid)($xeTable, item);
- const matchObj = parentRowId ? _xeUtils.default.findTree(tableFullTreeData, item => parentRowId === item[rowField], {
- children: mapChildrenField
- }) : null;
- if (matchObj) {
- const {
- item: parentRow
- } = matchObj;
- const parentRest = fullAllDataRowIdData[(0, _util.getRowid)($xeTable, parentRow)];
- const parentLevel = parentRest ? parentRest.level : 0;
- let parentChilds = parentRow[childrenField];
- let mapChilds = parentRow[mapChildrenField];
- if (!_xeUtils.default.isArray(parentChilds)) {
- parentChilds = parentRow[childrenField] = [];
- }
- if (!_xeUtils.default.isArray(mapChilds)) {
- mapChilds = parentRow[childrenField] = [];
- }
- parentChilds[funcName](item);
- mapChilds[funcName](item);
- const rest = {
- row: item,
- rowid,
- seq: -1,
- index: -1,
- _index: -1,
- $index: -1,
- treeIndex: -1,
- _tIndex: -1,
- items: parentChilds,
- parent: parentRow,
- level: parentLevel + 1,
- height: 0,
- resizeHeight: 0,
- oTop: 0,
- expandHeight: 0
- };
- fullDataRowIdData[rowid] = rest;
- fullAllDataRowIdData[rowid] = rest;
- } else {
- if (parentRowId) {
- (0, _log.warnLog)('vxe.error.unableInsert');
- }
- afterFullData[funcName](item);
- tableFullTreeData[funcName](item);
- const rest = {
- row: item,
- rowid,
- seq: -1,
- index: -1,
- _index: -1,
- $index: -1,
- treeIndex: -1,
- _tIndex: -1,
- items: tableFullTreeData,
- parent: null,
- level: 0,
- height: 0,
- resizeHeight: 0,
- oTop: 0,
- expandHeight: 0
- };
- fullDataRowIdData[rowid] = rest;
- fullAllDataRowIdData[rowid] = rest;
- }
- });
- }
- // function insertGroupRow ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, newRecords: any[], isAppend: boolean) {
- // }
- function handleInsertRowAt($xeTable, records, targetRow, isInsertNextRow) {
- const props = $xeTable;
- const reactData = $xeTable;
- const internalData = $xeTable;
- const {
- treeConfig
- } = props;
- const {
- isRowGroupStatus
- } = reactData;
- const {
- tableFullTreeData,
- afterFullData,
- mergeBodyList,
- tableFullData,
- fullDataRowIdData,
- fullAllDataRowIdData,
- insertRowMaps,
- removeRowMaps
- } = internalData;
- const treeOpts = $xeTable.computeTreeOpts;
- const {
- transform,
- parentField,
- rowField,
- mapChildrenField
- } = treeOpts;
- const childrenField = treeOpts.children || treeOpts.childrenField;
- if (!_xeUtils.default.isArray(records)) {
- records = [records];
- }
- const newRecords = $xeTable.defineField(records.map(record => Object.assign(treeConfig && transform ? {
- [mapChildrenField]: [],
- [childrenField]: []
- } : {}, record)));
- let treeRecords = [];
- if (treeConfig && transform) {
- treeRecords = _xeUtils.default.toArrayTree(newRecords, {
- key: rowField,
- parentKey: parentField,
- children: childrenField
- });
- }
- if (_xeUtils.default.eqNull(targetRow)) {
- // 如果为虚拟树
- if (treeConfig && transform) {
- insertTreeRow($xeTable, newRecords, false);
- } else if (isRowGroupStatus) {
- // 如果分组
- if (treeConfig) {
- throw new Error(getI18n('vxe.error.noTree', ['insert']));
- }
- (0, _log.warnLog)(getI18n('vxe.error.noGroup', ['remove']));
- // insertGroupRow($xeTable, newRecords, false)
- } else {
- newRecords.forEach(item => {
- const rowid = (0, _util.getRowid)($xeTable, item);
- const rest = {
- row: item,
- rowid,
- seq: -1,
- index: -1,
- _index: -1,
- $index: -1,
- treeIndex: -1,
- _tIndex: -1,
- items: afterFullData,
- parent: null,
- level: 0,
- height: 0,
- resizeHeight: 0,
- oTop: 0,
- expandHeight: 0
- };
- fullDataRowIdData[rowid] = rest;
- fullAllDataRowIdData[rowid] = rest;
- afterFullData.unshift(item);
- tableFullData.unshift(item);
- });
- // 刷新单元格合并
- mergeBodyList.forEach(mergeItem => {
- const {
- row: mergeRowIndex
- } = mergeItem;
- if (mergeRowIndex >= 0) {
- mergeItem.row = mergeRowIndex + newRecords.length;
- }
- });
- }
- } else {
- if (targetRow === -1) {
- // 如果为虚拟树
- if (treeConfig && transform) {
- insertTreeRow($xeTable, newRecords, true);
- } else if (isRowGroupStatus) {
- // 如果分组
- if (treeConfig) {
- throw new Error(getI18n('vxe.error.noTree', ['insert']));
- }
- (0, _log.warnLog)(getI18n('vxe.error.noGroup', ['remove']));
- // insertGroupRow($xeTable, newRecords, true)
- } else {
- newRecords.forEach(item => {
- const rowid = (0, _util.getRowid)($xeTable, item);
- const rest = {
- row: item,
- rowid,
- seq: -1,
- index: -1,
- _index: -1,
- $index: -1,
- treeIndex: -1,
- _tIndex: -1,
- items: afterFullData,
- parent: null,
- level: 0,
- height: 0,
- resizeHeight: 0,
- oTop: 0,
- expandHeight: 0
- };
- fullDataRowIdData[rowid] = rest;
- fullAllDataRowIdData[rowid] = rest;
- afterFullData.push(item);
- tableFullData.push(item);
- });
- }
- } else {
- // 如果为虚拟树
- if (treeConfig && transform) {
- const matchMapObj = _xeUtils.default.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], {
- children: mapChildrenField
- });
- if (matchMapObj) {
- const {
- parent: parentRow
- } = matchMapObj;
- const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData;
- const parentRest = fullAllDataRowIdData[(0, _util.getRowid)($xeTable, parentRow)];
- const parentLevel = parentRest ? parentRest.level : 0;
- treeRecords.forEach((row, i) => {
- if (parentRow) {
- if (row[parentField] !== parentRow[rowField]) {
- row[parentField] = parentRow[rowField];
- (0, _log.errLog)('vxe.error.errProp', [`${parentField}=${row[parentField]}`, `${parentField}=${parentRow[rowField]}`]);
- }
- } else {
- if (row[parentField] !== null) {
- row[parentField] = null;
- (0, _log.errLog)('vxe.error.errProp', [`${parentField}=${row[parentField]}`, 'null']);
- }
- }
- let targetIndex = matchMapObj.index + i;
- if (isInsertNextRow) {
- targetIndex = targetIndex + 1;
- }
- parentMapChilds.splice(targetIndex, 0, row);
- });
- _xeUtils.default.eachTree(treeRecords, item => {
- const rowid = (0, _util.getRowid)($xeTable, item);
- const rest = {
- row: item,
- rowid,
- seq: -1,
- index: -1,
- _index: -1,
- $index: -1,
- treeIndex: -1,
- _tIndex: -1,
- items: parentMapChilds,
- parent: parentRow,
- level: parentLevel + 1,
- height: 0,
- resizeHeight: 0,
- oTop: 0,
- expandHeight: 0
- };
- if (item[childrenField]) {
- item[mapChildrenField] = item[childrenField];
- }
- fullDataRowIdData[rowid] = rest;
- fullAllDataRowIdData[rowid] = rest;
- }, {
- children: childrenField
- });
- // 源
- if (parentRow) {
- const matchObj = _xeUtils.default.findTree(tableFullTreeData, item => targetRow[rowField] === item[rowField], {
- children: childrenField
- });
- if (matchObj) {
- const parentChilds = matchObj.items;
- let targetIndex = matchObj.index;
- if (isInsertNextRow) {
- targetIndex = targetIndex + 1;
- }
- parentChilds.splice(targetIndex, 0, ...treeRecords);
- }
- }
- } else {
- (0, _log.warnLog)('vxe.error.unableInsert');
- insertTreeRow($xeTable, newRecords, true);
- }
- } else if (isRowGroupStatus) {
- // 如果分组
- if (treeConfig) {
- throw new Error(getI18n('vxe.error.noTree', ['insert']));
- }
- (0, _log.warnLog)(getI18n('vxe.error.noGroup', ['remove']));
- } else {
- if (treeConfig) {
- throw new Error(getI18n('vxe.error.noTree', ['insert']));
- }
- let afIndex = -1;
- // 如果是可视索引
- if (_xeUtils.default.isNumber(targetRow)) {
- if (targetRow < afterFullData.length) {
- afIndex = targetRow;
- }
- } else {
- afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow);
- }
- // 如果是插入指定行的下一行
- if (isInsertNextRow) {
- afIndex = Math.min(afterFullData.length, afIndex + 1);
- }
- if (afIndex === -1) {
- throw new Error(getI18n('vxe.error.unableInsert'));
- }
- afterFullData.splice(afIndex, 0, ...newRecords);
- const tfIndex = $xeTable.findRowIndexOf(tableFullData, targetRow);
- if (tfIndex > -1) {
- tableFullData.splice(tfIndex + (isInsertNextRow ? 1 : 0), 0, ...newRecords);
- } else {
- tableFullData.push(...newRecords);
- }
- // 刷新单元格合并
- mergeBodyList.forEach(mergeItem => {
- const {
- row: mergeRowIndex,
- rowspan: mergeRowspan
- } = mergeItem;
- if (mergeRowIndex >= afIndex) {
- mergeItem.row = mergeRowIndex + newRecords.length;
- } else if (isInsertNextRow ? mergeRowIndex + mergeRowspan >= afIndex : mergeRowIndex + mergeRowspan > afIndex) {
- mergeItem.rowspan = mergeRowspan + newRecords.length;
- }
- });
- }
- }
- }
- const handleStatus = newRow => {
- const rowid = (0, _util.getRowid)($xeTable, newRow);
- // 如果是被删除的数据,则还原状态
- if (removeRowMaps[rowid]) {
- delete removeRowMaps[rowid];
- if (insertRowMaps[rowid]) {
- delete insertRowMaps[rowid];
- }
- } else {
- insertRowMaps[rowid] = newRow;
- }
- };
- // 如果为虚拟树
- if (treeConfig && transform) {
- _xeUtils.default.eachTree(treeRecords, handleStatus, {
- children: mapChildrenField
- });
- } else {
- newRecords.forEach(handleStatus);
- }
- reactData.removeRowFlag++;
- reactData.insertRowFlag++;
- $xeTable.cacheRowMap(false);
- $xeTable.updateScrollYStatus();
- $xeTable.handleTableData(treeConfig && transform);
- if (!(treeConfig && transform)) {
- $xeTable.updateAfterDataIndex();
- }
- $xeTable.updateFooter();
- $xeTable.handleUpdateBodyMerge();
- $xeTable.checkSelectionStatus();
- if (reactData.scrollYLoad) {
- $xeTable.updateScrollYSpace();
- }
- return $xeTable.$nextTick().then(() => {
- $xeTable.updateCellAreas();
- return $xeTable.recalculate(true);
- }).then(() => {
- return {
- row: newRecords.length ? newRecords[newRecords.length - 1] : null,
- rows: newRecords
- };
- });
- }
- function handleInsertChildRowAt($xeTable, records, parentRow, targetRow, isInsertNextRow) {
- const props = $xeTable;
- const {
- treeConfig
- } = props;
- const treeOpts = $xeTable.computeTreeOpts;
- const {
- transform,
- rowField,
- parentField
- } = treeOpts;
- if (treeConfig && transform) {
- if (!_xeUtils.default.isArray(records)) {
- records = [records];
- }
- return handleInsertRowAt($xeTable, records.map(item => Object.assign({}, item, {
- [parentField]: parentRow[rowField]
- })), targetRow, isInsertNextRow);
- } else {
- (0, _log.errLog)('vxe.error.errProp', ['tree-config.transform=false', 'tree-config.transform=true']);
- }
- return Promise.resolve({
- row: null,
- rows: []
- });
- }
- function handleClearEdit($xeTable, evnt, targetRow) {
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- const {
- actived,
- focused
- } = editStore;
- const {
- row,
- column
- } = actived;
- const validOpts = $xeTable.computeValidOpts;
- if (row || column) {
- if (targetRow && (0, _util.getRowid)($xeTable, targetRow) !== (0, _util.getRowid)($xeTable, row)) {
- return $xeTable.$nextTick();
- }
- syncActivedCell($xeTable);
- actived.args = null;
- actived.row = null;
- actived.column = null;
- $xeTable.updateFooter();
- $xeTable.dispatchEvent('edit-closed', {
- row,
- rowIndex: $xeTable.getRowIndex(row),
- $rowIndex: $xeTable.getVMRowIndex(row),
- column,
- columnIndex: $xeTable.getColumnIndex(column),
- $columnIndex: $xeTable.getVMColumnIndex(column)
- }, evnt || null);
- }
- focused.row = null;
- focused.column = null;
- if (validOpts.autoClear) {
- if (validOpts.msgMode !== 'full' || getConfig().cellVaildMode === 'obsolete') {
- if ($xeTable.clearValidate) {
- return $xeTable.clearValidate();
- }
- }
- }
- return $xeTable.$nextTick().then(() => $xeTable.updateCellAreas());
- }
- function handleEditActive($xeTable, params, evnt, isFocus, isPos) {
- const props = $xeTable;
- const reactData = $xeTable;
- const $xeGrid = $xeTable.$xeGrid;
- const {
- editConfig,
- mouseConfig
- } = props;
- const {
- editStore,
- tableColumn
- } = reactData;
- const editOpts = $xeTable.computeEditOpts;
- const {
- mode
- } = editOpts;
- const {
- actived,
- focused
- } = editStore;
- const {
- row,
- column
- } = params;
- const {
- editRender
- } = column;
- const cell = params.cell || $xeTable.getCellElement(row, column);
- const beforeEditMethod = editOpts.beforeEditMethod || editOpts.activeMethod;
- params.cell = cell;
- if (cell && (0, _utils.isEnableConf)(editConfig) && (0, _utils.isEnableConf)(editRender)) {
- // 激活编辑
- if (!$xeTable.isPendingByRow(row) && !$xeTable.isAggregateRecord(row)) {
- if (actived.row !== row || (mode === 'cell' ? actived.column !== column : false)) {
- // 判断是否禁用编辑
- let type = 'edit-disabled';
- if (!beforeEditMethod || beforeEditMethod(Object.assign(Object.assign({}, params), {
- $table: $xeTable,
- $grid: $xeGrid
- }))) {
- if (mouseConfig) {
- $xeTable.clearSelected();
- if ($xeTable.clearCellAreas) {
- $xeTable.clearCellAreas();
- $xeTable.clearCopyCellArea();
- }
- }
- $xeTable.closeTooltip();
- if (actived.column) {
- handleClearEdit($xeTable, evnt);
- }
- type = 'edit-activated';
- column.renderHeight = cell.offsetHeight;
- actived.args = params;
- actived.row = row;
- actived.column = column;
- if (mode === 'row') {
- tableColumn.forEach(column => getEditColumnModel(row, column));
- } else {
- getEditColumnModel(row, column);
- }
- const afterEditMethod = editOpts.afterEditMethod;
- $xeTable.$nextTick(() => {
- if (isFocus) {
- $xeTable.handleFocus(params, evnt);
- }
- if (afterEditMethod) {
- afterEditMethod(Object.assign(Object.assign({}, params), {
- $table: $xeTable,
- $grid: $xeGrid
- }));
- }
- });
- }
- $xeTable.dispatchEvent(type, {
- row,
- rowIndex: $xeTable.getRowIndex(row),
- $rowIndex: $xeTable.getVMRowIndex(row),
- column,
- columnIndex: $xeTable.getColumnIndex(column),
- $columnIndex: $xeTable.getVMColumnIndex(column)
- }, evnt);
- // v4已废弃
- if (type === 'edit-activated') {
- $xeTable.dispatchEvent('edit-actived', {
- row,
- rowIndex: $xeTable.getRowIndex(row),
- $rowIndex: $xeTable.getVMRowIndex(row),
- column,
- columnIndex: $xeTable.getColumnIndex(column),
- $columnIndex: $xeTable.getVMColumnIndex(column)
- }, evnt);
- }
- } else {
- const {
- column: oldColumn
- } = actived;
- if (mouseConfig) {
- $xeTable.clearSelected();
- if ($xeTable.clearCellAreas) {
- $xeTable.clearCellAreas();
- $xeTable.clearCopyCellArea();
- }
- }
- if (oldColumn !== column) {
- const {
- model: oldModel
- } = oldColumn;
- if (oldModel.update) {
- (0, _util.setCellValue)(row, oldColumn, oldModel.value);
- }
- if ($xeTable.clearValidate) {
- $xeTable.clearValidate(row, column);
- }
- }
- column.renderHeight = cell.offsetHeight;
- actived.args = params;
- actived.column = column;
- if (isPos) {
- setTimeout(() => {
- $xeTable.handleFocus(params, evnt);
- });
- }
- }
- focused.column = null;
- focused.row = null;
- $xeTable.focus();
- }
- }
- return $xeTable.$nextTick();
- }
- function handleEditCell($xeTable, row, fieldOrColumn, isPos) {
- const props = $xeTable;
- const internalData = $xeTable;
- const {
- editConfig
- } = props;
- const column = _xeUtils.default.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn;
- if (row && column && (0, _utils.isEnableConf)(editConfig) && (0, _utils.isEnableConf)(column.editRender) && !$xeTable.isAggregateRecord(row)) {
- return Promise.resolve(isPos ? $xeTable.scrollToRow(row, column) : null).then(() => {
- const cell = $xeTable.getCellElement(row, column);
- if (cell) {
- handleEditActive($xeTable, {
- row,
- rowIndex: $xeTable.getRowIndex(row),
- column,
- columnIndex: $xeTable.getColumnIndex(column),
- cell,
- $table: $xeTable
- }, null, isPos, isPos);
- internalData._lastCallTime = Date.now();
- }
- return $xeTable.$nextTick();
- });
- }
- return $xeTable.$nextTick();
- }
- var _default = exports.default = {
- methods: {
- /**
- * 往表格中插入临时数据
- *
- * @param {*} records
- */
- _insert(records) {
- return handleInsertRowAt(this, records, null);
- },
- /**
- * 往表格指定行中插入临时数据
- * 如果 row 为空则从插入到顶部
- * 如果 row 为 -1 则从插入到底部
- * 如果 row 为有效行则插入到该行的位置
- * @param {Object/Array} records 新的数据
- * @param {Row} targetRow 指定行
- * @returns
- */
- _insertAt(records, targetRow) {
- return handleInsertRowAt(this, records, targetRow);
- },
- _insertNextAt(records, targetRow) {
- return handleInsertRowAt(this, records, targetRow, true);
- },
- _insertChild(records, parentRow) {
- return handleInsertChildRowAt(this, records, parentRow, null);
- },
- _insertChildAt(records, parentRow, targetRow) {
- return handleInsertChildRowAt(this, records, parentRow, targetRow);
- },
- _insertChildNextAt(records, parentRow, targetRow) {
- return handleInsertChildRowAt(this, records, parentRow, targetRow, true);
- },
- /**
- * 删除指定行数据
- * 如果传 row 则删除一行
- * 如果传 rows 则删除多行
- * 如果为空则删除所有
- */
- _remove(rows) {
- const $xeTable = this;
- const props = $xeTable;
- const reactData = $xeTable;
- const internalData = $xeTable;
- const {
- treeConfig
- } = props;
- const {
- editStore,
- isRowGroupStatus
- } = reactData;
- const {
- tableFullTreeData,
- selectCheckboxMaps,
- afterFullData,
- mergeBodyList,
- tableFullData,
- pendingRowMaps,
- insertRowMaps,
- removeRowMaps
- } = internalData;
- const checkboxOpts = $xeTable.computeCheckboxOpts;
- const treeOpts = $xeTable.computeTreeOpts;
- const {
- transform,
- mapChildrenField
- } = treeOpts;
- const childrenField = treeOpts.children || treeOpts.childrenField;
- const {
- actived
- } = editStore;
- const {
- checkField
- } = checkboxOpts;
- let delList = [];
- if (!rows) {
- rows = tableFullData;
- } else if (!_xeUtils.default.isArray(rows)) {
- rows = [rows];
- }
- // 如果是新增,则保存记录
- rows.forEach(row => {
- if (!$xeTable.isInsertByRow(row)) {
- const rowid = (0, _util.getRowid)($xeTable, row);
- removeRowMaps[rowid] = row;
- }
- });
- // 如果绑定了多选属性,则更新状态
- if (!checkField) {
- rows.forEach(row => {
- const rowid = (0, _util.getRowid)(this, row);
- if (selectCheckboxMaps[rowid]) {
- delete selectCheckboxMaps[rowid];
- }
- });
- reactData.updateCheckboxFlag++;
- }
- // 从数据源中移除
- if (tableFullData === rows) {
- rows = delList = tableFullData.slice(0);
- this.tableFullData = [];
- this.afterFullData = [];
- this.clearMergeCells();
- } else {
- // 如果为虚拟树
- if (treeConfig && transform) {
- rows.forEach(row => {
- const rowid = (0, _util.getRowid)(this, row);
- const matchMapObj = _xeUtils.default.findTree(tableFullTreeData, item => rowid === (0, _util.getRowid)(this, item), {
- children: mapChildrenField
- });
- if (matchMapObj) {
- const rItems = matchMapObj.items.splice(matchMapObj.index, 1);
- delList.push(rItems[0]);
- }
- const matchObj = _xeUtils.default.findTree(tableFullTreeData, item => rowid === (0, _util.getRowid)(this, item), {
- children: childrenField
- });
- if (matchObj) {
- matchObj.items.splice(matchObj.index, 1);
- }
- const afIndex = this.findRowIndexOf(afterFullData, row);
- if (afIndex > -1) {
- afterFullData.splice(afIndex, 1);
- }
- });
- } else if (isRowGroupStatus) {
- // 如果分组
- (0, _log.warnLog)(getI18n('vxe.error.noGroup', ['remove']));
- } else {
- rows.forEach(row => {
- const tfIndex = this.findRowIndexOf(tableFullData, row);
- if (tfIndex > -1) {
- const rItems = tableFullData.splice(tfIndex, 1);
- delList.push(rItems[0]);
- }
- const afIndex = this.findRowIndexOf(afterFullData, row);
- if (afIndex > -1) {
- // 刷新单元格合并
- mergeBodyList.forEach(mergeItem => {
- const {
- row: mergeRowIndex,
- rowspan: mergeRowspan
- } = mergeItem;
- if (mergeRowIndex > afIndex) {
- mergeItem.row = mergeRowIndex - 1;
- } else if (mergeRowIndex + mergeRowspan > afIndex) {
- mergeItem.rowspan = mergeRowspan - 1;
- }
- });
- afterFullData.splice(afIndex, 1);
- }
- });
- }
- }
- // 如果当前行被激活编辑,则清除激活状态
- if (actived.row && $xeTable.findRowIndexOf(rows, actived.row) > -1) {
- $xeTable.clearEdit();
- }
- // 从新增中移除已删除的数据
- rows.forEach(row => {
- const rowid = (0, _util.getRowid)($xeTable, row);
- if (insertRowMaps[rowid]) {
- delete insertRowMaps[rowid];
- }
- if (pendingRowMaps[rowid]) {
- delete pendingRowMaps[rowid];
- }
- });
- reactData.removeRowFlag++;
- reactData.insertRowFlag++;
- reactData.pendingRowFlag++;
- $xeTable.cacheRowMap(false);
- $xeTable.handleTableData(treeConfig && transform);
- $xeTable.updateFooter();
- $xeTable.handleUpdateBodyMerge();
- if (!(treeConfig && transform)) {
- $xeTable.updateAfterDataIndex();
- }
- $xeTable.checkSelectionStatus();
- if (reactData.scrollYLoad) {
- $xeTable.updateScrollYSpace();
- }
- return this.$nextTick().then(() => {
- this.updateCellAreas();
- return this.recalculate(true);
- }).then(() => {
- return {
- row: delList.length ? delList[delList.length - 1] : null,
- rows: delList
- };
- });
- },
- /**
- * 删除复选框选中的数据
- */
- _removeCheckboxRow() {
- return this.remove(this.getCheckboxRecords()).then(params => {
- this.clearCheckboxRow();
- return params;
- });
- },
- /**
- * 删除单选框选中的数据
- */
- _removeRadioRow() {
- const radioRecord = this.getRadioRecord();
- return this.remove(radioRecord || []).then(params => {
- this.clearRadioRow();
- return params;
- });
- },
- /**
- * 删除当前行选中的数据
- */
- _removeCurrentRow() {
- const currentRecord = this.getCurrentRecord();
- return this.remove(currentRecord || []).then(params => {
- this.clearCurrentRow();
- return params;
- });
- },
- /**
- * 获取表格数据集,包含新增、删除、修改
- */
- _getRecordset() {
- const removeRecords = this.getRemoveRecords();
- const pendingRecords = this.getPendingRecords();
- const delRecords = removeRecords.concat(pendingRecords);
- // 如果已经被删除,则无需放到更新数组
- const updateRecords = this.getUpdateRecords().filter(row => {
- return !delRecords.some(item => this.eqRow(item, row));
- });
- return {
- insertRecords: this.getInsertRecords(),
- removeRecords,
- updateRecords,
- pendingRecords
- };
- },
- /**
- * 获取新增的临时数据
- */
- _getInsertRecords() {
- const $xeTable = this;
- const internalData = $xeTable;
- const {
- fullAllDataRowIdData,
- insertRowMaps
- } = internalData;
- const insertRecords = [];
- _xeUtils.default.each(insertRowMaps, (row, rowid) => {
- if (fullAllDataRowIdData[rowid]) {
- insertRecords.push(row);
- }
- });
- return insertRecords;
- },
- /**
- * 获取已删除的数据
- */
- _getRemoveRecords() {
- const $xeTable = this;
- const internalData = $xeTable;
- const {
- removeRowMaps
- } = internalData;
- const removeRecords = [];
- _xeUtils.default.each(removeRowMaps, row => {
- removeRecords.push(row);
- });
- return removeRecords;
- },
- /**
- * 获取更新数据
- * 只精准匹配 row 的更改
- * 如果是树表格,子节点更改状态不会影响父节点的更新状态
- */
- _getUpdateRecords() {
- const $xeTable = this;
- const props = $xeTable;
- const internalData = $xeTable;
- const {
- keepSource,
- treeConfig
- } = props;
- const {
- tableFullData
- } = internalData;
- const treeOpts = $xeTable.computeTreeOpts;
- if (keepSource) {
- syncActivedCell($xeTable);
- if (treeConfig) {
- return _xeUtils.default.filterTree(tableFullData, row => $xeTable.isUpdateByRow(row), treeOpts);
- }
- return tableFullData.filter(row => $xeTable.isUpdateByRow(row));
- }
- return [];
- },
- /**
- * 处理激活编辑
- */
- handleEdit(params, evnt) {
- const $xeTable = this;
- return handleEditActive($xeTable, params, evnt, true, true);
- },
- /**
- * @deprecated
- */
- handleActived(params, evnt) {
- return this.handleEdit(params, evnt);
- },
- _getColumnModel(row, column) {
- getEditColumnModel(row, column);
- },
- _setColumnModel(row, column) {
- setEditColumnModel(row, column);
- },
- _syncActivedCell() {
- const $xeTable = this;
- syncActivedCell($xeTable);
- },
- _clearActived(row) {
- (0, _log.warnLog)('vxe.error.delFunc', ['clearActived', 'clearEdit']);
- // 即将废弃
- return this.clearEdit(row);
- },
- /**
- * 清除激活的编辑
- */
- _clearEdit(row) {
- const $xeTable = this;
- return handleClearEdit($xeTable, null, row);
- },
- /**
- * 取消编辑
- */
- handleClearEdit(evnt, targetRow) {
- const $xeTable = this;
- return handleClearEdit($xeTable, evnt, targetRow);
- },
- _getActiveRecord() {
- const $xeTable = this;
- const reactData = $xeTable;
- const internalData = $xeTable;
- (0, _log.warnLog)('vxe.error.delFunc', ['getActiveRecord', 'getEditCell']);
- const {
- editStore
- } = reactData;
- const {
- fullAllDataRowIdData
- } = internalData;
- const {
- args,
- row
- } = editStore.actived;
- if (args && row && fullAllDataRowIdData[(0, _util.getRowid)($xeTable, row)]) {
- return Object.assign({}, args, {
- row
- });
- }
- return null;
- },
- _getEditRecord() {
- const $xeTable = this;
- const reactData = $xeTable;
- const internalData = $xeTable;
- (0, _log.warnLog)('vxe.error.delFunc', ['getEditRecord', 'getEditCell']);
- const {
- editStore
- } = reactData;
- const {
- fullAllDataRowIdData
- } = internalData;
- const {
- args,
- row
- } = editStore.actived;
- if (args && row && fullAllDataRowIdData[(0, _util.getRowid)($xeTable, row)]) {
- return Object.assign({}, args, {
- row
- });
- }
- return null;
- },
- _getEditCell() {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- const {
- row,
- column
- } = editStore.actived;
- if (column && row) {
- return {
- row,
- rowIndex: $xeTable.getRowIndex(row),
- column,
- columnIndex: $xeTable.getColumnIndex(column)
- };
- }
- return null;
- },
- _isActiveByRow(row) {
- const $xeTable = this;
- (0, _log.warnLog)('vxe.error.delFunc', ['isActiveByRow', 'isEditByRow']);
- // 即将废弃
- return $xeTable.isEditByRow(row);
- },
- /**
- * 判断行是否为激活编辑状态
- * @param {Row} row 行对象
- */
- _isEditByRow(row) {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- return editStore.actived.row === row;
- },
- /**
- * 处理聚焦
- */
- handleFocus(params) {
- const $xeTable = this;
- const {
- row,
- column,
- cell
- } = params;
- const {
- editRender
- } = column;
- const editOpts = $xeTable.computeEditOpts;
- if ((0, _utils.isEnableConf)(editRender)) {
- const compRender = renderer.get(editRender.name);
- let autoFocus = editRender.autofocus || editRender.autoFocus;
- let autoSelect = editRender.autoSelect || editRender.autoselect;
- let inputElem;
- // 是否启用聚焦
- if (editOpts.autoFocus) {
- if (!autoFocus && compRender) {
- autoFocus = compRender.tableAutoFocus || compRender.tableAutofocus || compRender.autoFocus || compRender.autofocus;
- }
- if (!autoSelect && compRender) {
- autoSelect = compRender.tableAutoSelect || compRender.autoSelect || compRender.autoselect;
- }
- // 如果指定了聚焦 class
- if (_xeUtils.default.isFunction(autoFocus)) {
- inputElem = autoFocus.call($xeTable, params);
- } else if (autoFocus) {
- if (autoFocus === true) {
- // 自动匹配模式,会自动匹配第一个可输入元素
- inputElem = cell.querySelector('input,textarea');
- } else {
- inputElem = cell.querySelector(autoFocus);
- }
- if (inputElem) {
- inputElem.focus();
- }
- }
- }
- if (inputElem) {
- if (autoSelect) {
- inputElem.select();
- } else {
- // 保持一致行为,光标移到末端
- if (browseObj.msie) {
- const textRange = inputElem.createTextRange();
- textRange.collapse(false);
- textRange.select();
- }
- }
- } else {
- // 是否自动定位
- if (editOpts.autoPos) {
- if (!column.fixed) {
- // 显示到可视区中
- $xeTable.scrollToRow(row, column);
- }
- }
- }
- }
- },
- _setActiveRow(row) {
- const $xeTable = this;
- (0, _log.warnLog)('vxe.error.delFunc', ['setActiveRow', 'setEditRow']);
- // 即将废弃
- return $xeTable.setEditRow(row);
- },
- /**
- * 激活行编辑
- */
- _setEditRow(row, fieldOrColumn) {
- const $xeTable = this;
- let column = _xeUtils.default.find(this.visibleColumn, column => (0, _utils.isEnableConf)(column.editRender));
- let isPos = false;
- if (fieldOrColumn) {
- isPos = true;
- if (fieldOrColumn !== true) {
- column = _xeUtils.default.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn;
- }
- }
- return handleEditCell($xeTable, row, column, isPos);
- },
- _setActiveCell(row, fieldOrColumn) {
- (0, _log.warnLog)('vxe.error.delFunc', ['setActiveCell', 'setEditCell']);
- // 即将废弃
- return this.setEditCell(row, fieldOrColumn);
- },
- /**
- * 激活单元格编辑
- */
- _setEditCell(row, fieldOrColumn) {
- const $xeTable = this;
- return handleEditCell($xeTable, row, fieldOrColumn, true);
- },
- /**
- * 只对 trigger=dblclick 有效,选中单元格
- */
- _setSelectCell(row, fieldOrColumn) {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- tableData
- } = reactData;
- const editOpts = $xeTable.computeEditOpts;
- const column = _xeUtils.default.isString(fieldOrColumn) ? $xeTable.getColumnByField(fieldOrColumn) : fieldOrColumn;
- if (row && column && editOpts.trigger !== 'manual') {
- const rowIndex = $xeTable.findRowIndexOf(tableData, row);
- if (rowIndex > -1) {
- const cell = $xeTable.getCellElement(row, column);
- const params = {
- row,
- rowIndex,
- column,
- columnIndex: $xeTable.getColumnIndex(column),
- cell
- };
- $xeTable.handleSelected(params, {});
- }
- }
- return $xeTable.$nextTick();
- },
- /**
- * 处理选中源
- */
- handleSelected(params, evnt) {
- const $xeTable = this;
- const props = $xeTable;
- const reactData = $xeTable;
- const {
- mouseConfig
- } = props;
- const {
- editStore
- } = reactData;
- const mouseOpts = $xeTable.computeMouseOpts;
- const editOpts = $xeTable.computeEditOpts;
- const {
- actived,
- selected
- } = editStore;
- const {
- row,
- column
- } = params;
- const isMouseSelected = mouseConfig && mouseOpts.selected;
- const selectMethod = () => {
- if (isMouseSelected && (selected.row !== row || selected.column !== column)) {
- if (actived.row !== row || (editOpts.mode === 'cell' ? actived.column !== column : false)) {
- handleClearEdit($xeTable, evnt);
- $xeTable.clearSelected();
- if ($xeTable.clearCellAreas) {
- $xeTable.clearCellAreas();
- $xeTable.clearCopyCellArea();
- }
- selected.args = params;
- selected.row = row;
- selected.column = column;
- if (isMouseSelected) {
- this.addCellSelectedClass();
- }
- $xeTable.focus();
- if (evnt) {
- $xeTable.dispatchEvent('cell-selected', params, evnt);
- }
- }
- }
- return $xeTable.$nextTick();
- };
- return selectMethod();
- },
- /**
- * 获取选中的单元格
- */
- _getSelectedCell() {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- const {
- row,
- column
- } = editStore.selected;
- if (row && column) {
- return {
- row,
- column
- };
- }
- return null;
- },
- /**
- * 清除所选中源状态
- */
- _clearSelected() {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- const {
- selected
- } = editStore;
- selected.row = null;
- selected.column = null;
- removeCellSelectedClass($xeTable);
- return $xeTable.$nextTick();
- },
- reColTitleSdCls() {
- const headerElem = this.elemStore['main-header-list'];
- if (headerElem) {
- _xeUtils.default.arrayEach(headerElem.querySelectorAll('.col--title-selected'), elem => (0, _dom.removeClass)(elem, 'col--title-selected'));
- }
- },
- addCellSelectedClass() {
- const $xeTable = this;
- const reactData = $xeTable;
- const {
- editStore
- } = reactData;
- const {
- selected
- } = editStore;
- const {
- row,
- column
- } = selected;
- removeCellSelectedClass($xeTable);
- if (row && column) {
- const cell = $xeTable.getCellElement(row, column);
- if (cell) {
- (0, _dom.addClass)(cell, 'col--selected');
- }
- }
- }
- }
- };
|