vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
1 lines • 9.17 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _ctor=_interopRequireDefault(require("xe-utils/ctor")),_vXETable=_interopRequireDefault(require("../../v-x-e-table")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}var _default={methods:{_insert:function(e){return this.insertAt(e)},_insertAt:function(e,t){var r,o=this,l=this.mergeList,i=this.afterFullData,n=this.editStore,s=this.sYOpts,a=this.scrollYLoad,c=this.tableFullData,u=this.treeConfig;_ctor.default.isArray(e)||(e=[e]);var d=e.map(function(e){return o.defineField(Object.assign({},e))});if(t)if(-1===t)i.push.apply(i,_toConsumableArray(d)),c.push.apply(c,_toConsumableArray(d)),l.forEach(function(e){var t=e.row,r=e.rowspan;t+r>i.length&&(e.rowspan=r+d.length)});else{if(u)throw new Error(_tools.UtilTools.getLog("vxe.error.noTree",["insert"]));var h=i.indexOf(t);if(-1===h)throw new Error(_tools.UtilTools.error("vxe.error.unableInsert"));i.splice.apply(i,[h,0].concat(_toConsumableArray(d))),c.splice.apply(c,[c.indexOf(t),0].concat(_toConsumableArray(d))),l.forEach(function(e){var t=e.row,r=e.rowspan;h<t?e.row=t+d.length:h<t+r&&(e.rowspan=r+d.length)})}else i.unshift.apply(i,_toConsumableArray(d)),c.unshift.apply(c,_toConsumableArray(d)),l.forEach(function(e){var t=e.row;0<t&&(e.row=t+d.length)});return(r=n.insertList).unshift.apply(r,_toConsumableArray(d)),this.scrollYLoad=!u&&-1<s.gt&&s.gt<c.length,this.handleTableData(),this.updateFooter(),this.updateCache(),this.checkSelectionStatus(),a&&this.updateScrollYSpace(),this.$nextTick().then(function(){return o.recalculate(),{row:d.length?d[d.length-1]:null,rows:d}})},_remove:function(e){var t=this,l=this.afterFullData,i=this.tableFullData,r=this.treeConfig,n=this.mergeList,o=this.editStore,s=this.checkboxOpts,a=this.selection,c=this.isInsertByRow,u=this.sYOpts,d=this.scrollYLoad,h=o.actived,f=o.removeList,v=o.insertList,m=s.checkField,p=[];return e?_ctor.default.isArray(e)||(e=[e]):e=i,e.forEach(function(e){c(e)||f.push(e)}),m||e.forEach(function(e){var t=a.indexOf(e);-1<t&&a.splice(t,1)}),i===e?(e=p=i.slice(0),this.tableFullData=[],this.afterFullData=[],this.clearMergeCells()):e.forEach(function(e){var t=i.indexOf(e);if(-1<t){var r=i.splice(t,1);p.push(r[0])}var o=l.indexOf(e);-1<o&&(n.forEach(function(e){var t=e.row,r=e.rowspan;o<t?e.row=t-1:o<t+r&&(e.rowspan=r-1)}),l.splice(o,1))}),h.row&&-1<e.indexOf(h.row)&&this.clearActived(),e.forEach(function(e){var t=v.indexOf(e);-1<t&&v.splice(t,1)}),this.scrollYLoad=!r&&-1<u.gt&&u.gt<i.length,this.handleTableData(),this.updateFooter(),this.updateCache(),this.checkSelectionStatus(),d&&this.updateScrollYSpace(),this.$nextTick().then(function(){return t.recalculate(),{row:p.length?p[p.length-1]:null,rows:p}})},_removeCheckboxRow:function(){var t=this;return this.remove(this.getCheckboxRecords()).then(function(e){return t.clearCheckboxRow(),e})},_removeRadioRow:function(){var t=this,e=this.getRadioRecord();return this.remove(e||[]).then(function(e){return t.clearRadioRow(),e})},_removeCurrentRow:function(){var t=this,e=this.getCurrentRecord();return this.remove(e||[]).then(function(e){return t.clearCurrentRow(),e})},_getRecordset:function(){return{insertRecords:this.getInsertRecords(),removeRecords:this.getRemoveRecords(),updateRecords:this.getUpdateRecords()}},_getInsertRecords:function(){var t=this.editStore.insertList,r=[];return t.length&&this.tableFullData.forEach(function(e){-1<t.indexOf(e)&&r.push(e)}),r},_getRemoveRecords:function(){return this.editStore.removeList},_getUpdateRecords:function(){var e=this.keepSource,t=this.tableFullData,r=this.isUpdateByRow,o=this.treeConfig,l=this.treeOpts;return e?o?_ctor.default.filterTree(t,function(e){return r(e)},l):t.filter(function(e){return r(e)}):[]},handleActived:function(e,t){var r=this,o=this.editStore,l=this.editOpts,i=this.tableColumn,n=this.mouseConfig,s=l.mode,a=l.activeMethod,c=o.actived,u=e.row,d=e.column,h=e.cell;if(d.editRender&&h){if(c.row!==u||"cell"===s&&c.column!==d){var f="edit-disabled";a&&!a(e)||(n&&(this.clearSelected(t),this.clearCellAreas(t),this.clearCopyCellArea(t)),this.clostTooltip(),this.clearActived(t),f="edit-actived",d.renderHeight=h.offsetHeight,c.args=e,c.row=u,c.column=d,"row"===s?i.forEach(function(e){return r._getColumnModel(u,e)}):this._getColumnModel(u,d),this.$nextTick(function(){r.handleFocus(e,t)})),this.emitEvent(f,e,t)}else{var v=c.column;if(n&&(this.clearSelected(t),this.clearCellAreas(t),this.clearCopyCellArea(t)),v!==d){var m=v.model;m.update&&_tools.UtilTools.setCellValue(u,v,m.value),this.clearValidate()}d.renderHeight=h.offsetHeight,c.args=e,c.column=d,setTimeout(function(){r.handleFocus(e,t)})}this.focus()}return this.$nextTick()},_getColumnModel:function(e,t){var r=t.model;t.editRender&&(r.value=_tools.UtilTools.getCellValue(e,t),r.update=!1)},_setColumnModel:function(e,t){var r=t.model;t.editRender&&r.update&&(_tools.UtilTools.setCellValue(e,t,r.value),r.update=!1,r.value=null)},_clearActived:function(e){var t=this,r=this.tableColumn,o=this.editStore,l=this.editOpts,i=o.actived,n=i.args,s=i.row,a=i.column;return(s||a)&&("row"===l.mode?r.forEach(function(e){return t._setColumnModel(s,e)}):this._setColumnModel(s,a),this.updateFooter(),this.emitEvent("edit-closed",n,e)),i.args=null,i.row=null,i.column=null,(_vXETable.default._valid?this.clearValidate():this.$nextTick()).then(this.recalculate)},_getActiveRecord:function(){var e=this.$el,t=this.editStore,r=this.afterFullData,o=t.actived,l=o.args,i=o.row;return l&&-1<r.indexOf(i)&&e.querySelectorAll(".vxe-body--column.col--actived").length?Object.assign({},l):null},_isActiveByRow:function(e){return this.editStore.actived.row===e},handleFocus:function(e){var t=e.row,r=e.column,o=e.cell,l=r.editRender;if(l){var i,n=_vXETable.default.renderer.get(l.name),s=l.autofocus,a=l.autoselect;if(s&&(i=o.querySelector(s)),!i&&n&&n.autofocus&&(i=o.querySelector(n.autofocus)),i){if(i.focus(),a)i.select();else if(_tools.DomTools.browse.msie){var c=i.createTextRange();c.collapse(!1),c.select()}}else this.scrollToRow(t,r)}},_setActiveRow:function(e){return this.setActiveCell(e,_ctor.default.find(this.visibleColumn,function(e){return e.editRender}).property)},_setActiveCell:function(r,o){var l=this;return this.scrollToRow(r,!0).then(function(){if(r&&o){var e=_ctor.default.find(l.visibleColumn,function(e){return e.property===o});if(e&&e.editRender){var t=l.getCell(r,e);t&&(l.handleActived({row:r,rowIndex:l.getRowIndex(r),column:e,columnIndex:l.getColumnIndex(e),cell:t,$table:l}),l.lastCallTime=Date.now())}}return l.$nextTick()})},_setSelectCell:function(e,t){var r=this.tableData,o=this.editOpts,l=this.visibleColumn;if(e&&t&&"manual"!==o.trigger){var i=_ctor.default.find(l,function(e){return e.property===t}),n=r.indexOf(e);if(-1<n&&i){var s=this.getCell(e,i),a={row:e,rowIndex:n,column:i,columnIndex:l.indexOf(i),cell:s};this.handleSelected(a,{})}}return this.$nextTick()},handleSelected:function(e,t){var r=this,o=this.mouseConfig,l=this.mouseOpts,i=this.editOpts,n=this.editStore,s=n.actived,a=n.selected,c=e.row,u=e.column,d=o&&l.selected;return!d||a.row===c&&a.column===u||(s.row!==c||"cell"===i.mode&&s.column!==u)&&(r.clearActived(t),r.clearSelected(t),r.clearCellAreas(t),r.clearCopyCellArea(t),a.args=e,a.row=c,a.column=u,d&&r.addColSdCls(),r.focus(),t&&r.emitEvent("cell-selected",e,t)),r.$nextTick()},_getSelectedCell:function(){var e=this.editStore.selected,t=e.args,r=e.column;return t&&r?Object.assign({},t):null},_clearSelected:function(){var e=this.editStore.selected;return e.row=null,e.column=null,this.reColTitleSdCls(),this.reColSdCls(),this.$nextTick()},reColTitleSdCls:function(){var e=this.elemStore["main-header-list"];e&&_ctor.default.arrayEach(e.querySelectorAll(".col--title-selected"),function(e){return _tools.DomTools.removeClass(e,"col--title-selected")})},reColSdCls:function(){var e=this.$el.querySelector(".col--selected");e&&_tools.DomTools.removeClass(e,"col--selected")},addColSdCls:function(){var e=this.editStore.selected,t=e.row,r=e.column;if(this.reColSdCls(),t&&r){var o=this.getCell(t,r);o&&_tools.DomTools.addClass(o,"col--selected")}}}};exports.default=_default;