1 line
5.1 KiB
JavaScript
1 line
5.1 KiB
JavaScript
var _vue=require("vue"),_ui=require("../../../ui"),_xeUtils=_interopRequireDefault(require("xe-utils")),_util=require("../../src/util");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}let tableCustomMethodKeys=["openCustom","closeCustom","toggleCustom","saveCustom","cancelCustom","resetCustom","toggleCustomAllCheckbox","setCustomAllCheckbox"];_ui.VxeUI.hooks.add("tableCustomModule",{setupTable(m){let{reactData:c,internalData:b}=m,{computeCustomOpts:v,computeRowGroupFields:o}=m.getComputeMaps(),s=m.getRefMaps().refElem,l=m.xeGrid,i=m.xeGantt,r=()=>{var e,t=c.customStore;let l=s.value,r=0;(l=i&&(e=i.getRefMaps().refGanttContainerElem,e=e.value)?e:l)&&(r=l.clientHeight-28),t.maxHeight=Math.max(88,r)},a=()=>{var{initStore:e,customStore:t}=c;return t.visible=!0,e.custom=!0,u(),d(),r(),(0,_vue.nextTick)().then(()=>r())},u=()=>{var e=c.customStore,t=b.collectColumn;if(e.visible){let l={},r={},s={};_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,r[t]=e.fixed,s[t]=e.visible}),e.oldSortMaps=l,e.oldFixedMaps=r,e.oldVisibleMaps=s,c.customColumnList=t.slice(0)}},n=()=>{var e=c.customStore,t=v.value;return e.visible&&(e.visible=!1,t.immediate||m.handleCustom()),(0,_vue.nextTick)()};let t=e=>{var t=c.customStore,l=c.customColumnList,r=v.value;let{checkMethod:s,visibleMethod:i}=r,o=!!e;return r.immediate?(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:m,column:e})||s&&!s({$table:m,column:e})||(e.visible=o,e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o,c.isCustomStatus=!0,m.handleCustom(),m.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:m,column:e})||s&&!s({$table:m,column:e})||(e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o),m.checkCustomStatus(),(0,_vue.nextTick)()};var e={getCustomVisible(){var e=c.customStore;return e.visible},openCustom:a,closeCustom:n,toggleCustom:()=>{var e=c.customStore;return(e.visible?n:a)()},saveCustom:()=>{let{customColumnList:e,aggHandleFields:l,rowGroupList:t}=c;let{allowVisible:i,allowSort:o,allowFixed:a,allowResizable:u,allowGroup:n,allowValues:d}=v.value;return _xeUtils.default.eachTree(e,(e,t,l,r,s)=>{s?e.fixed=s.fixed:(o&&(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&&d&&(e.aggFunc=e.renderAggFn)}),c.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()),o&&(b.collectColumn=e),m.saveCustomStore("confirm")},cancelCustom:()=>{var{customColumnList:e,customStore:t}=c;let{oldSortMaps:s,oldFixedMaps:i,oldVisibleMaps:o}=t,{allowVisible:a,allowSort:u,allowFixed:n,allowResizable:d}=v.value;return _xeUtils.default.eachTree(e,e=>{var t=e.getKey(),l=!!o[t],r=i[t]||"";a&&(e.renderVisible=l,e.visible=l),n&&(e.renderFixed=r,e.fixed=r),u&&(e.renderSortNumber=s[t]||0),d&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),(0,_vue.nextTick)()},resetCustom(e){let t=c.rowGroupList;var l=b.collectColumn;let r=v.value.checkMethod,s=Object.assign({visible:!0,resizable:!0===e,fixed:!0===e,sort:!0===e,aggFunc:!0===e},e),i=[];return _xeUtils.default.eachTree(l,e=>{s.resizable&&(e.resizeWidth=0),s.fixed&&(e.fixed=e.defaultFixed),s.sort&&(e.renderSortNumber=e.sortNumber,e.parentId=e.defaultParentId),r&&!r({$table:m,column:e})||(e.visible=e.defaultVisible),s.aggFunc&&(e.aggFunc=e.defaultAggFunc,e.renderAggFn=e.defaultAggFunc),e.renderResizeWidth=e.renderWidth,i.push(e)}),s.sort&&(e=_xeUtils.default.toArrayTree(_xeUtils.default.orderBy(i,"renderSortNumber"),{key:"id",parentKey:"parentId",children:"children"}),b.collectColumn=e,b.tableFullColumn=(0,_util.getColumnList)(e)),c.isCustomStatus=!1,m.handleCustom().then(()=>{var e;s.aggFunc&&m.handlePivotTableAggregateData&&(((e=o.value)||t).length?e&&e.length?m.setRowGroups(e):m.clearRowGroups():m.handleUpdateAggData()),m.saveCustomStore("reset")})},toggleCustomAllCheckbox(){var e=c.customStore,e=!e.isAll;return t(e)},setCustomAllCheckbox:t};let d=()=>{var e=c.customStore,t=b.collectColumn;let l=v.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))},h=(e,t)=>{(l||i||m).dispatchEvent("custom",{type:e},t)};var g={checkCustomStatus:d,emitCustomEvent:h,triggerCustomEvent(e){var t=m.reactData.customStore;t.visible?(n(),h("close",e)):(t.btnEl=e.target,a(),h("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:u};return Object.assign(Object.assign({},e),g)},setupGrid(e){return e.extendTableMethods(tableCustomMethodKeys)},setupGantt(e){return e.extendTableMethods(tableCustomMethodKeys)}}); |