UNPKG

vxe-table

Version:

A PC-end table component based on Vxe UI, supporting copy-paste, data pivot table, and high-performance virtual list table solution.

1 lines 6.43 kB
var _vue=require("vue"),_ui=require("../../../ui"),_xeUtils=_interopRequireDefault(require("xe-utils")),_util=require("../../src/util"),_dom=require("../../../ui/src/dom");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}let tableCustomMethodKeys=["openCustom","closeCustom","getCustomVisible","toggleCustom","saveCustom","cancelCustom","resetCustom","toggleCustomAllCheckbox","setCustomAllCheckbox"];_ui.VxeUI.hooks.add("tableCustomModule",{setupTable(m){let{reactData:h,internalData:c}=m,{computeCustomOpts:b,computeRowGroupFields:i,computeCustomSimpleMode:g}=m.getComputeMaps(),v=m.getRefMaps().refElem;var e=m.xeGrid;let p=m.xeGantt,C=e||p,u=()=>{var e=h.customStore,{mode:t,placement:l,popupOptions:o}=b.value,t=!("modal"===t||"drawer"===t),{transfer:o,maxHeight:r}=o||{},s="outside"===g.value,i=document.documentElement;let u=v.value,a=0,n=0;var d={},m=(u=p&&(m=p.getRefMaps().refGanttContainerElem,m=m.value)?m:u).getBoundingClientRect();n=t&&o?(a=m.top+i.scrollTop,_xeUtils.default.eqNull(r)?360:r):s?(C&&u&&(a=u.offsetTop),_xeUtils.default.eqNull(r)?360:r):(u&&(n=u.clientHeight-22),Math.max(88,n));let c=0;return"left"!==l&&"right"!==l&&(c=_xeUtils.default.eqNull(r)?n:r),l&&["left","right","bottom-left","bottom-right"].includes(l)||a&&(d.top=(0,_dom.toCssUnit)(a)),t&&o&&("bottom-left"!==l&&"bottom-right"!==l||(d.bottom=(0,_dom.toCssUnit)(i.scrollHeight-m.top-m.height+1)),"top-left"===l||"bottom-left"===l?d.left=(0,_dom.toCssUnit)(m.left):l&&"top-right"!==l&&"bottom-right"!==l||(d.right=(0,_dom.toCssUnit)(i.scrollWidth-m.left-m.width+1))),c&&(d.maxHeight=(0,_dom.toCssUnit)(c)),e.popupStyle=d,e.maxHeight=c,(0,_vue.nextTick)()},l=()=>{var{initStore:e,customStore:t}=h,{mode:l,popupOptions:o}=b.value,l=!("modal"===l||"drawer"===l),o=(o||{}).transfer,r=g.value;let s=null;return l&&o?s=document.body:"outside"===r&&C&&(l=C.getRefMaps().refPopupContainerElem,o=l.value)&&(s=o),c.customPopupToElem!==s&&h.ctPopupFlag++,c.customPopupToElem=s,t.visible=!0,e.custom=!0,a(),n(),u(),(0,_vue.nextTick)().then(()=>u())},a=()=>{var e=h.customStore,t=c.collectColumn;if(e.visible){let l={},o={},r={};_xeUtils.default.eachTree(t,e=>{var t=e.getKey();e.renderFixed=e.fixed,e.renderVisible=e.visible,e.renderResizeWidth=e.renderWidth,l[t]=e.renderSortNumber,o[t]=e.fixed,r[t]=e.visible}),e.oldSortMaps=l,e.oldFixedMaps=o,e.oldVisibleMaps=r,h.customColumnList=t.slice(0)}},o=()=>{var e=h.customStore,t=b.value;return e.visible&&(e.visible=!1,t.immediate||m.handleCustom()),(0,_vue.nextTick)()};let t=e=>{var t=h.customStore,l=h.customColumnList,o=b.value;let{checkMethod:r,visibleMethod:s}=o,i=!!e;return o.immediate?(_xeUtils.default.eachTree(l,e=>{s&&!s({$table:m,column:e})||r&&!r({$table:m,column:e})||(e.visible=i,e.renderVisible=i,e.halfVisible=!1)}),t.isAll=i,h.isCustomStatus=!0,m.handleCustom(),m.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(l,e=>{s&&!s({$table:m,column:e})||r&&!r({$table:m,column:e})||(e.renderVisible=i,e.halfVisible=!1)}),t.isAll=i),m.checkCustomStatus(),(0,_vue.nextTick)()};e={getCustomVisible(){var e=h.customStore;return e.visible},openCustom:l,closeCustom:o,toggleCustom:()=>{var e=h.customStore;return(e.visible?o:l)()},saveCustom:()=>{let{customColumnList:e,aggHandleFields:l,rowGroupList:t}=h;let{allowVisible:s,allowSort:i,allowFixed:u,allowResizable:a,allowGroup:n,allowValues:d}=b.value;return _xeUtils.default.eachTree(e,(e,t,l,o,r)=>{r?e.fixed=r.fixed:(i&&(e.renderSortNumber=t+1),u&&(e.fixed=e.renderFixed)),!a||!e.renderVisible||e.children&&e.children.length||e.renderResizeWidth!==e.renderWidth&&(e.resizeWidth=e.renderResizeWidth,e.renderWidth=e.renderResizeWidth),s&&(e.visible=e.renderVisible),n&&d&&(e.aggFunc=e.renderAggFn)}),h.isCustomStatus=!0,n&&m.handlePivotTableAggregateData&&(t.length!==l.length||t.some((e,t)=>e.field!==l[t])?l.length?m.setRowGroups(l):m.clearRowGroups():d&&m.handleUpdateAggData()),i&&(c.collectColumn=e),m.saveCustomStore("confirm")},cancelCustom:()=>{var{customColumnList:e,customStore:t}=h;let{oldSortMaps:r,oldFixedMaps:s,oldVisibleMaps:i}=t,{allowVisible:u,allowSort:a,allowFixed:n,allowResizable:d}=b.value;return _xeUtils.default.eachTree(e,e=>{var t=e.getKey(),l=!!i[t],o=s[t]||"";u&&(e.renderVisible=l,e.visible=l),n&&(e.renderFixed=o,e.fixed=o),a&&(e.renderSortNumber=r[t]||0),d&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),(0,_vue.nextTick)()},resetCustom(e){let t=h.rowGroupList;var l=c.collectColumn;let o=b.value.checkMethod,r=Object.assign({visible:!0,resizable:!0===e,fixed:!0===e,sort:!0===e,aggFunc:!0===e},e),s=[];return _xeUtils.default.eachTree(l,e=>{r.resizable&&(e.resizeWidth=0),r.fixed&&(e.fixed=e.defaultFixed),r.sort&&(e.renderSortNumber=e.sortNumber,e.parentId=e.defaultParentId),o&&!o({$table:m,column:e})||(e.visible=e.defaultVisible),r.aggFunc&&(e.aggFunc=e.defaultAggFunc,e.renderAggFn=e.defaultAggFunc),e.renderResizeWidth=e.renderWidth,s.push(e)}),r.sort&&(e=_xeUtils.default.toArrayTree(_xeUtils.default.orderBy(s,"renderSortNumber"),{key:"id",parentKey:"parentId",children:"children"}),c.collectColumn=e,c.tableFullColumn=(0,_util.getColumnList)(e)),h.isCustomStatus=!1,m.handleCustom().then(()=>{var e;r.aggFunc&&m.handlePivotTableAggregateData&&(((e=i.value)||t).length?e&&e.length?m.setRowGroups(e):m.clearRowGroups():m.handleUpdateAggData()),m.saveCustomStore("reset")})},toggleCustomAllCheckbox(){var e=h.customStore,e=!e.isAll;return t(e)},setCustomAllCheckbox:t};let n=()=>{var e=h.customStore,t=c.collectColumn;let l=b.value.checkMethod;e.isAll=t.every(e=>!!l&&!l({$table:m,column:e})||e.renderVisible),e.isIndeterminate=!e.isAll&&t.some(e=>(!l||l({$table:m,column:e}))&&(e.renderVisible||e.halfVisible))},r=(e,t)=>{m.dispatchEvent("custom",{type:e},t)};var s={checkCustomStatus:n,emitCustomEvent:r,triggerCustomEvent(e){var t=m.reactData.customStore;t.visible?(o(),r("close",e)):(t.btnEl=e.target,l(),r("open",e))},customOpenEvent(e){var t=m.reactData.customStore;t.visible||(t.activeBtn=!0,t.btnEl=e.target,m.openCustom(),m.emitCustomEvent("open",e))},customCloseEvent(e){var t=m.reactData.customStore;t.visible&&(t.activeBtn=!1,m.closeCustom(),m.emitCustomEvent("close",e))},handleUpdateCustomColumn:a,handleCustomStyle(){return m.reactData.isCustomDragStatus=!1,u()}};return Object.assign(Object.assign({},e),s)},setupGrid(e){return e.extendTableMethods(tableCustomMethodKeys)},setupGantt(e){return e.extendTableMethods(tableCustomMethodKeys)}});