mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-11 18:42:54 +00:00
2 lines
5.5 KiB
JavaScript
Vendored
2 lines
5.5 KiB
JavaScript
Vendored
import{V as c,n as m}from"./app.256678e2.js";typeof/./!="function"&&typeof Int8Array!="object"&&(c.prototype.$isServer||document.childNodes);const v=function(){return!c.prototype.$isServer&&!!window.navigator.userAgent.match(/firefox/i)};function d(e){let i=!1;return function(...t){i||(i=!0,window.requestAnimationFrame(s=>{e.apply(this,t),i=!1}))}}const h=c.prototype.$isServer,r=function(){return!h&&document.addEventListener?function(e,i,t){e&&i&&t&&e.addEventListener(i,t,!1)}:function(e,i,t){e&&i&&t&&e.attachEvent("on"+i,t)}}(),l=function(){return!h&&document.removeEventListener?function(e,i,t){e&&i&&e.removeEventListener(i,t,!1)}:function(e,i,t){e&&i&&e.detachEvent("on"+i,t)}}();var g=function(){var e=this,i=e.$createElement,t=e._self._c||i;return t("div",{ref:"view",staticClass:"common-preview-image"},[t("div",{staticClass:"common-preview-view no-dark-content"},[e.isSingle?e._e():[t("div",{staticClass:"preview-view-prev",class:{"is-disabled":!e.infinite&&e.isFirst},on:{click:e.prev}},[t("i",{staticClass:"taskfont"},[e._v("\uE72D")])]),t("div",{staticClass:"preview-view-next",class:{"is-disabled":!e.infinite&&e.isLast},on:{click:e.next}},[t("i",{staticClass:"taskfont"},[e._v("\uE733")])])],t("div",{staticClass:"preview-view-actions"},[t("div",{staticClass:"actions-inner"},[t("i",{staticClass:"taskfont",on:{click:function(s){return e.handleActions("zoomOut")}}},[e._v("\uE7A2")]),t("i",{staticClass:"taskfont",on:{click:function(s){return e.handleActions("zoomIn")}}},[e._v("\uE79F")]),t("i",{staticClass:"actions-divider"}),t("i",{staticClass:"taskfont",domProps:{innerHTML:e._s(e.mode.icon)},on:{click:e.toggleMode}}),t("i",{staticClass:"actions-divider"}),t("i",{staticClass:"taskfont",on:{click:function(s){return e.handleActions("anticlocelise")}}},[e._v("\uE7A7")]),t("i",{staticClass:"taskfont",on:{click:function(s){return e.handleActions("clocelise")}}},[e._v("\uE7A6")])])]),t("div",{staticClass:"preview-view-canvas"},e._l(e.urlList,function(s,o){return o===e.index?t("img",{key:o,ref:"img",refInFor:!0,staticClass:"preview-view-img",style:e.imgStyle,attrs:{src:e.currentImg},on:{load:e.handleImgLoad,error:e.handleImgError,mousedown:e.handleMouseDown}}):e._e()}),0)],2)])},p=[];const a={CONTAIN:{name:"contain",icon:""},ORIGINAL:{name:"original",icon:""}},u=v()?"DOMMouseScroll":"mousewheel",_={props:{urlList:{type:Array,default:()=>[]},initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!1},onSwitch:{type:Function,default:()=>{}}},data(){return{index:this.initialIndex,loading:!1,mode:a.CONTAIN,transform:{scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}}},mounted(){this.deviceSupportInstall(),this.$refs.view.focus()},beforeDestroy(){this.deviceSupportUninstall()},computed:{isSingle(){return this.urlList.length<=1},isFirst(){return this.index===0},isLast(){return this.index===this.urlList.length-1},currentImg(){let e=this.urlList[this.index];return $A.isJson(e)&&(e=e.src),$A.rightDelete(e,"_thumb.jpg")},imgStyle(){const{scale:e,deg:i,offsetX:t,offsetY:s,enableTransition:o}=this.transform,n={transform:`scale(${e}) rotate(${i}deg)`,transition:o?"transform .3s":"","margin-left":`${t}px`,"margin-top":`${s}px`};return this.mode===a.CONTAIN&&(n.maxWidth=n.maxHeight="100%"),n}},watch:{index:{handler:function(e){this.reset(),this.onSwitch(e)}},initialIndex(e){this.index=e},currentImg(){this.$nextTick(e=>{this.$refs.img[0].complete||(this.loading=!0)})}},methods:{deviceSupportInstall(){this._keyDownHandler=e=>{switch(e.stopPropagation(),e.keyCode){case 32:this.toggleMode();break;case 37:this.prev();break;case 38:this.handleActions("zoomIn");break;case 39:this.next();break;case 40:this.handleActions("zoomOut");break}},this._mouseWheelHandler=d(e=>{(e.wheelDelta?e.wheelDelta:-e.detail)>0?this.handleActions("zoomIn",{zoomRate:.015,enableTransition:!1}):this.handleActions("zoomOut",{zoomRate:.015,enableTransition:!1})}),r(document,"keydown",this._keyDownHandler),r(document,u,this._mouseWheelHandler)},deviceSupportUninstall(){l(document,"keydown",this._keyDownHandler),l(document,u,this._mouseWheelHandler),this._keyDownHandler=null,this._mouseWheelHandler=null},handleImgLoad(e){this.loading=!1},handleImgError(e){this.loading=!1,e.target.alt="\u52A0\u8F7D\u5931\u8D25"},handleMouseDown(e){if(this.loading||e.button!==0)return;const{offsetX:i,offsetY:t}=this.transform,s=e.pageX,o=e.pageY;this._dragHandler=d(n=>{this.transform.offsetX=i+n.pageX-s,this.transform.offsetY=t+n.pageY-o}),r(document,"mousemove",this._dragHandler),r(document,"mouseup",n=>{l(document,"mousemove",this._dragHandler)}),e.preventDefault()},reset(){this.transform={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},toggleMode(){if(this.loading)return;const e=Object.keys(a),s=(Object.values(a).indexOf(this.mode)+1)%e.length;this.mode=a[e[s]],this.reset()},prev(){if(this.isFirst&&!this.infinite)return;const e=this.urlList.length;this.index=(this.index-1+e)%e},next(){if(this.isLast&&!this.infinite)return;const e=this.urlList.length;this.index=(this.index+1)%e},handleActions(e,i={}){if(this.loading)return;const{zoomRate:t,rotateDeg:s,enableTransition:o}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...i},{transform:n}=this;switch(e){case"zoomOut":n.scale>.2&&(n.scale=parseFloat((n.scale-t).toFixed(3)));break;case"zoomIn":n.scale=parseFloat((n.scale+t).toFixed(3));break;case"clocelise":n.deg+=s;break;case"anticlocelise":n.deg-=s;break}n.enableTransition=o}}},f={};var w=m(_,g,p,!1,x,"124de060",null,null);function x(e){for(let i in f)this[i]=f[i]}var y=function(){return w.exports}();export{y as default};
|