Files
vxe-table/lib/table/src/table.min.js
xuliangzhan bd586b8b79 内部优化
2020-02-03 16:24:12 +08:00

1 line
17 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils/methods/xe-utils")),_conf=_interopRequireDefault(require("../../conf")),_vXETable=_interopRequireDefault(require("../../v-x-e-table")),_body=_interopRequireDefault(require("../../body")),_tools=require("../../tools"),_methods=_interopRequireDefault(require("./methods"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function renderFixed(e,t,o){var i=t.tableData,l=t.tableColumn,n=t.visibleColumn,r=t.collectColumn,s=t.isGroup,a=t.vSize,u=t.showHeader,c=t.showFooter,h=t.columnStore,f=t.footerData,d=h["".concat(o,"List")];return e("div",{class:"vxe-table--fixed-".concat(o,"-wrapper"),ref:"".concat(o,"Container")},[u?e("vxe-table-header",{props:{fixedType:o,tableData:i,tableColumn:l,visibleColumn:n,collectColumn:r,size:a,fixedColumn:d,isGroup:s},ref:"".concat(o,"Header")}):null,e("vxe-table-body",{props:{fixedType:o,tableData:i,tableColumn:l,visibleColumn:n,collectColumn:r,fixedColumn:d,size:a,isGroup:s},ref:"".concat(o,"Body")}),c?e("vxe-table-footer",{props:{fixedType:o,footerData:f,tableColumn:l,visibleColumn:n,size:a,fixedColumn:d},ref:"".concat(o,"Footer")}):null])}var _default2={name:"VxeTable",props:{data:Array,customs:Array,height:[Number,String],maxHeight:[Number,String],resizable:{type:Boolean,default:function(){return _conf.default.resizable}},stripe:{type:Boolean,default:function(){return _conf.default.stripe}},border:{type:[Boolean,String],default:function(){return _conf.default.border}},size:{type:String,default:function(){return _conf.default.size}},fit:{type:Boolean,default:function(){return _conf.default.fit}},loading:Boolean,align:{type:String,default:function(){return _conf.default.align}},headerAlign:{type:String,default:function(){return _conf.default.headerAlign}},footerAlign:{type:String,default:function(){return _conf.default.footerAlign}},showHeader:{type:Boolean,default:function(){return _conf.default.showHeader}},startIndex:{type:Number,default:0},highlightCurrentRow:{type:Boolean,default:function(){return _conf.default.highlightCurrentRow}},highlightHoverRow:{type:Boolean,default:function(){return _conf.default.highlightHoverRow}},highlightCurrentColumn:{type:Boolean,default:function(){return _conf.default.highlightCurrentColumn}},highlightHoverColumn:{type:Boolean,default:function(){return _conf.default.highlightHoverColumn}},highlightCell:Boolean,showFooter:Boolean,footerMethod:Function,rowClassName:[String,Function],cellClassName:[String,Function],headerRowClassName:[String,Function],headerCellClassName:[String,Function],footerRowClassName:[String,Function],footerCellClassName:[String,Function],cellStyle:[Object,Function],headerCellStyle:[Object,Function],footerCellStyle:[Object,Function],rowStyle:[Object,Function],headerRowStyle:[Object,Function],footerRowStyle:[Object,Function],spanMethod:Function,footerSpanMethod:Function,showOverflow:{type:[Boolean,String],default:function(){return _conf.default.showOverflow}},showHeaderOverflow:{type:[Boolean,String],default:function(){return _conf.default.showHeaderOverflow}},remoteFilter:Boolean,remoteSort:Boolean,sortMethod:Function,columnWidth:[Number,String],columnMinWidth:[Number,String],columnKey:Boolean,rowKey:Boolean,rowId:{type:String,default:function(){return _conf.default.rowId}},zIndex:Number,keepSource:{type:Boolean,default:function(){return _conf.default.keepSource}},autoResize:Boolean,syncResize:[Boolean,String],seqConfig:Object,sortConfig:Object,filterConfig:Object,radioConfig:Object,selectConfig:Object,checkboxConfig:Object,tooltipConfig:Object,exportConfig:[Boolean,Object],importConfig:[Boolean,Object],printConfig:Object,expandConfig:Object,treeConfig:[Boolean,Object],contextMenu:[Boolean,Object],mouseConfig:Object,keyboardConfig:Object,editConfig:[Boolean,Object],validConfig:Object,editRules:Object,optimization:Object,params:Object},components:{VxeTableBody:_body.default},provide:function(){return{$xetable:this}},inject:{$xegrid:{default:null}},mixins:[],data:function(){return{id:"".concat(_xeUtils.default.uniqueId()),collectColumn:[],tableFullColumn:[],tableColumn:[],tableData:[],scrollXLoad:!1,scrollYLoad:!1,overflowY:!0,overflowX:!1,scrollbarWidth:0,scrollbarHeight:0,rowHeight:0,isAllSelected:!1,isIndeterminate:!1,selection:[],currentRow:null,selectRow:null,footerData:[],rowExpandeds:[],expandLazyLoadeds:[],treeExpandeds:[],treeLazyLoadeds:[],treeIndeterminates:[],filterStore:{isAllSelected:!1,isIndeterminate:!1,style:null,options:[],column:null,multiple:!1,visible:!1},columnStore:{leftList:[],centerList:[],rightList:[],resizeList:[],pxList:[],pxMinList:[],scaleList:[],scaleMinList:[],autoList:[]},ctxMenuStore:{selected:null,visible:!1,showChild:!1,selectChild:null,list:[],childPos:null,style:null},editStore:{indexs:{columns:[]},titles:{columns:[]},checked:{rows:[],columns:[],tRows:[],tColumns:[]},selected:{row:null,column:null},copyed:{cut:!1,rows:[],columns:[]},actived:{row:null,column:null},insertList:[],removeList:[]},validStore:{visible:!1,row:null,column:null,content:"",rule:null,isArrow:!1},importStore:{file:null,type:"",filename:"",visible:!1},importParams:{mode:"",types:null,message:!0},exportStore:{name:"",mode:"",columns:[],selectRecords:[],hasFooter:!1,visible:!1,isTree:!1},exportParams:{filename:"",sheetName:"",type:"",types:[],original:!1,message:!0,isHeader:!1,isFooter:!1}}},computed:{vSize:function(){return this.size||this.$parent.size||this.$parent.vSize},validOpts:function(){return Object.assign({message:"default"},_conf.default.validConfig,this.validConfig)},optimizeOpts:function(){return Object.assign({},_conf.default.optimization,this.optimization)},rowHeightMaps:function(){return Object.assign({default:48,medium:44,small:40,mini:36},this.optimizeOpts.rHeights)},seqOpts:function(){return Object.assign({startIndex:0},_conf.default.seqConfig,this.seqConfig)},radioOpts:function(){return Object.assign({},_conf.default.radioConfig,this.radioConfig)},checkboxOpts:function(){return Object.assign({},_conf.default.checkboxConfig,this.checkboxConfig||this.selectConfig)},tooltipOpts:function(){return Object.assign({size:this.vSize,leaveDelay:300},_conf.default.tooltipConfig,this.tooltipConfig)},vaildTipOpts:function(){return Object.assign({isArrow:!1},this.tooltipOpts)},editOpts:function(){return Object.assign({},_conf.default.editConfig,this.editConfig)},sortOpts:function(){return Object.assign({},_conf.default.sortConfig,this.sortConfig)},filterOpts:function(){return Object.assign({},_conf.default.filterConfig,this.filterConfig)},mouseOpts:function(){return Object.assign({},_conf.default.mouseConfig,this.mouseConfig)},isGroup:function(){return this.collectColumn.some(function(e){return _tools.UtilTools.hasChildrenList(e)})},hasTip:function(){return _vXETable.default._tooltip},visibleColumn:function(){return this.tableFullColumn?this.tableFullColumn.filter(function(e){return e.visible}):[]},isResizable:function(){return this.resizable||this.tableFullColumn.some(function(e){return e.resizable})},hasFilter:function(){return this.tableColumn.some(function(e){return e.filters&&e.filters.length})},headerCtxMenu:function(){return this.ctxMenuOpts.header&&this.ctxMenuOpts.header.options?this.ctxMenuOpts.header.options:[]},bodyCtxMenu:function(){return this.ctxMenuOpts.body&&this.ctxMenuOpts.body.options?this.ctxMenuOpts.body.options:[]},isCtxMenu:function(){return this.headerCtxMenu.length||this.bodyCtxMenu.length},ctxMenuOpts:function(){return Object.assign({},_conf.default.contextMenu,this.contextMenu)},ctxMenuList:function(){var t=[];return this.ctxMenuStore.list.forEach(function(e){e.forEach(function(e){t.push(e)})}),t},exportOpts:function(){return Object.assign({},_conf.default.exportConfig,this.exportConfig)},importOpts:function(){return Object.assign({},_conf.default.importConfig,this.importConfig)},printOpts:function(){return Object.assign({},_conf.default.printConfig,this.printConfig)},expandOpts:function(){return Object.assign({},_conf.default.expandConfig,this.expandConfig)},treeOpts:function(){return Object.assign({children:"children",hasChild:"hasChild",indent:20},_conf.default.treeConfig,this.treeConfig)},cellOffsetWidth:function(){return this.border?Math.max(2,Math.ceil(this.scrollbarWidth/this.tableColumn.length)):1},expandColumn:function(){return this.tableColumn.find(function(e){return"expand"===e.type})},isAllCheckboxDisabled:function(){var e=this.tableFullData,t=(this.treeConfig,this.checkboxOpts),o=t.strict,i=t.checkMethod;return!!o&&(!e.length||!!i&&e.every(function(e,t){return!i({row:e,rowIndex:t,$rowIndex:t})}))}},watch:{data:function(e){var t=this;this.loadTableData(e).then(function(){t.inited||(t.inited=!0,t.handleDefaults())})},customs:function(e){this.isUpdateCustoms||this.mergeCustomColumn(e),this.isUpdateCustoms=!1},collectColumn:function(e){var t=this,o=_tools.UtilTools.getColumnList(e);if(this.tableFullColumn=o,this.cacheColumnMap(),this.customs&&this.mergeCustomColumn(this.customs),this.refreshColumn().then(function(){t.scrollXLoad&&t.loadScrollXData(!0)}),this.handleTableData(!0),this.$toolbar&&this.$toolbar.updateColumns(o),o.length){var i=Math.floor((o.length-1)/2);o[i].prop&&_tools.UtilTools.warn("vxe.error.delProp",["prop","field"]),o[i].label&&_tools.UtilTools.warn("vxe.error.delProp",["label","title"])}this.treeConfig&&o.some(function(e){return e.fixed})&&o.some(function(e){return"expand"===e.type})&&_tools.UtilTools.warn("vxe.error.treeFixedExpand")},tableColumn:function(){this.analyColumnWidth()},showHeader:function(){var e=this;this.$nextTick(function(){return e.recalculate(!0)})},showFooter:function(){var e=this;this.$nextTick(function(){return e.recalculate(!0)})},height:function(){var e=this;this.$nextTick(function(){return e.recalculate(!0)})},loading:function(){this._isLoading||(this._isLoading=!0)},syncResize:function(e){var t=this;e&&this.$nextTick(function(){t.$el.clientWidth&&t.$el.clientHeight&&t.recalculate(!0)})}},created:function(){var e,t=this,o=Object.assign(this,{tZindex:0,elemStore:{},scrollXStore:{},scrollYStore:{},tooltipStore:{},parentHeight:0,tableWidth:0,tableHeight:0,headerHeight:0,footerHeight:0,lastScrollLeft:0,lastScrollTop:0,selectReserveRowMap:{},tableFullData:[],afterFullData:[],fullAllDataRowMap:new Map,fullAllDataRowIdData:{},fullDataRowMap:new Map,fullDataRowIdData:{},fullColumnMap:new Map,fullColumnIdData:{}}),i=o.scrollXStore,l=o.scrollYStore,n=o.optimizeOpts,r=o.data,s=o.loading,a=o.editOpts,u=o.treeOpts,c=o.treeConfig,h=o.showOverflow,f=n.scrollX,d=n.scrollY;if(this._isLoading=s,_tools.UtilTools.getRowkey(this)||_tools.UtilTools.error("vxe.error.emptyProp",["row-id"]),this.startIndex&&_tools.UtilTools.warn("vxe.error.delProp",["start-index","seq-config.startIndex"]),this.selectConfig&&_tools.UtilTools.warn("vxe.error.delProp",["select-config","checkbox-config"]),a.showStatus&&!this.keepSource&&_tools.UtilTools.warn("vxe.error.reqProp",["keep-source"]),!c||!u.line||this.rowKey&&h||_tools.UtilTools.warn("vxe.error.reqProp",["row-key | show-overflow"]),this.customs&&_tools.UtilTools.warn("vxe.error.removeProp",["customs"]),this.sortMethod&&_tools.UtilTools.warn("vxe.error.delProp",["sort-method","sort-config.sortMethod"]),this.remoteSort&&_tools.UtilTools.warn("vxe.error.delProp",["remote-sort","sort-config.remote"]),this.remoteFilter&&_tools.UtilTools.warn("vxe.error.delProp",["remote-filter","filter-config.remote"]),!_vXETable.default._edit&&this.editConfig?e="Edit":!_vXETable.default._valid&&this.editRules?e="Validator":_vXETable.default._keyboard||!this.keyboardConfig&&!this.mouseConfig?!_vXETable.default._resize&&this.autoResize&&(e="Resize"):e="Keyboard",e)throw new Error(_tools.UtilTools.getLog("vxe.error.reqModule",[e]));d&&Object.assign(l,{startIndex:0,visibleIndex:0,adaptive:!_xeUtils.default.isBoolean(d.adaptive)||d.adaptive,renderSize:_xeUtils.default.toNumber(d.rSize),offsetSize:_xeUtils.default.toNumber(d.oSize)}),f&&Object.assign(i,{startIndex:0,visibleIndex:0,renderSize:_xeUtils.default.toNumber(f.rSize),offsetSize:_xeUtils.default.toNumber(f.oSize)}),this.loadTableData(r).then(function(){r&&r.length&&(t.inited=!0,t.handleDefaults()),t.updateStyle()}),_tools.GlobalEvent.on(this,"mousedown",this.handleGlobalMousedownEvent),_tools.GlobalEvent.on(this,"blur",this.handleGlobalBlurEvent),_tools.GlobalEvent.on(this,"mousewheel",this.handleGlobalMousewheelEvent),_tools.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent),_tools.GlobalEvent.on(this,"resize",this.handleGlobalResizeEvent),_tools.GlobalEvent.on(this,"contextmenu",this.handleGlobalContextmenuEvent),this.preventEvent(null,"created",{$table:this})},mounted:function(){this.autoResize&&_vXETable.default._resize&&this.bindResize(),!this.$xegrid&&this.customs&&_tools.UtilTools.warn("vxe.error.removeProp",["customs"]),document.body.appendChild(this.$refs.tableWrapper),this.preventEvent(null,"mounted",{$table:this})},activated:function(){this.refreshScroll(),this.preventEvent(null,"activated",{$table:this})},deactivated:function(){this.preventEvent(null,"deactivated",{$table:this})},beforeDestroy:function(){var e=this.$refs.tableWrapper;e&&e.parentNode&&e.parentNode.removeChild(e),_vXETable.default._resize&&this.unbindResize(),this.closeFilter(),this.closeMenu(),this.clearAll(),this.preventEvent(null,"beforeDestroy",{$table:this})},destroyed:function(){_tools.GlobalEvent.off(this,"mousedown"),_tools.GlobalEvent.off(this,"blur"),_tools.GlobalEvent.off(this,"mousewheel"),_tools.GlobalEvent.off(this,"keydown"),_tools.GlobalEvent.off(this,"resize"),_tools.GlobalEvent.off(this,"contextmenu"),this.preventEvent(null,"destroyed",{$table:this})},render:function(e){var t=this._e,o=this.id,i=this.tableData,l=this.tableColumn,n=this.visibleColumn,r=this.collectColumn,s=this.isGroup,a=this.hasFilter,u=this.isResizable,c=this.isCtxMenu,h=this.loading,f=this.stripe,d=this._isLoading,p=this.showHeader,b=this.height,m=this.border,g=this.treeOpts,v=this.treeConfig,x=this.mouseConfig,C=this.mouseOpts,_=this.vSize,w=this.validOpts,O=this.editRules,y=this.showFooter,S=this.footerMethod,z=this.overflowX,M=this.overflowY,j=this.scrollXLoad,T=this.scrollYLoad,E=this.scrollbarHeight,F=this.highlightCell,R=this.highlightHoverRow,D=this.highlightHoverColumn,L=this.editConfig,B=this.checkboxOpts,k=this.optimizeOpts,H=this.vaildTipOpts,U=this.tooltipOpts,$=this.columnStore,G=this.filterStore,q=this.ctxMenuStore,I=this.footerData,P=this.hasTip,N=$.leftList,X=$.rightList,A=x&&(C.range||C.checked);return e("div",{class:["vxe-table","tid_".concat(o),_?"size--".concat(_):"",m&&_xeUtils.default.isString(m)?"b--style-".concat(m):"",{"vxe-editable":L,"show--head":p,"show--foot":y,"is--group":s,"has--height":b,"has--tree-line":v&&g.line,"fixed--left":N.length,"fixed--right":X.length,"c--highlight":F,"t--animat":k.animat,"t--stripe":f,"t--border":m,"t--selected":x&&C.selected,"t--checked":A,"row--highlight":R,"column--highlight":D,"is--loading":h,"is--empty":!h&&!i.length,"scroll--y":M,"scroll--x":z,"virtual--x":j,"virtual--y":T}]},[e("div",{class:"vxe-table-hidden-column",ref:"hideColumn"},this.$slots.default),e("div",{class:"vxe-table--main-wrapper"},[p?e("vxe-table-header",{ref:"tableHeader",props:{tableData:i,tableColumn:l,visibleColumn:n,collectColumn:r,size:_,isGroup:s}}):t(),e("vxe-table-body",{ref:"tableBody",props:{tableData:i,tableColumn:l,visibleColumn:n,collectColumn:r,size:_,isGroup:s}}),y?e("vxe-table-footer",{props:{footerData:I,footerMethod:S,tableColumn:l,visibleColumn:n,size:_},ref:"tableFooter"}):null]),N&&N.length&&z?renderFixed(e,this,"left"):t(),X&&X.length&&z?renderFixed(e,this,"right"):t(),e("div",{ref:"emptyPlaceholder",class:"vxe-table--empty-placeholder"},[e("div",{class:"vxe-table--empty-content"},this.$scopedSlots.empty?this.$scopedSlots.empty.call(this,{$table:this},e):_conf.default.i18n("vxe.table.emptyText"))]),e("div",{class:"vxe-table--border-line"}),u?e("div",{class:"vxe-table--resizable-bar",style:z?{"padding-bottom":"".concat(E,"px")}:null,ref:"resizeBar"}):t(),d?e("vxe-table-loading",{props:{visible:h}}):t(),a?e("vxe-table-filter",{props:{optimizeOpts:k,filterStore:G},ref:"filterWrapper"}):t(),_vXETable.default._export?e("vxe-import-panel",{props:{defaultOptions:this.importParams,storeData:this.importStore},on:{import:this.confirmImportEvent}}):t(),_vXETable.default._export?e("vxe-export-panel",{props:{defaultOptions:this.exportParams,storeData:this.exportStore},on:{print:this.confirmPrintEvent,export:this.confirmExportEvent}}):t(),e("div",{class:"vxe-table".concat(o,"-wrapper ").concat(this.$vnode.data.staticClass||""),ref:"tableWrapper"},[B.range?e("div",{class:"vxe-table--checkbox-range",ref:"checkboxRange"}):t(),c?e("vxe-table-context-menu",{props:{ctxMenuStore:q},ref:"ctxWrapper"}):t(),P?e("vxe-tooltip",{ref:"tooltip",props:U,on:U.enterable?{leave:this.handleTooltipLeaveEvent}:null}):t(),P&&O&&("default"===w.message?!b:"tooltip"===w.message)?e("vxe-tooltip",{class:"vxe-table--valid-error",props:"tooltip"===w.message||1===i.length?H:null,ref:"validTip"}):t()])])},methods:_methods.default};exports.default=_default2;