vxe-table
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...
1 lines • 5.67 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils")),_tools=require("../../tools"),_dom=require("../../tools/src/dom");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getTargetOffset(e,t){var o,l,n=0,r=0,s=!_dom.browse.firefox&&_tools.DomTools.hasClass(e,"vxe-checkbox--label");for(s&&(o=getComputedStyle(e),n-=_xeUtils.default.toNumber(o.paddingTop),r-=_xeUtils.default.toNumber(o.paddingLeft));e&&e!==t;)n+=e.offsetTop,r+=e.offsetLeft,e=e.offsetParent,s&&(l=getComputedStyle(e),n-=_xeUtils.default.toNumber(l.paddingTop),r-=_xeUtils.default.toNumber(l.paddingLeft));return{offsetTop:n,offsetLeft:r}}function getCheckboxRangeRows(e,t,o,l){var n=0,r=[],s=0<l,i=0<l?l:Math.abs(l)+o.offsetHeight,c=e.afterFullData,l=e.scrollYStore;if(e.scrollYLoad)t=e.getVTRowIndex(t.row),r=s?c.slice(t,t+Math.ceil(i/l.rowHeight)):c.slice(t-Math.floor(i/l.rowHeight)+1,t+1);else for(var a=s?"next":"previous";o&&n<i;)r.push(e.getRowNode(o).item),n+=o.offsetHeight,o=o["".concat(a,"ElementSibling")];return r}var _default={methods:{moveTabSelected:function(e,t,o){var l,n,r,s=this,i=this.afterFullData,c=this.visibleColumn,a=this.editConfig,u=this.editOpts,h=Object.assign({},e),d=this.getVTRowIndex(h.row),e=this.getVTColumnIndex(h.column);o.preventDefault(),t?e<=0?0<d&&(l=i[n=d-1],r=c.length-1):r=e-1:e>=c.length-1?d<i.length-1&&(l=i[n=d+1],r=0):r=e+1;c=c[r];c&&(l?(h.rowIndex=n,h.row=l):h.rowIndex=d,h.columnIndex=r,h.column=c,h.cell=this.getCell(h.row,h.column),a?"click"!==u.trigger&&"dblclick"!==u.trigger||("row"===u.mode?this.handleActived(h,o):this.scrollToRow(h.row,h.column).then(function(){return s.handleSelected(h,o)})):this.scrollToRow(h.row,h.column).then(function(){return s.handleSelected(h,o)}))},moveCurrentRow:function(e,t,o){var l,n,r,s=this,i=this.currentRow,c=this.treeConfig,a=this.treeOpts,u=this.afterFullData;o.preventDefault(),i?c?(n=(a=_xeUtils.default.findTree(u,function(e){return e===i},a)).index,a=a.items,e&&0<n?l=a[n-1]:t&&n<a.length-1&&(l=a[n+1])):(n=this.getVTRowIndex(i),e&&0<n?l=u[n-1]:t&&n<u.length-1&&(l=u[n+1])):l=u[0],l&&(r={$table:this,row:l},this.scrollToRow(l).then(function(){return s.triggerCurrentRowEvent(o,r)}))},moveSelected:function(e,t,o,l,n,r){var s=this,i=this.afterFullData,c=this.visibleColumn,a=Object.assign({},e),u=this.getVTRowIndex(a.row),e=this.getVTColumnIndex(a.column);r.preventDefault(),o&&0<u?(a.rowIndex=u-1,a.row=i[a.rowIndex]):n&&u<i.length-1?(a.rowIndex=u+1,a.row=i[a.rowIndex]):t&&e?(a.columnIndex=e-1,a.column=c[a.columnIndex]):l&&e<c.length-1&&(a.columnIndex=e+1,a.column=c[a.columnIndex]),this.scrollToRow(a.row,a.column).then(function(){a.cell=s.getCell(a.row,a.column),s.handleSelected(a,r)})},triggerHeaderCellMousedownEvent:function(e,t){var o,l=this.mouseConfig,n=this.mouseOpts;l&&n.area&&this.handleHeaderCellAreaEvent&&(o=e.currentTarget,l=_tools.DomTools.getEventTargetNode(e,o,"vxe-cell--sort").flag,n=_tools.DomTools.getEventTargetNode(e,o,"vxe-cell--filter").flag,this.handleHeaderCellAreaEvent(e,Object.assign({cell:o,triggerSort:l,triggerFilter:n},t))),this.focus(),this.closeMenu()},triggerCellMousedownEvent:function(e,t){var o=e.currentTarget;t.cell=o,this.handleCellMousedownEvent(e,t),this.focus(),this.closeFilter(),this.closeMenu()},handleCellMousedownEvent:function(e,t){var o=this.editConfig,l=this.editOpts,n=this.handleSelected,r=this.checkboxConfig,s=this.checkboxOpts,i=this.mouseConfig,c=this.mouseOpts;if(i&&c.area&&this.handleCellAreaEvent)return this.handleCellAreaEvent(e,t);r&&s.range&&this.handleCheckboxRangeEvent(e,t),i&&c.selected&&(o&&"cell"!==l.mode||n(t,e))},handleCheckboxRangeEvent:function(e,i){var t,o,c,a,u,h,l,n,d,f,g,m,x,v,p,w,b,T,C,R,_,r,k=this,s=i.column,I=i.cell;"checkbox"===s.type&&(t=this.$el,o=this.elemStore,c=e.clientX,a=e.clientY,u=o["".concat(s.fixed||"main","-body-wrapper")]||o["main-body-wrapper"],h=u.querySelector(".vxe-table--checkbox-range"),l=document.onmousemove,n=document.onmouseup,d=I.parentNode,f=this.getCheckboxRecords(),g=[],I=getTargetOffset(e.target,u),m=I.offsetTop+e.offsetY,x=I.offsetLeft+e.offsetX,v=u.scrollTop,p=d.offsetHeight,w=null,b=!1,T=1,C=function(e,t){k.emitEvent("checkbox-range-".concat(e),{records:k.getCheckboxRecords(),reserves:k.getCheckboxReserveRecords()},t)},R=function(e){var t=e.clientX,o=e.clientY,l=t-c,n=o-a+(u.scrollTop-v),r=Math.abs(n),s=Math.abs(l),t=m,o=x;n<1?(t+=n)<1&&(t=1,r=m):r=Math.min(r,u.scrollHeight-m-1),l<1?(o+=l,x<s&&(o=1,s=x)):s=Math.min(s,u.clientWidth-x-1),h.style.height="".concat(r,"px"),h.style.width="".concat(s,"px"),h.style.left="".concat(o,"px"),h.style.top="".concat(t,"px"),h.style.display="block";n=getCheckboxRangeRows(k,i,d,n<1?-r:r);10<r&&n.length!==g.length&&(g=n,e.ctrlKey?n.forEach(function(e){k.handleSelectRow({row:e},-1===f.indexOf(e))}):(k.setAllCheckboxRow(!1),k.setCheckboxRow(n,!0)),C("change",e))},_=function(){clearTimeout(w),w=null},r=function r(s){_(),w=setTimeout(function(){var e,t,o,l,n;w&&(e=u.scrollLeft,t=u.scrollTop,o=u.clientHeight,l=u.scrollHeight,n=Math.ceil(50*T/p),b?t+o<l?(k.scrollTo(e,t+n),r(s),R(s)):_():t?(k.scrollTo(e,t-n),r(s),R(s)):_())},50)},_tools.DomTools.addClass(t,"drag--range"),document.onmousemove=function(e){e.preventDefault(),e.stopPropagation();var t=e.clientY,o=_tools.DomTools.getAbsolutePos(u).boundingTop;t<o?(b=!1,T=o-t,w||r(e)):t>o+u.clientHeight?(b=!0,T=t-o-u.clientHeight,w||r(e)):w&&_(),R(e)},document.onmouseup=function(e){_(),_tools.DomTools.removeClass(t,"drag--range"),h.removeAttribute("style"),document.onmousemove=l,document.onmouseup=n,C("end",e)},C("start",e))}}};exports.default=_default;