index-8cbf1e33.js 13 KB

1
  1. var he=Object.defineProperty,ye=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var ee=Object.getOwnPropertySymbols;var be=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable;var te=(n,l,s)=>l in n?he(n,l,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[l]=s,_=(n,l)=>{for(var s in l||(l={}))be.call(l,s)&&te(n,s,l[s]);if(ee)for(var s of ee(l))Me.call(l,s)&&te(n,s,l[s]);return n},I=(n,l)=>ye(n,ve(l));var q=(n,l,s)=>new Promise((i,t)=>{var u=c=>{try{r(s.next(c))}catch(d){t(d)}},e=c=>{try{r(s.throw(c))}catch(d){t(d)}},r=c=>c.done?i(c.value):Promise.resolve(c.value).then(u,e);r((s=s.apply(n,l)).next())});import{a as re,q as He,aq as Ce,ar as _e,w as Se,v as ke,as as Be,S as Fe,h as ie,at as Te,_ as we,d as Oe,au as $e,av as ce,aw as Pe,ax as Ne}from"./index.js";import{h as U,u as o,d as R,G as De,l as H,i as Re,f as h,c as S,w as ue,o as We,b as de,x as w,q as xe,Y as b,a6 as N,a7 as y,n as Ee,Z as D,N as O,ad as je,F as Ie,a9 as Y,a0 as Le,a5 as pe,E as J,$ as X,aa as L,J as Ae,g as K,y as qe,ab as oe,a8 as ne,ag as ae,ah as le,r as fe,H as z}from"./vue-8fccce23.js";import{M as ze,ab as Ve,T as G,ac as Ye,ad as Xe,o as V,e as ge,a as Ue}from"./antd-ecb53b14.js";import{u as Ge}from"./useWindowSizeFn-8ad2dbf2.js";const{t:se}=re(),Je={open:{type:Boolean},scrollTop:{type:Boolean,default:!0},height:{type:Number},minHeight:{type:Number},draggable:{type:Boolean,default:!0},centered:{type:Boolean},cancelText:{type:String,default:se("common.cancelText")},okText:{type:String,default:se("common.okText")},closeFunc:Function},Q=Object.assign({},Je,{defaultFullscreen:{type:Boolean},canFullscreen:{type:Boolean,default:!1},wrapperFooterOffset:{type:Number,default:0},helpMessage:[String,Array],useWrapper:{type:Boolean,default:!0},loading:{type:Boolean},loadingTip:{type:String},showCancelBtn:{type:Boolean,default:!0},showOkBtn:{type:Boolean,default:!0},wrapperProps:Object,afterClose:Function,bodyStyle:Object,closable:{type:Boolean,default:!0},closeIcon:Object,confirmLoading:{type:Boolean},destroyOnClose:{type:Boolean},footer:Object,getContainer:Function,mask:{type:Boolean,default:!0},maskClosable:{type:Boolean,default:!0},keyboard:{type:Boolean,default:!0},maskStyle:Object,okType:{type:String,default:"primary"},okButtonProps:Object,cancelButtonProps:Object,title:{type:String},subTitle:{type:String},open:{type:Boolean},width:[String,Number],wrapClassName:{type:String},zIndex:{type:Number}});function Ze(n){const l=(t,u)=>getComputedStyle(t)[u],s=t=>{if(!t)return;t.setAttribute("data-drag",o(n.draggable));const u=t.querySelector(".ant-modal-header"),e=t.querySelector(".ant-modal");!u||!e||!o(n.draggable)||(u.style.cursor="move",u.onmousedown=r=>{if(!r)return;const c=r.clientX,d=r.clientY,C=document.body.clientWidth,f=document.documentElement.clientHeight,p=e.offsetWidth,m=e.offsetHeight,g=e.offsetLeft,v=C-e.offsetLeft-p,k=e.offsetTop,B=f-e.offsetTop-m,M=l(e,"left"),W=l(e,"top");let x=+M,E=+W;M.includes("%")?(x=+document.body.clientWidth*(+M.replace(/%/g,"")/100),E=+document.body.clientHeight*(+W.replace(/%/g,"")/100)):(x=+M.replace(/px/g,""),E=+W.replace(/px/g,"")),document.onmousemove=function(A){let T=A.clientX-c,a=A.clientY-d;-T>g?T=-g:T>v&&(T=v),-a>k?a=-k:a>B&&(a=B),e.style.cssText+=`;left:${T+x}px;top:${a+E}px;`},document.onmouseup=()=>{document.onmousemove=null,document.onmouseup=null}})},i=()=>{const t=document.querySelectorAll(".ant-modal-wrap");for(const u of Array.from(t)){if(!u)continue;const e=l(u,"display"),r=u.getAttribute("data-drag");e!=="none"&&(r===null||o(n.destroyOnClose))&&s(u)}};U(()=>{!o(n.open)||!o(n.draggable)||He(()=>{i()},30)})}function Ke(n){return typeof n=="function"||Object.prototype.toString.call(n)==="[object Object]"&&!Re(n)}const Qe=R({name:"Modal",inheritAttrs:!1,props:Q,emits:["cancel"],setup(n,{slots:l,emit:s}){const{open:i,draggable:t,destroyOnClose:u}=De(n),e=Ce();Ze({open:i,destroyOnClose:u,draggable:t});const r=c=>{s("cancel",c)};return()=>{let c;const d=I(_(_({},o(e)),n),{onCancel:r});return H(ze,d,Ke(c=_e(l))?c:{default:()=>[c]})}}}),me=Symbol();function et(n){return ke(n,me)}function yt(){return Se(me)}const tt=["loading-tip"],ot=R({name:"ModalWrapper",inheritAttrs:!1,__name:"ModalWrapper",props:{loading:{type:Boolean},useWrapper:{type:Boolean,default:!0},modalHeaderHeight:{type:Number,default:57},modalFooterHeight:{type:Number,default:74},minHeight:{type:Number,default:200},height:{type:Number},footerOffset:{type:Number,default:0},open:{type:Boolean},fullScreen:{type:Boolean},loadingTip:{type:String}},emits:["height-change","ext-height"],setup(n,{expose:l,emit:s}){const i=n,t=h(null),u=h(null),e=h(0),r=h(0),c=h(0);Ge(f.bind(null)),Be(u,()=>{f()},{attributes:!0,subtree:!0}),et({redoModalHeight:f});const d=S(()=>({minHeight:`${i.minHeight}px`,[i.fullScreen?"height":"maxHeight"]:`${o(e)}px`}));U(()=>{i.useWrapper&&f()}),ue(()=>i.fullScreen,p=>{f(),p?r.value=e.value:e.value=r.value}),We(()=>{const{modalHeaderHeight:p,modalFooterHeight:m}=i;s("ext-height",p+m)}),de(()=>{});function C(){return q(this,null,function*(){w(()=>{var m;const p=o(t);p&&((m=p==null?void 0:p.scrollTo)==null||m.call(p,0))})})}function f(){return q(this,null,function*(){if(!i.open)return;const p=o(t);if(!p)return;const m=p.$el.parentElement;if(m){m.style.padding="0",yield w();try{const g=m.parentElement&&m.parentElement.parentElement;if(!g)return;const v=getComputedStyle(g).top,k=Number.parseInt(v);let B=window.innerHeight-k*2+(i.footerOffset||0)-i.modalFooterHeight-i.modalHeaderHeight;k<40&&(B-=26),yield w();const M=o(u);if(!M)return;yield w(),c.value=M.scrollHeight,i.fullScreen?e.value=window.innerHeight-i.modalFooterHeight-i.modalHeaderHeight-28:e.value=i.height?i.height:c.value>B?B:c.value,s("height-change",o(e))}catch(g){console.log(g)}}})}return l({scrollTop:C,setModalHeight:f}),(p,m)=>{const g=xe("loading");return b(),N(o(Fe),{ref_key:"wrapperRef",ref:t,scrollHeight:c.value},{default:y(()=>[Ee((b(),D("div",{ref_key:"spinRef",ref:u,style:je(d.value),"loading-tip":n.loadingTip},[O(p.$slots,"default")],12,tt)),[[g,n.loading]])]),_:3},8,["scrollHeight"])}}}),nt=R({name:"ModalClose",__name:"ModalClose",props:{canFullscreen:{type:Boolean,default:!0},fullScreen:{type:Boolean}},emits:["cancel","fullscreen"],setup(n,{emit:l}){const s=n,{prefixCls:i}=ie("basic-modal-close"),{t}=re(),u=S(()=>[i,`${i}--custom`,{[`${i}--can-full`]:s.canFullscreen}]);function e(c){l("cancel",c)}function r(c){c==null||c.stopPropagation(),c==null||c.preventDefault(),l("fullscreen")}return(c,d)=>(b(),D("div",{class:Le(u.value)},[n.canFullscreen?(b(),D(Ie,{key:0},[n.fullScreen?(b(),N(o(G),{key:0,title:o(t)("component.modal.restore"),placement:"bottom"},{default:y(()=>[H(o(Ve),{role:"full",onClick:r})]),_:1},8,["title"])):(b(),N(o(G),{key:1,title:o(t)("component.modal.maximize"),placement:"bottom"},{default:y(()=>[H(o(Ye),{role:"close",onClick:r})]),_:1},8,["title"]))],64)):Y("",!0),H(o(G),{title:o(t)("component.modal.close"),placement:"bottom"},{default:y(()=>[H(o(Xe),{onClick:e})]),_:1},8,["title"])],2))}});const at=R({name:"BasicModalFooter",__name:"ModalFooter",props:Q,emits:["ok","cancel"],setup(n,{emit:l}){function s(t){l("ok",t)}function i(t){l("cancel",t)}return(t,u)=>{const e=pe("a-button");return b(),D("div",null,[O(t.$slots,"insertFooter"),t.showCancelBtn?(b(),N(e,L({key:0},t.cancelButtonProps,{onClick:i}),{default:y(()=>[J(X(t.cancelText),1)]),_:1},16)):Y("",!0),O(t.$slots,"centerFooter"),t.showOkBtn?(b(),N(e,L({key:1,type:t.okType,onClick:s,loading:t.confirmLoading},t.okButtonProps),{default:y(()=>[J(X(t.okText),1)]),_:1},16,["type","loading"])):Y("",!0),O(t.$slots,"appendFooter")])}}}),lt=R({name:"BasicModalHeader",components:{BasicTitle:Te},props:{helpMessage:{type:[String,Array]},title:{type:String},subTitle:{type:String}},emits:["dblclick"]});const st={class:"title-wrap"},rt={key:0,class:"subTitle"};function it(n,l,s,i,t,u){const e=pe("BasicTitle");return b(),D("span",st,[H(e,{helpMessage:n.helpMessage,class:"!font-semibold title"},{default:y(()=>[J(X(n.title),1)]),_:1},8,["helpMessage"]),!n.helpMessage&&n.subTitle?(b(),D("span",rt,X(n.subTitle),1)):Y("",!0)])}const ct=we(lt,[["render",it],["__scopeId","data-v-8fb42aca"]]);function ut(n){const l=h(!1),s=S(()=>{const t=o(n.wrapClassName)||"";return o(l)?`fullscreen-modal ${t} `:o(t)});function i(t){t&&t.stopPropagation(),l.value=!o(l)}return{getWrapClassName:s,handleFullScreen:i,fullScreenRef:l}}const dt=R({name:"BasicModal",inheritAttrs:!1,__name:"BasicModal",props:Q,emits:["open-change","height-change","cancel","ok","register","update:open"],setup(n,{emit:l}){const s=n,i=Ae(),t=h(!1),u=h(null),e=h(null),{prefixCls:r}=ie("basic-modal"),c=h(0),d={setModalProps:W,emitOpen:void 0,redoModalHeight:()=>{w(()=>{o(e)&&o(e).setModalHeight()})}},C=K();C&&l("register",d,C.uid);const f=S(()=>_(_({},s),o(u))),{handleFullScreen:p,getWrapClassName:m,fullScreenRef:g}=ut({modalWrapperRef:e,extHeightRef:c,wrapClassName:qe(f.value,"wrapClassName")}),v=S(()=>{const a=I(_({},o(f)),{open:o(t),okButtonProps:void 0,cancelButtonProps:void 0,title:void 0});return I(_({},a),{wrapClassName:o(m)})}),k=S(()=>{const a=I(_(_({},i),o(f)),{open:o(t)});return a.wrapClassName=`${(a==null?void 0:a.wrapClassName)||""} ${o(m)}vben-basic-modal-wrap`,o(g)?V(a,["height","title"]):V(a,"title")}),B=S(()=>{if(!o(g))return o(v).height});U(()=>{t.value=!!s.open,g.value=!!s.defaultFullscreen}),ue(()=>o(t),a=>{var $;l("open-change",a),l("update:open",a),C&&(($=d.emitOpen)==null||$.call(d,a,C.uid)),w(()=>{s.scrollTop&&a&&o(e)&&o(e).scrollTop()})},{immediate:!1});function M(a){return q(this,null,function*(){var $,F;if(a==null||a.stopPropagation(),!((F=($=a.target)==null?void 0:$.classList)!=null&&F.contains(r+"-close--custom"))){if(s.closeFunc&&ge(s.closeFunc)){const j=yield s.closeFunc();t.value=!j;return}t.value=!1,l("cancel",a)}})}function W(a){u.value=Oe(o(u)||{},a),Reflect.has(a,"open")&&(t.value=!!a.open),Reflect.has(a,"defaultFullscreen")&&(g.value=!!a.defaultFullscreen)}function x(a){l("ok",a)}function E(a){l("height-change",a)}function A(a){c.value=a}function T(a){s.canFullscreen&&(a.stopPropagation(),p(a))}return(a,$)=>(b(),N(o(Qe),L(k.value,{onCancel:M}),oe({default:y(()=>[H(ot,L({useWrapper:v.value.useWrapper,footerOffset:a.wrapperFooterOffset,fullScreen:o(g),ref_key:"modalWrapperRef",ref:e,loading:v.value.loading,"loading-tip":v.value.loadingTip,minHeight:v.value.minHeight,height:B.value,open:t.value,modalFooterHeight:a.footer!==void 0&&!a.footer?0:void 0},o(V)(v.value.wrapperProps,"open","height","modalFooterHeight"),{onExtHeight:A,onHeightChange:E}),{default:y(()=>[O(a.$slots,"default")]),_:3},16,["useWrapper","footerOffset","fullScreen","loading","loading-tip","minHeight","height","open","modalFooterHeight"])]),_:2},[a.$slots.closeIcon?void 0:{name:"closeIcon",fn:y(()=>[H(nt,{canFullscreen:v.value.canFullscreen,fullScreen:o(g),onCancel:M,onFullscreen:o(p)},null,8,["canFullscreen","fullScreen","onFullscreen"])]),key:"0"},a.$slots.title?void 0:{name:"title",fn:y(()=>[H(ct,{helpMessage:v.value.helpMessage,title:f.value.title,"sub-title":f.value.subTitle,onDblclick:T},null,8,["helpMessage","title","sub-title"])]),key:"1"},a.$slots.footer?void 0:{name:"footer",fn:y(()=>[H(at,L(k.value,{onOk:x,onCancel:M}),oe({_:2},[ne(Object.keys(a.$slots),F=>({name:F,fn:y(j=>[O(a.$slots,F,ae(le(j||{})))])}))]),1040)]),key:"2"},ne(Object.keys(o(V)(a.$slots,"default")),F=>({name:F,fn:y(j=>[O(a.$slots,F,ae(le(j||{})))])}))]),1040))}});const P=fe({}),Z=fe({});function vt(){const n=h(null),l=h(!1),s=h(0);function i(e,r){if(!K())throw new Error("useModal() can only be used inside setup() or functional components!");s.value=r,de(()=>{n.value=null,l.value=!1,P[String(o(s))]=null}),!(o(l)&&$e()&&e===o(n))&&(n.value=e,l.value=!0,e.emitOpen=(c,d)=>{Z[d]=c})}const t=()=>{const e=o(n);return console.log("🚀 ~ file: useModal.ts:59 ~ getInstance ~ instance:",e),e||ce("useModal instance is undefined!"),e},u={setModalProps:e=>{var r;(r=t())==null||r.setModalProps(e)},getOpen:S(()=>Z[~~o(s)]),redoModalHeight:()=>{var e,r;(r=(e=t())==null?void 0:e.redoModalHeight)==null||r.call(e)},openModal:(e=!0,r,c=!0)=>{var f;if((f=t())==null||f.setModalProps({open:e}),!r)return;const d=o(s);if(c){P[d]=null,P[d]=z(r);return}Ue(z(P[d]),z(r))||(P[d]=z(r))},closeModal:()=>{var e;(e=t())==null||e.setModalProps({open:!1})}};return[i,u]}const bt=n=>{const l=h(null),s=K(),i=h(0),t=()=>{const e=o(l);return e||ce("useModalInner instance is undefined!"),e},u=(e,r)=>{Pe(()=>{l.value=null}),i.value=r,l.value=e,s==null||s.emit("register",e,r)};return U(()=>{const e=P[o(i)];e&&(!n||!ge(n)||w(()=>{n(e)}))}),[u,{changeLoading:(e=!0)=>{var r;(r=t())==null||r.setModalProps({loading:e})},getOpen:S(()=>Z[~~o(i)]),changeOkLoading:(e=!0)=>{var r;(r=t())==null||r.setModalProps({confirmLoading:e})},closeModal:()=>{var e;(e=t())==null||e.setModalProps({open:!1})},setModalProps:e=>{var r;(r=t())==null||r.setModalProps(e)},redoModalHeight:()=>{var r;const e=(r=t())==null?void 0:r.redoModalHeight;e&&e()}}]},Mt=Ne(dt);export{Mt as B,bt as a,yt as b,vt as u};