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 • 8.01 kB
JavaScript
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"],customColumnCssKeys=["checkbox","sort","title","width","fixed","align","header-align","footer-align"];_ui.VxeUI.hooks.add("tableCustomModule",{setupTable(h){let{reactData:C,internalData:v}=h,{computeCustomOpts:f,computeRowGroupFields:s,computeCustomSimpleMode:x}=h.getComputeMaps(),A=h.getRefMaps().refElem;var e=h.xeGrid;let S=h.xeGantt,_=e||S,a=()=>{var e=C.customStore,{mode:t,placement:l,popupOptions:o}=f.value,t=!("modal"===t||"drawer"===t),{transfer:o,minWidth:r,maxWidth:i,maxHeight:s}=o||{},a="outside"===x.value,u=document.documentElement;let n=A.value,d=0,m=0;var c={};let g={};var h=(n=S&&(h=S.getRefMaps().refGanttContainerElem,h=h.value)?h:n).getBoundingClientRect();m=t&&o?(d=h.top+u.scrollTop,_xeUtils.default.eqNull(s)?360:s):a?(_&&n&&(d=n.offsetTop),_xeUtils.default.eqNull(s)?360:s):(n&&(m=n.clientHeight-22),Math.max(88,m));let v=0,b=("left"!==l&&"right"!==l&&(v=_xeUtils.default.eqNull(s)?m:s),l&&["left","right","bottom-left","bottom-right"].includes(l)||d&&(c.top=(0,_dom.toCssUnit)(d)),t&&o&&("bottom-left"!==l&&"bottom-right"!==l||(c.bottom=(0,_dom.toCssUnit)(u.scrollHeight-h.top-h.height+1)),"top-left"===l||"bottom-left"===l?c.left=(0,_dom.toCssUnit)(h.left):l&&"top-right"!==l&&"bottom-right"!==l||(c.right=(0,_dom.toCssUnit)(u.scrollWidth-h.left-h.width+1))),getComputedStyle(u)),p=getComputedStyle(n);return customColumnCssKeys.forEach(e=>{var e=`--vxe-ui-vxe-table-custom-column-${e}-${"title"===e?"min-":""}width`,t=p.getPropertyValue(e);t&&t!==b.getPropertyValue(e)&&(g[e]=t)}),r&&(c["--vxe-ui-vxe-table-custom-default-min-width"]=(0,_dom.toCssUnit)(r)),i&&(c["--vxe-ui-vxe-table-custom-default-max-width"]=(0,_dom.toCssUnit)(i)),v&&(c.maxHeight=(0,_dom.toCssUnit)(v)),e.defPopupStyle=c,e.panePopupStyle=g,e.maxHeight=v,(0,_vue.nextTick)()},l=()=>{var{initStore:e,customStore:t}=C,{mode:l,popupOptions:o}=f.value,l=!("modal"===l||"drawer"===l),o=(o||{}).transfer,r=x.value;let i=null;return l&&o?i=document.body:"outside"===r&&_&&(l=_.getRefMaps().refPopupContainerElem,o=l.value)&&(i=o),v.customPopupToElem!==i&&C.ctPopupFlag++,v.customPopupToElem=i,t.visible=!0,e.custom=!0,u(),n(),a(),(0,_vue.nextTick)().then(()=>a())},u=()=>{var e=C.customStore,t=v.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,e.renderAlign=e.align,e.renderHeaderAlign=e.headerAlign,e.renderFooterAlign=e.footerAlign,l[t]=e.renderSortNumber,o[t]=e.fixed,r[t]=e.visible}),e.oldSortMaps=l,e.oldFixedMaps=o,e.oldVisibleMaps=r,C.customColumnList=t.slice(0)}},o=()=>{var e=C.customStore,t=f.value;return e.visible&&(e.visible=!1,t.immediate||h.handleCustom()),(0,_vue.nextTick)()};let t=e=>{var t=C.customStore,l=C.customColumnList,o=f.value;let{checkMethod:r,visibleMethod:i}=o,s=!!e;return o.immediate?(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:h,column:e})||r&&!r({$table:h,column:e})||(e.visible=s,e.renderVisible=s,e.halfVisible=!1)}),t.isAll=s,C.isCustomStatus=!0,h.handleCustom(),h.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:h,column:e})||r&&!r({$table:h,column:e})||(e.renderVisible=s,e.halfVisible=!1)}),t.isAll=s),h.checkCustomStatus(),(0,_vue.nextTick)()};e={getCustomVisible(){var e=C.customStore;return e.visible},openCustom:l,closeCustom:o,toggleCustom:()=>{var e=C.customStore;return(e.visible?o:l)()},saveCustom:e=>{let{customColumnList:t,aggHandleFields:l,rowGroupList:o}=C;let{allowVisible:i,allowSort:s,allowFixed:a,allowResizable:u,allowAlign:n,allowHeaderAlign:d,allowFooterAlign:m,allowGroup:c,allowValues:g}=f.value;return e?_xeUtils.default.eachTree(t,e=>{!u||!e.renderVisible||e.children&&e.children.length||(e.resizeWidth=Math.max(0,_xeUtils.default.toNumber(e.renderWidth)))}):_xeUtils.default.eachTree(t,(e,t,l,o,r)=>{r?e.fixed=r.fixed:(s&&(e.renderSortNumber=t+1),a&&(e.fixed=e.renderFixed)),!u||!e.renderVisible||e.children&&e.children.length||e.renderResizeWidth!==e.renderWidth&&(e.resizeWidth=e.renderResizeWidth,e.renderWidth=e.renderResizeWidth),i&&(e.visible=e.renderVisible),n&&(e.align=e.renderAlign),d&&(e.headerAlign=e.renderHeaderAlign),m&&(e.footerAlign=e.renderFooterAlign),c&&g&&(e.aggFunc=e.renderAggFn)}),C.isCustomStatus=!0,c&&h.handlePivotTableAggData&&(o.length!==l.length||o.some((e,t)=>e.field!==l[t])?l.length?h.setRowGroups(l):h.clearRowGroups():g&&h.handleUpdateAggData()),s&&(v.collectColumn=t),h.saveCustomStore("confirm")},cancelCustom:()=>{var{customColumnList:e,customStore:t}=C;let{oldSortMaps:r,oldFixedMaps:i,oldVisibleMaps:s}=t,{allowVisible:a,allowSort:u,allowFixed:n,allowAlign:d,allowHeaderAlign:m,allowFooterAlign:c,allowResizable:g,allowGroup:h,allowValues:v}=f.value;return _xeUtils.default.eachTree(e,e=>{var t=e.getKey(),l=!!s[t],o=i[t]||"";a&&(e.renderVisible=l,e.visible=l),n&&(e.renderFixed=o,e.fixed=o),u&&(e.renderSortNumber=r[t]||0),g&&(e.renderResizeWidth=e.renderWidth),d&&(e.align=e.renderAlign),m&&(e.headerAlign=e.renderHeaderAlign),c&&(e.footerAlign=e.renderFooterAlign),h,v},{children:"children"}),(0,_vue.nextTick)()},resetCustom(e){let t=C.rowGroupList;var l=v.collectColumn;let o=f.value.checkMethod,r=Object.assign({visible:!0,resizable:!0===e,fixed:!0===e,sort:!0===e,aggFunc:!0===e,align:!0===e,headerAlign:!0===e,footerAlign:!0===e},e),i=[];return _xeUtils.default.eachTree(l,e=>{r.resizable&&(e.resizeWidth=0),r.fixed&&(e.fixed=e.defaultFixed,e.renderFixed=e.defaultFixed),r.sort&&(e.renderSortNumber=e.sortNumber,e.parentId=e.defaultParentId),o&&!o({$table:h,column:e})||(e.visible=e.defaultVisible),r.align&&(e.align=e.defaultAlign,e.renderAlign=e.defaultAlign),r.headerAlign&&(e.headerAlign=e.defaultHeaderAlign,e.renderHeaderAlign=e.defaultHeaderAlign),r.footerAlign&&(e.footerAlign=e.defaultFooterAlign,e.renderFooterAlign=e.defaultFooterAlign),r.aggFunc&&(e.aggFunc=e.defaultAggFunc,e.renderAggFn=e.defaultAggFunc),e.renderResizeWidth=e.renderWidth,i.push(e)}),r.sort&&(e=_xeUtils.default.toArrayTree(_xeUtils.default.orderBy(i,"renderSortNumber"),{key:"id",parentKey:"parentId",children:"children"}),v.collectColumn=e,v.tableFullColumn=(0,_util.getColumnList)(e)),C.isCustomStatus=!1,h.handleCustom().then(()=>{var e;r.aggFunc&&h.handlePivotTableAggData&&(((e=s.value)||t).length?e&&e.length?h.setRowGroups(e):h.clearRowGroups():h.handleUpdateAggData()),h.saveCustomStore("reset")})},toggleCustomAllCheckbox(){var e=C.customStore,e=!e.isAll;return t(e)},setCustomAllCheckbox:t};let n=()=>{var e=C.customStore,t=v.collectColumn;let l=f.value.checkMethod;e.isAll=t.every(e=>!!l&&!l({$table:h,column:e})||e.renderVisible),e.isIndeterminate=!e.isAll&&t.some(e=>(!l||l({$table:h,column:e}))&&(e.renderVisible||e.halfVisible))},r=(e,t)=>{h.dispatchEvent("custom",{type:e},t)};var i={checkCustomStatus:n,emitCustomEvent:r,triggerCustomEvent(e){var t=h.reactData.customStore;t.visible?(o(),r("close",e),h.dispatchEvent("custom-close",{},e)):(t.btnEl=e.target,l(),r("open",e),h.dispatchEvent("custom-open",{},e))},customOpenEvent(e){var t=h.reactData.customStore;t.visible||(t.activeBtn=!0,t.btnEl=e.target,h.openCustom(),h.emitCustomEvent("open",e),h.dispatchEvent("custom-open",{},e))},customCloseEvent(e){var t=h.reactData.customStore;t.visible&&(t.activeBtn=!1,h.closeCustom(),h.emitCustomEvent("close",e),h.dispatchEvent("custom-close",{},e))},handleUpdateCustomColumn:u,handleCustomStyle(){return h.reactData.isCustomDragStatus=!1,a()}};return Object.assign(Object.assign({},e),i)},setupGrid(e){return e.extendTableMethods(tableCustomMethodKeys)},setupGantt(e){return e.extendTableMethods(tableCustomMethodKeys)}});