text: "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _conf=_interopRequireDefault(require("../../conf")),_xeUtils=_interopRequireDefault(require("xe-utils")),_queue=_interopRequireDefault(require("./queue")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var cumsumZindex=0,maxZindex=0;function getZIndex(){return maxZindex=_conf.default.modal.zIndex+cumsumZindex++}var _default2={name:"VxeModal",props:{value:Boolean,id:String,type:{type:String,default:"modal"},status:String,top:{type:[Number,String],default:15},title:String,duration:{type:[Number,String],default:function(){return _conf.default.modal.duration}},message:[String,Function],lockView:{type:Boolean,default:function(){return _conf.default.modal.lockView}},lockScroll:Boolean,mask:{type:Boolean,default:function(){return _conf.default.modal.mask}},maskClosable:Boolean,escClosable:Boolean,resize:Boolean,showHeader:{type:Boolean,default:!0},showFooter:{type:Boolean,default:!0},width:[Number,String],height:[Number,String],zIndex:[Number,String],marginSize:{type:[Number,String],default:_conf.default.modal.marginSize},animat:{type:Boolean,default:function(){return _conf.default.modal.animat}},slots:Object,events:Object},data:function(){return{visible:!1,contentVisible:!1,modalTop:0,modalZindex:0,zoomLocat:null}},computed:{vSize:function(){return this.size||this.$parent&&(this.$parent.size||this.$parent.vSize)},isMsg:function(){return"message"===this.type}},watch:{value:function(e){this[e?"open":"close"]()}},created:function(){this.value&&this.open(),this.modalZindex=this.zIndex||getZIndex()},mounted:function(){this.escClosable&&_tools.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent),document.body.appendChild(this.$el)},beforeDestroy:function(){_tools.GlobalEvent.off(this,"keydown"),this.removeMsgQueue(),this.$el.parentNode.removeChild(this.$el)},render:function(t){var e,o=this,i=this.$scopedSlots,n=this.slots,s=void 0===n?{}:n,l=this.vSize,a=this.type,c=this.resize,u=this.animat,d=this.width,r=this.height,h=this.status,m=this.showHeader,f=this.showFooter,p=this.zoomLocat,v=this.modalTop,x=this.contentVisible,g=this.visible,y=this.title,b=this.message,_=this.lockScroll,w=this.lockView,z=this.mask,$=this.isMsg,k=i.default||s.default,S=i.footer||s.footer;return t("div",{class:["vxe-modal--wrapper","type--".concat(a),(e={},_defineProperty(e,"size--".concat(l),l),_defineProperty(e,"status--".concat(h),h),_defineProperty(e,"is--animat",u),_defineProperty(e,"lock--scroll",_),_defineProperty(e,"lock--view",w),_defineProperty(e,"is--mask",z),_defineProperty(e,"is--visible",x),_defineProperty(e,"active",g),e)],style:{zIndex:this.modalZindex,top:v?"".concat(v,"px"):null},on:{click:this.selfClickEvent}},[t("div",{class:"vxe-modal--box",style:{width:d?isNaN(d)?d:"".concat(d,"px"):null,height:r?isNaN(r)?r:"".concat(r,"px"):null},on:{mousedown:this.updateZindex},ref:"modalBox"},[m?t("div",{class:"vxe-modal--header",on:{mousedown:this.mousedownEvent}},[t("span",{class:"vxe-modal--title"},y?_tools.UtilTools.getFuncText(y):_conf.default.i18n("vxe.alert.title")),c?t("i",{class:["vxe-modal--zoom-btn","trigger--btn",p?_conf.default.icon.zoomOut:_conf.default.icon.zoomIn],on:{click:this.zoomInEvent}}):null,t("i",{class:["vxe-modal--close-btn","trigger--btn",_conf.default.icon.modalClose],on:{click:this.closeEvent}})]):null,t("div",{class:"vxe-modal--body"},[h?t("div",{class:"vxe-modal--status-wrapper"},[t("i",{class:["vxe-modal--status-icon",_conf.default.icon["modal".concat(h.replace(/\b(\w)/,function(e){return e.toUpperCase()}))]]})]):null,t("div",{class:"vxe-modal--content"},k?k.call(this,{$modal:this},t):_xeUtils.default.isFunction(b)?b.call(this,t):b)]),f?t("div",{class:"vxe-modal--footer"},S?S.call(this,{$modal:this},t):["confirm"===a?t("vxe-button",{on:{click:this.cancelEvent}},_conf.default.i18n("vxe.button.cancel")):null,t("vxe-button",{props:{type:"primary"},on:{click:this.confirmEvent}},_conf.default.i18n("vxe.button.confirm"))]):null,!$&&c?t("span",{class:"vxe-modal--resize"},["wl","wr","swst","sest","st","swlb","selb","sb"].map(function(e){return t("span",{class:"".concat(e,"-resize"),attrs:{"data-type":e},on:{mousedown:o.dragEvent}})})):null])])},methods:{selfClickEvent:function(e){if(this.maskClosable&&e.target===this.$el){this.close("mask")}},updateZindex:function(){this.modalZindex<maxZindex&&(this.modalZindex=getZIndex())},closeEvent:function(e){var t="close";this.$emit(t,{type:t,$modal:this},e),this.close(t)},confirmEvent:function(e){var t="confirm";this.$emit(t,{type:t,$modal:this},e),this.close(t)},cancelEvent:function(e){var t="cancel";this.$emit(t,{type:t,$modal:this},e),this.close(t)},open:function(){var s=this,e=this.$listeners,t=this.events,o=void 0===t?{}:t,i=this.duration,n=this.visible,l=this.isMsg;if(!n){var a={type:"show",$modal:this};this.visible=!0,this.contentVisible=!1,this.updateZindex(),o.show||(this.$emit("input",!0),this.$emit("show",a)),setTimeout(function(){s.contentVisible=!0,!e.show&&o.show&&s.$nextTick(function(){o.show.call(s,a)})},10),l?(this.addMsgQueue(),setTimeout(this.close,_xeUtils.default.toNumber(i))):this.$nextTick(function(){var e=s.$refs,t=s.marginSize,o=e.modalBox,i=document.documentElement.clientWidth||document.body.clientWidth,n=document.documentElement.clientHeight||document.body.clientHeight;o.style.left="".concat(i/2-o.offsetWidth/2,"px"),o.offsetHeight+o.offsetTop+t>n&&(o.style.top="".concat(t,"px"))})}},addMsgQueue:function(){-1===_queue.default.indexOf(this)&&_queue.default.push(this),this.updateStyle()},removeMsgQueue:function(){var t=this;-1<_queue.default.indexOf(this)&&_xeUtils.default.remove(_queue.default,function(e){return e===t}),this.updateStyle()},updateStyle:function(){this.$nextTick(function(){var t=0;_queue.default.forEach(function(e){t+=_xeUtils.default.toNumber(e.top),e.modalTop=t,t+=e.$refs.modalBox.clientHeight})})},close:function(t){var o=this,e=this.events,i=void 0===e?{}:e,n=this.visible,s=this.isMsg;n&&(s&&this.removeMsgQueue(),this.contentVisible=!1,setTimeout(function(){o.visible=!1;var e={type:t,$modal:o};i.hide?i.hide.call(o,e):(o.$emit("input",!1),o.$emit("hide",e))},200))},handleGlobalKeydownEvent:function(e){27===e.keyCode&&this.close()},zoomInEvent:function(e){var t=this.$listeners,o=this.$refs,i=this.marginSize,n=this.zoomLocat,s=this.events,l=void 0===s?{}:s,a=o.modalBox,c=_tools.DomTools.getDomNode(),u=c.visibleHeight,d=c.visibleWidth,r="min";n?(this.zoomLocat=null,Object.assign(a.style,{top:"".concat(n.top,"px"),left:"".concat(n.left,"px"),width:"".concat(n.width,"px"),height:"".concat(n.height,"px")})):(r="max",this.zoomLocat={top:a.offsetTop,left:a.offsetLeft,width:a.clientWidth,height:a.clientHeight},Object.assign(a.style,{top:"".concat(i,"px"),left:"".concat(i,"px"),width:"".concat(d-2*i,"px"),height:"".concat(u-2*i,"px")}));var h={type:r,$modal:this};t.zoom?this.$emit("zoom",h,e):l.zoom&&l.zoom.call(this,h,e)},mousedownEvent:function(e){var t=this,o=this.$refs,u=this.marginSize,d=o.modalBox;if(0===e.button&&!_tools.DomTools.getEventTargetNode(e,d,"trigger--btn").flag){e.preventDefault();var i=document.onmousemove,n=document.onmouseup,r=e.clientX-d.offsetLeft,h=e.clientY-d.offsetTop,s=_tools.DomTools.getDomNode(),m=s.visibleHeight,f=s.visibleWidth;document.onmousemove=function(e){e.preventDefault();var t=d.offsetWidth,o=d.offsetHeight,i=u,n=f-t-u,s=u,l=m-o-u,a=e.clientX-r,c=e.clientY-h;n<a&&(a=n),a<i&&(a=i),l<c&&(c=l),c<s&&(c=s),d.style.left="".concat(a,"px"),d.style.top="".concat(c,"px"),d.className=d.className.replace(/\s?is--drag/,"")+" is--drag"},document.onmouseup=function(e){document.onmousemove=i,document.onmouseup=n,t.$nextTick(function(){d.className=d.className.replace(/\s?is--drag/,"")})}}},dragEvent:function(e){var s=this;e.preventDefault();var l=this.$listeners,a=this.marginSize,t=this.events,c=void 0===t?{}:t,o=_tools.DomTools.getDomNode(),u=o.visibleHeight,d=o.visibleWidth,r=e.target.dataset.type,h=d-20,m=u-20,f=this.$refs.modalBox,i=document.onmousemove,n=document.onmouseup,p=f.clientWidth,v=f.clientHeight,x=e.clientX,g=e.clientY,y=f.offsetTop,b=f.offsetLeft,_={type:"resize",$modal:this};document.onmousemove=function(e){var t,o,i,n;switch(e.preventDefault(),r){case"wl":i=(t=x-e.clientX)+p,a<b-t&&340<i&&(f.style.width="".concat(i<h?i:h,"px"),f.style.left="".concat(b-t,"px"));break;case"swst":t=x-e.clientX,o=g-e.clientY,i=t+p,n=o+v,a<b-t&&340<i&&(f.style.width="".concat(i<h?i:h,"px"),f.style.left="".concat(b-t,"px")),a<y-o&&200<n&&(f.style.height="".concat(n<m?n:m,"px"),f.style.top="".concat(y-o,"px"));break;case"swlb":t=x-e.clientX,o=e.clientY-g,i=t+p,n=o+v,a<b-t&&340<i&&(f.style.width="".concat(i<h?i:h,"px"),f.style.left="".concat(b-t,"px")),y+n+a<u&&200<n&&(f.style.height="".concat(n<m?n:m,"px"));break;case"st":o=g-e.clientY,n=v+o,a<y-o&&200<n&&(f.style.height="".concat(n<m?n:m,"px"),f.style.top="".concat(y-o,"px"));break;case"wr":t=e.clientX-x,b+(i=t+p)+a<d&&340<i&&(f.style.width="".concat(i<h?i:h,"px"));break;case"sest":t=e.clientX-x,n=(o=g-e.clientY)+v,b+(i=t+p)+a<d&&340<i&&(f.style.width="".concat(i<h?i:h,"px")),a<y-o&&200<n&&(f.style.height="".concat(n<m?n:m,"px"),f.style.top="".concat(y-o,"px"));break;case"selb":t=e.clientX-x,n=(o=e.clientY-g)+v,b+(i=t+p)+a<d&&340<i&&(f.style.width="".concat(i<h?i:h,"px")),y+n+a<u&&200<n&&(f.style.height="".concat(n<m?n:m,"px"));break;case"sb":o=e.clientY-g,y+(n=o+v)+a<u&&200<n&&(f.style.height="".concat(n<m?n:m,"px"))}f.className=f.className.replace(/\s?is--drag/,"")+" is--drag",l.zoom?s.$emit("zoom",_,e):c.zoom&&c.zoom.call(s,_,e)},document.onmouseup=function(e){document.onmousemove=i,document.onmouseup=n,setTimeout(function(){f.className=f.className.replace(/\s?is--drag/,"")},50)}}}};exports.default=_default2;