Files
vxe-table/lib/header/src/header.min.js
xuliangzhan ac68fa40a1 update
2019-07-26 16:10:07 +08:00

1 line
6.3 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,l,o){return l in e?Object.defineProperty(e,l,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[l]=o,e}var getAllColumns=function l(e){var o=[];return e.forEach(function(e){e.visible&&(e.children&&e.children.length&&e.children.some(function(e){return e.visible})?(o.push(e),o.push.apply(o,l(e.children))):o.push(e))}),o},convertToRows=function(e){var n=1;e.forEach(function(e){e.level=1,function l(o,e){if(e&&(o.level=e.level+1,n<o.level&&(n=o.level)),o.children&&o.children.length&&o.children.some(function(e){return e.visible})){var t=0;o.children.forEach(function(e){e.visible&&(l(e,o),t+=e.colSpan)}),o.colSpan=t}else o.colSpan=1}(e)});for(var l=[],o=0;o<n;o++)l.push([]);return getAllColumns(e).forEach(function(e){e.children&&e.children.length&&e.children.some(function(e){return e.visible})?e.rowSpan=1:e.rowSpan=n-e.level+1,l[e.level-1].push(e)}),l},_default={name:"VxeTableHeader",props:{tableData:Array,tableColumn:Array,visibleColumn:Array,collectColumn:Array,fixedColumn:Array,size:String,fixedType:String,isGroup:Boolean},data:function(){return{headerColumn:[]}},watch:{tableColumn:function(){this.uploadColumn()}},created:function(){this.uploadColumn()},mounted:function(){var e=this.$parent,l=this.$el,o=this.$refs,t=this.fixedType,n=e.elemStore,i="".concat(t||"main","-header-");n["".concat(i,"wrapper")]=l,n["".concat(i,"table")]=o.table,n["".concat(i,"colgroup")]=o.colgroup,n["".concat(i,"list")]=o.thead,n["".concat(i,"x-space")]=o.xSpace,n["".concat(i,"repair")]=o.repair},render:function(b){var g=this,e=this._e,_=this.$parent,C=this.fixedType,l=this.headerColumn,o=this.tableColumn,t=this.fixedColumn,$=_.$listeners,w=_.resizable,y=_.border,I=_.columnKey,n=_.headerRowClassName,T=_.headerCellClassName,z=_.showHeaderOverflow,S=_.headerAlign,k=_.align,P=_.highlightCurrentColumn,i=_.mouseConfig,E=void 0===i?{}:i,r=_.scrollXLoad,R=_.overflowX,D=_.getColumnIndex;return r&&C&&(o=t),b("div",{class:["vxe-table--header-wrapper",C?"fixed-".concat(C,"--wrapper"):"body--wrapper"]},[C?e():b("div",{class:"vxe-body--x-space",ref:"xSpace"}),b("table",{class:"vxe-table--header",attrs:{cellspacing:0,cellpadding:0,border:0},ref:"table"},[b("colgroup",{ref:"colgroup"},o.map(function(e,l){return b("col",{attrs:{name:e.id},key:l})}).concat([b("col",{attrs:{name:"col-gutter"}})])),b("thead",{ref:"thead"},l.map(function(e,v){return b("tr",{class:["vxe-header--row",n?_xeUtils.default.isFunction(n)?n({$table:_,$rowIndex:v,fixed:C}):n:""]},e.map(function(l,o){var e,t=l.showHeaderOverflow,n=l.headerAlign,i=l.align,r=l.own,a=l.children&&l.children.length,c=C?l.fixed!==C&&!a:l.fixed&&R,s=_xeUtils.default.isUndefined(t)||_xeUtils.default.isNull(t)?z:t,d=n||i||S||k,u="ellipsis"===s,f="title"===s,h=!0===s||"tooltip"===s,m=f||h||u,p={},x=D(l);return h&&(p.mouseover=function(e){_._isResize||_.triggerHeaderTooltipEvent(e,{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C})},p.mouseout=function(e){_._isResize||_.clostTooltip()}),(P||$["header-cell-click"]||E.checked)&&(p.click=function(e){return _.triggerHeaderCellClickEvent(e,{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C,cell:e.currentTarget})}),$["header-cell-dblclick"]&&(p.dblclick=function(e){return _tools.UtilTools.emitEvent(_,"header-cell-dblclick",[{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C,cell:e.currentTarget},e])}),E.checked&&(p.mousedown=function(e){return _.triggerHeaderCellMousedownEvent(e,{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C,cell:e.currentTarget})}),b("th",{class:["vxe-header--column",l.id,(e={},_defineProperty(e,"col--".concat(d),d),_defineProperty(e,"col--fixed",l.fixed),_defineProperty(e,"col--index","index"===l.type),_defineProperty(e,"col--group",a),_defineProperty(e,"col--ellipsis",m),_defineProperty(e,"fixed--hidden",c),_defineProperty(e,"filter--active",l.filters.some(function(e){return e.checked})),e),T?_xeUtils.default.isFunction(T)?T({$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C}):T:""],attrs:{"data-colid":l.id,colspan:l.colSpan,rowspan:l.rowSpan},on:p,key:I||a?l.id:x},[b("div",{class:["vxe-cell",{"c--title":f,"c--tooltip":h,"c--ellipsis":u}],attrs:{title:f?r.title||r.label:null}},l.renderHeader(b,{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C,isHidden:c})),!c&&!a&&(_xeUtils.default.isBoolean(l.resizable)?l.resizable:w)?b("div",{class:["vxe-resizable",{"is--line":!y}],on:{mousedown:function(e){return g.resizeMousedown(e,{$table:_,$rowIndex:v,column:l,columnIndex:x,$columnIndex:o,fixed:C,isHidden:c})}}}):null])}).concat([b("th",{class:"col--gutter"})]))}))]),b("div",{class:"vxe-table--repair",ref:"repair"})])},methods:{uploadColumn:function(){this.headerColumn=this.isGroup?convertToRows(this.collectColumn):[this.$parent.scrollXLoad&&this.fixedType?this.fixedColumn:this.tableColumn]},resizeMousedown:function(e,l){var o=l.column,t=this.$parent,n=this.$el,i=this.fixedType,r=t.$refs,a=r.tableBody,c=r.leftContainer,s=r.rightContainer,d=r.resizeBar,u=e.target,f=e.clientX,h=u.parentNode,m=0,p=a.$el,x=_tools.DomTools.getOffsetPos(u,n),v=u.clientWidth,b=x.left-h.clientWidth+v+36,g=x.left+Math.floor(v/2),_=document.onmousemove,C=document.onmouseup,$="left"===i,w="right"===i,y=0;if($||w){for(var I=$?"nextElementSibling":"previousElementSibling",T=h[I];T&&!_tools.DomTools.hasClass(T,"fixed--hidden");)_tools.DomTools.hasClass(T,"col--group")||(y+=T.offsetWidth),T=T[I];w&&s&&(g=s.offsetLeft+y)}var z=function(e){e.stopPropagation(),e.preventDefault();var l=e.clientX-f,o=g+l,t=i?0:p.scrollLeft;$?o=Math.min(o,(s?s.offsetLeft:p.clientWidth)-y-36):w&&(b=(c?c.clientWidth:0)+y+36,o=Math.min(o,g+h.clientWidth-36)),m=Math.max(o,b),d.style.left="".concat(m-t,"px")};t._isResize=!0,_tools.DomTools.addClass(t.$el,"c--resize"),d.style.display="block",document.onmousemove=z,document.onmouseup=function(e){document.onmousemove=_,document.onmouseup=C,o.resizeWidth=o.renderWidth+(w?g-m:m-g),d.style.display="none",t._isResize=!1,t._lastResizeTime=Date.now(),t.analyColumnWidth(),t.recalculate(!0),_tools.DomTools.removeClass(t.$el,"c--resize"),t._toolbar&&t._toolbar.updateResizable(),_tools.UtilTools.emitEvent(t,"resizable-change",[l])},z(e)}}};exports.default=_default;