vxe-table-select-area
Version:
一个基于 vxe-table 的可区域选中复制、粘贴的组件
1 lines • 19.7 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.msgQueue=exports.default=exports.allActivedModals=void 0;var _conf=_interopRequireDefault(require("../../v-x-e-table/src/conf")),_size=_interopRequireDefault(require("../../mixins/size")),_xeUtils=_interopRequireDefault(require("xe-utils")),_utils=_interopRequireWildcard(require("../../tools/utils")),_dom=_interopRequireDefault(require("../../tools/dom")),_event=require("../../tools/event"),_log=require("../../tools/log"),_vn=require("../../tools/vn"),_index=_interopRequireDefault(require("../../loading/index"));function _getRequireWildcardCache(t){var e,o;return"function"!=typeof WeakMap?null:(e=new WeakMap,o=new WeakMap,(_getRequireWildcardCache=function(t){return t?o:e})(t))}function _interopRequireWildcard(t,e){if(!e&&t&&t.__esModule)return t;if(null===t||"object"!==_typeof(t)&&"function"!=typeof t)return{default:t};e=_getRequireWildcardCache(e);if(e&&e.has(t))return e.get(t);var o,i,n={},s=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(o in t)"default"!==o&&Object.prototype.hasOwnProperty.call(t,o)&&((i=s?Object.getOwnPropertyDescriptor(t,o):null)&&(i.get||i.set)?Object.defineProperty(n,o,i):n[o]=t[o]);return n.default=t,e&&e.set(t,n),n}function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(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){var o;if(t)return"string"==typeof t?_arrayLikeToArray(t,e):"Map"===(o="Object"===(o=Object.prototype.toString.call(t).slice(8,-1))&&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){var o=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=o){var i,n,s,l,a=[],r=!0,c=!1;try{if(s=(o=o.call(t)).next,0===e){if(Object(o)!==o)return;r=!1}else for(;!(r=(i=s.call(o)).done)&&(a.push(i.value),a.length!==e);r=!0);}catch(t){c=!0,n=t}finally{try{if(!r&&null!=o.return&&(l=o.return(),Object(l)!==l))return}finally{if(c)throw n}}return a}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _defineProperty(t,e,o){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0===o)return("string"===e?String:Number)(t);o=o.call(t,e||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}var allActivedModals=[],msgQueue=(exports.allActivedModals=allActivedModals,[]),_default2=(exports.msgQueue=msgQueue,{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],content:[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},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,events:Object},data:function(){return{inited:!1,visible:!1,contentVisible:!1,modalTop:0,modalZindex:0,zoomLocat:null,firstOpen:!0}},computed:{isMsg:function(){return"message"===this.type}},watch:{width:function(){this.recalculate()},height:function(){this.recalculate()},value:function(t){this[t?"open":"close"]("model")}},created:function(){this.storage&&!this.id&&(0,_log.errLog)("vxe.error.reqProp",["modal.id"])},mounted:function(){var t=this.$listeners,e=this.events,e=void 0===e?{}:e,o=(this.value&&this.open(),this.recalculate(),this.escClosable&&_event.GlobalEvent.on(this,"keydown",this.handleGlobalKeydownEvent),"inserted"),o={type:o,$modal:this,$event:{type:o}};t.inserted?this.$emit("inserted",o):e.inserted&&e.inserted.call(this,o)},beforeDestroy:function(){var t=this.$el;_event.GlobalEvent.off(this,"keydown"),this.removeMsgQueue(),t.parentNode===document.body&&t.parentNode.removeChild(t)},render:function(e){var o=this,t=this._e,i=this.$scopedSlots,n=this.slots,n=void 0===n?{}:n,s=this.inited,l=this.vSize,a=this.className,r=this.type,c=this.resize,u=this.showClose,d=this.showZoom,f=this.animat,h=this.draggable,m=this.loading,p=this.status,v=this.iconStatus,g=this.showFooter,y=this.zoomLocat,x=this.modalTop,b=this.dblclickZoom,_=this.contentVisible,w=this.visible,S=this.title,z=this.lockScroll,k=this.lockView,$=this.mask,N=this.isMsg,T=this.showTitleOverflow,M=this.destroyOnClose,B=this.content||this.message,O=i.default||n.default,P=i.footer||n.footer,L=i.header||n.header,E=i.title||n.title,i=i.corner||n.corner,n={};return h&&(n.mousedown=this.mousedownEvent),d&&b&&"modal"===r&&(n.dblclick=this.toggleZoomEvent),e("div",{class:["vxe-modal--wrapper","type--".concat(r),a||"",(_defineProperty(b={},"size--".concat(l),l),_defineProperty(b,"status--".concat(p),p),_defineProperty(b,"is--animat",f),_defineProperty(b,"lock--scroll",z),_defineProperty(b,"lock--view",k),_defineProperty(b,"is--resize",c),_defineProperty(b,"is--mask",$),_defineProperty(b,"is--maximize",y),_defineProperty(b,"is--visible",_),_defineProperty(b,"is--active",w),_defineProperty(b,"is--loading",m),b)],style:{zIndex:this.modalZindex,top:x?"".concat(x,"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",{"is--draggable":h,"is--ellipsis":!N&&T}],on:n},L?!s||M&&!w?[]:(0,_vn.getSlotVNs)(L.call(this,{$modal:this},e)):[e("div",{class:"vxe-modal--header-title"},E?(0,_vn.getSlotVNs)(E.call(this,{$modal:this},e)):S?(0,_utils.getFuncText)(S):_conf.default.i18n("vxe.alert.title")),e("div",{class:"vxe-modal--header-right"},[i?e("span",{class:"vxe-modal--corner-warpper"},(0,_vn.getSlotVNs)(i({$modal:this}))):t(),d?e("i",{class:["vxe-modal--zoom-btn","trigger--btn",y?_conf.default.icon.MODAL_ZOOM_OUT:_conf.default.icon.MODAL_ZOOM_IN],attrs:{title:_conf.default.i18n("vxe.modal.zoom".concat(y?"Out":"In"))},on:{click:this.toggleZoomEvent}}):t(),u?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}}):t()])]):null,e("div",{class:"vxe-modal--body"},[p?e("div",{class:"vxe-modal--status-wrapper"},[e("i",{class:["vxe-modal--status-icon",v||_conf.default.icon["MODAL_".concat(p).toLocaleUpperCase()]]})]):null,e("div",{class:"vxe-modal--content"},O?!s||M&&!w?[]:(0,_vn.getSlotVNs)(O.call(this,{$modal:this},e)):(0,_utils.getFuncText)(B)),N?null:e(_index.default,{class:"vxe-modal--loading",props:{value:m}})]),g?e("div",{class:"vxe-modal--footer"},P?!s||M&&!w?[]:(0,_vn.getSlotVNs)(P.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,!N&&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<_utils.default.getLastZIndex()&&(this.modalZindex=_utils.default.nextZIndex())},closeEvent:function(t){var e=this.events,e=void 0===e?{}:e,o="close",t={type:o,$modal:this,$event:t};e[o]?e[o].call(this,t):this.$emit(o,t),this.close(o)},confirmEvent:function(t){var e=this.events,e=void 0===e?{}:e,o="confirm",t={type:o,$modal:this,$event:t};e[o]?e[o].call(this,t):this.$emit(o,t),this.close(o)},cancelEvent:function(t){var e=this.events,e=void 0===e?{}:e,o="cancel",t={type:o,$modal:this,$event:t};e[o]?e[o].call(this,t):this.$emit(o,t),this.close(o)},open:function(){var o=this,e=this.$refs,t=this.events,i=void 0===t?{}:t,t=this.inited,n=this.duration,s=this.visible,l=this.isMsg,a=this.remember,r=this.showFooter;t||(this.inited=!0,this.transfer&&document.body.appendChild(this.$el)),s||(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),l?(this.addMsgQueue(),-1!==n&&setTimeout(function(){return o.close("close")},_xeUtils.default.toNumber(n))):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=!1,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,e=s?{top:e,left:e}:Object.assign({},e),l=e.top,e=e.left,a=s||"center"===l,r="",c="",c=e&&!(s||"center"===e)?isNaN(e)?e:"".concat(e,"px"):"".concat(Math.max(t,i/2-o.offsetWidth/2),"px"),r=l&&!a?isNaN(l)?l:"".concat(l,"px"):"".concat(Math.max(t,n/2-o.offsetHeight/2),"px");o.style.top=r,o.style.left=c})},close:function(t){var e=this,o=this.events,i=void 0===o?{}:o,n=this.remember,o=this.visible,s=this.isMsg,l=this.beforeHideMethod,a={type:t,$modal:this};o&&Promise.resolve(l?l(a):null).then(function(t){_xeUtils.default.isError(t)||(s&&e.removeMsgQueue(),e.contentVisible=!1,n||(e.zoomLocat=null),_xeUtils.default.remove(allActivedModals,function(t){return t===e}),e.$emit("before-hide",a),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("exit")},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=Math.max(0,n.marginSize),e=n.getBox(),o=(i=_dom.default.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||_dom.default.getEventTargetNode(t,f,"trigger--btn").flag||(t.preventDefault(),e=document.onmousemove,o=document.onmouseup,n=t.clientX-f.offsetLeft,s=t.clientY-f.offsetTop,d=_dom.default.getDomNode(),l=d.visibleHeight,a=d.visibleWidth,document.onmousemove=function(t){t.preventDefault();var e=f.offsetWidth,o=f.offsetHeight,e=a-e-u-1,o=l-o-u-1,i=t.clientX-n,t=t.clientY-s;(t=o<t?o:t)<u&&(t=u),f.style.left="".concat(i=(i=e<i?e:i)<u?u:i,"px"),f.style.top="".concat(t,"px"),f.className=f.className.replace(/\s?is--drag/,"")+" is--drag"},document.onmouseup=function(){document.onmousemove=e,document.onmouseup=o,r&&c&&i.$nextTick(function(){i.savePosStorage()}),setTimeout(function(){f.className=f.className.replace(/\s?is--drag/,"")},50)})},dragEvent:function(t){var s=this,l=(t.preventDefault(),this.$listeners),a=this.marginSize,e=this.events,r=void 0===e?{}:e,c=this.remember,u=this.storage,e=_dom.default.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,y=this.getBox(),o=document.onmousemove,i=document.onmouseup,x=y.clientWidth,b=y.clientHeight,_=t.clientX,w=t.clientY,S=y.offsetTop,z=y.offsetLeft,k={type:"resize",$modal:this};document.onmousemove=function(t){var e,o,i,n;switch(t.preventDefault(),h){case"wl":i=(e=_-t.clientX)+x,a<z-e&&m<i&&(y.style.width="".concat(i<v?i:v,"px"),y.style.left="".concat(z-e,"px"));break;case"swst":e=_-t.clientX,o=w-t.clientY,i=e+x,n=o+b,a<z-e&&m<i&&(y.style.width="".concat(i<v?i:v,"px"),y.style.left="".concat(z-e,"px")),a<S-o&&p<n&&(y.style.height="".concat(n<g?n:g,"px"),y.style.top="".concat(S-o,"px"));break;case"swlb":e=_-t.clientX,o=t.clientY-w,i=e+x,n=o+b,a<z-e&&m<i&&(y.style.width="".concat(i<v?i:v,"px"),y.style.left="".concat(z-e,"px")),S+n+a<d&&p<n&&(y.style.height="".concat(n<g?n:g,"px"));break;case"st":o=w-t.clientY,n=b+o,a<S-o&&p<n&&(y.style.height="".concat(n<g?n:g,"px"),y.style.top="".concat(S-o,"px"));break;case"wr":e=t.clientX-_,z+(i=e+x)+a<f&&m<i&&(y.style.width="".concat(i<v?i:v,"px"));break;case"sest":e=t.clientX-_,n=(o=w-t.clientY)+b,z+(i=e+x)+a<f&&m<i&&(y.style.width="".concat(i<v?i:v,"px")),a<S-o&&p<n&&(y.style.height="".concat(n<g?n:g,"px"),y.style.top="".concat(S-o,"px"));break;case"selb":e=t.clientX-_,n=(o=t.clientY-w)+b,z+(i=e+x)+a<f&&m<i&&(y.style.width="".concat(i<v?i:v,"px")),S+n+a<d&&p<n&&(y.style.height="".concat(n<g?n:g,"px"));break;case"sb":o=t.clientY-w,S+(n=o+b)+a<d&&p<n&&(y.style.height="".concat(n<g?n:g,"px"))}y.className=y.className.replace(/\s?is--drag/,"")+" is--drag",c&&u&&s.savePosStorage(),l.zoom?s.$emit("zoom",k):r.zoom&&r.zoom.call(s,k)},document.onmouseup=function(){s.zoomLocat=null,document.onmousemove=o,document.onmouseup=i,setTimeout(function(){y.className=y.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&&(l=this.getStorageMap(r)[s])&&(a=this.getBox(),s=(r=_slicedToArray(l.split(","),8))[0],l=r[1],t=r[2],e=r[3],o=r[4],i=r[5],n=r[6],r=r[7],s&&(a.style.left="".concat(s,"px")),l&&(a.style.top="".concat(l,"px")),t&&(a.style.width="".concat(t,"px")),e&&(a.style.height="".concat(e,"px")),o)&&i&&(this.zoomLocat={left:o,top:i,width:n,height:r})},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;