vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
1 lines • 9.67 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils")),_vXETable=_interopRequireDefault(require("../../v-x-e-table")),_tools=require("../../tools"),_dom=require("../../tools/src/dom");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"Map"===(r="Object"===r&&e.constructor?e.constructor.name: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=this,o=this.mergeList,l=this.afterFullData,i=this.editStore,n=this.sYOpts,s=this.scrollYLoad,a=this.tableFullData,c=this.treeConfig,u=(e=!_xeUtils.default.isArray(e)?[e]:e).map(function(e){return r.defineField(Object.assign({},e))});if(t)if(-1===t)l.push.apply(l,_toConsumableArray(u)),a.push.apply(a,_toConsumableArray(u)),o.forEach(function(e){var t=e.row,r=e.rowspan;t+r>l.length&&(e.rowspan=r+u.length)});else{if(c)throw new Error(_tools.UtilTools.getLog("vxe.error.noTree",["insert"]));var d=l.indexOf(t);if(-1===d)throw new Error(_tools.UtilTools.error("vxe.error.unableInsert"));l.splice.apply(l,[d,0].concat(_toConsumableArray(u))),a.splice.apply(a,[a.indexOf(t),0].concat(_toConsumableArray(u))),o.forEach(function(e){var t=e.row,r=e.rowspan;d<t?e.row=t+u.length:d<t+r&&(e.rowspan=r+u.length)})}else l.unshift.apply(l,_toConsumableArray(u)),a.unshift.apply(a,_toConsumableArray(u)),o.forEach(function(e){var t=e.row;0<t&&(e.row=t+u.length)});return(i=i.insertList).unshift.apply(i,_toConsumableArray(u)),this.scrollYLoad=!c&&-1<n.gt&&n.gt<a.length,this.handleTableData(),this.updateFooter(),this.updateCache(),this.checkSelectionStatus(),s&&this.updateScrollYSpace(),this.$nextTick().then(function(){return r.updateCellAreas(),r.recalculate()}).then(function(){return{row:u.length?u[u.length-1]:null,rows:u}})},_remove:function(e){var t=this,r=this.afterFullData,l=this.tableFullData,o=this.treeConfig,i=this.mergeList,n=this.editStore,s=this.checkboxOpts,a=this.selection,c=this.isInsertByRow,u=this.sYOpts,d=this.scrollYLoad,h=n.actived,f=n.removeList,m=n.insertList,s=s.checkField,v=[];return e?_xeUtils.default.isArray(e)||(e=[e]):e=l,e.forEach(function(e){c(e)||f.push(e)}),s||e.forEach(function(e){e=a.indexOf(e);-1<e&&a.splice(e,1)}),l===e?(e=v=l.slice(0),this.tableFullData=[],this.afterFullData=[],this.clearMergeCells()):e.forEach(function(e){var t=l.indexOf(e);-1<t&&(t=l.splice(t,1),v.push(t[0]));var o=r.indexOf(e);-1<o&&(i.forEach(function(e){var t=e.row,r=e.rowspan;o<t?e.row=t-1:o<t+r&&(e.rowspan=r-1)}),r.splice(o,1))}),h.row&&-1<e.indexOf(h.row)&&this.clearActived(),e.forEach(function(e){e=m.indexOf(e);-1<e&&m.splice(e,1)}),this.scrollYLoad=!o&&-1<u.gt&&u.gt<l.length,this.handleTableData(),this.updateFooter(),this.updateCache(),this.checkSelectionStatus(),d&&this.updateScrollYSpace(),this.$nextTick().then(function(){return t.updateCellAreas(),t.recalculate()}).then(function(){return{row:v.length?v[v.length-1]:null,rows:v}})},_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,i=this.editStore;if(e){e=i.actived,i=e.row,e=e.column;return(i||e)&&this.clearActived(),o?_xeUtils.default.filterTree(t,function(e){return r(e)},l):t.filter(function(e){return r(e)})}return[]},handleActived:function(e,t){var r,o=this,l=this.editStore,i=this.editOpts,n=this.tableColumn,s=this.mouseConfig,a=i.mode,c=i.activeMethod,u=l.actived,d=e.row,h=e.column,i=h.editRender,l=e.cell=e.cell||this.getCell(d,h);return(0,_tools.isEnableConf)(i)&&l&&(u.row!==d||"cell"===a&&u.column!==h?(r="edit-disabled",c&&!c(e)||(s&&(this.clearSelected(t),this.clearCellAreas(t),this.clearCopyCellArea(t)),this.closeTooltip(),this.clearActived(t),r="edit-actived",h.renderHeight=l.offsetHeight,u.args=e,u.row=d,u.column=h,"row"===a?n.forEach(function(e){return o._getColumnModel(d,e)}):this._getColumnModel(d,h),this.$nextTick(function(){o.handleFocus(e,t)})),this.emitEvent(r,{row:d,rowIndex:this.getRowIndex(d),$rowIndex:this.getVMRowIndex(d),column:h,columnIndex:this.getColumnIndex(h),$columnIndex:this.getVMColumnIndex(h)},t)):(r=u.column,s&&(this.clearSelected(t),this.clearCellAreas(t),this.clearCopyCellArea(t)),r!==h&&((s=r.model).update&&_tools.UtilTools.setCellValue(d,r,s.value),this.clearValidate()),h.renderHeight=l.offsetHeight,u.args=e,u.column=h,setTimeout(function(){o.handleFocus(e,t)})),this.focus()),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.row,o=i.column;return(n||o)&&("row"===l.mode?r.forEach(function(e){return t._setColumnModel(n,e)}):this._setColumnModel(n,o),i.args=null,i.row=null,i.column=null,this.updateFooter(),this.emitEvent("edit-closed",{row:n,rowIndex:this.getRowIndex(n),$rowIndex:this.getVMRowIndex(n),column:o,columnIndex:this.getColumnIndex(o),$columnIndex:this.getVMColumnIndex(o)},e)),(_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,t=o.args,o=o.row;return t&&-1<r.indexOf(o)&&e.querySelectorAll(".vxe-body--column.col--actived").length?Object.assign({},t):null},_isActiveByRow:function(e){return this.editStore.actived.row===e},handleFocus:function(e){var t,r,o=e.row,l=e.column,i=e.cell,n=l.editRender;(0,_tools.isEnableConf)(n)&&(t=_vXETable.default.renderer.get(n.name),e=n.autofocus,n=n.autoselect,(r=!(r=e?i.querySelector(e):r)&&t&&t.autofocus?i.querySelector(t.autofocus):r)?(r.focus(),n?r.select():_dom.browse.msie&&((r=r.createTextRange()).collapse(!1),r.select())):this.scrollToRow(o,l))},_setActiveRow:function(e){return this.setActiveCell(e,_xeUtils.default.find(this.visibleColumn,function(e){return(0,_tools.isEnableConf)(e.editRender)}))},_setActiveCell:function(t,e){var r=this,o=_xeUtils.default.isString(e)?this.getColumnByField(e):e;return t&&o&&(0,_tools.isEnableConf)(o.editRender)?this.scrollToRow(t,!0).then(function(){var e=r.getCell(t,o);e&&(r.handleActived({row:t,rowIndex:r.getRowIndex(t),column:o,columnIndex:r.getColumnIndex(o),cell:e,$table:r}),r.lastCallTime=Date.now())}):this.$nextTick()},_setSelectCell:function(e,t){var r=this.tableData,o=this.editOpts,l=this.visibleColumn,t=_xeUtils.default.isString(t)?this.getColumnByField(t):t;return e&&t&&"manual"!==o.trigger&&(-1<(o=r.indexOf(e))&&(r=this.getCell(e,t),r={row:e,rowIndex:o,column:t,columnIndex:l.indexOf(t),cell:r},this.handleSelected(r,{}))),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,e=e.column;return t&&e?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&&_xeUtils.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,e=e.column;this.reColSdCls(),t&&e&&((e=this.getCell(t,e))&&_tools.DomTools.addClass(e,"col--selected"))}}};exports.default=_default;