UNPKG

vxe-table

Version:

一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟滚动、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、虚拟列表、模态窗口、自定义模板、渲染器、贼灵活的配置项、扩展接口等...

1 lines 17.2 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.msgQueue=exports.allActivedModals=void 0;var _conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=_interopRequireDefault(require("../../mixins/size")),_xeUtils=_interopRequireDefault(require("xe-utils")),_tools=require("../../tools");function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(o="Object"===o&&t.constructor?t.constructor.name:o)||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?_arrayLikeToArray(t,e):void 0}}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,i=new Array(e);o<e;o++)i[o]=t[o];return i}function _iterableToArrayLimit(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var o=[],i=!0,n=!1,s=void 0;try{for(var l,a=t[Symbol.iterator]();!(i=(l=a.next()).done)&&(o.push(l.value),!e||o.length!==e);i=!0);}catch(t){n=!0,s=t}finally{try{i||null==a.return||a.return()}finally{if(n)throw s}}return o}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _defineProperty(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}var allActivedModals=[];exports.allActivedModals=allActivedModals;var msgQueue=[];exports.msgQueue=msgQueue;var _default2={name:"VxeModal",mixins:[_size.default],props:{value: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:[String,Function],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:{type:Boolean,default:function(){return _conf.default.modal.resize}},showHeader:{type:Boolean,default:function(){return _conf.default.modal.showHeader}},showFooter:{type:Boolean,default:function(){return _conf.default.modal.showFooter}},showZoom:{type:Boolean,default:null},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:_conf.default.modal.marginSize},fullscreen:Boolean,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,events:Object},data:function(){return{inited:!1,visible:!1,contentVisible:!1,modalTop:0,modalZindex:0,zoomLocat:null,firstOpen:!1}},computed:{isMsg:function(){return"message"===this.type}},watch:{width:function(){this.recalculate()},height:function(){this.recalculate()},value:function(t){this[t?"open":"close"]()}},created:function(){this.storage&&!this.id&&_tools.UtilTools.error("vxe.error.reqProp",["modal.id"])},mounted:function(){var t=this.$listeners,e=this.events,o=void 0===e?{}:e;this.value&&this.open(),this.recalculate(),this.escClosable&&_tools.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent);e="inserted",e={type:e,$modal:this,$event:{type:e}};t.inserted?this.$emit("inserted",e):o.inserted&&o.inserted.call(this,e)},beforeDestroy:function(){var t=this.$el;_tools.GlobalEvent.off(this,"keydown"),this.removeMsgQueue(),t.parentNode===document.body&&t.parentNode.removeChild(t)},render:function(e){var o=this,t=this.$scopedSlots,i=this.slots,n=void 0===i?{}:i,s=this.inited,l=this.vSize,a=this.className,r=this.type,c=this.resize,u=this.showZoom,d=this.animat,f=this.loading,h=this.status,m=this.iconStatus,p=this.showFooter,v=this.zoomLocat,g=this.modalTop,x=this.dblclickZoom,y=this.contentVisible,b=this.visible,_=this.title,w=this.message,S=this.lockScroll,z=this.lockView,T=this.mask,k=this.isMsg,$=this.showTitleOverflow,B=this.destroyOnClose,M=t.default||n.default,N=t.footer||n.footer,i=t.header||n.header,t=t.title||n.title,n={mousedown:this.mousedownEvent};return u&&x&&"modal"===r&&(n.dblclick=this.toggleZoomEvent),e("div",{class:["vxe-modal--wrapper","type--".concat(r),a||"",(_defineProperty(a={},"size--".concat(l),l),_defineProperty(a,"status--".concat(h),h),_defineProperty(a,"is--animat",d),_defineProperty(a,"lock--scroll",S),_defineProperty(a,"lock--view",z),_defineProperty(a,"is--resize",c),_defineProperty(a,"is--mask",T),_defineProperty(a,"is--maximize",v),_defineProperty(a,"is--visible",y),_defineProperty(a,"is--active",b),_defineProperty(a,"is--loading",f),a)],style:{zIndex:this.modalZindex,top:g?"".concat(g,"px"):null},on:{click:this.selfClickEvent}},[e("div",{class:"vxe-modal--box",on:{mousedown:this.boxMousedownEvent},ref:"modalBox"},[this.showHeader?e("div",{class:["vxe-modal--header",!k&&$?"is--ellipsis":""],on:n},i?!s||B&&!b?[]:i.call(this,{$modal:this},e):[t?t.call(this,{$modal:this},e):e("span",{class:"vxe-modal--title"},_?_tools.UtilTools.getFuncText(_):_conf.default.i18n("vxe.alert.title")),u?e("i",{class:["vxe-modal--zoom-btn","trigger--btn",v?_conf.default.icon.MODAL_ZOOM_OUT:_conf.default.icon.MODAL_ZOOM_IN],attrs:{title:_conf.default.i18n("vxe.modal.zoom".concat(v?"Out":"In"))},on:{click:this.toggleZoomEvent}}):null,e("i",{class:["vxe-modal--close-btn","trigger--btn",_conf.default.icon.MODAL_CLOSE],attrs:{title:_conf.default.i18n("vxe.modal.close")},on:{click:this.closeEvent}})]):null,e("div",{class:"vxe-modal--body"},[h?e("div",{class:"vxe-modal--status-wrapper"},[e("i",{class:["vxe-modal--status-icon",m||_conf.default.icon["MODAL_".concat(h).toLocaleUpperCase()]]})]):null,e("div",{class:"vxe-modal--content"},M?!s||B&&!b?[]:M.call(this,{$modal:this},e):_tools.UtilTools.getFuncText(w)),k?null:e("div",{class:["vxe-loading",{"is--visible":f}]},[e("div",{class:"vxe-loading--spinner"})])]),p?e("div",{class:"vxe-modal--footer"},N?!s||B&&!b?[]:N.call(this,{$modal:this},e):["confirm"===r?e("vxe-button",{ref:"cancelBtn",on:{click:this.cancelEvent}},this.cancelButtonText||_conf.default.i18n("vxe.button.cancel")):null,e("vxe-button",{ref:"confirmBtn",props:{status:"primary"},on:{click:this.confirmEvent}},this.confirmButtonText||_conf.default.i18n("vxe.button.confirm"))]):null,!k&&c?e("span",{class:"vxe-modal--resize"},["wl","wr","swst","sest","st","swlb","selb","sb"].map(function(t){return e("span",{class:"".concat(t,"-resize"),attrs:{type:t},on:{mousedown:o.dragEvent}})})):null])])},methods:{recalculate:function(){var t=this.width,e=this.height,o=this.getBox();return o.style.width=t?isNaN(t)?t:"".concat(t,"px"):null,o.style.height=e?isNaN(e)?e:"".concat(e,"px"):null,this.$nextTick()},selfClickEvent:function(t){this.maskClosable&&t.target===this.$el&&this.close("mask")},updateZindex:function(){var t=this.zIndex,e=this.modalZindex;t?this.modalZindex=t:e<_tools.UtilTools.getLastZIndex()&&(this.modalZindex=_tools.UtilTools.nextZIndex())},closeEvent:function(t){var e="close";this.$emit(e,{type:e,$modal:this,$event:t}),this.close(e)},confirmEvent:function(t){var e="confirm";this.$emit(e,{type:e,$modal:this,$event:t}),this.close(e)},cancelEvent:function(t){var e="cancel";this.$emit(e,{type:e,$modal:this,$event:t}),this.close(e)},open:function(){var o=this,e=this.$refs,t=this.events,i=void 0===t?{}:t,n=this.inited,s=this.duration,l=this.visible,t=this.isMsg,a=this.remember,r=this.showFooter;n||(this.inited=!0,this.transfer&&document.body.appendChild(this.$el)),l||(a||this.recalculate(),this.visible=!0,this.contentVisible=!1,this.updateZindex(),allActivedModals.push(this),setTimeout(function(){o.contentVisible=!0,o.$nextTick(function(){!r||(t=e.confirmBtn||e.cancelBtn)&&t.focus();var t={type:"",$modal:o};i.show?i.show.call(o,t):(o.$emit("input",!0),o.$emit("show",t))})},10),t?(this.addMsgQueue(),-1!==s&&setTimeout(this.close,_xeUtils.default.toNumber(s))):this.$nextTick(function(){var t=o.firstOpen,e=o.fullscreen;a&&t||o.updatePosition().then(function(){setTimeout(function(){return o.updatePosition()},20)}),t||(o.firstOpen=!0,o.hasPosStorage()?o.restorePosStorage():e&&o.$nextTick(function(){return o.maximize()}))}))},addMsgQueue:function(){-1===msgQueue.indexOf(this)&&msgQueue.push(this),this.updateStyle()},removeMsgQueue:function(){var e=this;-1<msgQueue.indexOf(this)&&_xeUtils.default.remove(msgQueue,function(t){return t===e}),this.updateStyle()},updateStyle:function(){this.$nextTick(function(){var e=0;msgQueue.forEach(function(t){e+=_xeUtils.default.toNumber(t.top),t.modalTop=e,e+=t.$refs.modalBox.clientHeight})})},updatePosition:function(){var u=this;return this.$nextTick().then(function(){var t=u.marginSize,e=u.position,o=u.getBox(),i=document.documentElement.clientWidth||document.body.clientWidth,n=document.documentElement.clientHeight||document.body.clientHeight,s="center"===e,l=s?{top:e,left:e}:Object.assign({},e),a=l.top,r=l.left,c=s||"center"===a,e="",l="",l=r&&!(s||"center"===r)?isNaN(r)?r:"".concat(r,"px"):"".concat(Math.max(t,i/2-o.offsetWidth/2),"px"),e=a&&!c?isNaN(a)?a:"".concat(a,"px"):"".concat(Math.max(t,n/2-o.offsetHeight/2),"px");o.style.top=e,o.style.left=l})},close:function(t){var e=this,o=this.events,i=void 0===o?{}:o,n=this.remember,s=this.visible,l=this.isMsg,o=this.beforeHideMethod,a={type:t,$modal:this};s&&Promise.resolve(o?o(a):null).then(function(t){_xeUtils.default.isError(t)||(l&&e.removeMsgQueue(),e.contentVisible=!1,n||(e.zoomLocat=null),_xeUtils.default.remove(allActivedModals,function(t){return t===e}),setTimeout(function(){e.visible=!1,i.hide?i.hide.call(e,a):(e.$emit("input",!1),e.$emit("hide",a))},200))}).catch(function(t){return t})},handleGlobalKeydownEvent:function(t){var e,o=this;27!==t.keyCode||(e=_xeUtils.default.max(allActivedModals,function(t){return t.modalZindex}))&&setTimeout(function(){e===o&&e.escClosable&&o.close()},10)},getBox:function(){return this.$refs.modalBox},isMaximized:function(){return!!this.zoomLocat},maximize:function(){var n=this;return this.$nextTick().then(function(){var t,e,o,i;n.zoomLocat||(t=n.marginSize,e=n.getBox(),o=(i=_tools.DomTools.getDomNode()).visibleHeight,i=i.visibleWidth,n.zoomLocat={top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth+(e.style.width?0:1),height:e.offsetHeight+(e.style.height?0:1)},Object.assign(e.style,{top:"".concat(t,"px"),left:"".concat(t,"px"),width:"".concat(i-2*t,"px"),height:"".concat(o-2*t,"px")}),n.savePosStorage())})},revert:function(){var o=this;return this.$nextTick().then(function(){var t,e=o.zoomLocat;e&&(t=o.getBox(),o.zoomLocat=null,Object.assign(t.style,{top:"".concat(e.top,"px"),left:"".concat(e.left,"px"),width:"".concat(e.width,"px"),height:"".concat(e.height,"px")}),o.savePosStorage())})},zoom:function(){var t=this;return this[this.zoomLocat?"revert":"maximize"]().then(function(){return t.isMaximized()})},toggleZoomEvent:function(t){var e=this,o=this.$listeners,i=this.zoomLocat,n=this.events,s=void 0===n?{}:n,l={type:i?"revert":"max",$modal:this,$event:t};return this.zoom().then(function(){o.zoom?e.$emit("zoom",l):s.zoom&&s.zoom.call(e,l)})},getPosition:function(){if(!this.isMsg){var t=this.getBox();if(t)return{top:t.offsetTop,left:t.offsetLeft}}return null},setPosition:function(t,e){var o;return this.isMsg||(o=this.getBox(),_xeUtils.default.isNumber(t)&&(o.style.top="".concat(t,"px")),_xeUtils.default.isNumber(e)&&(o.style.left="".concat(e,"px"))),this.$nextTick()},boxMousedownEvent:function(){var e=this.modalZindex;allActivedModals.some(function(t){return t.visible&&t.modalZindex>e})&&this.updateZindex()},mousedownEvent:function(t){var e,o,n,s,l,a,i=this,r=this.remember,c=this.storage,u=this.marginSize,d=this.zoomLocat,f=this.getBox();d||0!==t.button||_tools.DomTools.getEventTargetNode(t,f,"trigger--btn").flag||(t.preventDefault(),e=document.onmousemove,o=document.onmouseup,n=t.clientX-f.offsetLeft,s=t.clientY-f.offsetTop,t=_tools.DomTools.getDomNode(),l=t.visibleHeight,a=t.visibleWidth,document.onmousemove=function(t){t.preventDefault();var e=f.offsetWidth,o=f.offsetHeight,i=a-e-u-1,e=l-o-u-1,o=t.clientX-n,t=t.clientY-s;(o=i<o?i:o)<u&&(o=u),(t=e<t?e:t)<u&&(t=u),f.style.left="".concat(o,"px"),f.style.top="".concat(t,"px")},document.onmouseup=function(){document.onmousemove=e,document.onmouseup=o,r&&c&&i.$nextTick(function(){i.savePosStorage()})})},dragEvent:function(t){var s=this;t.preventDefault();var l=this.$listeners,a=this.marginSize,e=this.events,r=void 0===e?{}:e,c=this.remember,u=this.storage,e=_tools.DomTools.getDomNode(),d=e.visibleHeight,f=e.visibleWidth,h=t.target.getAttribute("type"),m=_xeUtils.default.toNumber(this.minWidth),p=_xeUtils.default.toNumber(this.minHeight),v=f,g=d,x=this.getBox(),o=document.onmousemove,i=document.onmouseup,y=x.clientWidth,b=x.clientHeight,_=t.clientX,w=t.clientY,S=x.offsetTop,z=x.offsetLeft,T={type:"resize",$modal:this};document.onmousemove=function(t){var e,o,i,n;switch(t.preventDefault(),h){case"wl":i=(e=_-t.clientX)+y,a<z-e&&m<i&&(x.style.width="".concat(i<v?i:v,"px"),x.style.left="".concat(z-e,"px"));break;case"swst":e=_-t.clientX,o=w-t.clientY,i=e+y,n=o+b,a<z-e&&m<i&&(x.style.width="".concat(i<v?i:v,"px"),x.style.left="".concat(z-e,"px")),a<S-o&&p<n&&(x.style.height="".concat(n<g?n:g,"px"),x.style.top="".concat(S-o,"px"));break;case"swlb":e=_-t.clientX,o=t.clientY-w,i=e+y,n=o+b,a<z-e&&m<i&&(x.style.width="".concat(i<v?i:v,"px"),x.style.left="".concat(z-e,"px")),S+n+a<d&&p<n&&(x.style.height="".concat(n<g?n:g,"px"));break;case"st":o=w-t.clientY,n=b+o,a<S-o&&p<n&&(x.style.height="".concat(n<g?n:g,"px"),x.style.top="".concat(S-o,"px"));break;case"wr":e=t.clientX-_,z+(i=e+y)+a<f&&m<i&&(x.style.width="".concat(i<v?i:v,"px"));break;case"sest":e=t.clientX-_,n=(o=w-t.clientY)+b,z+(i=e+y)+a<f&&m<i&&(x.style.width="".concat(i<v?i:v,"px")),a<S-o&&p<n&&(x.style.height="".concat(n<g?n:g,"px"),x.style.top="".concat(S-o,"px"));break;case"selb":e=t.clientX-_,n=(o=t.clientY-w)+b,z+(i=e+y)+a<f&&m<i&&(x.style.width="".concat(i<v?i:v,"px")),S+n+a<d&&p<n&&(x.style.height="".concat(n<g?n:g,"px"));break;case"sb":o=t.clientY-w,S+(n=o+b)+a<d&&p<n&&(x.style.height="".concat(n<g?n:g,"px"))}x.className=x.className.replace(/\s?is--drag/,"")+" is--drag",c&&u&&s.savePosStorage(),l.zoom?s.$emit("zoom",T):r.zoom&&r.zoom.call(s,T)},document.onmouseup=function(){s.zoomLocat=null,document.onmousemove=o,document.onmouseup=i,setTimeout(function(){x.className=x.className.replace(/\s?is--drag/,"")},50)}},getStorageMap:function(t){var e=_conf.default.version,t=_xeUtils.default.toStringJSON(localStorage.getItem(t));return t&&t._v===e?t:{_v:e}},hasPosStorage:function(){var t=this.id,e=this.remember,o=this.storage,i=this.storageKey;return!!(e&&o&&this.getStorageMap(i)[t])},restorePosStorage:function(){var t,e,o,i,n,s=this.id,l=this.remember,a=this.storage,r=this.storageKey;l&&a&&((i=this.getStorageMap(r)[s])&&(t=this.getBox(),e=(n=_slicedToArray(i.split(","),8))[0],o=n[1],l=n[2],a=n[3],r=n[4],s=n[5],i=n[6],n=n[7],e&&(t.style.left="".concat(e,"px")),o&&(t.style.top="".concat(o,"px")),l&&(t.style.width="".concat(l,"px")),a&&(t.style.height="".concat(a,"px")),r&&s&&(this.zoomLocat={left:r,top:s,width:i,height:n})))},savePosStorage:function(){var t=this.id,e=this.remember,o=this.storage,i=this.storageKey,n=this.zoomLocat;e&&o&&(e=this.getBox(),(o=this.getStorageMap(i))[t]=[e.style.left,e.style.top,e.style.width,e.style.height].concat(n?[n.left,n.top,n.width,n.height]:[]).map(function(t){return t?_xeUtils.default.toNumber(t):""}).join(","),localStorage.setItem(i,_xeUtils.default.toJSONString(o)))}}};exports.default=_default2;