UNPKG

@jecloud/ui

Version:

JECloud UI库,基于ant-design-vue封装

1 lines 3.25 kB
import{nextTick as t,onMounted as e,onBeforeUnmount as i,onDeactivated as n,onActivated as o,ref as l,watch as a,reactive as f}from"vue";import{getPaddingSize as r,getBorderSize as u,removeResizeListener as h,addResizeListener as c,debounce as s,hasClass as d,uniqueId as p}from"@jecloud/utils";import{useProvidePanel as v,useInjectPanel as g}from"../context";export function useMehtod(b){var m=b.refMaps,x=b.props,y=b.emit,w=b.computeStyle,j=[],P={},O={id:p("panel-"),refMaps:m,activated:l(!0),refreshChildPanel:function(){j.forEach((function(t){var e;null===(e=null==t?void 0:t.refreshLayout)||void 0===e||e.call(t)}))},addChildPanel:function(t){j.push(t)},addPanelItem:function(t,e){P[t]=e},getPanelItem:function(t){return P[t]}};v(O);var S=g(),k=function(t,e,i){var n,o=t,l=r(o),a=u(o),f={height:o.offsetHeight-l.top-l.bottom-a.top-a.bottom,width:o.offsetWidth-l.left-l.right-a.left-a.right,top:0,left:0};e.forEach((function(t){var e,i,n,o,l=t.item,a=t.splitter,r=t.region,u=null!==(n=l.offsetWidth)&&void 0!==n?n:0,h=null!==(o=l.offsetHeight)&&void 0!==o?o:0,c=d(a,"is--collapsible"),s=d(a,"is--collapsed"),p={};switch(r){case"top":f.top=h+0,f.height=f.height-h-0,p={top:0,left:0,width:"100%"};break;case"bottom":f.height=f.height-h-0,p={left:0,bottom:0,width:"100%"};break;case"left":f.left=u+0,f.width=f.width-u-0,p={top:f.top+"px",left:0,height:f.height+"px"};break;case"right":f.width=f.width-u-0,p={top:f.top+"px",right:0,height:f.height+"px"}}Object.assign(l.style,p),a&&(["top","bottom"].includes(r)?Object.assign(a.style,((e={})[r]=c&&s?h+"px":h-a.offsetHeight+"px",e.left=0,e.width="100%",e)):Object.assign(a.style,((i={top:f.top+"px"})[r]=c&&s?u+"px":u-a.offsetWidth+"px",i.height=f.height+"px",i)))})),Object.assign(null!==(n=null==i?void 0:i.style)&&void 0!==n?n:{},{top:f.top+"px",left:f.left+"px",width:f.width+"px",height:f.height+"px"})},C=function(t){for(var e,i="bars"===t?m.center.value:m.body.value,n=[],o=0;o<i.children.length;o++){var l=i.children[o];if(d(l,"je-panel-item")){var a=null!==(e=l.getAttribute("data-region"))&&void 0!==e?e:"default";if("default"!==a){var f=null;d(l.nextSibling,"je-panel-splitter-"+a)&&(f=l.nextSibling),n.push({region:a,item:l,splitter:f})}}}return n},E=function(){t((function(){if(m.body.value){var t="none"!==w.value.display,e=m.body.value.offsetWidth,i=m.body.value.offsetHeight;if(t&&O.activated.value&&e>0&&i>0){if(m.center.value){var n=m.center.value.querySelector(".je-panel-item-region-default");k(m.body.value,C("items"),m.center.value),k(m.center.value,C("bars"),n)}O.refreshChildPanel()}}}))};O.refreshLayout=E;var H=f(x);Object.keys(x).forEach((function(t){a((function(){return H[t]}),(function(){y("update:"+t,H[t])}),{deep:!0})}));var W=function(t,e,i){H[t]&&(H[t][e]=i)},I=s((function(){E()}),100);return e((function(){t((function(){E(),null==S||S.addChildPanel(O),c(m.el.value,I)}))})),i((function(){h(m.el.value,I)})),o((function(){O.activated.value=!0,E()})),n((function(){O.activated.value=!1})),Object.assign(O,{propsReactive:H,refreshLayout:E,getPanelDomItems:C,setSize:function(t,e){W(t,"size",e)},setVisible:function(t,e){W(t,"hidden",!e)},setExpand:function(t,e){W(t,"collapsed",!e)},collapse:function(t){W(t,"collapsed",!0)},expand:function(t){W(t,"collapsed",!1)}}),O}