kpmg-smart-table
Version:
2 lines • 37.4 kB
JavaScript
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["smart-table-vue"]=t():e["smart-table-vue"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function a(i){if(t[i])return t[i].exports;var r=t[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,a),r.l=!0,r.exports}return a.m=e,a.c=t,a.d=function(e,t,i){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},a.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(a.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)a.d(i,r,function(t){return e[t]}.bind(null,r));return i},a.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s="fb15")}({5100:function(e,t,a){"use strict";a("cc6a")},"9d96":function(e,t,a){},b282:function(e,t,a){},bbde:function(e,t,a){"use strict";a("b282")},c4e3:function(e,t,a){"use strict";a("9d96")},cc6a:function(e,t,a){},fb15:function(e,t,a){"use strict";a.r(t),a.d(t,"install",(function(){return B})),a.d(t,"SmartTable",(function(){return O})),a.d(t,"SmartPagination",(function(){return S})),a.d(t,"SmartQuery",(function(){return k})),a.d(t,"performance",(function(){return i}));var i={};if(a.r(i),a.d(i,"debounce",(function(){return o})),a.d(i,"throttle",(function(){return u})),a.d(i,"memoize",(function(){return c})),a.d(i,"rafThrottle",(function(){return d})),a.d(i,"calcTextWidth",(function(){return h})),a.d(i,"flexColumnWidth",(function(){return p})),"undefined"!==typeof window){var r=window.document.currentScript,n=r&&r.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);n&&(a.p=n[1])}var l=function(){var e=this,t=e._self._c;return t("div",{staticClass:"smart-table-container",class:{"is-loading":e.loading}},[e.showToolbar?t("div",{staticClass:"smart-table-toolbar"},[e._t("toolbar",(function(){return[e.title?t("div",{staticClass:"smart-table-toolbar__title"},[e._v(e._s(e.title))]):e._e(),t("div",{staticClass:"smart-table-toolbar__actions"},[e._t("toolbar-actions")],2)]}))],2):e._e(),t("div",{ref:"tableWrapper",staticClass:"smart-table-wrapper",style:{height:e.realTableHeight}},[t("el-table",e._b({directives:[{name:"loading",rawName:"v-loading",value:e.loading,expression:"loading"}],ref:"elTable",attrs:{data:e.enableVirtualScroll?e.visibleData:e.tableData,height:e.realTableHeight},on:{"sort-change":e.handleSortChange,"selection-change":e.handleSelectionChange,"row-click":e.handleRowClick}},"el-table",e.tableProps,!1),[e.showSelection?t("el-table-column",{attrs:{type:"selection",width:"50",fixed:"left",align:"center",selectable:e.selectable}}):e._e(),e.showIndex?t("el-table-column",{attrs:{type:"index",width:"60",fixed:"left",align:"center",label:e.indexLabel,index:e.customIndex}}):e._e(),e._l(e.normalizedColumns,(function(a,i){return[e._t("column-"+a.prop,(function(){return[a.children&&a.children.length?t("el-table-column",{key:"group-"+(a.prop||i),attrs:{label:a.label,align:a.align}},[e._l(a.children,(function(a,i){return[t("el-table-column",e._b({scopedSlots:e._u([{key:"default",fn:function(i){return[e._t("content-"+a.prop,(function(){return[t("cell-renderer",{attrs:{column:a,row:i.row,value:i.row[a.prop],index:i.$index}})]}),null,{...i,column:a})]}}],null,!0)},"el-table-column",e.getColumnProps(a),!1))]}))],2):t("el-table-column",e._b({key:"col-"+(a.prop||i),scopedSlots:e._u([e.$scopedSlots["header-"+a.prop]?{key:"header",fn:function(t){return[e._t("header-"+a.prop,null,null,t)]}}:null,{key:"default",fn:function(i){return[e._t("content-"+a.prop,(function(){return[t("cell-renderer",{attrs:{column:a,row:i.row,value:i.row[a.prop],index:i.$index}})]}),null,{...i,column:a})]}}],null,!0)},"el-table-column",e.getColumnProps(a),!1))]}),{column:a})]})),e.$slots["action-column"]||e.$scopedSlots["action-column"]?t("el-table-column",{attrs:{label:e.actionColumnLabel,width:e.actionColumnWidth,fixed:e.actionColumnFixed,align:e.actionColumnAlign},scopedSlots:e._u([{key:"default",fn:function(t){return[e._t("action-column",null,null,t)]}}],null,!0)}):e._e(),e.$slots.expand||e.$scopedSlots.expand?[t("el-table-column",{attrs:{type:"expand"},scopedSlots:e._u([{key:"default",fn:function(t){return[e._t("expand",null,null,t)]}}],null,!0)})]:e._e()],2),!e.showEmptyPlaceholder||e.tableData.length||e.loading?e._e():t("div",{staticClass:"smart-table-empty"},[e._t("empty",(function(){return[t("div",{staticClass:"smart-table-empty__content"},[t("i",{staticClass:"el-icon-document"}),t("p",[e._v(e._s(e.emptyText))])])]}))],2),e.enableVirtualScroll&&e.tableData.length?t("div",{staticClass:"smart-table-virtual-placeholder",style:{height:e.virtualPlaceholderHeight+"px"}}):e._e()],1),e.showPagination&&e.total>0?t("div",{staticClass:"smart-table-pagination"},[e._t("pagination",(function(){return[t("smart-pagination",{attrs:{"current-page":e.currentPage,"page-size":e.pageSize,total:e.total,"page-sizes":e.pageSizes,layout:e.paginationLayout},on:{"update:currentPage":function(t){e.currentPage=t},"update:current-page":function(t){e.currentPage=t},"update:pageSize":function(t){e.pageSize=t},"update:page-size":function(t){e.pageSize=t},"size-change":e.handleSizeChange,"current-change":e.handleCurrentChange}})]}))],2):e._e()])},s=[];function o(e,t=300){let a=null;return function(...i){a&&clearTimeout(a),a=setTimeout(()=>{e.apply(this,i),a=null},t)}}function u(e,t=300){let a=0,i=null;return function(...r){const n=Date.now(),l=t-(n-a);l<=0||l>t?(i&&(clearTimeout(i),i=null),a=n,e.apply(this,r)):i||(i=setTimeout(()=>{a=Date.now(),i=null,e.apply(this,r)},l))}}function c(e){const t=new Map;return function(...a){const i=JSON.stringify(a);if(t.has(i))return t.get(i);const r=e.apply(this,a);return t.set(i,r),r}}function d(e){let t=!1;return function(...a){t||(t=!0,window.requestAnimationFrame(()=>{e.apply(this,a),t=!1}))}}function h(e){if(!e)return 0;let t=0;for(let a=0;a<e.length;a++){const i=e.charCodeAt(a);t+=i>=19968&&i<=40869?18:10}return t}function p(e,t=[],a="",i=80,r=250){const n=h(a)+30;if(!e||!t||!t.length)return Math.max(i,n);let l=0;for(let o=0;o<t.length;o++){const a=t[o],i=a[e];if(void 0!==i&&null!==i){const e=i.toString(),t=h(e)+30;l=Math.max(l,t)}}const s=Math.max(n,l);return Math.min(r,Math.max(i,s))}var m=function(){var e=this,t=e._self._c;return t("div",{staticClass:"smart-pagination"},[t("el-pagination",e._b({attrs:{"current-page":e.currentPage,"page-size":e.pageSize,total:e.total,"page-sizes":e.pageSizes,layout:e.layout},on:{"size-change":e.handleSizeChange,"current-change":e.handleCurrentChange,"prev-click":e.handlePrevClick,"next-click":e.handleNextClick},scopedSlots:e._u([e._l(e.$slots,(function(t,a){return{key:a,fn:function(t){return[e._t(a,null,null,t)]}}}))],null,!0)},"el-pagination",e.paginationProps,!1)),e.showQuickJumper?t("div",{staticClass:"smart-pagination__jumper"},[t("span",[e._v("跳至")]),t("el-input",{staticClass:"smart-pagination__jumper-input",attrs:{size:"mini"},nativeOn:{keyup:function(t){return!t.type.indexOf("key")&&e._k(t.keyCode,"enter",13,t.key,"Enter")?null:e.handleJumpTo.apply(null,arguments)}},model:{value:e.jumpPage,callback:function(t){e.jumpPage=e._n(t)},expression:"jumpPage"}}),t("span",[e._v("页")])],1):e._e(),e.showSizeChanger&&!e.layout.includes("sizes")?t("div",{staticClass:"smart-pagination__sizer"},[t("el-select",{attrs:{size:"mini"},on:{change:e.handleSizeChange},model:{value:e.internalPageSize,callback:function(t){e.internalPageSize=t},expression:"internalPageSize"}},e._l(e.pageSizes,(function(e){return t("el-option",{key:e,attrs:{label:e+"条/页",value:e}})})),1)],1):e._e()],1)},f=[],g={name:"SmartPagination",props:{currentPage:{type:Number,default:1},pageSize:{type:Number,default:20},total:{type:Number,default:0},pageSizes:{type:Array,default:()=>[10,20,50,100,200]},layout:{type:String,default:"total, sizes, prev, pager, next, jumper"},showQuickJumper:{type:Boolean,default:!1},showSizeChanger:{type:Boolean,default:!0},showTotal:{type:Boolean,default:!0},paginationProps:{type:Object,default:()=>({})},small:{type:Boolean,default:!1},background:{type:Boolean,default:!0},disabled:{type:Boolean,default:!1},pagerCount:{type:Number,default:7}},data(){return{internalCurrentPage:this.currentPage,internalPageSize:this.pageSize,jumpPage:this.currentPage}},watch:{currentPage(e){this.internalCurrentPage=e,this.jumpPage=e},pageSize(e){this.internalPageSize=e},internalCurrentPage(e){this.$emit("update:currentPage",e)},internalPageSize(e){this.$emit("update:pageSize",e)}},methods:{handleCurrentChange(e){this.internalCurrentPage=e,this.jumpPage=e,this.$emit("current-change",e)},handleSizeChange(e){this.internalPageSize=e;const t=Math.ceil(this.total/e)||1;this.internalCurrentPage>t&&this.handleCurrentChange(t),this.$emit("size-change",e)},handlePrevClick(e){this.$emit("prev-click",e)},handleNextClick(e){this.$emit("next-click",e)},handleJumpTo(){if(!this.jumpPage||isNaN(this.jumpPage))return void(this.jumpPage=this.internalCurrentPage);let e=this.jumpPage;if(e<1)e=1;else{const t=Math.ceil(this.total/this.internalPageSize)||1;e>t&&(e=t)}e!==this.internalCurrentPage&&this.handleCurrentChange(e),this.jumpPage=e}}},y=g;a("5100");function b(e,t,a,i,r,n,l,s){var o,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=a,u._compiled=!0),i&&(u.functional=!0),n&&(u._scopeId="data-v-"+n),l?(o=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),r&&r.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(l)},u._ssrRegister=o):r&&(o=s?function(){r.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:r),o)if(u.functional){u._injectStyles=o;var c=u.render;u.render=function(e,t){return o.call(t),c(e,t)}}else{var d=u.beforeCreate;u.beforeCreate=d?[].concat(d,o):[o]}return{exports:e,options:u}}var v=b(y,m,f,!1,null,"dab337fa",null),C=v.exports;C.install=function(e){e.component(C.name,C)};var S=C,_=function(){var e=this,t=e._self._c;return t(e.renderComponent,e._b({tag:"component",scopedSlots:e._u([e._l(e.$slots,(function(t,a){return{key:a,fn:function(t){return[e._t(a,null,null,t)]}}}))],null,!0)},"component",e.componentProps,!1))},T=[],D={name:"CellRenderer",props:{column:{type:Object,required:!0},row:{type:Object,required:!0},value:{type:[String,Number,Boolean,Array,Object,Date],default:null},index:{type:Number,default:0}},computed:{renderComponent(){const{renderType:e}=this.column;if(this.column.renderComponent)return this.column.renderComponent;if(!e)return"span";switch(e){case"link":return"el-link";case"tag":return"el-tag";case"image":return"el-image";case"button":return"el-button";case"switch":return"el-switch";case"progress":return"el-progress";default:return"span"}},componentProps(){const{renderType:e,renderProps:t={}}=this.column;if(this.column.renderComponentProps)return"function"===typeof this.column.renderComponentProps?this.column.renderComponentProps({row:this.row,value:this.value,index:this.index}):this.column.renderComponentProps;const a={innerHTML:this.formattedValue};switch(e){case"link":return{type:"primary",underline:!1,...t,...a};case"tag":return{type:this.getTagType(this.value),size:"small",effect:"light",...t,...a};case"image":return{src:this.value,fit:"cover","preview-src-list":[this.value],style:{width:"50px",height:"50px"},...t};case"button":return{type:"text",size:"small",...t,...a};case"switch":return{value:Boolean(this.value),disabled:!0,...t};case"progress":return{percentage:Number(this.value)||0,...t};default:return a}},formattedValue(){if(this.column.formatter&&"function"===typeof this.column.formatter)return this.column.formatter(this.row,this.column,this.value,this.index);const e=this.column.dataType||this.inferDataType();switch(e){case"number":case"NUMBER":return this.formatNumber(this.value);case"date":case"DATE":return this.formatDate(this.value);case"boolean":case"BOOLEAN":return this.formatBoolean(this.value);default:return void 0===this.value||null===this.value?"-":String(this.value)}}},methods:{getTagType(e){if(this.column.tagMap&&this.column.tagMap[e])return this.column.tagMap[e];if("string"===typeof e){if(/success|passed|完成|成功|有效|正常|active|活跃|启用|是/.test(e))return"success";if(/warning|警告|注意|pending|等待|wait/.test(e))return"warning";if(/danger|error|failed|失败|无效|异常|disabled|禁用|否/.test(e))return"danger";if(/info|信息|primary|主要/.test(e))return"info"}return""},inferDataType(){const{prop:e}=this.column;if(!e)return"string";const t=this.value;return"number"===typeof t?"number":t instanceof Date?"date":"boolean"===typeof t?"boolean":/id$/i.test(e)||/amount/i.test(e)||/price/i.test(e)||/count/i.test(e)?"number":/date/i.test(e)||/time/i.test(e)||/created/i.test(e)||/updated/i.test(e)?"date":/is[A-Z]/i.test(e)||/enable/i.test(e)||/status/i.test(e)?"boolean":"string"},formatNumber(e,t){return void 0===e||null===e||""===e?"-":(t=t||this.column.precision||0,"number"!==typeof e&&(e=parseFloat(e),isNaN(e))?"-":t?e.toFixed(t):e.toString())},formatDate(e){if(!e)return"-";this.column.dateFormat;const t=new Date(e);return isNaN(t.getTime())?e:t.toLocaleDateString()},formatBoolean(e){return void 0===e||null===e?"-":this.column.booleanMap&&this.column.booleanMap[e?"true":"false"]||(e?"是":"否")}}},N=D,w=b(N,_,T,!1,null,null,null),x=w.exports,P={name:"SmartTable",components:{SmartPagination:S,CellRenderer:x},props:{columns:{type:Array,required:!0,default:()=>[]},data:{type:Array,default:()=>[]},height:{type:[String,Number],default:null},maxHeight:{type:[String,Number],default:null},autoHeight:{type:Boolean,default:!1},title:{type:String,default:""},showToolbar:{type:Boolean,default:!0},loading:{type:Boolean,default:!1},showSelection:{type:Boolean,default:!1},showIndex:{type:Boolean,default:!0},selectable:{type:Function,default:null},showPagination:{type:Boolean,default:!0},showEmptyPlaceholder:{type:Boolean,default:!0},total:{type:Number,default:0},currentPage:{type:Number,default:1},pageSize:{type:Number,default:20},pageSizes:{type:Array,default:()=>[10,20,50,100,200]},paginationLayout:{type:String,default:"total, sizes, prev, pager, next, jumper"},indexMethod:{type:Function,default:null},indexLabel:{type:String,default:"序号"},actionColumnLabel:{type:String,default:"操作"},actionColumnWidth:{type:[String,Number],default:150},actionColumnFixed:{type:String,default:"right"},actionColumnAlign:{type:String,default:"center"},emptyText:{type:String,default:"暂无数据"},tableProps:{type:Object,default:()=>({border:!0,stripe:!0,highlightCurrentRow:!0,headerCellStyle:{background:"#F5F7FA",color:"#333"}})},remote:{type:Boolean,default:!1},loadMethod:{type:Function,default:null},autoColumnWidth:{type:Boolean,default:!0},defaultColumnWidth:{type:[String,Number],default:100},rowClassName:{type:[String,Function],default:null},rowKey:{type:[String,Function],default:"id"},enableVirtualScroll:{type:Boolean,default:!1},rowHeight:{type:Number,default:40},bufferSize:{type:Number,default:10},virtualScrollThreshold:{type:Number,default:100}},data(){return{tableData:[],calculatedHeight:null,selectedRows:[],tableSort:{prop:"",order:""},internalCurrentPage:this.currentPage,internalPageSize:this.pageSize,resizeObserver:null,visibleData:[],startIndex:0,endIndex:0,scrollTop:0,visibleCount:0,bodyWrapperEl:null,isScrolling:!1,scrollingTimer:null,_visibleDataCache:null,_columnPropsCache:null,_numberFormatCache:null,_dateFormatCache:null}},computed:{normalizedColumns(){const e=new Map;return this.columns.map(t=>{const a=`${t.prop}-${t.align}-${t.width}`;if(e.has(a))return e.get(a);const i={...t,align:t.align||this.getDefaultAlign(t),width:this.getColumnWidth(t),formatter:t.formatter||this.getDefaultFormatter(t),dataType:this.inferDataType(t)};return e.set(a,i),i})},realTableHeight(){return this.calculatedHeight&&this.autoHeight?this.calculatedHeight+"px":this.height?"number"===typeof this.height?this.height+"px":this.height:null},shouldUseVirtualScroll(){return this.enableVirtualScroll&&this.tableData.length>this.virtualScrollThreshold},virtualPlaceholderHeight(){return this.tableData.length*this.rowHeight},visibleData(){if(!this.shouldUseVirtualScroll)return this.tableData;const e=this._visibleDataCache||(this._visibleDataCache=new Map),t=`${this.startIndex}-${this.endIndex}`;if(e.has(t))return e.get(t);const a=this.tableData.slice(this.startIndex,this.endIndex);if(e.set(t,a),e.size>100){const t=e.keys().next().value;e.delete(t)}return a}},watch:{data:{handler(e){this.tableData=[...e],this.$nextTick(()=>{this.updateTableLayout(),this.calculateAutoHeight(),this.shouldUseVirtualScroll&&this.initVirtualScroll(),this._visibleDataCache=new Map,this.getColumnWidth.cache.clear()})},deep:!1},startIndex(){this.shouldUseVirtualScroll&&(this._visibleDataCache=new Map)},endIndex(){this.shouldUseVirtualScroll&&(this._visibleDataCache=new Map)},currentPage(e){this.internalCurrentPage=e,this.handlePageChange()},pageSize(e){this.internalPageSize=e,this.handlePageChange()},internalCurrentPage(e){this.$emit("update:currentPage",e)},internalPageSize(e){this.$emit("update:pageSize",e)}},created(){this.memoizedGetColumnWidth=c(this.getColumnWidth),this.memoizedFormatNumber=c(this.formatNumber),this.memoizedFormatDate=c(this.formatDate),this.memoizedInferDataType=c(this.inferDataType)},mounted(){this.init(),this.addWindowResizeListener(),this.setupResizeObserver(),this.remote&&this.loadMethod&&this.loadRemoteData()},beforeDestroy(){this.clearCache(),this.removeWindowResizeListener(),this.destroyResizeObserver(),this.cleanupVirtualScroll()},methods:{init(){this.calculateAutoHeight(),this.updateTableLayout()},setupResizeObserver(){"undefined"!==typeof ResizeObserver&&this.autoHeight&&(this.resizeObserver=new ResizeObserver(u(()=>{this.calculateAutoHeight(),this.shouldUseVirtualScroll&&(this.updateVisibleCount(),this.updateVisibleData())},200)),this.resizeObserver.observe(this.$el))},destroyResizeObserver(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)},addWindowResizeListener(){this.autoHeight&&window.addEventListener("resize",this.handleWindowResize)},removeWindowResizeListener(){window.removeEventListener("resize",this.handleWindowResize)},handleWindowResize:u((function(){this.calculateAutoHeight(),this.updateTableLayout(),this.shouldUseVirtualScroll&&(this.updateVisibleCount(),this.updateVisibleData())}),200),calculateAutoHeight(){this.autoHeight&&this.$el&&this.$nextTick(()=>{const{top:e}=this.$el.getBoundingClientRect(),t=this.showPagination?50:0,a=this.showToolbar?this.$el.querySelector(".smart-table-toolbar"):null,i=a?a.offsetHeight:0,r=window.innerHeight-e-t-i-20;this.calculatedHeight=Math.max(300,r)})},updateTableLayout(){this.$nextTick(()=>{this.$refs.elTable&&this.$refs.elTable.doLayout()})},getColumnProps(e){const t=`${e.prop}-${e.width}-${e.align}`;if(this._columnPropsCache&&this._columnPropsCache.has(t))return this._columnPropsCache.get(t);const a={prop:e.prop,label:e.label,width:this.getColumnWidth(e),minWidth:e.minWidth,align:e.align,headerAlign:e.headerAlign||e.align,fixed:e.fixed,sortable:e.sortable,showOverflowTooltip:!1!==e.showOverflowTooltip,formatter:e.formatter};return this._columnPropsCache||(this._columnPropsCache=new Map),this._columnPropsCache.set(t,a),a},getDefaultAlign(e){const t=e.dataType||this.inferDataType(e);switch(t){case"number":case"NUMBER":return"right";case"date":case"DATE":case"boolean":case"BOOLEAN":return"center";default:return"left"}},inferDataType(e){const t=e.prop;return t?/id$/i.test(t)||/amount/i.test(t)||/price/i.test(t)||/count/i.test(t)?"number":/date/i.test(t)||/time/i.test(t)||/created/i.test(t)||/updated/i.test(t)?"date":/is[A-Z]/i.test(t)||/enable/i.test(t)||/status/i.test(t)?"boolean":"string":"string"},getDefaultFormatter(e){if(e.formatter)return e.formatter;const t=e.dataType||this.inferDataType(e);switch(t){case"number":case"NUMBER":return(e,t,a)=>void 0===a||null===a||""===a?"-":this.formatNumber(a,t.precision);case"date":case"DATE":return(e,t,a)=>a?this.formatDate(a,t.dateFormat||"YYYY-MM-DD"):"-";case"boolean":case"BOOLEAN":return(e,t,a)=>void 0===a||null===a?"-":a?"是":"否";default:return(e,t,a)=>void 0===a||null===a||""===a?"-":a}},formatNumber(e,t=2){const a=`${e}-${t}`;if(this._numberFormatCache&&this._numberFormatCache.has(a))return this._numberFormatCache.get(a);let i;this._numberFormatCache||(this._numberFormatCache=new Map);try{i=Number(e).toFixed(t)}catch(r){i=e}return this._numberFormatCache.set(a,i),i},formatDate(e,t="YYYY-MM-DD"){const a=`${e}-${t}`;if(this._dateFormatCache&&this._dateFormatCache.has(a))return this._dateFormatCache.get(a);let i;this._dateFormatCache||(this._dateFormatCache=new Map);try{i=this.$moment(e).format(t)}catch(r){i=e}return this._dateFormatCache.set(a,i),i},getColumnWidth(e){if(e.width)return e.width;const t=e.label?e.label.length:0,a=Math.max(80,15*t);return e.minWidth||a},customIndex(e){return this.indexMethod?this.indexMethod(e):this.shouldUseVirtualScroll?(this.internalCurrentPage-1)*this.internalPageSize+this.startIndex+e+1:(this.internalCurrentPage-1)*this.internalPageSize+e+1},handleSortChange({column:e,prop:t,order:a}){this.tableSort={prop:t,order:a},this.$emit("sort-change",{prop:t,order:a}),this.remote&&this.loadMethod&&this.loadRemoteData()},handleSelectionChange(e){this.selectedRows=e,this.$emit("selection-change",e)},handleRowClick(e,t,a){this.$emit("row-click",e,t,a)},handleCurrentChange(e){this.internalCurrentPage=e,this.$emit("current-change",e),this.remote&&this.loadMethod&&this.loadRemoteData(),this.shouldUseVirtualScroll&&this.resetScroll()},handleSizeChange(e){this.internalPageSize=e,this.$emit("size-change",e),this.remote&&this.loadMethod&&this.loadRemoteData(),this.shouldUseVirtualScroll&&this.resetScroll()},handlePageChange(){this.$emit("page-change",{page:this.internalCurrentPage,size:this.internalPageSize})},loadRemoteData(){if(!this.loadMethod)return;const e={page:this.internalCurrentPage,size:this.internalPageSize,sort:this.tableSort.prop,order:this.tableSort.order};this.loadMethod(e)},initVirtualScroll(){this.$nextTick(()=>{this.$refs.elTable&&(this.bodyWrapperEl=this.$refs.elTable.$el.querySelector(".el-table__body-wrapper"),this.bodyWrapperEl&&(this.updateVisibleCount(),this.bodyWrapperEl.addEventListener("scroll",this.handleVirtualScroll),this.updateVisibleData()))})},cleanupVirtualScroll(){this.bodyWrapperEl&&this.bodyWrapperEl.removeEventListener("scroll",this.handleVirtualScroll),this.scrollingTimer&&(clearTimeout(this.scrollingTimer),this.scrollingTimer=null)},handleVirtualScroll:u((function(e){this.bodyWrapperEl&&(this.isScrolling=!0,this.scrollTop=this.bodyWrapperEl.scrollTop,this.updateVisibleData(),this.scrollingTimer&&clearTimeout(this.scrollingTimer),this.scrollingTimer=setTimeout(()=>{this.isScrolling=!1},200))}),16),updateVisibleCount(){if(!this.bodyWrapperEl)return;const e=this.bodyWrapperEl.clientHeight;this.visibleCount=Math.ceil(e/this.rowHeight)+2*this.bufferSize},updateVisibleData(){if(!this.shouldUseVirtualScroll||!this.bodyWrapperEl||!this.tableData.length)return;const e=Math.max(0,Math.floor(this.scrollTop/this.rowHeight)-this.bufferSize),t=Math.min(this.tableData.length,e+this.visibleCount);this.startIndex=e,this.endIndex=t,this.visibleData=this.tableData.slice(e,t);const a=e*this.rowHeight;this.bodyWrapperEl.querySelector("table")&&(this.bodyWrapperEl.querySelector("table").style.transform=`translateY(${a}px)`)},resetScroll(){this.bodyWrapperEl&&(this.bodyWrapperEl.scrollTop=0,this.scrollTop=0,this.updateVisibleData())},getSelections(){return this.selectedRows},clearSelection(){this.$refs.elTable.clearSelection()},toggleRowSelection(e,t){this.$refs.elTable.toggleRowSelection(e,t)},toggleAllSelection(){this.$refs.elTable.toggleAllSelection()},setCurrentRow(e){this.$refs.elTable.setCurrentRow(e)},doLayout(){this.$refs.elTable.doLayout()},refresh(){this.remote&&this.loadMethod&&this.loadRemoteData(),this.shouldUseVirtualScroll&&this.updateVisibleData()},exportCsv(e={}){const t={filename:"table-export.csv",columns:this.columns,data:this.tableData},a={...t,...e};this.$emit("export",a)},clearCache(){this._visibleDataCache=new Map,this._columnPropsCache=new Map,this._numberFormatCache=new Map,this._dateFormatCache=new Map,this.getColumnWidth.cache.clear(),this.formatNumber.cache.clear(),this.formatDate.cache.clear(),this.inferDataType.cache.clear()}}},z=P,$=(a("bbde"),b(z,l,s,!1,null,"12f1df5b",null)),E=$.exports;E.install=function(e){e.component(E.name,E)};var O=E,L=function(){var e=this,t=e._self._c;return t("div",{staticClass:"smart-query-container",class:{"is-collapse":e.isCollapse}},[t("div",{staticClass:"smart-query-panel"},[t("el-form",{ref:"queryForm",attrs:{model:e.formData,"label-width":e.labelWidth,"label-position":e.labelPosition,size:"small"}},[t("div",{staticClass:"smart-query-content"},[e._l(e.visibleFields,(function(a,i){return[t("el-form-item",{attrs:{label:a.fieldDesc,prop:a.fieldName}},[t(e.getComponentByType(a.fieldDataType),e._b({tag:"component",on:{change:function(t){return e.handleFieldChange(a.fieldName,a.fieldDataType)}},model:{value:e.formData[a.fieldName],callback:function(t){e.$set(e.formData,a.fieldName,t)},expression:"formData[field.fieldName]"}},"component",e.getComponentProps(a),!1),[e.hasOptions(a.fieldDataType)?e._l(e.getFieldOptions(a),(function(e){return t("el-option",{key:e.value,attrs:{label:e.label,value:e.value}})})):e._e()],2),e.showLogicSelector&&a.operators&&a.operators.length?t("el-select",{staticClass:"smart-query-logic-selector",attrs:{size:"small"},on:{change:function(t){return e.handleOperatorChange(a.fieldName)}},model:{value:a.compareType,callback:function(t){e.$set(a,"compareType",t)},expression:"field.compareType"}},e._l(a.operators,(function(e){return t("el-option",{key:e.code,attrs:{label:e.desc,value:e.code}})})),1):e._e()],1)]})),t("div",{staticClass:"smart-query-actions"},[t("el-button",{attrs:{type:"primary",size:"small",icon:"el-icon-search"},on:{click:e.handleSearch}},[e._v(" 查询 ")]),t("el-button",{attrs:{size:"small",icon:"el-icon-refresh-left"},on:{click:e.handleReset}},[e._v(" 重置 ")]),e.enableCollapse&&e.fields.length>e.startupFields?t("el-button",{attrs:{size:"small",text:"",type:"text"},on:{click:e.toggleCollapse}},[e._v(" "+e._s(e.isCollapse?"展开":"收起")+" "),t("i",{class:e.isCollapse?"el-icon-arrow-down":"el-icon-arrow-up"})]):e._e()],1)],2)])],1),e.enableAdvanced?t("div",{staticClass:"smart-query-advanced"},[t("el-collapse",{model:{value:e.activeAdvanced,callback:function(t){e.activeAdvanced=t},expression:"activeAdvanced"}},[t("el-collapse-item",{attrs:{name:"advanced",title:"高级查询"}},[e._t("advanced-content",(function(){return[t("div",{staticClass:"smart-query-advanced-content"},e._l(e.advancedFields,(function(a,i){return t("div",{key:"advanced-"+a.fieldName,staticClass:"smart-query-advanced-item"},[t("span",{staticClass:"smart-query-advanced-label"},[e._v(e._s(a.fieldDesc))]),t(e.getComponentByType(a.fieldDataType),e._b({tag:"component",on:{change:function(t){return e.handleFieldChange(a.fieldName,a.fieldDataType)}},model:{value:e.formData[a.fieldName],callback:function(t){e.$set(e.formData,a.fieldName,t)},expression:"formData[field.fieldName]"}},"component",e.getComponentProps(a),!1),[e.hasOptions(a.fieldDataType)?e._l(e.getFieldOptions(a),(function(e){return t("el-option",{key:e.value,attrs:{label:e.label,value:e.value}})})):e._e()],2),a.operators&&a.operators.length?t("el-select",{staticClass:"smart-query-logic-selector",attrs:{size:"small"},on:{change:function(t){return e.handleOperatorChange(a.fieldName)}},model:{value:a.compareType,callback:function(t){e.$set(a,"compareType",t)},expression:"field.compareType"}},e._l(a.operators,(function(e){return t("el-option",{key:e.code,attrs:{label:e.desc,value:e.code}})})),1):e._e()],1)})),0)]}))],2)],1)],1):e._e(),t("el-dialog",{attrs:{title:"查询历史",visible:e.historyDialogVisible,width:"600px","append-to-body":""},on:{"update:visible":function(t){e.historyDialogVisible=t}}},[t("div",{staticClass:"smart-query-history-list"},[e._l(e.queryHistory,(function(a,i){return t("div",{key:i,staticClass:"smart-query-history-item",on:{click:function(t){return e.loadHistoryQuery(a)}}},[t("div",{staticClass:"smart-query-history-time"},[e._v(e._s(e.formatDateTime(a.timestamp)))]),t("div",{staticClass:"smart-query-history-content"},e._l(a.conditions,(function(a,i){return t("el-tag",{key:i,staticClass:"smart-query-history-tag",attrs:{size:"small"}},[e._v(" "+e._s(a.fieldDesc)+": "+e._s(e.formatConditionValue(a))+" ")])})),1),t("el-button",{staticClass:"smart-query-history-use",attrs:{type:"text",size:"mini"},on:{click:function(t){return t.stopPropagation(),e.loadHistoryQuery(a)}}},[e._v(" 使用 ")])],1)})),e.queryHistory.length?e._e():t("div",{staticClass:"smart-query-history-empty"},[e._v(" 暂无查询历史 ")])],2)])],1)},F=[],A={name:"SmartQuery",props:{fields:{type:Array,required:!0},initialValues:{type:Object,default:()=>({})},labelWidth:{type:String,default:"100px"},labelPosition:{type:String,default:"right"},enableCollapse:{type:Boolean,default:!0},startupFields:{type:Number,default:3},enableAdvanced:{type:Boolean,default:!1},advancedFields:{type:Array,default:()=>[]},showLogicSelector:{type:Boolean,default:!0},enableHistory:{type:Boolean,default:!0},historyMaxCount:{type:Number,default:10},historyStorageKey:{type:String,default:"smart_query_history"}},data(){return{formData:{},isCollapse:!1,activeAdvanced:[],historyDialogVisible:!1,queryHistory:[],innerFields:[],delayedSearch:null}},computed:{visibleFields(){return this.isCollapse?this.innerFields.slice(0,this.startupFields):this.innerFields}},watch:{fields:{immediate:!0,handler(e){this.processFields(e)}},initialValues:{handler(e){this.initFormData(e)}}},created(){this.initFormData(this.initialValues),this.enableHistory&&this.loadQueryHistory(),this.delayedSearch=o(this.executeSearch,300)},methods:{processFields(e){e&&e.length&&(this.innerFields=e.map(e=>{const t=e.operators||this.getDefaultOperators(e.fieldDataType),a=e.compareType||(t.length?t[0].code:"");return{...e,operators:t,compareType:a}}))},initFormData(e){const t={};this.innerFields.forEach(a=>{e&&void 0!==e[a.fieldName]?t[a.fieldName]=e[a.fieldName]:void 0!==a.defaultValue?t[a.fieldName]=a.defaultValue:t[a.fieldName]=this.getEmptyValueByType(a.fieldDataType)}),this.advancedFields.forEach(a=>{e&&void 0!==e[a.fieldName]?t[a.fieldName]=e[a.fieldName]:void 0!==a.defaultValue?t[a.fieldName]=a.defaultValue:t[a.fieldName]=this.getEmptyValueByType(a.fieldDataType)}),this.formData=t},getEmptyValueByType(e){switch(e){case"BOOLEAN":return;case"NUMBER":return;case"DATE":return"";case"DICT":return[];default:return""}},getDefaultOperators(e){switch(e){case"NUMBER":return[{code:"EQUAL",desc:"等于"},{code:"NOT_EQUAL",desc:"不等于"},{code:"GREATER_THAN",desc:"大于"},{code:"LESS_THAN",desc:"小于"},{code:"GREATER_EQUAL",desc:"大于等于"},{code:"LESS_EQUAL",desc:"小于等于"},{code:"IS_NULL",desc:"为空"},{code:"NOT_NULL",desc:"非空"}];case"DATE":return[{code:"EQUAL",desc:"等于"},{code:"NOT_EQUAL",desc:"不等于"},{code:"GREATER_THAN",desc:"晚于"},{code:"LESS_THAN",desc:"早于"},{code:"BETWEEN",desc:"范围"},{code:"IS_NULL",desc:"为空"},{code:"NOT_NULL",desc:"非空"}];case"BOOLEAN":return[{code:"EQUAL",desc:"等于"},{code:"NOT_EQUAL",desc:"不等于"}];case"DICT":return[{code:"IN",desc:"包含"},{code:"NOT_IN",desc:"不包含"},{code:"IS_NULL",desc:"为空"},{code:"NOT_NULL",desc:"非空"}];default:return[{code:"EQUAL",desc:"等于"},{code:"NOT_EQUAL",desc:"不等于"},{code:"LIKE",desc:"包含"},{code:"START_WITH",desc:"开始于"},{code:"END_WITH",desc:"结束于"},{code:"IS_NULL",desc:"为空"},{code:"NOT_NULL",desc:"非空"}]}},getComponentByType(e){switch(e){case"STRING":return"el-input";case"NUMBER":return"el-input-number";case"DATE":return"el-date-picker";case"BOOLEAN":return"el-select";case"DICT":return"el-select";default:return"el-input"}},getComponentProps(e){const t={placeholder:"请输入"+e.fieldDesc,clearable:!0,size:"small"};switch(e.fieldDataType){case"STRING":return{...t,maxlength:e.maxLength||50};case"NUMBER":return{...t,precision:e.precision||0,step:e.step||1,min:void 0!==e.min?e.min:void 0,max:void 0!==e.max?e.max:void 0,controls:!0};case"DATE":return{...t,placeholder:"请选择"+e.fieldDesc,type:e.dateType||"date",format:e.format||"yyyy-MM-dd","value-format":e.valueFormat||"yyyy-MM-dd"};case"BOOLEAN":return{...t,placeholder:"请选择"+e.fieldDesc};case"DICT":return{...t,placeholder:"请选择"+e.fieldDesc,multiple:!1!==e.multiple,"collapse-tags":!0,filterable:!0};default:return t}},hasOptions(e){return["BOOLEAN","DICT"].includes(e)},getFieldOptions(e){return"BOOLEAN"===e.fieldDataType?[{label:"是",value:!0},{label:"否",value:!1}]:"DICT"===e.fieldDataType&&e.options||[]},handleFieldChange(e,t){this.$emit("field-change",e,this.formData[e],t),this.searchOnChange&&this.delayedSearch()},handleOperatorChange(e){const t=this.innerFields.find(t=>t.fieldName===e)||this.advancedFields.find(t=>t.fieldName===e);if(!t)return;const a=["IS_NULL","NOT_NULL"];a.includes(t.compareType)&&(this.formData[e]=this.getEmptyValueByType(t.fieldDataType)),this.$emit("operator-change",e,t.compareType)},toggleCollapse(){this.isCollapse=!this.isCollapse,this.$emit("collapse-change",this.isCollapse),this.$nextTick(()=>{this.$emit("layout-change")})},executeSearch(){const e=this.buildQueryConditions();this.$emit("search",{queryConditions:e,formData:{...this.formData}}),this.enableHistory&&e.length>0&&this.saveQueryHistory(e)},handleSearch(){this.executeSearch()},handleReset(){this.$refs.queryForm.resetFields(),this.initFormData(this.initialValues),this.$emit("reset")},buildQueryConditions(){const e=[];return this.innerFields.forEach(t=>{const a=this.formData[t.fieldName],i=t.compareType;(void 0===a||null===a||""===a||Array.isArray(a)&&0===a.length)&&!["IS_NULL","NOT_NULL"].includes(i)||e.push({columnName:t.columnName||t.fieldName,fieldName:t.fieldName,fieldDesc:t.fieldDesc,fieldDataType:t.fieldDataType,compareType:i,fieldValue:a})}),this.advancedFields.forEach(t=>{const a=this.formData[t.fieldName],i=t.compareType;(void 0===a||null===a||""===a||Array.isArray(a)&&0===a.length)&&!["IS_NULL","NOT_NULL"].includes(i)||e.push({columnName:t.columnName||t.fieldName,fieldName:t.fieldName,fieldDesc:t.fieldDesc,fieldDataType:t.fieldDataType,compareType:i,fieldValue:a})}),e},loadQueryHistory(){try{const e=localStorage.getItem(this.historyStorageKey);e&&(this.queryHistory=JSON.parse(e)||[])}catch(e){console.error("Failed to load query history:",e),this.queryHistory=[]}},saveQueryHistory(e){if(!this.enableHistory||!e.length)return;const t={timestamp:(new Date).getTime(),conditions:JSON.parse(JSON.stringify(e))},a=this.queryHistory.some(t=>{if(t.conditions.length!==e.length)return!1;for(let a=0;a<e.length;a++){const i=e[a],r=t.conditions[a];if(i.fieldName!==r.fieldName||i.compareType!==r.compareType||JSON.stringify(i.fieldValue)!==JSON.stringify(r.fieldValue))return!1}return!0});if(!a){this.queryHistory.unshift(t),this.queryHistory.length>this.historyMaxCount&&(this.queryHistory=this.queryHistory.slice(0,this.historyMaxCount));try{localStorage.setItem(this.historyStorageKey,JSON.stringify(this.queryHistory))}catch(i){console.error("Failed to save query history:",i)}}},loadHistoryQuery(e){if(!e||!e.conditions)return;this.handleReset();const t={...this.formData};e.conditions.forEach(e=>{t[e.fieldName]=e.fieldValue;const a=this.innerFields.find(t=>t.fieldName===e.fieldName);if(a)a.compareType=e.compareType;else{const t=this.advancedFields.find(t=>t.fieldName===e.fieldName);t&&(t.compareType=e.compareType)}}),this.formData=t,this.historyDialogVisible=!1,this.executeSearch()},formatDateTime(e){if(!e)return"";const t=new Date(e),a=t.getFullYear(),i=(t.getMonth()+1).toString().padStart(2,"0"),r=t.getDate().toString().padStart(2,"0"),n=t.getHours().toString().padStart(2,"0"),l=t.getMinutes().toString().padStart(2,"0");return`${a}-${i}-${r} ${n}:${l}`},formatConditionValue(e){if(!e)return"";const{fieldDataType:t,fieldValue:a,compareType:i}=e;if("IS_NULL"===i)return"为空";if("NOT_NULL"===i)return"非空";if(void 0===a||null===a)return"";switch(t){case"BOOLEAN":return a?"是":"否";case"DICT":return Array.isArray(a)?a.length>1?`${a[0]}等${a.length}项`:a[0]||"":a||"";default:return String(a)}},showHistoryDialog(){this.enableHistory&&(this.loadQueryHistory(),this.historyDialogVisible=!0)}}},M=A,V=(a("c4e3"),b(M,L,F,!1,null,"77038a4d",null)),H=V.exports;H.install=function(e){e.component(H.name,H)};var k=H;const R=[O,S,k],B=function(e,t={}){R.forEach(t=>{e.component(t.name,t)}),e.prototype.$smartUtils={performance:i}};"undefined"!==typeof window&&window.Vue&&B(window.Vue);var U={install:B,version:"1.0.0"};t["default"]=U}})}));
//# sourceMappingURL=smart-table-vue.umd.min.js.map