|
- (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["components/xiaogang-crop/index"],{311:function(t,i,e){"use strict";e.r(i);var o=e(312),r=e(314);for(var c in r)["default"].indexOf(c)<0&&function(t){e.d(i,t,(function(){return r[t]}))}(c);e(316);var n,h=e(32),s=Object(h["default"])(r["default"],o["render"],o["staticRenderFns"],!1,null,"b6fe683a",null,!1,o["components"],n);s.options.__file="components/xiaogang-crop/index.vue",i["default"]=s.exports},312:function(t,i,e){"use strict";e.r(i);var o=e(313);e.d(i,"render",(function(){return o["render"]})),e.d(i,"staticRenderFns",(function(){return o["staticRenderFns"]})),e.d(i,"recyclableRender",(function(){return o["recyclableRender"]})),e.d(i,"components",(function(){return o["components"]}))},313:function(t,i,e){"use strict";var o;e.r(i),e.d(i,"render",(function(){return r})),e.d(i,"staticRenderFns",(function(){return n})),e.d(i,"recyclableRender",(function(){return c})),e.d(i,"components",(function(){return o}));var r=function(){var t=this,i=t.$createElement;t._self._c},c=!1,n=[];r._withStripped=!0},314:function(t,i,e){"use strict";e.r(i);var o=e(315),r=e.n(o);for(var c in o)["default"].indexOf(c)<0&&function(t){e.d(i,t,(function(){return o[t]}))}(c);i["default"]=r.a},315:function(t,i,e){"use strict";(function(t,o){var r=e(4);Object.defineProperty(i,"__esModule",{value:!0}),i.default=void 0;var c,n,h,s,a,p,d,u,g,f,l=r(e(56)),x=r(e(58)),B={name:"imageCropping",props:{src:{type:String},ratioGroup:{type:Array,default:function(){return[]}},isFixedSize:{type:Boolean,default:!1},cropShape:{type:String,default:"circular"}},data:function(){return{imageBoxWidth:0,imageBoxHeight:0,cropBoxX:0,cropBoxY:0,cropBoxWidth:0,cropBoxHeight:0,mode:"",cropSize:100,cropImgPath:""}},mounted:function(){this.getImageInfo()},methods:{getImageInfo:function(){var i=this;f=t.getWindowInfo(),this.src&&t.getImageInfo({src:this.src,success:function(t){console.log("图片尺寸信息",t),d=t.width,u=t.height;var e=d/f.windowWidth,o=u/f.windowHeight;g=e>o?e:o,i.imageBoxWidth=d/g,i.imageBoxHeight=u/g,i.setRatio("1:1")},fail:function(t){console.log("error",t)}})},touchstart:function(t){c=t.touches[0].clientX,n=t.touches[0].clientY,"handle"==t.target.dataset.body?(this.mode="zoom",a=this.cropBoxWidth,p=this.cropBoxHeight):(this.mode="move",h=this.cropBoxX,s=this.cropBoxY)},touchmove:function(t){var i=t.touches[0].clientX-c,e=t.touches[0].clientY-n,o=h+i,r=s+e,d=a+i,u=p+e,g=this.imageBoxWidth-this.cropBoxWidth,f=this.imageBoxHeight-this.cropBoxHeight,l=this.imageBoxWidth-this.cropBoxX,x=this.imageBoxHeight-this.cropBoxY;switch(this.mode){case"move":this.cropBoxX=o<0?0:o>g?g:o,this.cropBoxY=r<0?0:r>f?f:r;break;case"zoom":"rect"==this.cropShape?(this.cropBoxWidth=d>l?l:d,this.cropBoxHeight=u>x?x:u):(this.cropBoxHeight=u>x?x:u,this.cropBoxWidth=u>x?x:u);break}},setRatio:function(t){if("full"==t)this.cropBoxWidth=this.imageBoxWidth,this.cropBoxHeight=this.imageBoxHeight,this.cropBoxX=0,this.cropBoxY=0;else{var i=t.split(":")[0],e=t.split(":")[1],o=i/e,r=e/i;if(this.imageBoxWidth<this.imageBoxHeight){console.log("盒子宽度小于盒子高度");var c=this.imageBoxWidth;c/o>this.imageBoxHeight?(c=this.imageBoxHeight,this.cropBoxWidth=c/r-this.cropSize,this.cropBoxHeight=c-this.cropSize,this.cropBoxX=this.cropSize/2,this.cropBoxY=(this.imageBoxWidth-this.imageBoxWidth)/2):(this.cropBoxWidth=c-this.cropSize,this.cropBoxHeight=c/o-this.cropSize,this.cropBoxX=this.cropSize/2,this.cropBoxY=(this.imageBoxHeight-this.cropBoxHeight)/2)}else{var n=this.imageBoxHeight;n/o>this.imageBoxWidth?(n=this.imageBoxWidth,this.cropBoxWidth=n-this.cropSize,this.cropBoxHeight=n/r-this.cropSize,this.cropBoxX=(this.imageBoxWidth-this.cropBoxWidth)/2,this.cropBoxY=(this.imageBoxHeight-this.cropBoxHeight)/2):(this.cropBoxWidth=n/o-this.cropSize,this.cropBoxHeight=n-this.cropSize,this.cropBoxX=(this.imageBoxWidth-this.cropBoxWidth)/2,this.cropBoxY=(this.imageBoxWidth-this.cropBoxWidth)/2)}}},cropping:function(){var i=this;return(0,x.default)(l.default.mark((function e(){var r,c,n,h,s,a,p,d,u,f;return l.default.wrap((function(e){while(1)switch(e.prev=e.next){case 0:return r=i.cropBoxX*g,c=i.cropBoxY*g,n=i.cropBoxWidth*g,h=i.cropBoxHeight*g,s=t.createOffscreenCanvas({type:"2d",width:n,height:h}),a=s.getContext("2d"),a.fillStyle="#fff",a.globalCompositeOperation="source-over",p=s.createImage(),e.next=11,new Promise((function(t,e){p.onload=t,p.onerror=e,p.src=i.src,p.backgroundColor="red"}));case 11:a.clearRect(0,0,n,h),"circular"==i.cropShape&&(a.beginPath(),a.arc(n/2,h/2,n/2,0,2*Math.PI),a.fill(),a.clip(),a.clip()),a.drawImage(p,r,c,n,h,0,0,n,h),d=s.toDataURL(),u=o.getFileSystemManager(),f="".concat(o.env.USER_DATA_PATH,"/")+(new Date).getTime()+".png",u.writeFile({filePath:f,data:d.replace("data:image/png;base64,",""),encoding:"base64",success:function(t){i.$emit("completed",{tempFilePath:f}),i.cropImgPath=f},fail:function(t){console.error(t)}});case 18:case"end":return e.stop()}}),e)})))()},yuantu:function(){this.$emit("completed",{tempFilePath:this.src})},cancel:function(){this.$emit("cancel")}}};i.default=B}).call(this,e(2)["default"],e(1)["default"])},316:function(t,i,e){"use strict";e.r(i);var o=e(317),r=e.n(o);for(var c in o)["default"].indexOf(c)<0&&function(t){e.d(i,t,(function(){return o[t]}))}(c);i["default"]=r.a},317:function(t,i,e){}}]);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/components/xiaogang-crop/index.js.map
- ;(global["webpackJsonp"] = global["webpackJsonp"] || []).push([
- 'components/xiaogang-crop/index-create-component',
- {
- 'components/xiaogang-crop/index-create-component':(function(module, exports, __webpack_require__){
- __webpack_require__('2')['createComponent'](__webpack_require__(311))
- })
- },
- [['components/xiaogang-crop/index-create-component']]
- ]);
|