app头像上传vue_mui+vue+photoclip做APP头像裁剪上传

本文介绍了如何使用Vue.js和mui库结合PhotoClip组件来实现APP中的头像上传和裁剪功能。通过拍照或从相册选择图片,然后进行裁剪,最终将裁剪后的图片以base64格式提交给后台处理。
摘要由CSDN通过智能技术生成

changeFace:function(){this.selectFace = true;this.mask = mui.createMask((res)=>{this.selectFace = false;

});this.mask.show();

},//拍照

takingPictures:function(){this.selectFace = false;this.mask.close();//拍照

var c =plus.camera.getCamera();

c.captureImage((e)=>{

plus.io.resolveLocalFileSystemURL(e,(entry)=>{var path = entry.toLocalURL() + "?version=" + newDate().getTime();

console.log(path);this.cutOutPictures(path);//alert(imgPath);

},(e)=>{

console.log("读取拍照片文件错误:" +e.message);

});

},(s)=>{

console.log("error:"+s);

},{

filename:"_doc/head.png"});//this.cutOutPictures();

//console.log('takingPictures');

},//从相册中选择

selectFromalbum:function(){this.selectFace = false;this.mask.close();//从相册中选择图片

console.log("从相册中选择图片");

plus.gallery.pick((path)=>{

console.log(path);this.cutOutPictures(path);

},(e)=>{

console.log("取消选择图片");

},{filter:"image"});//console.log('selectFromalbum');

},//裁剪图片

cutOutPictures:function(imgSrc){var that = this;

that.showSelectFace= true;var saveImg = (imgPath)=>{

imgPath= imgPath.replace("data:image/jpeg;base64,", "");this.data ={avatar:imgPath};this.data = config.getParam(this.data);

mui.post(config.userProfileUpdate,this.data,(res)=>{if(res.code == 200){

config.userInfo.avatar=res.data.avatar;

config.setStorage('userInfo',JSON.stringify(config.userInfo));

mui.toast("头像修改成功");

}else{

mui.toast(res.msg);

};

});

};var clipArea = new PhotoClip("#clipArea", {

size: [300, 300],//裁剪框大小

outputSize:[0,0],//打开图片大小,[0,0]表示原图大小

file: "#file",

ok:"#clipBtn",//img: "http://127.0.0.1/ff.jpg",

//img:'http://m3.biz.itc.cn/pic/new/n/50/14/Img5431450_n.jpg',

//img:"file:///F:/MuiProject/domo6/images/music0.jpg",

//img: "../images/music0.jpg",

//img: "../images/huiyuan_03.jpg?version=124545487878",

img:imgSrc,//图片开始加载的回调函数。this 指向当前 PhotoClip 的实例对象,并将正在加载的 file 对象作为参数传入。(如果是使用非 file 的方式加载图片,则该参数为图片的 url)

loadStart: function(){

$(".loading").removeClass("displaynone");

},//图片加载完成的回调函数。this 指向当前 PhotoClip 的实例对象,并将图片的 对象作为参数传入。

loadComplete: function() {

$(".loading").addClass("displaynone");

},//裁剪完成的回调函数。this 指向当前 PhotoClip 实例对象,会将裁剪出的图像数据DataURL作为参数传入。

done: function(dataURL){

that.showSelectFace= false;

saveImg(dataURL);//console.log(dataURL);//dataURL裁剪后图片地址base64格式提交给后台处理

$(".clipbg").hide()

}

});

$("#cancelBtn").on('tap',()=>{

that.showSelectFace= false;

$(".clipbg").hide();

});//this.showSelectFace = true;

//var clipArea = new PhotoClip("#clipArea", {

//size: [300, 300],//裁剪框大小

//outputSize:[0,0],//打开图片大小,[0,0]表示原图大小

//file: "#file",

//ok: "#clipBtn",

img: "http://127.0.0.1/ff.jpg",

img:'http://m3.biz.itc.cn/pic/new/n/50/14/Img5431450_n.jpg',

img:"file:///F:/MuiProject/domo6/images/music0.jpg",

//img: "../images/music0.jpg",

//loadStart: function() { //图片开始加载的回调函数。this 指向当前 PhotoClip 的实例对象,并将正在加载的 file 对象作为参数传入。(如果是使用非 file 的方式加载图片,则该参数为图片的 url)

//$(".loading").removeClass("displaynone");

//},

//loadComplete: function() {//图片加载完成的回调函数。this 指向当前 PhotoClip 的实例对象,并将图片的 对象作为参数传入。

//$(".loading").addClass("displaynone");

//},

//done: function(dataURL) { //裁剪完成的回调函数。this 指向当前 PhotoClip 的实例对象,会将裁剪出的图像数据DataURL作为参数传入。

//console.log(dataURL);//dataURL裁剪后图片地址base64格式提交给后台处理

//$(".clipbg").hide()

//}

//});

},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值