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 5.1 kB
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(c){let{reactData:m,internalData:b}=c,{computeCustomOpts:v,computeRowGroupFields:o}=c.getComputeMaps(),r=c.getRefMaps().refElem,l=c.xeGrid,s=()=>{var e=m.customStore,t=r.value;let l=0;t&&(l=t.clientHeight-28),e.maxHeight=Math.max(88,l)},i=()=>{var{initStore:e,customStore:t}=m;return t.visible=!0,e.custom=!0,u(),n(),s(),(0,_vue.nextTick)().then(()=>s())},u=()=>{var e=m.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,m.customColumnList=t.slice(0)}},a=()=>{var e=m.customStore,t=v.value;return e.visible&&(e.visible=!1,t.immediate||c.handleCustom()),(0,_vue.nextTick)()};let t=e=>{var t=m.customStore,l=m.customColumnList,r=v.value;let{checkMethod:s,visibleMethod:i}=r,o=!!e;return r.immediate?(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:c,column:e})||s&&!s({$table:c,column:e})||(e.visible=o,e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o,m.isCustomStatus=!0,c.handleCustom(),c.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(l,e=>{i&&!i({$table:c,column:e})||s&&!s({$table:c,column:e})||(e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o),c.checkCustomStatus(),(0,_vue.nextTick)()};var e={getCustomVisible(){var e=m.customStore;return e.visible},openCustom:i,closeCustom:a,toggleCustom:()=>{var e=m.customStore;return(e.visible?a:i)()},saveCustom:()=>{let{customColumnList:e,aggHandleFields:l,rowGroupList:t}=m;let{allowVisible:i,allowSort:o,allowFixed:u,allowResizable:a,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),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),i&&(e.visible=e.renderVisible),n&&d&&(e.aggFunc=e.renderAggFn)}),m.isCustomStatus=!0,n&&c.handlePivotTableAggregateData&&(t.length!==l.length||t.some((e,t)=>e.field!==l[t])?l.length?c.setRowGroups(l):c.clearRowGroups():d&&c.handleUpdateAggData()),o&&(b.collectColumn=e),c.saveCustomStore("confirm")},cancelCustom:()=>{var{customColumnList:e,customStore:t}=m;let{oldSortMaps:s,oldFixedMaps:i,oldVisibleMaps:o}=t,{allowVisible:u,allowSort:a,allowFixed:n,allowResizable:d}=v.value;return _xeUtils.default.eachTree(e,e=>{var t=e.getKey(),l=!!o[t],r=i[t]||"";u&&(e.renderVisible=l,e.visible=l),n&&(e.renderFixed=r,e.fixed=r),a&&(e.renderSortNumber=s[t]||0),d&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),(0,_vue.nextTick)()},resetCustom(e){let t=m.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:c,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)),m.isCustomStatus=!1,c.handleCustom().then(()=>{var e;s.aggFunc&&c.handlePivotTableAggregateData&&(((e=o.value)||t).length?e&&e.length?c.setRowGroups(e):c.clearRowGroups():c.handleUpdateAggData()),c.saveCustomStore("reset")})},toggleCustomAllCheckbox(){var e=m.customStore,e=!e.isAll;return t(e)},setCustomAllCheckbox:t};let n=()=>{var e=m.customStore,t=b.collectColumn;let l=v.value.checkMethod;e.isAll=t.every(e=>!!l&&!l({$table:c,column:e})||e.renderVisible),e.isIndeterminate=!e.isAll&&t.some(e=>(!l||l({$table:c,column:e}))&&(e.renderVisible||e.halfVisible))},d=(e,t)=>{(l||c).dispatchEvent("custom",{type:e},t)};var h={checkCustomStatus:n,emitCustomEvent:d,triggerCustomEvent(e){var t=c.reactData.customStore;t.visible?(a(),d("close",e)):(t.btnEl=e.target,i(),d("open",e))},customOpenEvent(e){var t=c.reactData.customStore;t.visible||(t.activeBtn=!0,t.btnEl=e.target,c.openCustom(),c.emitCustomEvent("open",e))},customCloseEvent(e){var t=c.reactData.customStore;t.visible&&(t.activeBtn=!1,c.closeCustom(),c.emitCustomEvent("close",e))},handleUpdateCustomColumn:u};return Object.assign(Object.assign({},e),h)},setupGrid(e){return e.extendTableMethods(tableCustomMethodKeys)},setupGantt(e){return e.extendTableMethods(tableCustomMethodKeys)}});