UNPKG

@jecloud/ui

Version:

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

1 lines 3.72 kB
var t=this&&this.__spreadArrays||function(){for(var t=0,e=0,o=arguments.length;e<o;e++)t+=arguments[e].length;var n=Array(t),i=0;for(e=0;e<o;e++)for(var r=arguments[e],a=0,c=r.length;a<c;a++,i++)n[i]=r[a];return n};import{nextTick as e}from"vue";import{isString as o,getBodyHeight as n,getBodyWidth as i,getDomNode as r,computedDomSize as a,isNumber as c}from"@jecloud/utils";import{getLastZIndex as u,nextZIndex as s}from"./use-manager";import{useListeners as f}from"../../../hooks";export var msgQueue=[];export function useMethods(l){var m=l.props,d=l.reactData,h=l.getRef,p=l.context.emit,v=f({props:m}).fireListener,x=function(e,o){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];v.apply(void 0,t([e,Object.assign({$modal:l},o)],n))},g=function(){var t=h("box",!0),o=t.offsetHeight,r=t.offsetWidth,u=i(),s=n(),f={width:{val:a({size:m.width,parentSize:u}),min:a(m.minWidth),max:u,domVal:r},height:{val:a({size:m.height,parentSize:s}),min:a(m.minHeight),max:s,domVal:o}};return Object.keys(f).forEach((function(e){var o=f[e],n=o.val,i=o.min,r=o.max,a=o.domVal;c(n)?n=Math.max(Math.min(n,r),i):"auto"===n?n=a===(n=Math.max(Math.min(a,r),i))?"auto":n:"modal"===m.type&&(n=r-100),t.style[e]=""+(n?isNaN(n)?n:n+"px":"")})),e()},b=function(){var t=m.zIndex,e=d.modalZindex;t?d.modalZindex=t:e<u()&&(d.modalZindex=s())},y=function(){return e().then((function(){var t=m.position,e=h("box",!0),n=document.documentElement.clientWidth||document.body.clientWidth,i=document.documentElement.clientHeight||document.body.clientHeight,r="center"===t,a=o(t)?{top:t,left:t}:Object.assign({},t),c=a.top,u=a.left,s=r||"center"===c,f="",l="";l=u&&!(r||"center"===u)?isNaN(u)?u:u+"px":Math.max(0,n/2-e.offsetWidth/2)+"px",f=c&&!s?isNaN(c)?c:c+"px":Math.max(0,i/2-e.offsetHeight/2)+"px",e.style.top=f,e.style.left=l}))},z=function(){return!!d.zoomLocation},w=function(){return e().then((function(){if(!d.zoomLocation){var t=h("box",!0),e=r(),o=e.height,n=e.width;d.zoomLocation={top:t.offsetTop,left:t.offsetLeft,width:t.offsetWidth+(t.style.width?0:1),height:t.offsetHeight+(t.style.height?0:1)},Object.assign(t.style,{top:"0px",left:"0px",width:n-0+"px",height:o-0+"px"})}}))},M=function(){return e().then((function(){var t=d.zoomLocation;if(t){var e=h("box",!0);d.zoomLocation=null,Object.assign(e.style,{top:t.top+"px",left:t.left+"px",width:t.width+"px",height:t.height+"px"})}}))};return{fireEvent:x,isMaximized:z,maximize:w,revert:M,zoom:function(){return d.zoomLocation?M().then((function(){return z()})):w().then((function(){return z()}))},show:function(){var t=m.showFooter,o=m.buttonFocus,n=d.inited,i=d.active;return!1===x("beforeshow")||(n||(d.inited=!0),i||(g(),d.active=!0,d.contentVisible=!1,b(),setTimeout((function(){d.contentVisible=!0,e((function(){var n=h("el",!0);if(null==n||n.focus(),t&&o){var i=h("footer",!0),r=null==i?void 0:i.querySelector(".je-modal--button");null==r||r.focus()}p("update:visible",!0),x("show"),g(),y().then((function(){setTimeout((function(){return y()}),20)})),m.maximized&&e((function(){return w()}))}))}),10))),e()},close:function(t){var o=m.remember,n=m.closeAction;return d.active&&!1!==x("beforeclose",{type:t})&&(d.contentVisible=!1,o||(d.zoomLocation=null),d.active=!1,setTimeout((function(){if(p("update:visible",!1),x("close",{type:t}),"destroy"===n){var e=h("el",!0);e&&e.parentNode.removeChild(e)}}),200)),e()},recalculate:g,isMessage:function(){return"message"===m.type},updateZindex:b,dispatchEvent:function(t,e,o){p(t,Object.assign({$modal:l,$event:o},e))}}}export function renderModalContainer(t){void 0===t&&(t="je-modal--container");var e=document.querySelector("."+t);return e||((e=document.createElement("div")).className=t,document.body.appendChild(e)),e}