vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
1 lines • 20.4 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _ctor=_interopRequireDefault(require("xe-utils/ctor")),_conf=_interopRequireDefault(require("../../conf")),_vXETable=_interopRequireDefault(require("../../v-x-e-table")),_body=_interopRequireDefault(require("./body")),_size=_interopRequireDefault(require("../../mixins/size")),_tools=require("../../tools"),_methods=_interopRequireDefault(require("./methods"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function renderFixed(e,t,o){var n=t._e,i=t.tableData,r=t.tableColumn,l=t.tableGroupColumn,s=t.vSize,a=t.showHeader,u=t.showFooter,c=t.columnStore,f=t.footerData,d=c["".concat(o,"List")];return e("div",{class:"vxe-table--fixed-".concat(o,"-wrapper"),ref:"".concat(o,"Container")},[a?e("vxe-table-header",{props:{fixedType:o,tableData:i,tableColumn:r,tableGroupColumn:l,size:s,fixedColumn:d},ref:"".concat(o,"Header")}):n(),e("vxe-table-body",{props:{fixedType:o,tableData:i,tableColumn:r,fixedColumn:d,size:s},ref:"".concat(o,"Body")}),u?e("vxe-table-footer",{props:{footerData:f,tableColumn:r,fixedColumn:d,fixedType:o,size:s},ref:"".concat(o,"Footer")}):n()])}function renderEmptyContenet(e,t){var o=t.$scopedSlots,n=t.emptyOpts,i="",r={$table:t};if(o.empty)i=o.empty.call(t,r,e);else{var l=t.emptyRender?_vXETable.default.renderer.get(n.name):null;i=l?l.renderEmpty.call(t,e,n,r):t.emptyText||_conf.default.i18n("vxe.table.emptyText")}return i}function handleUupdateResize(e){var t=e.$el;t&&t.clientWidth&&t.clientHeight&&e.recalculate()}var _default2={name:"VxeTable",mixins:[_size.default],props:{id:String,data:Array,height:[Number,String],maxHeight:[Number,String],resizable:{type:Boolean,default:function(){return _conf.default.table.resizable}},stripe:{type:Boolean,default:function(){return _conf.default.table.stripe}},border:{type:[Boolean,String],default:function(){return _conf.default.table.border}},round:{type:Boolean,default:function(){return _conf.default.table.round}},size:{type:String,default:function(){return _conf.default.table.size||_conf.default.size}},fit:{type:Boolean,default:function(){return _conf.default.table.fit}},loading:Boolean,align:{type:String,default:function(){return _conf.default.table.align}},headerAlign:{type:String,default:function(){return _conf.default.table.headerAlign}},footerAlign:{type:String,default:function(){return _conf.default.table.footerAlign}},showHeader:{type:Boolean,default:function(){return _conf.default.table.showHeader}},highlightCurrentRow:{type:Boolean,default:function(){return _conf.default.table.highlightCurrentRow}},highlightHoverRow:{type:Boolean,default:function(){return _conf.default.table.highlightHoverRow}},highlightCurrentColumn:{type:Boolean,default:function(){return _conf.default.table.highlightCurrentColumn}},highlightHoverColumn:{type:Boolean,default:function(){return _conf.default.table.highlightHoverColumn}},highlightCell:Boolean,showFooter:Boolean,footerMethod:{type:Function,default:function(){return _conf.default.table.footerMethod}},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],mergeCells:Array,mergeFooterItems:Array,spanMethod:Function,footerSpanMethod:Function,showOverflow:{type:[Boolean,String],default:function(){return _conf.default.table.showOverflow}},showHeaderOverflow:{type:[Boolean,String],default:function(){return _conf.default.table.showHeaderOverflow}},showFooterOverflow:{type:[Boolean,String],default:function(){return _conf.default.table.showFooterOverflow}},columnKey:Boolean,rowKey:Boolean,rowId:{type:String,default:function(){return _conf.default.table.rowId}},zIndex:Number,emptyText:String,keepSource:{type:Boolean,default:function(){return _conf.default.table.keepSource}},autoResize:{type:Boolean,default:function(){return _conf.default.table.autoResize}},syncResize:[Boolean,String,Number],columnConfig:Object,seqConfig:Object,sortConfig:Object,filterConfig:Object,radioConfig:Object,checkboxConfig:Object,tooltipConfig:Object,exportConfig:[Boolean,Object],importConfig:[Boolean,Object],printConfig:Object,expandConfig:Object,treeConfig:[Boolean,Object],menuConfig:[Boolean,Object],contextMenu:[Boolean,Object],mouseConfig:Object,keyboardConfig:Object,clipConfig:Object,editConfig:[Boolean,Object],validConfig:Object,editRules:Object,emptyRender:[Boolean,Object],customConfig:[Boolean,Object],scrollX:Object,scrollY:Object,animat:{type:Boolean,default:function(){return _conf.default.table.animat}},delayHover:{type:Number,default:function(){return _conf.default.table.delayHover}},params:Object},components:{VxeTableBody:_body.default},provide:function(){return{$xetable:this,xecolgroup:null}},inject:{$xegrid:{default:null}},data:function(){return{tId:"".concat(_ctor.default.uniqueId()),staticColumns:[],tableGroupColumn:[],tableColumn:[],tableData:[],scrollXLoad:!1,scrollYLoad:!1,overflowY:!0,overflowX:!1,scrollbarWidth:0,scrollbarHeight:0,rowHeight:0,parentHeight:0,isGroup:!1,isAllSelected:!1,isIndeterminate:!1,selection:[],currentRow:null,currentColumn:null,selectRow:null,footerData:[],expandColumn:null,treeNodeColumn:null,rowExpandeds:[],expandLazyLoadeds:[],treeExpandeds:[],treeLazyLoadeds:[],treeIndeterminates:[],mergeList:[],mergeFooterList:[],initStore:{filter:!1,import:!1,export:!1},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:[],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:{inited:!1,file:null,type:"",modeList:[],typeList:[],filename:"",visible:!1},importParams:{mode:"",types:null,message:!0},exportStore:{inited:!1,name:"",modeList:[],typeList:[],columns:[],isPrint:!1,hasFooter:!1,hasMerge:!1,hasColgroup:!1,visible:!1},exportParams:{filename:"",sheetName:"",mode:"",type:"",isColgroup:!1,isMerge:!1,original:!1,message:!0,isHeader:!1,isFooter:!1}}},computed:{validOpts:function(){return Object.assign({message:"default"},_conf.default.table.validConfig,this.validConfig)},sXOpts:function(){return Object.assign({},_conf.default.table.scrollX,this.scrollX)},sYOpts:function(){return Object.assign({},_conf.default.table.scrollY,this.scrollY)},rowHeightMaps:function(){return{default:48,medium:44,small:40,mini:36}},columnOpts:function(){return Object.assign({},this.columnConfig)},seqOpts:function(){return Object.assign({startIndex:0},_conf.default.table.seqConfig,this.seqConfig)},radioOpts:function(){return Object.assign({},_conf.default.table.radioConfig,this.radioConfig)},checkboxOpts:function(){return Object.assign({},_conf.default.table.checkboxConfig,this.checkboxConfig)},tooltipOpts:function(){var e=Object.assign({leaveDelay:300},_conf.default.table.tooltipConfig,this.tooltipConfig);return e.enterable&&(e.leaveMethod=this.handleTooltipLeaveMethod),e},validTipOpts:function(){return Object.assign({isArrow:!1},this.tooltipOpts)},editOpts:function(){return Object.assign({},_conf.default.table.editConfig,this.editConfig)},sortOpts:function(){return Object.assign({orders:["asc","desc",null]},_conf.default.table.sortConfig,this.sortConfig)},filterOpts:function(){return Object.assign({},_conf.default.table.filterConfig,this.filterConfig)},mouseOpts:function(){return Object.assign({},_conf.default.table.mouseConfig,this.mouseConfig)},keyboardOpts:function(){return Object.assign({},this.keyboardConfig)},clipOpts:function(){return Object.assign({},this.clipConfig)},hasTip:function(){return _vXETable.default._tooltip},headerCtxMenu:function(){var e=this.ctxMenuOpts.header;return e&&e.options?e.options:[]},bodyCtxMenu:function(){var e=this.ctxMenuOpts.body;return e&&e.options?e.options:[]},footerCtxMenu:function(){var e=this.ctxMenuOpts.footer;return e&&e.options?e.options:[]},isCtxMenu:function(){return this.headerCtxMenu.length||this.bodyCtxMenu.length||this.footerCtxMenu.length},ctxMenuOpts:function(){return Object.assign({},_conf.default.table.menuConfig,this.contextMenu,this.menuConfig)},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.table.exportConfig,this.exportConfig)},importOpts:function(){return Object.assign({},_conf.default.table.importConfig,this.importConfig)},printOpts:function(){return Object.assign({},_conf.default.table.printConfig,this.printConfig)},expandOpts:function(){return Object.assign({},_conf.default.table.expandConfig,this.expandConfig)},treeOpts:function(){return Object.assign({},_conf.default.table.treeConfig,this.treeConfig)},emptyOpts:function(){return Object.assign({},_conf.default.table.emptyRender,this.emptyRender)},cellOffsetWidth:function(){return this.border?Math.max(2,Math.ceil(this.scrollbarWidth/this.tableColumn.length)):1},customOpts:function(){return Object.assign({},_conf.default.table.customConfig,this.customConfig)},tableBorder:function(){var e=this.border;return!0===e?"full":e||"default"},isAllCheckboxDisabled:function(){var e=this.tableFullData,t=(this.treeConfig,this.checkboxOpts),o=t.strict,n=t.checkMethod;return!!o&&(!e.length||!!n&&e.every(function(e){return!n({row:e})}))}},watch:{data:function(e){var t=this;this.loadTableData(e).then(function(){t.inited||(t.inited=!0,t.handleDefaults()),(t.scrollXLoad||t.scrollYLoad)&&t.expandColumn&&_tools.UtilTools.warn("vxe.error.scrollErrProp",["column.type=expand"])})},staticColumns:function(e){this.handleColumn(e)},tableColumn:function(){this.analyColumnWidth()},showHeader:function(){var e=this;this.$nextTick(function(){e.recalculate(!0).then(function(){return e.refreshScroll()})})},showFooter:function(){var e=this;this.$nextTick(function(){e.recalculate(!0).then(function(){return e.refreshScroll()})})},height:function(){var e=this;this.$nextTick(function(){return e.recalculate(!0)})},maxHeight:function(){var e=this;this.$nextTick(function(){return e.recalculate(!0)})},syncResize:function(e){var t=this;e&&(handleUupdateResize(this),this.$nextTick(function(){handleUupdateResize(t),setTimeout(function(){return handleUupdateResize(t)})}))}},created:function(){var e=this,t=Object.assign(this,{tZindex:0,elemStore:{},scrollXStore:{},scrollYStore:{},tooltipStore:{},tableWidth:0,tableHeight:0,headerHeight:0,footerHeight:0,lastScrollLeft:0,lastScrollTop:0,radioReserveRow:null,checkboxReserveRowMap:{},rowExpandedReserveRowMap:{},treeExpandedReserveRowMap:{},tableFullData:[],afterFullData:[],collectColumn:[],tableFullColumn:[],visibleColumn:[],fullAllDataRowMap:new Map,fullAllDataRowIdData:{},fullDataRowMap:new Map,fullDataRowIdData:{},fullColumnMap:new Map,fullColumnIdData:{},fullColumnFieldData:{}}),o=t.scrollXStore,n=t.sYOpts,i=t.scrollYStore,r=t.data,l=t.editOpts,s=t.treeOpts,a=t.treeConfig,u=t.showOverflow;if("development"===process.env.VUE_APP_VXE_TABLE_ENV){!this.rowId&&(this.checkboxOpts.reserve||this.checkboxOpts.checkRowKeys||this.radioOpts.reserve||this.radioOpts.checkRowKey||this.expandOpts.expandRowKeys||this.treeOpts.expandRowKeys)&&_tools.UtilTools.warn("vxe.error.reqProp",["row-id"]),this.editConfig&&l.showStatus&&!this.keepSource&&_tools.UtilTools.warn("vxe.error.reqProp",["keep-source"]),!a||!s.line||this.rowKey&&u||_tools.UtilTools.warn("vxe.error.reqProp",["row-key | show-overflow"]),a&&this.stripe&&_tools.UtilTools.warn("vxe.error.noTree",["stripe"]);var c=this.exportConfig,f=this.exportOpts,d=this.importConfig,h=this.importOpts;d&&h.types&&!_ctor.default.includeArrays(_vXETable.default.importTypes,h.types)&&_tools.UtilTools.warn("vxe.error.errProp",["export-config.types=".concat(h.types.join(",")),h.types.filter(function(e){return _ctor.default.includes(_vXETable.default.importTypes,e)}).join(",")||_vXETable.default.importTypes.join(",")]),c&&f.types&&!_ctor.default.includeArrays(_vXETable.default.exportTypes,f.types)&&_tools.UtilTools.warn("vxe.error.errProp",["export-config.types=".concat(f.types.join(",")),f.types.filter(function(e){return _ctor.default.includes(_vXETable.default.exportTypes,e)}).join(",")||_vXETable.default.exportTypes.join(",")])}var p=this.customOpts;if(!this.id&&this.customConfig&&(!0===p.storage||p.storage&&p.storage.resizable||p.storage&&p.storage.visible)&&_tools.UtilTools.error("vxe.error.reqProp",["id"]),this.treeConfig&&this.checkboxOpts.range&&_tools.UtilTools.error("vxe.error.noTree",["checkbox-config.range"]),"development"===process.env.VUE_APP_VXE_TABLE_ENV){if(this.mouseOpts.area&&!this.handleUpdateCellAreas)return void console.error('[vxe-table] This feature requires use the "vxe-table.pro"');this.treeConfig&&this.mouseOpts.area&&_tools.UtilTools.error("vxe.error.noTree",["mouse-config.area"])}"development"===process.env.VUE_APP_VXE_TABLE_ENV&&(this.contextMenu&&(_tools.UtilTools.warn("vxe.error.delProp",["context-menu","menu-config"]),_ctor.default.isObject(this.contextMenu)||_tools.UtilTools.warn("vxe.error.errProp",["table.context-menu=".concat(this.contextMenu),"table.context-menu={}"])),this.menuConfig&&!_ctor.default.isObject(this.menuConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.menu-config=".concat(this.menuConfig),"table.menu-config={}"]),this.exportConfig&&!_ctor.default.isObject(this.exportConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.export-config=".concat(this.exportConfig),"table.export-config={}"]),this.importConfig&&!_ctor.default.isObject(this.importConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.import-config=".concat(this.importConfig),"table.import-config={}"]),this.printConfig&&!_ctor.default.isObject(this.printConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.print-config=".concat(this.printConfig),"table.print-config={}"]),this.treeConfig&&!_ctor.default.isObject(this.treeConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.tree-config=".concat(this.treeConfig),"table.tree-config={}"]),this.customConfig&&!_ctor.default.isObject(this.customConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.custom-config=".concat(this.customConfig),"table.custom-config={}"]),this.editConfig&&!_ctor.default.isObject(this.editConfig)&&_tools.UtilTools.warn("vxe.error.errProp",["table.edit-config=".concat(this.editConfig),"table.edit-config={}"]),this.emptyRender&&!_ctor.default.isObject(this.emptyRender)&&_tools.UtilTools.warn("vxe.error.errProp",["table.empty-render=".concat(this.emptyRender),"table.empty-render={}"])),"development"===process.env.VUE_APP_VXE_TABLE_ENV&&(this.editConfig&&!this._insert&&_tools.UtilTools.error("vxe.error.reqModule",["Edit"]),this.editRules&&!this._validate&&_tools.UtilTools.error("vxe.error.reqModule",["Validator"]),!this.keyboardConfig&&!this.mouseConfig||this.triggerCellMousedownEvent||_tools.UtilTools.error("vxe.error.reqModule",["Keyboard"]),(this.printConfig||this.importConfig||this.exportConfig)&&!this._exportData&&_tools.UtilTools.error("vxe.error.reqModule",["Export"])),Object.assign(i,{startIndex:0,endIndex:0,visibleSize:0,adaptive:!1!==n.adaptive}),Object.assign(o,{startIndex:0,endIndex:0,visibleSize:0}),this.loadTableData(r).then(function(){r&&r.length&&(e.inited=!0,e.handleDefaults()),e.updateStyle()}),_tools.GlobalEvent.on(this,"paste",this.handleGlobalPasteEvent),_tools.GlobalEvent.on(this,"copy",this.handleGlobalCopyEvent),_tools.GlobalEvent.on(this,"cut",this.handleGlobalCutEvent),_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")},mounted:function(){var e=this;if(this.autoResize){var t=(0,_tools.createResizeEvent)(function(){return e.recalculate(!0)});t.observe(this.$el),t.observe(this.getParentElem()),this.$resize=t}this.preventEvent(null,"mounted")},activated:function(){var e=this;this.recalculate().then(function(){return e.refreshScroll()}),this.preventEvent(null,"activated")},deactivated:function(){this.preventEvent(null,"deactivated")},beforeDestroy:function(){this.$resize&&this.$resize.disconnect(),this.closeFilter(),this.closeMenu(),this.preventEvent(null,"beforeDestroy")},destroyed:function(){_tools.GlobalEvent.off(this,"paste"),_tools.GlobalEvent.off(this,"copy"),_tools.GlobalEvent.off(this,"cut"),_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")},render:function(e){var t=this._e,o=this.tId,n=this.tableData,i=this.tableColumn,r=this.tableGroupColumn,l=this.isGroup,s=this.loading,a=this.stripe,u=this.showHeader,c=this.height,f=this.tableBorder,d=this.treeOpts,h=this.treeConfig,p=this.mouseConfig,b=this.mouseOpts,g=this.vSize,v=this.validOpts,m=this.showFooter,x=this.overflowX,C=this.overflowY,_=this.scrollXLoad,y=this.scrollYLoad,O=this.scrollbarHeight,w=this.highlightCell,j=this.highlightHoverRow,E=this.highlightHoverColumn,T=this.editConfig,S=this.validTipOpts,M=this.tooltipOpts,R=this.initStore,z=this.columnStore,B=this.filterStore,D=this.ctxMenuStore,L=this.ctxMenuOpts,F=this.footerData,G=this.hasTip,P=z.leftList,k=z.rightList;return e("div",{class:["vxe-table","tid_".concat(o),g?"size--".concat(g):"","border--".concat(f),{"vxe-editable":!!T,"show--head":u,"show--foot":m,"is--group":l,"has--height":c,"has--tree-line":h&&d.line,"fixed--left":P.length,"fixed--right":k.length,"c--highlight":w,"t--animat":!!this.animat,"is--round":this.round,"t--stripe":!h&&a,"t--selected":p&&b.selected,"is--area":p&&b.area,"row--highlight":j,"column--highlight":E,"is--loading":s,"is--empty":!s&&!n.length,"scroll--y":C,"scroll--x":x,"virtual--x":_,"virtual--y":y}]},[e("div",{class:"vxe-table-slots",ref:"hideColumn"},this.$slots.default),e("div",{class:"vxe-table--main-wrapper"},[u?e("vxe-table-header",{ref:"tableHeader",props:{tableData:n,tableColumn:i,tableGroupColumn:r,size:g}}):t(),e("vxe-table-body",{ref:"tableBody",props:{tableData:n,tableColumn:i,size:g}}),m?e("vxe-table-footer",{ref:"tableFooter",props:{footerData:F,tableColumn:i,size:g}}):t()]),e("div",{class:"vxe-table--fixed-wrapper"},[P&&P.length&&x?renderFixed(e,this,"left"):t(),k&&k.length&&x?renderFixed(e,this,"right"):t()]),e("div",{ref:"emptyPlaceholder",class:"vxe-table--empty-placeholder"},[e("div",{class:"vxe-table--empty-content"},renderEmptyContenet(e,this))]),e("div",{class:"vxe-table--border-line"}),e("div",{class:"vxe-table--resizable-bar",style:x?{"padding-bottom":"".concat(O,"px")}:null,ref:"resizeBar"}),e("div",{class:["vxe-table--loading vxe-loading",{"is--visible":s}]},[e("div",{class:"vxe-loading--spinner"})]),R.filter?e("vxe-table-filter",{ref:"filterWrapper",props:{filterStore:B}}):t(),R.import&&this.importConfig?e("vxe-import-panel",{props:{defaultOptions:this.importParams,storeData:this.importStore}}):t(),R.export&&(this.exportConfig||this.printConfig)?e("vxe-export-panel",{props:{defaultOptions:this.exportParams,storeData:this.exportStore}}):t(),D.visible&&this.isCtxMenu?e("vxe-table-context-menu",{ref:"ctxWrapper",props:{ctxMenuStore:D,ctxMenuOpts:L}}):t(),G?e("vxe-tooltip",{key:"mTip",ref:"tooltip",props:M}):t(),G&&this.editRules&&("default"===v.message?!c:"tooltip"===v.message)?e("vxe-tooltip",{key:"vTip",ref:"validTip",class:"vxe-table--valid-error",props:"tooltip"===v.message||1===n.length?S:null}):t()])},methods:_methods.default};exports.default=_default2;