mirror of
https://gitee.com/myxzgzs/boyue-kfcode-hasfj.git
synced 2025-06-21 17:19:36 +08:00
8 lines
33 KiB
JavaScript
8 lines
33 KiB
JavaScript
![]() |
import{C as U,c as M,o as Y,i as I,f as v,F as E,R as T,ax as S,a5 as R,B as $,_ as D,b as F,d as V,r as L,O as j,j as H,e as C,k as y,w as x,h as q,m as N,P as G}from"./index-CrAWI0wi.js";import{b as Z}from"./user-Bxl06CMk.js";const A={};A.getData=t=>new Promise((e,s)=>{let i={};J(t).then(r=>{i.arrayBuffer=r;try{i.orientation=et(r)}catch{i.orientation=-1}e(i)}).catch(r=>{s(r)})});function J(t){let e=null;return new Promise((s,i)=>{if(t.src)if(/^data\:/i.test(t.src))e=Q(t.src),s(e);else if(/^blob\:/i.test(t.src)){var r=new FileReader;r.onload=function(o){e=o.target.result,s(e)},K(t.src,function(o){r.readAsArrayBuffer(o)})}else{var h=new XMLHttpRequest;h.onload=function(){if(this.status==200||this.status===0)e=h.response,s(e);else throw"Could not load image";h=null},h.open("GET",t.src,!0),h.responseType="arraybuffer",h.send(null)}else i("img error")})}function K(t,e){var s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="blob",s.onload=function(i){(this.status==200||this.status===0)&&e(this.response)},s.send()}function Q(t,e){e=e||t.match(/^data\:([^\;]+)\;base64,/mi)[1]||"",t=t.replace(/^data\:([^\;]+)\;base64,/gmi,"");for(var s=atob(t),i=s.length%2==0?s.length:s.length+1,r=new ArrayBuffer(i),h=new Uint16Array(r),o=0;o<i;o++)h[o]=s.charCodeAt(o);return r}function tt(t,e,s){var i="",r;for(r=e,s+=e;r<s;r++)i+=String.fromCharCode(t.getUint8(r));return i}function et(t){var e=new DataView(t),s=e.byteLength,i,r,h,o,c,l,n,a,p,u;if(e.getUint8(0)===255&&e.getUint8(1)===216)for(p=2;p<s;){if(e.getUint8(p)===255&&e.getUint8(p+1)===225){n=p;break}p++}if(n&&(r=n+4,h=n+10,tt(e,r,4)==="Exif"&&(l=e.getUint16(h),c=l===18761,(c||l===19789)&&e.getUint16(h+2,c)===42&&(o=e.getUint32(h+4,c),o>=8&&(a=h+o)))),a){for(s=e.getUint16(a,c),u=0;u<s;u++)if(p=a+u*12+2,e.getUint16(p,c)===274){p+=8,i=e.getUint16(p,c);break}}return i}const st=(t,e)=>{const s=t.__vccOpts||t;for(const[i,r]of e)s[i]=r;return s},it=U({data:function(){return{w:0,h:0,scale:1,x:0,y:0,loading:!0,trueWidth:0,trueHeight:0,move:!0,moveX:0,moveY:0,crop:!1,cropping:!1,cropW:0,cropH:0,cropOldW:0,cropOldH:0,canChangeX:!1,canChangeY:!1,changeCropTypeX:1,changeCropTypeY:1,cropX:0,cropY:0,cropChangeX:0,cropChangeY:0,cropOffsertX:0,cropOffsertY:0,support:"",touches:[],touchNow:!1,rotate:0,isIos:!1,orientation:0,imgs:"",coe:.2,scaling:!1,scalingSet:"",coeStatus:"",isCanShow:!0}},props:{img:{type:[String,Blob,null,File],default:""},outputSize:{type:Number,default:1},outputType:{type:String,default:"jpeg"},info:{type:Boolean,default:!0},canScale:{type:Boolean,default:!0},autoCrop:{type:Boolean,default:!1},autoCropWidth:{type:[Number,String],default:0},autoCropHeight:{type:[Number,String],default:0},fixed:{type:Boolean,default:!1},fixedNumber:{type:Array,default:()=>[1,1]},fixedBox:{type:Boolean,default:!1},full:{type:Boolean,default:!1},canMove:{type:Boolean,default:!0},canMoveBox:{type:Boolean,default:!0},original:{type:Boolean,default:!1},centerBox:{type:Boolean,default:!1},high:{type:Boolean,default:!0},infoTrue:{type:Boolean,default:!1},maxImgSize:{type:[Number,String],default:2e3},enlarge:{type:[Number,String],default:1},preW:{type:[Number,String],default:0},mode:{type:String,default:"contain"},limitMinSize:{type:[Number,Array,String],default:()=>10,validator:function(t){return Array.isArray(t)?Number(t[0])>=0&&Number(t[1])>=0:Number(t)>=0}},fillColor:{type:String,default:""}},computed:{cropInfo(){let t={};if(t.top=this.cropOffsertY>21?"-21px":"0px",t.width=this.cropW>0?this.cropW:0,t.height=this.cropH>0?this.cropH:0,this.infoTrue){let e=1;this.high&&!this.full&&(e=window.devicePixelRatio),this.enlarge!==1&!this.full&&(e=Math.abs(Number(this.enlarge))),t.width=t.width*e,t.height=t.height*e,this.full&&(t.width=t.width/this.scale,t.height=t.height/this.scale)}return t.width=t.width.toFixed(0),t.height=t.height.toFixed(0),t},isIE(){return!!window.ActiveXObject||"ActiveXObject"in window},passive(){return this.isIE?null:{passive:!1}}},watch:{img(){this.checkedImg()},imgs(t){t!==""&&this.reload()},cropW(){this.showPreview()},cropH(){this.showPreview()},cropOffsertX(){this.showPreview()},cr
|
||
|
<div class="show-preview" style="width: ${i.w}px; height: ${i.h}px,; overflow: hidden">
|
||
|
<div style="width: ${t}px; height: ${e}px">
|
||
|
<img src=${i.url} style="width: ${this.trueWidth}px; height: ${this.trueHeight}px; transform:
|
||
|
scale(${s})translate3d(${r}px, ${h}px, ${o}px)rotateZ(${this.rotate*90}deg)">
|
||
|
</div>
|
||
|
</div>`,this.$emit("real-time",i)},reload(){let t=new Image;t.onload=()=>{this.w=parseFloat(window.getComputedStyle(this.$refs.cropper).width),this.h=parseFloat(window.getComputedStyle(this.$refs.cropper).height),this.trueWidth=t.width,this.trueHeight=t.height,this.original?this.scale=1:this.scale=this.checkedMode(),this.$nextTick(()=>{this.x=-(this.trueWidth-this.trueWidth*this.scale)/2+(this.w-this.trueWidth*this.scale)/2,this.y=-(this.trueHeight-this.trueHeight*this.scale)/2+(this.h-this.trueHeight*this.scale)/2,this.loading=!1,this.autoCrop&&this.goAutoCrop(),this.$emit("img-load","success"),setTimeout(()=>{this.showPreview()},20)})},t.onerror=()=>{this.$emit("img-load","error")},t.src=this.imgs},checkedMode(){let t=1,e=this.trueWidth,s=this.trueHeight;const i=this.mode.split(" ");switch(i[0]){case"contain":this.trueWidth>this.w&&(t=this.w/this.trueWidth),this.trueHeight*t>this.h&&(t=this.h/this.trueHeight);break;case"cover":e=this.w,t=e/this.trueWidth,s=s*t,s<this.h&&(s=this.h,t=s/this.trueHeight);break;default:try{let r=i[0];if(r.search("px")!==-1){r=r.replace("px",""),e=parseFloat(r);const h=e/this.trueWidth;let o=1,c=i[1];c.search("px")!==-1&&(c=c.replace("px",""),s=parseFloat(c),o=s/this.trueHeight),t=Math.min(h,o)}if(r.search("%")!==-1&&(r=r.replace("%",""),e=parseFloat(r)/100*this.w,t=e/this.trueWidth),i.length===2&&r==="auto"){let h=i[1];h.search("px")!==-1&&(h=h.replace("px",""),s=parseFloat(h),t=s/this.trueHeight),h.search("%")!==-1&&(h=h.replace("%",""),s=parseFloat(h)/100*this.h,t=s/this.trueHeight)}}catch{t=1}}return t},goAutoCrop(t,e){if(this.imgs===""||this.imgs===null)return;this.clearCrop(),this.cropping=!0;let s=this.w,i=this.h;if(this.centerBox){const o=Math.abs(this.rotate)%2>0;let c=(o?this.trueHeight:this.trueWidth)*this.scale,l=(o?this.trueWidth:this.trueHeight)*this.scale;s=c<s?c:s,i=l<i?l:i}var r=t||parseFloat(this.autoCropWidth),h=e||parseFloat(this.autoCropHeight);(r===0||h===0)&&(r=s*.8,h=i*.8),r=r>s?s:r,h=h>i?i:h,this.fixed&&(h=r/this.fixedNumber[0]*this.fixedNumber[1]),h>this.h&&(h=this.h,r=h/this.fixedNumber[1]*this.fixedNumber[0]),this.changeCrop(r,h)},changeCrop(t,e){if(this.centerBox){let s=this.getImgAxis();t>s.x2-s.x1&&(t=s.x2-s.x1,e=t/this.fixedNumber[0]*this.fixedNumber[1]),e>s.y2-s.y1&&(e=s.y2-s.y1,t=e/this.fixedNumber[1]*this.fixedNumber[0])}this.cropW=t,this.cropH=e,this.checkCropLimitSize(),this.$nextTick(()=>{this.cropOffsertX=(this.w-this.cropW)/2,this.cropOffsertY=(this.h-this.cropH)/2,this.centerBox&&this.moveCrop(null,!0)})},refresh(){this.img,this.imgs="",this.scale=1,this.crop=!1,this.rotate=0,this.w=0,this.h=0,this.trueWidth=0,this.trueHeight=0,this.clearCrop(),this.$nextTick(()=>{this.checkedImg()})},rotateLeft(){this.rotate=this.rotate<=-3?0:this.rotate-1},rotateRight(){this.rotate=this.rotate>=3?0:this.rotate+1},rotateClear(){this.rotate=0},checkoutImgAxis(t,e,s){t=t||this.x,e=e||this.y,s=s||this.scale;let i=!0;if(this.centerBox){let r=this.getImgAxis(t,e,s),h=this.getCropAxis();r.x1>=h.x1&&(i=!1),r.x2<=h.x2&&(i=!1),r.y1>=h.y1&&(i=!1),r.y2<=h.y2&&(i=!1)}return i}},mounted(){this.support="onwheel"in document.createElement("div")?"wheel":document.onmousewheel!==void 0?"mousewheel":"DOMMouseScroll";let t=this;var e=navigator.userAgent;this.isIOS=!!e.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(s,i,r){for(var h=atob(this.toDataURL(i,r).split(",")[1]),o=h.length,c=new Uint8Array(o),l=0;l<o;l++)c[l]=h.charCodeAt(l);s(new Blob([c],{type:t.type||"image/png"}))}}),this.showPreview(),this.checkedImg()},unmounted(){window.removeEventListener("mousemove",this.moveCrop),window.removeEventListener("mouseup",this.leaveCrop),window.removeEventListener("touchmove",this.moveCrop),window.removeEventListener("touchend",this.leaveCrop),this.cancelScale()}}),rt={key:0,class:"cropper-box"},ot=["src"],ht={class:"cropper-view-box"},at=["src"],ct={key:1};function nt(t,e,s,i,r,h){return Y(),M("div",{class:"vue-cropper",ref:"cropper",onMouseover:e[28]||(e[28]=(...o)=>t.scaleImg&&t.s
|