2 lines
20 KiB
JavaScript
2 lines
20 KiB
JavaScript
|
import{_ as t,av as s,aB as i,O as e,H as h,v as a,aC as l,p as o,B as n,G as r,x as c,aw as p,aD as d,aE as f,o as u,c as g,w as m,g as x,n as v,i as I,y as S,ax as w,k as y,j as H,D as W,u as b,s as k,z as T,q as _,U as D,t as R,h as C,d as P,e as O,F as U,r as M,N as z,a9 as Y,a8 as q,ae as A,A as B,aa as X,as as F}from"./index-22d2df30.js";const V=t({name:"yq-avatar",data:()=>({csH:"0px",sD:"none",sT:"-10000px",pT:"-10000px",iS:{},sS:{},sO:!0,bW:"19%",bD:"flex",tp:0,imgSrc:{imgSrc:""}}),watch:{avatarSrc(){this.imgSrc.imgSrc=this.avatarSrc}},computed:{inlineH:()=>0},props:{avatarSrc:"",avatarStyle:"",selWidth:"",selHeight:"",expWidth:"",expHeight:"",minScale:"",maxScale:"",canScale:"",canRotate:"",lockWidth:"",lockHeight:"",stretch:"",lock:"",fileType:"",noTab:"",inner:"",quality:"",index:"",bgImage:""},created(){this.cc=s("avatar-canvas",this),this.cco=s("oper-canvas",this),this.ccp=s("prv-canvas",this),this.qlty=parseFloat(this.quality)||1,this.imgSrc.imgSrc=this.avatarSrc,this.letRotate=!1===this.canRotate||!0===this.inner||"true"===this.inner||"false"===this.canRotate?0:1,this.letScale=!1===this.canScale||"false"===this.canScale?0:1,this.isin=!0===this.inner||"true"===this.inner?1:0,this.indx=this.index||void 0,this.mnScale=parseFloat(this.minScale)||.3,this.mxScale=parseFloat(this.maxScale)||4,this.noBar=!0===this.noTab||"true"===this.noTab?1:0,this.stc=this.stretch,this.lck=this.lock,this.fType="jpg"===this.fileType?"jpg":"png",this.isin||!this.letRotate?(this.bW="24%",this.bD="none"):(this.bW="19%",this.bD="flex"),this.noBar?this.fWindowResize():i({fail:()=>{this.noBar=1},success:()=>{this.noBar=0},complete:t=>{this.fWindowResize()}})},methods:{fWindowResize(){let t=e();this.platform=t.platform,this.wW=t.windowWidth,this.drawTop=t.windowTop,this.wH=t.windowHeight,this.noBar||(this.wH+=50),this.csH=this.wH-50-this.inlineH+"px",this.tp=this.csH,this.tp=t.windowTop+parseInt(this.csH)+"px",this.pxRatio=this.wW/750;let s=this.avatarStyle;if(s&&!0!==s&&(s=s.trim())){s=s.split(";");let t={};for(let i of s)if(i){if(i=i.trim().split(":"),i[1].toString().indexOf("upx")>=0){let t=i[1].trim().split(" ");for(let s in t)t[s]&&t[s].toString().indexOf("upx")>=0&&(t[s]=parseFloat(t[s])*this.pxRatio+"px");i[1]=t.join(" ")}t[i[0].trim()]=i[1].trim()}this.iS=t}this.expWidth&&(this.eW=this.expWidth.toString().indexOf("upx")>=0?parseInt(this.expWidth)*this.pxRatio:parseInt(this.expWidth)),this.expHeight&&(this.eH=this.expHeight.toString().indexOf("upx")>=0?parseInt(this.expHeight)*this.pxRatio:parseInt(this.expHeight)),"flex"===this.sD&&this.fDrawInit(!0),this.fHideImg()},fSelect(){this.fSelecting||(this.fSelecting=!0,setTimeout((()=>{this.fSelecting=!1}),500),h({count:1,sizeType:["original","compressed"],sourceType:["album","camera"],success:t=>{a({title:"加载中...",mask:!0});let s=this.imgPath=t.tempFilePaths[0];l({src:s,success:t=>{if(this.imgWidth=t.width,this.imgHeight=t.height,this.path=s,!this.hasSel){let t=this.sS||{};if(!this.selWidth||!this.selHeight)return void o({title:"裁剪框的宽或高没有设置",showCancel:!1});{let s=this.selWidth.toString().indexOf("upx")>=0?parseInt(this.selWidth)*this.pxRatio:parseInt(this.selWidth),i=this.selHeight.toString().indexOf("upx")>=0?parseInt(this.selHeight)*this.pxRatio:parseInt(this.selHeight);t.width=s+"px",t.height=i+"px",t.top=(this.wH-i-50|0)/2+"px",t.left=(this.wW-s|0)/2+"px"}this.sS=t}this.noBar?this.fDrawInit(!0):n({complete:()=>{this.fDrawInit(!0)}})},fail:()=>{r({title:"请选择正确图片",duration:2e3})},complete(){c()}})}}))},fUpload(){if(this.fUploading)return;this.fUploading=!0,setTimeout((()=>{this.fUploading=!1}),1e3);let t=this.sS,s=parseInt(t.left),e=parseInt(t.top),h=parseInt(t.width),l=parseInt(t.height),o=this.eW||h*this.pixelRatio,n=this.eH||l*this.pixelRatio;a({title:"加载中...",mask:!0}),this.sD="none",this.sT="-10000px",this.hasSel=!1,this.fHideImg(),p({x:s,y:e,width:h,height:l,destWidth:o,destHeight:n,canvasId:"avatar-canvas",fileType:this.fType,quality:this.qlty,success:t=>{t=t.tempFilePath,this.btop(t).then((t=>{this.$emit("upload",{avatar:th
|