vxe-table-ro-test
Version:
一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、列拖拽,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...
1 lines • 16.6 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _vue=require("vue"),_ui=require("../../../ui"),_utils=require("../../../ui/src/utils"),_dom=require("../../../ui/src/dom"),_log=require("../../../ui/src/log"),_xeUtils=_interopRequireDefault(require("xe-utils"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const{getI18n,getIcon}=_ui.VxeUI;var _default=exports.default=(0,_vue.defineComponent)({name:"TableCustomPanel",props:{customStore:{type:Object,default:()=>({})}},setup(L){const F=_ui.VxeUI.getComponent("VxeModal"),A=_ui.VxeUI.getComponent("VxeDrawer"),M=_ui.VxeUI.getComponent("VxeButton"),U=_ui.VxeUI.getComponent("VxeInput"),H=_ui.VxeUI.getComponent("VxeTooltip"),R=_ui.VxeUI.getComponent("VxeRadioGroup"),d=(0,_vue.inject)("$xeTable",{}),S=d["reactData"],{computeCustomOpts:D,computeColumnOpts:K,computeIsMaxFixedColumn:z}=d.getComputeMaps(),W=(0,_vue.ref)(),X=(0,_vue.ref)(),q=(0,_vue.ref)(),j=(0,_vue.ref)();let u;const G=e=>{var t=L["customStore"];t.activeWrapper=!0,d.customOpenEvent(e)},$=e=>{const t=L["customStore"];t.activeWrapper=!1,setTimeout(()=>{t.activeBtn||t.activeWrapper||d.customCloseEvent(e)},300)},P=({$event:e})=>{var t=S["customColumnList"];const{allowVisible:s,allowSort:a,allowFixed:r,allowResizable:n}=D.value;_xeUtils.default.eachTree(t,(e,t,o,l,i)=>{i?e.fixed=i.fixed:(a&&(e.renderSortNumber=t+1),r&&(e.fixed=e.renderFixed)),n&&e.renderVisible&&(!e.children||e.children.length)&&e.renderResizeWidth!==e.renderWidth&&(e.resizeWidth=e.renderResizeWidth,e.renderWidth=e.renderResizeWidth),s&&(e.visible=e.renderVisible)}),d.closeCustom(),d.emitCustomEvent("confirm",e),d.saveCustomStore("confirm")},Y=({$event:e})=>{d.closeCustom(),d.emitCustomEvent("close",e)},Z=({$event:e})=>{var t=L["customStore"],o=S["customColumnList"];const{oldSortMaps:i,oldFixedMaps:s,oldVisibleMaps:a}=t,{allowVisible:r,allowSort:n,allowFixed:u,allowResizable:c}=D.value;_xeUtils.default.eachTree(o,e=>{var t=e.getKey(),o=!!a[t],l=s[t]||"";r&&(e.renderVisible=o,e.visible=o),u&&(e.renderFixed=l,e.fixed=l),n&&(e.renderSortNumber=i[t]||0),c&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),d.closeCustom(),d.emitCustomEvent("cancel",e)},o=e=>{d.resetColumn(!0),d.closeCustom(),d.emitCustomEvent("reset",e)},J=({$event:t})=>{_ui.VxeUI.modal?_ui.VxeUI.modal.confirm({content:getI18n("vxe.custom.cstmConfirmRestore"),className:"vxe-table--ignore-clear",escClosable:!0}).then(e=>{"confirm"===e&&o(t)}):o(t)},l=t=>{var e=S["customColumnList"],e=_xeUtils.default.findTree(e,e=>e===t);e&&e.parent&&(e=e["parent"],e.children)&&e.children.length&&(e.renderVisible=e.children.every(e=>e.renderVisible),e.halfVisible=!e.renderVisible&&e.children.some(e=>e.renderVisible||e.halfVisible),l(e))},Q=e=>{const t=!e.renderVisible;D.value.immediate?(_xeUtils.default.eachTree([e],e=>{e.visible=t,e.renderVisible=t,e.halfVisible=!1}),d.handleCustom(),d.saveCustomStore("update:visible")):_xeUtils.default.eachTree([e],e=>{e.renderVisible=t,e.halfVisible=!1}),l(e),d.checkCustomStatus()},ee=(e,t)=>{var o=z.value;D.value.immediate?(e.renderFixed===t?_xeUtils.default.eachTree([e],e=>{e.fixed="",e.renderFixed=""}):o&&!e.renderFixed||_xeUtils.default.eachTree([e],e=>{e.fixed=t,e.renderFixed=t}),d.handleCustom(),d.saveCustomStore("update:fixed")):e.renderFixed===t?_xeUtils.default.eachTree([e],e=>{e.renderFixed=""}):o&&!e.renderFixed||_xeUtils.default.eachTree([e],e=>{e.renderFixed=t})},te=()=>{var e=L["customStore"],t=S["customColumnList"],o=D.value;const{checkMethod:l,visibleMethod:i}=o,s=!e.isAll;o.immediate?(_xeUtils.default.eachTree(t,e=>{i&&!i({column:e})||l&&!l({column:e})||(e.visible=s,e.renderVisible=s,e.halfVisible=!1)}),e.isAll=s,d.handleCustom(),d.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(t,e=>{i&&!i({column:e})||l&&!l({column:e})||(e.renderVisible=s,e.halfVisible=!1)}),e.isAll=s),d.checkCustomStatus()},oe=e=>{var e=e.currentTarget.parentNode.parentNode,t=e.getAttribute("colid"),t=d.getColumnById(t);e.draggable=!0,j.value=t,(0,_dom.addClass)(e,"active--drag-origin")},le=e=>{var e=e.currentTarget.parentNode.parentNode,t=q.value;e.draggable=!1,(j.value=null,_dom.removeClass)(e,"active--drag-origin"),t&&(t.style.display="")},ie=e=>{var t=new Image;e.dataTransfer&&e.dataTransfer.setDragImage(t,0,0)},se=e=>{var t=S["customColumnList"],o=D.value,e=e.currentTarget,l=q.value;if(u){if(u!==e){var i=u.getAttribute("drag-pos"),s=e.getAttribute("colid");const r=d.getColumnById(s);if(!r)return;var s=_xeUtils.default.findIndexOf(t,e=>e.id===r.id),a=u.getAttribute("colid");const n=d.getColumnById(a);if(!n)return;t.splice(s,1);a=_xeUtils.default.findIndexOf(t,e=>e.id===n.id);t.splice(a+("bottom"===i?1:0),0,r)}u.draggable=!1,u.removeAttribute("drag-pos"),(0,_dom.removeClass)(u,"active--drag-target")}j.value=null,e.draggable=!1,e.removeAttribute("drag-pos"),l&&(l.style.display=""),(0,_dom.removeClass)(e,"active--drag-target"),(0,_dom.removeClass)(e,"active--drag-origin"),o.immediate&&(_xeUtils.default.eachTree(t,(e,t,o,l,i)=>{i||(e.renderSortNumber=t+1)}),d.handleCustom(),d.saveCustomStore("update:sort"))},ae=e=>{var t=e.currentTarget,o=(u!==t&&(0,_dom.removeClass)(u,"active--drag-target"),t.getAttribute("colid")),o=d.getColumnById(o);o&&1===o.level&&(e.preventDefault(),o=e.clientY-t.getBoundingClientRect().y<t.clientHeight/2?"top":"bottom",(0,_dom.addClass)(t,"active--drag-target"),t.setAttribute("drag-pos",o),u=t);{o=e;var l=q.value,i=X.value;i&&l&&(e=(t=i.parentNode).getBoundingClientRect(),l.style.display="block",l.style.top=Math.min(t.clientHeight-t.scrollTop-l.clientHeight,o.clientY-e.y)+"px",l.style.left=Math.min(t.clientWidth-t.scrollLeft-l.clientWidth-16,o.clientX-e.x)+"px")}};return"development"===process.env.NODE_ENV&&(0,_vue.nextTick)(()=>{var e=D.value["mode"];F||(0,_log.errLog)("vxe.error.reqComp",["vxe-modal"]),A||"drawer"!==e||(0,_log.errLog)("vxe.error.reqComp",["vxe-drawer"]),M||(0,_log.errLog)("vxe.error.reqComp",["vxe-button"]),U||(0,_log.errLog)("vxe.error.reqComp",["vxe-input"]),H||(0,_log.errLog)("vxe.error.reqComp",["vxe-tooltip"]),R||(0,_log.errLog)("vxe.error.reqComp",["vxe-radio-group"])}),()=>{var e=D.value;if(["modal","drawer","popup"].includes(""+e.mode)){const r=L["customStore"];e=S["customColumnList"];const n=D.value,{modalOptions:u,drawerOptions:c,allowVisible:d,allowSort:m,allowFixed:v,allowResizable:h,checkMethod:x,visibleMethod:_}=n,p=K.value["maxFixedSize"];var t=n["mode"],o=Object.assign({},u),l=Object.assign({},c);const g=z.value,b=[],C=(_xeUtils.default.eachTree(e,(t,e,o,l,i)=>{if(!_||_({column:t})){var s=t.renderVisible,a=t.halfVisible,r=(0,_utils.formatText)(t.getTitle(),1),n=t.children&&t.children.length;const c=!!x&&!x({column:t});var u=!s;b.push((0,_vue.h)("tr",{key:t.id,colid:t.id,class:["vxe-table-custom-popup--row level--"+t.level,{"is--group":n}],onDragstart:ie,onDragend:se,onDragover:ae},[d?(0,_vue.h)("td",{class:"vxe-table-custom-popup--column-item col--visible"},[(0,_vue.h)("div",{class:["vxe-table-custom--checkbox-option",{"is--checked":s,"is--indeterminate":a,"is--disabled":c}],title:getI18n("vxe.custom.setting.colVisible"),onClick:()=>{c||Q(t)}},[(0,_vue.h)("span",{class:["vxe-checkbox--icon",a?getIcon().TABLE_CHECKBOX_INDETERMINATE:s?getIcon().TABLE_CHECKBOX_CHECKED:getIcon().TABLE_CHECKBOX_UNCHECKED]})])]):(0,_vue.createCommentVNode)(),m?(0,_vue.h)("td",{class:"vxe-table-custom-popup--column-item col--sort"},[1===t.level?(0,_vue.h)("span",Object.assign({class:["vxe-table-custom-popup--column-sort-btn",{"is--disabled":c||u}],title:getI18n("vxe.custom.setting.sortHelpTip")},c||u?{}:{onMousedown:oe,onMouseup:le}),[(0,_vue.h)("i",{class:getIcon().TABLE_CUSTOM_SORT})]):(0,_vue.h)("span","-")]):(0,_vue.createCommentVNode)(),(0,_vue.h)("td",{class:"vxe-table-custom-popup--column-item col--name"},["html"===t.type?(0,_vue.h)("div",{key:"1",class:"vxe-table-custom-popup--name",innerHTML:r}):(0,_vue.h)("div",{key:"0",class:"vxe-table-custom-popup--name",title:r},r)]),h?(0,_vue.h)("td",{class:"vxe-table-custom-popup--column-item col--resizable"},[t.children&&t.children.length?(0,_vue.h)("span","-"):U?(0,_vue.h)(U,{type:"integer",disabled:c||u,modelValue:t.renderResizeWidth,"onUpdate:modelValue"(e){t.renderResizeWidth=Math.max(0,Number(e))}}):(0,_vue.createCommentVNode)()]):(0,_vue.createCommentVNode)(),v?(0,_vue.h)("td",{class:"vxe-table-custom-popup--column-item col--fixed"},[i?(0,_vue.h)("span","-"):R?(0,_vue.h)(R,{modelValue:t.renderFixed||"",type:"button",size:"mini",disabled:c||u,options:[{label:getI18n("vxe.custom.setting.fixedLeft"),value:"left",disabled:c||u||g},{label:getI18n("vxe.custom.setting.fixedUnset"),value:"",disabled:c||u},{label:getI18n("vxe.custom.setting.fixedRight"),value:"right",disabled:c||u||g}],"onUpdate:modelValue"(e){t.renderFixed=e}}):(0,_vue.createCommentVNode)()]):(0,_vue.createCommentVNode)()]))}}),r.isAll),f=r.isIndeterminate,T=j.value;e={default:()=>(0,_vue.h)("div",{ref:X,class:"vxe-table-custom-popup--body"},[(0,_vue.h)("div",{class:"vxe-table-custom-popup--table-wrapper"},[(0,_vue.h)("table",{},[(0,_vue.h)("colgroup",{},[d?(0,_vue.h)("col",{style:{width:"80px"}}):(0,_vue.createCommentVNode)(),m?(0,_vue.h)("col",{style:{width:"80px"}}):(0,_vue.createCommentVNode)(),(0,_vue.h)("col",{style:{minWidth:"120px"}}),h?(0,_vue.h)("col",{style:{width:"140px"}}):(0,_vue.createCommentVNode)(),v?(0,_vue.h)("col",{style:{width:"200px"}}):(0,_vue.createCommentVNode)()]),(0,_vue.h)("thead",{},[(0,_vue.h)("tr",{},[d?(0,_vue.h)("th",{},[(0,_vue.h)("div",{class:["vxe-table-custom--checkbox-option",{"is--checked":C,"is--indeterminate":f}],title:getI18n("vxe.table.allTitle"),onClick:te},[(0,_vue.h)("span",{class:["vxe-checkbox--icon",f?getIcon().TABLE_CHECKBOX_INDETERMINATE:C?getIcon().TABLE_CHECKBOX_CHECKED:getIcon().TABLE_CHECKBOX_UNCHECKED]}),(0,_vue.h)("span",{class:"vxe-checkbox--label"},getI18n("vxe.toolbar.customAll"))])]):(0,_vue.createCommentVNode)(),m?(0,_vue.h)("th",{},[(0,_vue.h)("span",{class:"vxe-table-custom-popup--table-sort-help-title"},getI18n("vxe.custom.setting.colSort")),H?(0,_vue.h)(H,{enterable:!0,content:getI18n("vxe.custom.setting.sortHelpTip"),popupClassName:"vxe-table--ignore-clear"},{default:()=>(0,_vue.h)("i",{class:"vxe-table-custom-popup--table-sort-help-icon vxe-icon-question-circle-fill"})}):(0,_vue.createCommentVNode)()]):(0,_vue.createCommentVNode)(),(0,_vue.h)("th",{},getI18n("vxe.custom.setting.colTitle")),h?(0,_vue.h)("th",{},getI18n("vxe.custom.setting.colResizable")):(0,_vue.createCommentVNode)(),v?(0,_vue.h)("th",{},getI18n("vxe.custom.setting."+(p?"colFixedMax":"colFixed"),[p])):(0,_vue.createCommentVNode)()])]),(0,_vue.h)(_vue.TransitionGroup,{class:"vxe-table-custom--body",tag:"tbody",name:"vxe-table-custom--list"},{default:()=>b})])]),(0,_vue.h)("div",{ref:q,class:"vxe-table-custom-popup--drag-hint"},getI18n("vxe.custom.cstmDragTarget",[T?T.getTitle():""]))]),footer:()=>(0,_vue.h)("div",{class:"vxe-table-custom-popup--footer"},[M?(0,_vue.h)(M,{content:n.resetButtonText||getI18n("vxe.custom.cstmRestore"),onClick:J}):(0,_vue.createCommentVNode)(),M?(0,_vue.h)(M,{content:n.resetButtonText||getI18n("vxe.custom.cstmCancel"),onClick:Z}):(0,_vue.createCommentVNode)(),M?(0,_vue.h)(M,{status:"primary",content:n.confirmButtonText||getI18n("vxe.custom.cstmConfirm"),onClick:P}):(0,_vue.createCommentVNode)()])};return"drawer"===t?A?(0,_vue.h)(A,{key:"drawer",className:["vxe-table-custom-drawer-wrapper","vxe-table--ignore-clear",l.className||""].join(" "),modelValue:r.visible,title:l.title||getI18n("vxe.custom.cstmTitle"),width:l.width||Math.min(880,document.documentElement.clientWidth),position:l.position,escClosable:!!l.escClosable,destroyOnClose:!0,showFooter:!0,"onUpdate:modelValue"(e){r.visible=e}},e):(0,_vue.createCommentVNode)():F?(0,_vue.h)(F,{key:"modal",className:["vxe-table-custom-modal-wrapper","vxe-table--ignore-clear",o.className||""].join(" "),modelValue:r.visible,title:o.title||getI18n("vxe.custom.cstmTitle"),width:o.width||Math.min(880,document.documentElement.clientWidth),minWidth:o.minWidth||700,height:o.height||Math.min(680,document.documentElement.clientHeight),minHeight:o.minHeight||400,showZoom:o.showZoom,showMaximize:o.showMaximize,showMinimize:o.showMinimize,mask:o.mask,lockView:o.lockView,resize:o.resize,escClosable:!!o.escClosable,destroyOnClose:!0,showFooter:!0,"onUpdate:modelValue"(e){r.visible=e}},e):(0,_vue.createCommentVNode)()}{t=L["customStore"],l=S["customColumnList"],o=D.value,e=t["maxHeight"];const{checkMethod:I,visibleMethod:V,allowVisible:E,allowSort:N,allowFixed:w,trigger:k,placement:O}=o,y=z.value,B=[];var i={},l=("hover"===k&&(i.onMouseenter=G,i.onMouseleave=$),_xeUtils.default.eachTree(l,(e,t,o,l,i)=>{if(!V||V({column:e})){var s=e.renderVisible,a=e.halfVisible,r=e.children&&e.children.length,n=(0,_utils.formatText)(e.getTitle(),1);const c=!!I&&!I({column:e});var u=!s;B.push((0,_vue.h)("li",{key:e.id,colid:e.id,class:["vxe-table-custom--option","level--"+e.level,{"is--hidden":c||u,"is--group":r}],onDragstart:ie,onDragend:se,onDragover:ae},[E?(0,_vue.h)("div",{class:["vxe-table-custom--checkbox-option",{"is--checked":s,"is--indeterminate":a,"is--disabled":c}],title:getI18n("vxe.custom.setting.colVisible"),onClick:()=>{c||Q(e)}},[(0,_vue.h)("span",{class:["vxe-checkbox--icon",a?getIcon().TABLE_CHECKBOX_INDETERMINATE:s?getIcon().TABLE_CHECKBOX_CHECKED:getIcon().TABLE_CHECKBOX_UNCHECKED]})]):(0,_vue.createCommentVNode)(),N&&1===e.level?(0,_vue.h)("div",{class:"vxe-table-custom--sort-option"},[(0,_vue.h)("span",Object.assign({class:["vxe-table-custom--sort-btn",{"is--disabled":c||u}],title:getI18n("vxe.custom.setting.sortHelpTip")},c||u?{}:{onMousedown:oe,onMouseup:le}),[(0,_vue.h)("i",{class:getIcon().TABLE_CUSTOM_SORT})])]):(0,_vue.createCommentVNode)(),"html"===e.type?(0,_vue.h)("div",{key:"1",class:"vxe-table-custom--checkbox-label",innerHTML:n}):(0,_vue.h)("div",{key:"0",class:"vxe-table-custom--checkbox-label"},n),!i&&w?(0,_vue.h)("div",{class:"vxe-table-custom--fixed-option"},[M?(0,_vue.h)(M,{mode:"text",icon:"left"===e.renderFixed?getIcon().TOOLBAR_TOOLS_FIXED_LEFT_ACTIVE:getIcon().TOOLBAR_TOOLS_FIXED_LEFT,status:"left"===e.renderFixed?"primary":"",disabled:c||u||y&&!e.renderFixed,title:getI18n("left"===e.renderFixed?"vxe.toolbar.cancelFixed":"vxe.toolbar.fixedLeft"),onClick:()=>{ee(e,"left")}}):(0,_vue.createCommentVNode)(),M?(0,_vue.h)(M,{mode:"text",icon:"right"===e.renderFixed?getIcon().TOOLBAR_TOOLS_FIXED_RIGHT_ACTIVE:getIcon().TOOLBAR_TOOLS_FIXED_RIGHT,status:"right"===e.renderFixed?"primary":"",disabled:c||u||y&&!e.renderFixed,title:getI18n("right"===e.renderFixed?"vxe.toolbar.cancelFixed":"vxe.toolbar.fixedRight"),onClick:()=>{ee(e,"right")}}):(0,_vue.createCommentVNode)()]):(0,_vue.createCommentVNode)()]))}}),t.isAll),s=t.isIndeterminate,a=j.value;return(0,_vue.h)("div",{ref:W,key:"simple",class:["vxe-table-custom-wrapper","placement--"+O,{"is--active":t.visible}],style:e&&!["left","right"].includes(O)?{maxHeight:e+"px"}:{}},t.visible?[(0,_vue.h)("ul",{class:"vxe-table-custom--header"},[(0,_vue.h)("li",{class:"vxe-table-custom--option"},[E?(0,_vue.h)("div",{class:["vxe-table-custom--checkbox-option",{"is--checked":l,"is--indeterminate":s}],title:getI18n("vxe.table.allTitle"),onClick:te},[(0,_vue.h)("span",{class:["vxe-checkbox--icon",s?getIcon().TABLE_CHECKBOX_INDETERMINATE:l?getIcon().TABLE_CHECKBOX_CHECKED:getIcon().TABLE_CHECKBOX_UNCHECKED]}),(0,_vue.h)("span",{class:"vxe-checkbox--label"},getI18n("vxe.toolbar.customAll"))]):(0,_vue.h)("span",{class:"vxe-checkbox--label"},getI18n("vxe.table.customTitle"))])]),(0,_vue.h)("div",{ref:X,class:"vxe-table-custom--list-wrapper"},[(0,_vue.h)(_vue.TransitionGroup,Object.assign({class:"vxe-table-custom--body",name:"vxe-table-custom--list",tag:"ul"},i),{default:()=>B}),(0,_vue.h)("div",{ref:q,class:"vxe-table-custom-popup--drag-hint"},getI18n("vxe.custom.cstmDragTarget",[a&&"html"!==a.type?a.getTitle():""]))]),o.showFooter?(0,_vue.h)("div",{class:"vxe-table-custom--footer"},[M?(0,_vue.h)(M,{mode:"text",content:o.resetButtonText||getI18n("vxe.table.customRestore"),onClick:J}):(0,_vue.createCommentVNode)(),o.immediate?M?(0,_vue.h)(M,{mode:"text",content:o.closeButtonText||getI18n("vxe.table.customClose"),onClick:Y}):(0,_vue.createCommentVNode)():M?(0,_vue.h)(M,{mode:"text",content:o.cancelButtonText||getI18n("vxe.table.customCancel"),onClick:Z}):(0,_vue.createCommentVNode)(),!o.immediate&&M?(0,_vue.h)(M,{mode:"text",status:"primary",content:o.confirmButtonText||getI18n("vxe.table.customConfirm"),onClick:P}):(0,_vue.createCommentVNode)()]):null]:[]);return}}}});