UNPKG

@blueking/vxe-table

Version:

一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...

1 lines 4.02 kB
var _vue=require("vue"),_ui=require("../../../ui"),_xeUtils=_interopRequireDefault(require("xe-utils"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}let tableCustomMethodKeys=["openCustom","closeCustom","saveCustom","cancelCustom","resetCustom","toggleCustomAllCheckbox","setCustomAllCheckbox"];_ui.VxeUI.hooks.add("tableCustomModule",{setupTable(d){let{reactData:m,internalData:l}=d,c=d.getComputeMaps().computeCustomOpts,s=d.getRefMaps().refElem,i=d.xegrid,r=()=>{var e=m.customStore,t=s.value;let i=0;t&&(i=t.clientHeight-28),e.maxHeight=Math.max(88,i)},o=()=>{var{initStore:e,customStore:t}=m;return t.visible=!0,e.custom=!0,u(),n(),r(),(0,_vue.nextTick)().then(()=>r())},u=()=>{var e=m.customStore,t=l.collectColumn;if(e.visible){let i={},s={},l={};_xeUtils.default.eachTree(t,e=>{var t=e.getKey();e.renderFixed=e.fixed,e.renderVisible=e.visible,e.renderResizeWidth=e.renderWidth,i[t]=e.renderSortNumber,s[t]=e.fixed,l[t]=e.visible}),e.oldSortMaps=i,e.oldFixedMaps=s,e.oldVisibleMaps=l,m.customColumnList=t.slice(0)}},a=()=>{var e=m.customStore,t=c.value;return e.visible&&(e.visible=!1,t.immediate||d.handleCustom()),(0,_vue.nextTick)()};let t=e=>{var t=m.customStore,i=m.customColumnList,s=c.value;let{checkMethod:l,visibleMethod:r}=s,o=!!e;return s.immediate?(_xeUtils.default.eachTree(i,e=>{r&&!r({column:e})||l&&!l({column:e})||(e.visible=o,e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o,m.isCustomStatus=!0,d.handleCustom(),d.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(i,e=>{r&&!r({column:e})||l&&!l({column:e})||(e.renderVisible=o,e.halfVisible=!1)}),t.isAll=o),d.checkCustomStatus(),(0,_vue.nextTick)()};var e={openCustom:o,closeCustom:a,saveCustom:()=>{var e=m.customColumnList;let{allowVisible:r,allowSort:o,allowFixed:u,allowResizable:a}=c.value;return _xeUtils.default.eachTree(e,(e,t,i,s,l)=>{l?e.fixed=l.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),r&&(e.visible=e.renderVisible)}),m.isCustomStatus=!0,m.isDragColMove=!0,setTimeout(()=>{m.isDragColMove=!1},1e3),d.saveCustomStore("confirm")},cancelCustom:()=>{var{customColumnList:e,customStore:t}=m;let{oldSortMaps:l,oldFixedMaps:r,oldVisibleMaps:o}=t,{allowVisible:u,allowSort:a,allowFixed:d,allowResizable:n}=c.value;return _xeUtils.default.eachTree(e,e=>{var t=e.getKey(),i=!!o[t],s=r[t]||"";u&&(e.renderVisible=i,e.visible=i),d&&(e.renderFixed=s,e.fixed=s),a&&(e.renderSortNumber=l[t]||0),n&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),(0,_vue.nextTick)()},resetCustom(e){var t=l.collectColumn;let i=c.value.checkMethod,s=Object.assign({visible:!0,resizable:!0===e,fixed:!0===e,sort:!0===e},e);return _xeUtils.default.eachTree(t,e=>{s.resizable&&(e.resizeWidth=0),s.fixed&&(e.fixed=e.defaultFixed),s.sort&&(e.renderSortNumber=e.sortNumber),i&&!i({column:e})||(e.visible=e.defaultVisible),e.renderResizeWidth=e.renderWidth}),m.isCustomStatus=!1,d.saveCustomStore("reset"),d.handleCustom()},toggleCustomAllCheckbox(){var e=m.customStore,e=!e.isAll;return t(e)},setCustomAllCheckbox:t};let n=()=>{var e=m.customStore,t=l.collectColumn;let i=c.value.checkMethod;e.isAll=t.every(e=>!!i&&!i({column:e})||e.renderVisible),e.isIndeterminate=!e.isAll&&t.some(e=>(!i||i({column:e}))&&(e.renderVisible||e.halfVisible))},v=(e,t)=>{(i||d).dispatchEvent("custom",{type:e},t)};var b={checkCustomStatus:n,emitCustomEvent:v,triggerCustomEvent(e){var t=d.reactData.customStore;t.visible?(a(),v("close",e)):(t.btnEl=e.target,o(),v("open",e))},customOpenEvent(e){var t=m.customStore;t.visible||(t.activeBtn=!0,t.btnEl=e.target,d.openCustom(),d.emitCustomEvent("open",e))},customCloseEvent(e){var t=m.customStore;t.visible&&(t.activeBtn=!1,d.closeCustom(),d.emitCustomEvent("close",e))},handleUpdateCustomColumn:u};return Object.assign(Object.assign({},e),b)},setupGrid(e){return e.extendTableMethods(tableCustomMethodKeys)}});