vxe-table-demonic
Version:
一个基于 vue 的 PC 端表单/表格组件,支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式...
1 lines • 16.1 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.msgQueue=exports.default=exports.allActivedModals=void 0;var _vue=require("vue"),_xeUtils=_interopRequireDefault(require("xe-utils")),_size=require("../../hooks/size"),_dom=require("../../tools/dom"),_utils=require("../../tools/utils"),_log=require("../../tools/log"),_event=require("../../tools/event"),_conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_button=_interopRequireDefault(require("../../button/src/button")),_index=_interopRequireDefault(require("../../loading/index")),_vn=require("../../tools/vn");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var __assign=function(){return(__assign=Object.assign||function(e){for(var t,o=1,n=arguments.length;o<n;o++)for(var i in t=arguments[o])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},allActivedModals=[],msgQueue=(exports.allActivedModals=allActivedModals,[]),_default=(exports.msgQueue=msgQueue,(0,_vue.defineComponent)({name:"VxeModal",props:{modelValue:Boolean,id:String,type:{type:String,default:"modal"},loading:{type:Boolean,default:null},status:String,iconStatus:String,className:String,top:{type:[Number,String],default:function(){return _conf.default.modal.top}},position:[String,Object],title:String,duration:{type:[Number,String],default:function(){return _conf.default.modal.duration}},message:[Number,String],content:[Number,String],cancelButtonText:{type:String,default:function(){return _conf.default.modal.cancelButtonText}},confirmButtonText:{type:String,default:function(){return _conf.default.modal.confirmButtonText}},lockView:{type:Boolean,default:function(){return _conf.default.modal.lockView}},lockScroll:Boolean,mask:{type:Boolean,default:function(){return _conf.default.modal.mask}},maskClosable:{type:Boolean,default:function(){return _conf.default.modal.maskClosable}},escClosable:{type:Boolean,default:function(){return _conf.default.modal.escClosable}},resize:Boolean,showHeader:{type:Boolean,default:function(){return _conf.default.modal.showHeader}},showFooter:{type:Boolean,default:function(){return _conf.default.modal.showFooter}},showZoom:Boolean,showClose:{type:Boolean,default:function(){return _conf.default.modal.showClose}},dblclickZoom:{type:Boolean,default:function(){return _conf.default.modal.dblclickZoom}},width:[Number,String],height:[Number,String],minWidth:{type:[Number,String],default:function(){return _conf.default.modal.minWidth}},minHeight:{type:[Number,String],default:function(){return _conf.default.modal.minHeight}},zIndex:Number,marginSize:{type:[Number,String],default:function(){return _conf.default.modal.marginSize}},fullscreen:Boolean,draggable:{type:Boolean,default:function(){return _conf.default.modal.draggable}},remember:{type:Boolean,default:function(){return _conf.default.modal.remember}},destroyOnClose:{type:Boolean,default:function(){return _conf.default.modal.destroyOnClose}},showTitleOverflow:{type:Boolean,default:function(){return _conf.default.modal.showTitleOverflow}},transfer:{type:Boolean,default:function(){return _conf.default.modal.transfer}},storage:{type:Boolean,default:function(){return _conf.default.modal.storage}},storageKey:{type:String,default:function(){return _conf.default.modal.storageKey}},animat:{type:Boolean,default:function(){return _conf.default.modal.animat}},size:{type:String,default:function(){return _conf.default.modal.size||_conf.default.size}},beforeHideMethod:{type:Function,default:function(){return _conf.default.modal.beforeHideMethod}},slots:Object},emits:["update:modelValue","show","hide","before-hide","close","confirm","cancel","zoom"],setup:function(N,e){function a(){var e=N.width,t=N.height,o=O();return o.style.width="".concat(e?isNaN(e)?e:"".concat(e,"px"):""),o.style.height="".concat(t?isNaN(t)?t:"".concat(t,"px"):""),(0,_vue.nextTick)()}function d(){return(0,_vue.nextTick)().then(function(){var e=N.position,t=_xeUtils.default.toNumber(N.marginSize),o=O(),n=document.documentElement.clientWidth||document.body.clientWidth,i=document.documentElement.clientHeight||document.body.clientHeight,a="center"===e,e=_xeUtils.default.isString(e)?{top:e,left:e}:Object.assign({},e),l=e.top,e=e.left,u=a||"center"===l,c="",s="",s=e&&!(a||"center"===e)?isNaN(e)?e:"".concat(e,"px"):"".concat(Math.max(t,n/2-o.offsetWidth/2),"px"),c=l&&!u?isNaN(l)?l:"".concat(l,"px"):"".concat(Math.max(t,i/2-o.offsetHeight/2),"px");o.style.top=c,o.style.left=s})}function l(e){var t="close";S.dispatchEvent(t,{type:t},e),C(t)}function t(e){var t="confirm";S.dispatchEvent(t,{type:t},e),C(t)}function o(e){var t="cancel";S.dispatchEvent(t,{type:t},e),C(t)}function f(){return(0,_vue.nextTick)().then(function(){var e,t,o,n;z.zoomLocat||(e=Math.max(0,_xeUtils.default.toNumber(N.marginSize)),t=O(),o=(n=(0,_dom.getDomNode)()).visibleHeight,n=n.visibleWidth,z.zoomLocat={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:"".concat(e,"px"),left:"".concat(e,"px"),width:"".concat(n-2*e,"px"),height:"".concat(o-2*e,"px")}),V())})}function n(){var e=N.duration,r=N.remember,o=N.showFooter,t=z.inited,n=z.visible,i=T.value;return t||(z.inited=!0),n||(r||a(),z.visible=!0,z.contentVisible=!1,B(),allActivedModals.push(k),setTimeout(function(){z.contentVisible=!0,(0,_vue.nextTick)(function(){o&&(e=v.value,t=y.value,e=e||t)&&e.focus();var e,t={type:""};m("update:modelValue",!0),S.dispatchEvent("show",t)})},10),i?(-1===msgQueue.indexOf(k)&&msgQueue.push(k),M(),-1!==e&&setTimeout(function(){return C("close")},_xeUtils.default.toNumber(e))):(0,_vue.nextTick)(function(){var e,t,o,n,i,a,l,u,c=N.fullscreen,s=z.firstOpen;r&&!s||d().then(function(){setTimeout(d,20)}),s&&(z.firstOpen=!1,s=N.id,a=N.remember,l=N.storage,u=N.storageKey,s)&&a&&l&&E(u)[s]?(a=N.id,l=N.remember,u=N.storage,s=N.storageKey,a&&l&&u&&(l=E(s)[a])&&(u=O(),a=(s=l.split(","))[0],l=s[1],e=s[2],t=s[3],o=s[4],n=s[5],i=s[6],s=s[7],a&&(u.style.left="".concat(a,"px")),l&&(u.style.top="".concat(l,"px")),e&&(u.style.width="".concat(e,"px")),t&&(u.style.height="".concat(t,"px")),o)&&n&&(z.zoomLocat={left:o,top:n,width:i,height:s})):c&&(0,_vue.nextTick)(f)})),(0,_vue.nextTick)()}function p(e){var t=x.value;N.maskClosable&&e.target===t&&C("mask")}function i(e){var t;(0,_event.hasEventKey)(e,_event.EVENT_KEYS.ESCAPE)&&(t=_xeUtils.default.max(allActivedModals,function(e){return e.reactData.modalZindex}))&&setTimeout(function(){t===k&&t.props.escClosable&&C("exit")},10)}function u(){return!!z.zoomLocat}function c(){return(0,_vue.nextTick)().then(function(){var e,t=z.zoomLocat;t&&(e=O(),z.zoomLocat=null,Object.assign(e.style,{top:"".concat(t.top,"px"),left:"".concat(t.left,"px"),width:"".concat(t.width,"px"),height:"".concat(t.height,"px")}),V())})}function s(){return(z.zoomLocat?c:f)().then(u)}function h(){var t=z.modalZindex;allActivedModals.some(function(e){return e.reactData.visible&&e.reactData.modalZindex>t})&&B()}var _=e.slots,m=e.emit,r=_xeUtils.default.uniqueId(),g=(0,_size.useSize)(N),z=(0,_vue.reactive)({inited:!1,visible:!1,contentVisible:!1,modalTop:0,modalZindex:0,zoomLocat:null,firstOpen:!0}),x=(0,_vue.ref)(),b=(0,_vue.ref)(),v=(0,_vue.ref)(),y=(0,_vue.ref)(),w={refElem:x},k={xID:r,props:N,context:e,reactData:z,getRefMaps:function(){return w}},S={},T=(0,_vue.computed)(function(){return"message"===N.type}),O=function(){return b.value},B=function(){var e=N.zIndex,t=z.modalZindex;e?z.modalZindex=e:t<(0,_utils.getLastZIndex)()&&(z.modalZindex=(0,_utils.nextZIndex)())},M=function(){(0,_vue.nextTick)(function(){var o=0;msgQueue.forEach(function(e){var t=e.getBox();o+=_xeUtils.default.toNumber(e.props.top),e.reactData.modalTop=o,o+=t.clientHeight})})},L=function(){-1<msgQueue.indexOf(k)&&_xeUtils.default.remove(msgQueue,function(e){return e===k}),M()},C=function(e){var t=N.remember,o=N.beforeHideMethod,n=z.visible,i=T.value,a={type:e};return n&&Promise.resolve(o?o(a):null).then(function(e){_xeUtils.default.isError(e)||(i&&L(),z.contentVisible=!1,t||(z.zoomLocat=null),_xeUtils.default.remove(allActivedModals,function(e){return e===k}),S.dispatchEvent("before-hide",a),setTimeout(function(){z.visible=!1,m("update:modelValue",!1),S.dispatchEvent("hide",a)},200))}).catch(function(e){return e}),(0,_vue.nextTick)()},E=function(e){var t=_conf.default.version,e=_xeUtils.default.toStringJSON(localStorage.getItem(e)||"");return e&&e._v===t?e:{_v:t}},V=function(){var e=N.id,t=N.remember,o=N.storage,n=N.storageKey,i=z.zoomLocat;e&&t&&o&&(t=O(),(o=E(n))[e]=[t.style.left,t.style.top,t.style.width,t.style.height].concat(i?[i.left,i.top,i.width,i.height]:[]).map(function(e){return e?_xeUtils.default.toNumber(e):""}).join(","),localStorage.setItem(n,_xeUtils.default.toJSONString(o)))},D=function(e){var t={type:z.zoomLocat?"revert":"max"};return s().then(function(){S.dispatchEvent("zoom",t,e)})},U=function(e){var t,o,i,a,l,u,n=N.remember,c=N.storage,s=z.zoomLocat,r=_xeUtils.default.toNumber(N.marginSize),d=O();s||0!==e.button||(0,_dom.getEventTargetNode)(e,d,"trigger--btn").flag||(e.preventDefault(),t=document.onmousemove,o=document.onmouseup,i=e.clientX-d.offsetLeft,a=e.clientY-d.offsetTop,s=(0,_dom.getDomNode)(),l=s.visibleHeight,u=s.visibleWidth,document.onmousemove=function(e){e.preventDefault();var t=d.offsetWidth,o=d.offsetHeight,t=u-t-r-1,o=l-o-r-1,n=e.clientX-i,e=e.clientY-a;(e=o<e?o:e)<r&&(e=r),d.style.left="".concat(n=(n=t<n?t:n)<r?r:n,"px"),d.style.top="".concat(e,"px"),d.className=d.className.replace(/\s?is--drag/,"")+" is--drag"},document.onmouseup=function(){document.onmousemove=t,document.onmouseup=o,n&&c&&(0,_vue.nextTick)(function(){V()}),setTimeout(function(){d.className=d.className.replace(/\s?is--drag/,"")},50)})},H=function(e){e.preventDefault();var a=N.remember,l=N.storage,t=(0,_dom.getDomNode)(),u=t.visibleHeight,c=t.visibleWidth,s=_xeUtils.default.toNumber(N.marginSize),r=e.target.getAttribute("type"),d=_xeUtils.default.toNumber(N.minWidth),f=_xeUtils.default.toNumber(N.minHeight),m=c,v=u,p=O(),o=document.onmousemove,n=document.onmouseup,h=p.clientWidth,_=p.clientHeight,g=e.clientX,x=e.clientY,b=p.offsetTop,y=p.offsetLeft,w={type:"resize"};document.onmousemove=function(e){var t,o,n,i;switch(e.preventDefault(),r){case"wl":n=(t=g-e.clientX)+h,s<y-t&&d<n&&(p.style.width="".concat(n<m?n:m,"px"),p.style.left="".concat(y-t,"px"));break;case"swst":t=g-e.clientX,o=x-e.clientY,n=t+h,i=o+_,s<y-t&&d<n&&(p.style.width="".concat(n<m?n:m,"px"),p.style.left="".concat(y-t,"px")),s<b-o&&f<i&&(p.style.height="".concat(i<v?i:v,"px"),p.style.top="".concat(b-o,"px"));break;case"swlb":t=g-e.clientX,o=e.clientY-x,n=t+h,i=o+_,s<y-t&&d<n&&(p.style.width="".concat(n<m?n:m,"px"),p.style.left="".concat(y-t,"px")),b+i+s<u&&f<i&&(p.style.height="".concat(i<v?i:v,"px"));break;case"st":o=x-e.clientY,i=_+o,s<b-o&&f<i&&(p.style.height="".concat(i<v?i:v,"px"),p.style.top="".concat(b-o,"px"));break;case"wr":t=e.clientX-g,y+(n=t+h)+s<c&&d<n&&(p.style.width="".concat(n<m?n:m,"px"));break;case"sest":t=e.clientX-g,i=(o=x-e.clientY)+_,y+(n=t+h)+s<c&&d<n&&(p.style.width="".concat(n<m?n:m,"px")),s<b-o&&f<i&&(p.style.height="".concat(i<v?i:v,"px"),p.style.top="".concat(b-o,"px"));break;case"selb":t=e.clientX-g,i=(o=e.clientY-x)+_,y+(n=t+h)+s<c&&d<n&&(p.style.width="".concat(n<m?n:m,"px")),b+i+s<u&&f<i&&(p.style.height="".concat(i<v?i:v,"px"));break;case"sb":o=e.clientY-x,b+(i=o+_)+s<u&&f<i&&(p.style.height="".concat(i<v?i:v,"px"))}p.className=p.className.replace(/\s?is--drag/,"")+" is--drag",a&&l&&V(),S.dispatchEvent("zoom",w,e)},document.onmouseup=function(){z.zoomLocat=null,document.onmousemove=o,document.onmouseup=n,setTimeout(function(){p.className=p.className.replace(/\s?is--drag/,"")},50)}},q=function(){var e=N.slots,e=void 0===e?{}:e,t=N.showClose,o=N.showZoom,n=N.title,i=z.zoomLocat,a=_.title||e.title,e=_.corner||e.corner,a=[(0,_vue.h)("div",{class:"vxe-modal--header-title"},a?(0,_vn.getSlotVNs)(a({$modal:k})):n?(0,_utils.getFuncText)(n):_conf.default.i18n("vxe.alert.title"))],n=[];return e&&n.push((0,_vue.h)("span",{class:"vxe-modal--corner-warpper"},(0,_vn.getSlotVNs)(e({$modal:k})))),o&&n.push((0,_vue.h)("i",{class:["vxe-modal--zoom-btn","trigger--btn",i?_conf.default.icon.MODAL_ZOOM_OUT:_conf.default.icon.MODAL_ZOOM_IN],title:_conf.default.i18n("vxe.modal.zoom".concat(i?"Out":"In")),onClick:D})),t&&n.push((0,_vue.h)("i",{class:["vxe-modal--close-btn","trigger--btn",_conf.default.icon.MODAL_CLOSE],title:_conf.default.i18n("vxe.modal.close"),onClick:l})),a.push((0,_vue.h)("div",{class:"vxe-modal--header-right"},n)),a},Z=function(){var e=[];return"confirm"===N.type&&e.push((0,_vue.h)(_button.default,{ref:y,content:N.cancelButtonText||_conf.default.i18n("vxe.button.cancel"),onClick:o})),e.push((0,_vue.h)(_button.default,{ref:v,status:"primary",content:N.confirmButtonText||_conf.default.i18n("vxe.button.confirm"),onClick:t})),e},S={dispatchEvent:function(e,t,o){m(e,Object.assign({$modal:k,$event:o},t))},open:n,close:function(){return C("close")},getBox:O,getPosition:function(){if(!T.value){var e=O();if(e)return{top:e.offsetTop,left:e.offsetLeft}}return null},setPosition:function(e,t){var o;return T.value||(o=O(),_xeUtils.default.isNumber(e)&&(o.style.top="".concat(e,"px")),_xeUtils.default.isNumber(t)&&(o.style.left="".concat(t,"px"))),(0,_vue.nextTick)()},isMaximized:u,zoom:s,maximize:f,revert:c};Object.assign(k,S),(0,_vue.watch)(function(){return N.width},a),(0,_vue.watch)(function(){return N.height},a),(0,_vue.watch)(function(){return N.modelValue},function(e){e?n():C("model")}),(0,_vue.onMounted)(function(){(0,_vue.nextTick)(function(){N.storage&&!N.id&&(0,_log.errLog)("vxe.error.reqProp",["modal.id"]),N.modelValue&&n(),a()}),N.escClosable&&_event.GlobalEvent.on(k,"keydown",i)}),(0,_vue.onUnmounted)(function(){_event.GlobalEvent.off(k,"keydown"),L()});return k.renderVN=function(){var e=N.className,t=N.type,o=N.animat,n=N.loading,i=N.status,a=N.lockScroll,l=N.lockView,u=N.mask,c=N.resize,s=z.inited,r=z.zoomLocat,d=z.modalTop,f=z.contentVisible,m=z.visible,v=g.value;return(0,_vue.h)(_vue.Teleport,{to:"body",disabled:!N.transfer||!s},[(0,_vue.h)("div",{ref:x,class:["vxe-modal--wrapper","type--".concat(t),e||"",((s={})["size--".concat(v)]=v,s["status--".concat(i)]=i,s["is--animat"]=o,s["lock--scroll"]=a,s["lock--view"]=l,s["is--resize"]=c,s["is--mask"]=u,s["is--maximize"]=r,s["is--visible"]=f,s["is--active"]=m,s["is--loading"]=n,s)],style:{zIndex:z.modalZindex,top:d?"".concat(d,"px"):null},onClick:p},[(0,_vue.h)("div",{ref:b,class:"vxe-modal--box",onMousedown:h},(t=N.slots,e=N.showZoom,v=N.draggable,i=T.value,t=_.header||(void 0===t?{}:t).header,o=[],N.showHeader&&(a={},v&&(a.onMousedown=U),e&&N.dblclickZoom&&"modal"===N.type&&(a.onDblclick=D),o.push((0,_vue.h)("div",__assign({class:["vxe-modal--header",{"is--draggable":v,"is--ellipsis":!i&&N.showTitleOverflow}]},a),t?!z.inited||N.destroyOnClose&&!z.visible?[]:(0,_vn.getSlotVNs)(t({$modal:k})):q()))),o.concat((l=N.slots,c=N.status,u=N.message,u=N.content||u,r=T.value,l=_.default||(void 0===l?{}:l).default,f=[],c&&f.push((0,_vue.h)("div",{class:"vxe-modal--status-wrapper"},[(0,_vue.h)("i",{class:["vxe-modal--status-icon",N.iconStatus||_conf.default.icon["MODAL_".concat(c).toLocaleUpperCase()]]})])),f.push((0,_vue.h)("div",{class:"vxe-modal--content"},l?!z.inited||N.destroyOnClose&&!z.visible?[]:(0,_vn.getSlotVNs)(l({$modal:k})):(0,_utils.getFuncText)(u))),r||f.push((0,_vue.h)(_index.default,{class:"vxe-modal--loading",modelValue:N.loading})),[(0,_vue.h)("div",{class:"vxe-modal--body"},f)]),(m=N.slots,n=T.value,m=_.footer||(void 0===m?{}:m).footer,s=[],N.showFooter&&s.push((0,_vue.h)("div",{class:"vxe-modal--footer"},m?!z.inited||N.destroyOnClose&&!z.visible?[]:(0,_vn.getSlotVNs)(m({$modal:k})):Z())),!n&&N.resize&&s.push((0,_vue.h)("span",{class:"vxe-modal--resize"},["wl","wr","swst","sest","st","swlb","selb","sb"].map(function(e){return(0,_vue.h)("span",{class:"".concat(e,"-resize"),type:e,onMousedown:H})}))),s))))])])},k},render:function(){return this.renderVN()}}));exports.default=_default;