a-virtual-table
Version:
The virtual scrolling component developed based on the Table component of Ant Design supports dynamic height and solves the problem of scrolling stuck when the amount of data is large.
2 lines (1 loc) • 29.6 kB
JavaScript
var AVirtualTable=function(t,e,n,r){"use strict";function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=i(e),a=i(n);function l(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function s(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?l(Object(n),!0).forEach((function(e){h(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function c(){c=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,r=Object.defineProperty||function(t,e,n){t[e]=n.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",l=i.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function u(t,e,n,i){var o=e&&e.prototype instanceof h?e:h,a=Object.create(o.prototype),l=new E(i||[]);return r(a,"_invoke",{value:x(t,n,l)}),a}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var f={};function h(){}function p(){}function v(){}var y={};s(y,o,(function(){return this}));var b=Object.getPrototypeOf,m=b&&b(b(T([])));m&&m!==e&&n.call(m,o)&&(y=m);var g=v.prototype=h.prototype=Object.create(y);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function i(r,o,a,l){var s=d(t[r],t,o);if("throw"!==s.type){var c=s.arg,u=c.value;return u&&"object"==typeof u&&n.call(u,"__await")?e.resolve(u.__await).then((function(t){i("next",t,a,l)}),(function(t){i("throw",t,a,l)})):e.resolve(u).then((function(t){c.value=t,a(c)}),(function(t){return i("throw",t,a,l)}))}l(s.arg)}var o;r(this,"_invoke",{value:function(t,n){function r(){return new e((function(e,r){i(t,n,e,r)}))}return o=o?o.then(r,r):r()}})}function x(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return A()}for(n.method=i,n.arg=o;;){var a=n.delegate;if(a){var l=_(a,n);if(l){if(l===f)continue;return l}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var s=d(t,e,n);if("normal"===s.type){if(r=n.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(r="completed",n.method="throw",n.arg=s.arg)}}}function _(t,e){var n=e.method,r=t.iterator[n];if(void 0===r)return e.delegate=null,"throw"===n&&t.iterator.return&&(e.method="return",e.arg=void 0,_(t,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),f;var i=d(r,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,f;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function $(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach($,this),this.reset(!0)}function T(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:A}}function A(){return{value:void 0,done:!0}}return p.prototype=v,r(g,"constructor",{value:v,configurable:!0}),r(v,"constructor",{value:p,configurable:!0}),p.displayName=s(v,l,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,l,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},w(S.prototype),s(S.prototype,a,(function(){return this})),t.AsyncIterator=S,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var a=new S(u(e,n,r,i),o);return t.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(g),s(g,l,"Generator"),s(g,o,(function(){return this})),s(g,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},t.values=T,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return a.type="throw",a.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var l=n.call(o,"catchLoc"),s=n.call(o,"finallyLoc");if(l&&s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(l){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),k(n),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;k(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:T(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),f}},t}function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function d(t,e,n,r,i,o,a){try{var l=t[o](a),s=l.value}catch(t){return void n(t)}l.done?e(s):Promise.resolve(s).then(r,i)}function f(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function a(t){d(o,r,i,a,l,"next",t)}function l(t){d(o,r,i,a,l,"throw",t)}a(void 0)}))}}function h(t,e,n){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function p(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,i,o,a,l=[],s=!0,c=!1;try{if(o=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;s=!1}else for(;!(s=(r=o.call(n)).done)&&(l.push(r.value),l.length!==e);s=!0);}catch(t){c=!0,i=t}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return l}}(t,e)||y(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t){return function(t){if(Array.isArray(t))return b(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||y(t)||function(){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 y(t,e){if(t){if("string"==typeof t)return b(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(t,e):void 0}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var m=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},g="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},w="object"==typeof g&&g&&g.Object===Object&&g,S="object"==typeof self&&self&&self.Object===Object&&self,x=w||S||Function("return this")(),_=function(){return x.Date.now()},$=/\s/;var k=function(t){for(var e=t.length;e--&&$.test(t.charAt(e)););return e},E=/^\s+/;var T=function(t){return t?t.slice(0,k(t)+1).replace(E,""):t},A=x.Symbol,C=Object.prototype,O=C.hasOwnProperty,j=C.toString,P=A?A.toStringTag:void 0;var L=function(t){var e=O.call(t,P),n=t[P];try{t[P]=void 0;var r=!0}catch(t){}var i=j.call(t);return r&&(e?t[P]=n:delete t[P]),i},N=Object.prototype.toString;var D=function(t){return N.call(t)},I=A?A.toStringTag:void 0;var B=function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":I&&I in Object(t)?L(t):D(t)};var z=function(t){return null!=t&&"object"==typeof t};var R=function(t){return"symbol"==typeof t||z(t)&&"[object Symbol]"==B(t)},q=/^[-+]0x[0-9a-f]+$/i,U=/^0b[01]+$/i,F=/^0o[0-7]+$/i,H=parseInt;var M=function(t){if("number"==typeof t)return t;if(R(t))return NaN;if(m(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=m(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=T(t);var n=U.test(t);return n||F.test(t)?H(t.slice(2),n?2:8):q.test(t)?NaN:+t},Y=Math.max,G=Math.min;var V=function(t,e,n){var r,i,o,a,l,s,c=0,u=!1,d=!1,f=!0;if("function"!=typeof t)throw new TypeError("Expected a function");function h(e){var n=r,o=i;return r=i=void 0,c=e,a=t.apply(o,n)}function p(t){var n=t-s;return void 0===s||n>=e||n<0||d&&t-c>=o}function v(){var t=_();if(p(t))return y(t);l=setTimeout(v,function(t){var n=e-(t-s);return d?G(n,o-(t-c)):n}(t))}function y(t){return l=void 0,f&&r?h(t):(r=i=void 0,a)}function b(){var t=_(),n=p(t);if(r=arguments,i=this,s=t,n){if(void 0===l)return function(t){return c=t,l=setTimeout(v,e),u?h(t):a}(s);if(d)return clearTimeout(l),l=setTimeout(v,e),h(s)}return void 0===l&&(l=setTimeout(v,e)),a}return e=M(e)||0,m(n)&&(u=!!n.leading,o=(d="maxWait"in n)?Y(M(n.maxWait)||0,e):o,f="trailing"in n?!!n.trailing:f),b.cancel=function(){void 0!==l&&clearTimeout(l),c=0,r=s=i=l=void 0},b.flush=function(){return void 0===l?a:y(_())},b};var W=function(t,e,n){var r=!0,i=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return m(n)&&(r="leading"in n?!!n.leading:r,i="trailing"in n?!!n.trailing:i),V(t,e,{leading:r,maxWait:e,trailing:i})};function X(t){var e=window.getComputedStyle(t,null),n=["auto","scroll"];return n.includes(e.overflow)||n.includes(e["overflow-y"])}function J(t){return t===window?window.pageYOffset:t.scrollTop}function K(t){return t===window?window.pageXOffset:t.scrollLeft}function Z(t,e){return t===window?window.scroll(window.pageXOffset,e):t.scrollTop=e}function Q(t,e){return t===window?window.scroll(e,window.pageYOffset):t.scrollLeft=e}var tt=[".ant-table-scroll .ant-table-body",".ant-table-fixed-left .ant-table-body-inner",".ant-table-fixed-right .ant-table-body-inner"],et=0,nt={inheritAttrs:!1,name:"a-virtual-table",components:{ACheckbox:o.default,ATable:a.default},props:{dataSource:{type:Array,default:function(){return[]}},columns:{type:Array,default:function(){return[]}},keyProp:{type:String,default:"id"},itemSize:{type:Number,default:60},scrollBox:{type:String},buffer:{type:Number,default:100},throttleTime:{type:Number,default:10},dynamic:{type:Boolean,default:!0},virtualized:{type:Boolean,default:!0},isTree:{type:Boolean,default:!1}},provide:function(){return{virtualTable:this}},data:function(){return{start:0,end:void 0,sizes:{},renderData:[],isCheckedAll:!1,isCheckedImn:!1,isHideAppend:!1}},computed:{tableColumns:function(){var t=this,e=this.$createElement;return this.columns.map((function(n){return"selection"===n.type?s({title:function(){return e("a-checkbox",{attrs:{checked:t.isCheckedAll,indeterminate:t.isCheckedImn},on:{change:function(){return t.onCheckAllRows(!t.isCheckedAll)}}})},customRender:function(n,r){return e("a-checkbox",{attrs:{checked:r.$v_checked},on:{change:function(){return t.onCheckRow(r,!r.$v_checked)}}})},width:60},n):n.index?s({customRender:function(e,r,i){var o=t.start+i;return"function"==typeof n.index?n.index(o):o+1}},n):n}))},offsetMap:function(t){var e=t.keyProp,n=t.itemSize,r=t.sizes,i=t.dataSource;if(!this.dynamic)return{};for(var o={},a=0,l=0;l<i.length;l++){var s=i[l][e];o[s]=a;var c=r[s];a+="number"==typeof c?c:n}return o}},methods:{getSlotValue:function(t,e,n){if("object"===u(t)&&t.selectedKeys)return console.log("text",t),t;for(var r=arguments.length,i=new Array(r>3?r-3:0),o=3;o<r;o++)i[o-3]=arguments[o];return s("number"==typeof e?{record:t,index:e,$index:this.start+e}:{text:t,record:e,index:n,$index:this.start+n},i)},initData:function(){var t=this;this.isInnerScroll=!1,this.scrollPos=[0,0,0,0],this.isDeactivated=!1,this.scroller=this.getScroller(),this.setToTop(),this.recordTablePos(),this.handleScroll(),this.$nextTick((function(){t.handleScroll()})),this.onScroll=W(this.handleScroll,this.throttleTime),this.scroller.addEventListener("scroll",this.onScroll,{passive:!0}),window.addEventListener("resize",this.onScroll)},setToTop:function(){this.isInnerScroll?this.toTop=0:this.toTop=this.$el.getBoundingClientRect().top-(this.scroller===window?0:this.scroller.getBoundingClientRect().top)+J(this.scroller)},getScroller:function(){var t;if(this.scrollBox){if("window"===this.scrollBox||this.scrollBox===window)return window;if(!(t=document.querySelector(this.scrollBox)))throw new Error(" scrollBox prop: '".concat(this.scrollBox,"' is not a valid selector"));return X(t)||console.warn("Warning! scrollBox prop: '".concat(this.scrollBox,"' is not a scroll element")),t}return this.$attrs.scroll&&this.$attrs.scroll.y?(this.isInnerScroll=!0,this.$el.querySelector(".ant-table-body")):function(t){for(var e=t;e;){if([window,document,document.documentElement].includes(e))return window;if(X(e))return e;e=e.parentNode}return e||window}(this.$el)},handleScroll:function(){this.isDeactivated||(this.scrollPos[0]=J(this.scroller),this.scrollPos[1]=K(this.scroller),this.virtualized&&(this.updateSizes(),this.calcRenderData(),this.calcPosition()))},updateSizes:function(){var t=this;if(this.dynamic){var e=[];e=this.isTree?this.$el.querySelectorAll(".ant-table-body .ant-table-row-level-0"):this.$el.querySelectorAll(".ant-table-body .ant-table-tbody .ant-table-row"),Array.from(e).forEach((function(n,r){var i=t.renderData[r];if(i){var o=n.offsetHeight,a=n.nextSibling;if(a&&a.classList&&a.classList.contains("ant-table-expanded-row")&&(o+=n.nextSibling.offsetHeight),t.isTree)for(var l=n.nextSibling;l&&l!==e[r+1];){var s;o+=(null===(s=l)||void 0===s?void 0:s.offsetHeight)||0,l=l.nextSibling}var c=i[t.keyProp];t.sizes[c]!==o&&(t.$set(t.sizes,c,o),n._offsetHeight=o)}}))}},calcRenderData:function(){var t,e,n,r=this.scroller,i=this.buffer,o=this.dataSource,a=this.scrollPos[0]-i-this.toTop,l=this.isInnerScroll?this.$attrs.scroll.y:(t=r)===window?window.innerHeight:t.offsetHeight,s=this.scrollPos[0]+l+i-this.toTop;if(this.dynamic){for(var c=0,u=o.length-1,d=0;c<=u;){if(d=Math.floor((c+u)/2),this.getItemOffsetTop(d)<a){if(this.getItemOffsetTop(d+1)>a)break;c=d+1}else u=d-1}e=d,n=o.length-1;for(var f=e+1;f<o.length;f++){if(this.getItemOffsetTop(f)>=s){n=f;break}}}else e=a<=0?0:Math.floor(a/this.itemSize),n=s<=0?0:Math.ceil(s/this.itemSize);e%2&&(e-=1),this.top=a,this.bottom=s,this.start=e,this.end=n,this.renderData=o.slice(e,n+1),this.$emit("change",this.renderData,this.start,this.end)},calcPosition:function(){var t=this,e=this.dataSource.length,n=e-1,r=this.getItemOffsetTop(n)+this.getItemSize(n),i=this.getItemOffsetTop(this.start);tt.forEach((function(n){var o=t.$el.querySelector(n);if(o){if(!o.wrapEl){var a=document.createElement("div"),l=document.createElement("div");a.appendChild(l),l.appendChild(o.children[0]),o.insertBefore(a,o.firstChild),o.wrapEl=a,o.innerEl=l}o.wrapEl&&(o.wrapEl.style.display=0===e?"block":"inline-block",o.innerEl.style.display=0===e?"block":"inline-block",t.isInnerScroll&&!function(t){return t.scrollWidth>t.clientWidth}(t.scroller)&&(o.wrapEl.style.width="100%",o.innerEl.style.width="100%"),o.wrapEl.style.height=r+"px",o.innerEl.style.transform="translateY(".concat(i,"px)"))}}))},getItemOffsetTop:function(t){if(!this.dynamic)return this.itemSize*t;var e=this.dataSource[t];return e&&this.offsetMap[e[this.keyProp]]||0},getItemSize:function(t){if(t<=-1)return 0;var e=this.dataSource[t];if(e){var n=e[this.keyProp];return this.sizes[n]||this.itemSize}return this.itemSize},update:function(){this.setToTop(),this.handleScroll()},scrollTo:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];this.dataSource[t]&&this.scroller&&(this.updateSizes(),this.calcRenderData(),this.$nextTick((function(){var i,o,a=e.getItemOffsetTop(t)-n;i=e.scroller,o=a,i===window?window.scroll(0,o):i.scrollTop=o,r||setTimeout((function(){e.scrollTo(t,n,!0)}),50)})))},renderAllData:function(){var t=this;this.renderData=this.dataSource,this.$emit("change",this.dataSource,0,this.dataSource.length-1),this.$nextTick((function(){tt.forEach((function(e){var n=t.$el.querySelector(e);n&&n.wrapEl&&(n.wrapEl.style.height="auto",n.innerEl.style.transform="translateY(".concat(0,"px)"))}))}))},doUpdate:function(){var t=this;this.hasDoUpdate||this.scroller&&(this.isHideAppend=!0,this.update(),this.hasDoUpdate=!0,this.$nextTick((function(){t.hasDoUpdate=!1,t.isHideAppend=!1})))},onCheckAllRows:function(t){var e=this;t=!!this.isCheckedImn||t,this.dataSource.forEach((function(n){n.$v_checked!==t&&(e.$set(n,"$v_checked",t),e.$set(n,"$v_checkedOrder",t?et++:void 0))})),this.isCheckedAll=t,this.isCheckedImn=!1,this.emitSelectionChange(),!1===t&&(et=0)},onCheckRow:function(t,e){if(t.$v_checked!==e){this.$set(t,"$v_checked",e),this.$set(t,"$v_checkedOrder",e?et++:void 0);var n=this.dataSource.filter((function(t){return!0===t.$v_checked})).length;0===n?(this.isCheckedAll=!1,this.isCheckedImn=!1):n===this.dataSource.length?(this.isCheckedAll=!0,this.isCheckedImn=!1):(this.isCheckedAll=!1,this.isCheckedImn=!0),this.emitSelectionChange()}},emitSelectionChange:function(){var t=this.dataSource.filter((function(t){return t.$v_checked})).sort((function(t,e){return t.$v_checkedOrder-e.$v_checkedOrder}));this.$emit("selection-change",t)},toggleRowSelection:function(t,e){var n="boolean"==typeof e?e:!t.$v_checked;this.onCheckRow(t,n)},clearSelection:function(){this.isCheckedImn=!1,this.onCheckAllRows(!1)},recordTablePos:function(){var t=this;this.isInnerScroll&&(this.tableBodyEl=this.$el.querySelector(".ant-table-body"),this.onTableScroll=W((function(){t.scrollPos[2]=J(t.tableBodyEl),t.scrollPos[3]=K(t.tableBodyEl)}),100),this.tableBodyEl.addEventListener("scroll",this.onTableScroll,{passive:!0}))},restoreScrollY:function(){if(this.scroller){var t=p(this.scrollPos,4),e=t[0],n=t[1],r=t[2],i=t[3];if(Z(this.scroller,e),Q(this.scroller,n),this.isInnerScroll){var o=document.querySelector(tt[1]),a=document.querySelector(tt[2]);o&&Z(o,e),a&&Z(a,e)}else Z(this.tableBodyEl,r),Q(this.tableBodyEl,i)}},updateData:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.list=t,this.$emit("update:dataSource",this.list)},getData:function(){return this.list||this.dataSource}},watch:{dataSource:function(t,e){this.virtualized?this.doUpdate():this.renderAllData(),this.list&&t!==e&&(this.list=t)},virtualized:{immediate:!0,handler:function(t){t?this.doUpdate():this.renderAllData()}}},created:function(){var t=this;this.$nextTick((function(){t.initData()}))},mounted:function(){var t=this.$refs.append;this.$el.querySelector(".ant-table-body").appendChild(t)},beforeDestroy:function(){this.scroller&&(this.scroller.removeEventListener("scroll",this.onScroll),window.removeEventListener("resize",this.onScroll)),this.tableBodyEl&&this.tableBodyEl.removeEventListener("scroll",this.onTableScroll)},activated:function(){this.isDeactivated=!1,this.restoreScrollY()},deactivated:function(){this.isDeactivated=!0}};function rt(t,e,n,r,i,o,a,l,s,c){"boolean"!=typeof a&&(s=l,l=a,a=!1);const u="function"==typeof n?n.options:n;let d;if(t&&t.render&&(u.render=t.render,u.staticRenderFns=t.staticRenderFns,u._compiled=!0,i&&(u.functional=!0)),r&&(u._scopeId=r),o?(d=function(t){(t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),e&&e.call(this,s(t)),t&&t._registeredComponents&&t._registeredComponents.add(o)},u._ssrRegister=d):e&&(d=a?function(t){e.call(this,c(t,this.$root.$options.shadowRoot))}:function(t){e.call(this,l(t))}),d)if(u.functional){const t=u.render;u.render=function(e,n){return d.call(n),t(e,n)}}else{const t=u.beforeCreate;u.beforeCreate=t?[].concat(t,d):[d]}return n}var it=nt,ot=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("div",[n("a-table",t._g(t._b({attrs:{pagination:!1,columns:t.tableColumns,"data-source":t.renderData},scopedSlots:t._u([t._l(Object.keys(t.$scopedSlots),(function(e){return{key:e,fn:function(n,r,i,o){return[t._t(e,null,null,t.getSlotValue(n,r,i,o))]}}}))],null,!0)},"a-table",t.$attrs,!1),t.$listeners),[t._v(" "),t._l(Object.keys(t.$slots),(function(e){return n("template",{slot:e},[t._t(e)],2)}))],2),t._v(" "),n("div",{directives:[{name:"show",rawName:"v-show",value:!t.isHideAppend,expression:"!isHideAppend"}],ref:"append",staticClass:"ant-table-append"},[t._t("append")],2)],1)};ot._withStripped=!0;var at=rt({render:ot,staticRenderFns:[]},undefined,it,undefined,false,undefined,!1,void 0,void 0,void 0),lt={name:"a-virtual-tree",components:{Icon:r.Icon},props:{indentSize:{type:Number,default:20},row:{type:Object,required:!0},load:{type:Function,required:!0},check:{type:Function,default:function(t){return!1!==t.$v_hasChildren}}},inject:["virtualTable"],methods:{onTreeNodeExpand:function(t){var e=arguments,n=this;return f(c().mark((function r(){var i,o;return c().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(i=e.length>1&&void 0!==e[1]?e[1]:!n.row.$v_expanded,o=!(e.length>2&&void 0!==e[2])||e[2],t.$v_expanded!==i){r.next=4;break}return r.abrupt("return",[]);case 4:if(!i){r.next=13;break}if(!t.$v_loaded){r.next=9;break}return r.abrupt("return",n.loadOldChildNodes(t));case 9:if(!o){r.next=11;break}return r.abrupt("return",n.loadChildNodes(t));case 11:r.next=14;break;case 13:return r.abrupt("return",n.hideChildNodes(t));case 14:case"end":return r.stop()}}),r)})))()},loadChildNodes:function(t){var e=this;return new Promise((function(n,r){e.$set(t,"$v_loading",!0),e.load&&e.load(t,function(e){if(!Array.isArray(e))return this.$set(t,"$v_loading",!1),void n();this.$set(t,"$v_loading",!1),this.$set(t,"$v_expanded",!0),this.$set(t,"$v_loaded",!0),this.$set(t,"$v_hasChildren",!!e.length),e.forEach((function(e){e.$v_level="number"==typeof t.$v_level?t.$v_level+1:2}));var r=this.virtualTable.getData(),i=r.findIndex((function(e){return e===t}));i>-1&&this.virtualTable.updateData([].concat(v(r.slice(0,i+1)),v(e),v(r.slice(i+1))));n(e)}.bind(e))}))},loadOldChildNodes:function(t){this.$set(t,"$v_expanded",!0);var e=this.virtualTable.getData(),n=e.findIndex((function(e){return e===t}));return n>-1?(this.virtualTable.updateData([].concat(v(e.slice(0,n+1)),v(t.$v_hideNodes||[]),v(e.slice(n+1)))),t.$v_hideNodes):[]},hideChildNodes:function(t){var e=this.virtualTable.getData(),n=e.findIndex((function(e){return e===t}));if(-1!==n){for(var r=[],i=n+1;i<e.length;i++){var o=e[i];if((o.$v_level||1)<=(t.$v_level||1))break;r.push(o)}this.$set(t,"$v_hideNodes",r),this.$set(t,"$v_expanded",!1);var a=e.filter((function(t){return!r.includes(t)}));return this.virtualTable.updateData(a),this.virtualTable.update(),[]}},expand:function(t){var e=this,n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(Array.isArray(t)){var i=this.virtualTable,o=i.getData,a=i.keyProp,l=o(),s=[];return l.forEach((function(i){i[a]&&t.includes(i[a])&&s.push(e.onTreeNodeExpand(i,n,r))})),Promise.all(s)}},expandPath:function(t){var e=this;if(Array.isArray(t)){var n=function(){var r=f(c().mark((function r(i,a){var l;return c().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(a!==t.length){r.next=2;break}return r.abrupt("return",t[a-1]);case 2:if(Array.isArray(i)&&i.length){r.next=4;break}return r.abrupt("return",t[a-1]);case 4:if(!(l=i.find((function(e){return e[o]===t[a]})))){r.next=13;break}if(l.$v_expanded){r.next=10;break}return r.next=9,e.onTreeNodeExpand(l,!0);case 9:i=r.sent;case 10:return r.abrupt("return",n(i,a+1));case 13:return console.warn("[expandPath] 没有找到 ".concat(t[a]," key值对应的行")),r.abrupt("return",t[a-1]);case 15:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),r=this.virtualTable,i=r.getData,o=r.keyProp,a=i();return n(a,0)}},expandAll:function(){var t=this;!function e(n){Array.isArray(n)&&n.length&&n.forEach((function(n){t.onTreeNodeExpand(n,!0,!1),e(n.$v_hideNodes)}))}((0,this.virtualTable.getData)())},unexpandAll:function(){var t=this,e=(0,this.virtualTable.getData)(),n=[];e.forEach((function(t){var e=t.$v_level||1;!n[e]&&(n[e]=[]),n[e].push(t)}));for(var r=n.length-1;r>=0;r--)n[r]&&n[r].forEach((function(e){t.onTreeNodeExpand(e,!1)}))}}};const st="undefined"!=typeof navigator&&/msie [6-9]\\b/.test(navigator.userAgent.toLowerCase());function ct(t){return(t,e)=>function(t,e){const n=st?e.media||"default":t,r=dt[n]||(dt[n]={ids:new Set,styles:[]});if(!r.ids.has(t)){r.ids.add(t);let n=e.source;if(e.map&&(n+="\n/*# sourceURL="+e.map.sources[0]+" */",n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e.map))))+" */"),r.element||(r.element=document.createElement("style"),r.element.type="text/css",e.media&&r.element.setAttribute("media",e.media),void 0===ut&&(ut=document.head||document.getElementsByTagName("head")[0]),ut.appendChild(r.element)),"styleSheet"in r.element)r.styles.push(n),r.element.styleSheet.cssText=r.styles.filter(Boolean).join("\n");else{const t=r.ids.size-1,e=document.createTextNode(n),i=r.element.childNodes;i[t]&&r.element.removeChild(i[t]),i.length?r.element.insertBefore(e,i[t]):r.element.appendChild(e)}}}(t,e)}let ut;const dt={};var ft=lt,ht=function(){var t=this,e=t.$createElement,n=t._self._c||e;return n("span",{staticClass:"a-virtual-tree"},[n("span",{staticClass:"ant-table-row-indent",style:{paddingLeft:t.row.$v_level?(t.row.$v_level-1)*t.indentSize+"px":0}}),t._v(" "),t.row.$v_loading?t._t("loading",(function(){return[n("a-icon",{key:"loading",staticClass:"ant-table-row-expand-icon ant-table-row-loading-icon",attrs:{type:"loading"}})]})):t.check(t.row)?n("span",{staticClass:"ant-table-row-expand-icon",class:t.row.$v_expanded?"ant-table-row-expanded":"ant-table-row-collapsed",on:{click:function(e){return t.onTreeNodeExpand(t.row)}}}):n("span",{key:"spaced",staticClass:"ant-table-row-expand-icon ant-table-row-spaced"}),t._v(" "),t._t("default")],2)};ht._withStripped=!0;var pt=rt({render:ht,staticRenderFns:[]},(function(t){t&&t("data-v-7b97fa79_0",{source:".a-virtual-tree {\n display: inline-block;\n}\n.ant-table-row-loading-icon {\n transition: none;\n border: none;\n background: transparent;\n}\n",map:{version:3,sources:["a-virtual-tree.vue"],names:[],mappings:"AAAA;EACE,qBAAqB;AACvB;AACA;EACE,gBAAgB;EAChB,YAAY;EACZ,uBAAuB;AACzB",file:"a-virtual-tree.vue",sourcesContent:[".a-virtual-tree {\n display: inline-block;\n}\n.ant-table-row-loading-icon {\n transition: none;\n border: none;\n background: transparent;\n}\n"]},media:void 0})}),ft,undefined,false,undefined,!1,ct,void 0,void 0);return t.AVirtualTree=pt,t.default=at,Object.defineProperty(t,"__esModule",{value:!0}),t}({},Checkbox,Table,antDesignVue);