|
|
@ -8,21 +8,34 @@ Page({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
touchStart(e) {
|
|
|
|
touchStart(e) {
|
|
|
|
if(!this.mycropper)
|
|
|
|
|
|
|
|
return wx.showToast({
|
|
|
|
|
|
|
|
title: '请先选取图片',icon:"none"
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
this.mycropper.touchStart(e)
|
|
|
|
this.mycropper.touchStart(e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
touchMove(e) {
|
|
|
|
touchMove(e) {
|
|
|
|
this.mycropper.touchMove(e)
|
|
|
|
this.mycropper.touchMove(e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
touchEnd(e) {
|
|
|
|
touchEnd(e) {
|
|
|
|
this.mycropper.touchEnd(e)
|
|
|
|
this.mycropper.touchEnd(e)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
onGetUserInfo(e){
|
|
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
|
|
let {detail:{userInfo}} = e;
|
|
|
|
|
|
|
|
if(userInfo.avatarUrl){
|
|
|
|
|
|
|
|
let path = userInfo.avatarUrl;
|
|
|
|
|
|
|
|
this.mycropper.pushOrign(path);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
wx.showToast({
|
|
|
|
|
|
|
|
title: '微信头像获取失败',icon:"none"
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
async _checkImg({path}){
|
|
|
|
async _checkImg({path}){
|
|
|
|
let cloudPath = "images/avatars/"+ path.replace(/[\/\\:]/g, "_");
|
|
|
|
let match = path.match(/(\.[^\.]*?)$/)
|
|
|
|
|
|
|
|
if(match)
|
|
|
|
|
|
|
|
var ext = match[0];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
var ext = ".jpg";
|
|
|
|
|
|
|
|
let cloudPath = "images/temp/"+ app.globalData.openid + "-" + Date.now() + ext;
|
|
|
|
let res = await wx.cloud.uploadFile({
|
|
|
|
let res = await wx.cloud.uploadFile({
|
|
|
|
cloudPath,
|
|
|
|
cloudPath,
|
|
|
|
filePath: path
|
|
|
|
filePath: path
|
|
|
@ -33,7 +46,6 @@ Page({
|
|
|
|
checkImg({path}){
|
|
|
|
checkImg({path}){
|
|
|
|
if(this.promise&&path==this.tmp_path)
|
|
|
|
if(this.promise&&path==this.tmp_path)
|
|
|
|
return this.promise;
|
|
|
|
return this.promise;
|
|
|
|
let buffer = wx.getFileSystemManager().readFileSync(path);
|
|
|
|
|
|
|
|
this.promise = this._checkImg({path});
|
|
|
|
this.promise = this._checkImg({path});
|
|
|
|
this.tmp_path = path;
|
|
|
|
this.tmp_path = path;
|
|
|
|
this.promise.then(res=>{
|
|
|
|
this.promise.then(res=>{
|
|
|
@ -47,35 +59,49 @@ Page({
|
|
|
|
return this.promise;
|
|
|
|
return this.promise;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onConfirm(){
|
|
|
|
onConfirm(){
|
|
|
|
|
|
|
|
this.setData({submitting:1});
|
|
|
|
if(!this.mycropper||!this.mycropper.src)
|
|
|
|
if(!this.mycropper||!this.mycropper.src)
|
|
|
|
return wx.showToast({
|
|
|
|
return wx.showToast({
|
|
|
|
title: '请先选取图片',icon:"none"
|
|
|
|
title: '请先选取图片',icon:"none"
|
|
|
|
})
|
|
|
|
})
|
|
|
|
let {src} = this.mycropper;
|
|
|
|
let {croperTarget} = this.mycropper;
|
|
|
|
wx.showLoading({
|
|
|
|
wx.showLoading({
|
|
|
|
title: '检查图片中...',
|
|
|
|
title: '检查图片中...',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.checkImg({path: src}).then(res=>{
|
|
|
|
this.checkImg({path: croperTarget}).then(res=>{
|
|
|
|
if(res.errCode==0)
|
|
|
|
if(res.errCode==0)
|
|
|
|
this.startUpload();
|
|
|
|
this.startUpload();
|
|
|
|
else if(res.errCode==87014){
|
|
|
|
else if(res.errCode==87014){
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.showModal({
|
|
|
|
wx.showModal({
|
|
|
|
content:rich_message,showCancel: false
|
|
|
|
content:rich_message,showCancel: false
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
wx.showToast({
|
|
|
|
wx.showToast({
|
|
|
|
title: '发生了未知错误',icon:"none"
|
|
|
|
title: '发生了未知错误,请重试',icon:"none"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.promise = null;
|
|
|
|
|
|
|
|
let {croperTarget} = this.mycropper;
|
|
|
|
|
|
|
|
this.checkImg({path:croperTarget});
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
|
|
|
|
|
|
|
|
wx.reportMonitor('2', 1);
|
|
|
|
wx.reportMonitor('2', 1);
|
|
|
|
global.realTimeLog.error("未知错误 checkImg1");
|
|
|
|
global.realTimeLog.error("未知错误 checkImg1", res);
|
|
|
|
global.realTimeLog.setFilterMsg("unexpected");
|
|
|
|
global.realTimeLog.setFilterMsg("unexpected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).catch(e=>{
|
|
|
|
}).catch(e=>{
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
|
app.showError(e);
|
|
|
|
wx.showToast({
|
|
|
|
|
|
|
|
title: '请求超时,请重试',icon:"none"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.promise = null;
|
|
|
|
|
|
|
|
let {croperTarget} = this.mycropper;
|
|
|
|
|
|
|
|
this.checkImg({path:croperTarget});
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
|
|
|
|
|
|
|
|
wx.reportMonitor('2', 1);
|
|
|
|
wx.reportMonitor('2', 1);
|
|
|
|
global.realTimeLog.error("未知错误 checkImg2");
|
|
|
|
global.realTimeLog.error("未知错误 checkImg2", e);
|
|
|
|
global.realTimeLog.setFilterMsg("unexpected");
|
|
|
|
global.realTimeLog.setFilterMsg("unexpected");
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -93,10 +119,11 @@ Page({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
startUpload() {
|
|
|
|
startUpload() {
|
|
|
|
|
|
|
|
this.setData({submitting:1});
|
|
|
|
this.mycropper.getCropperImage((avatar) => {
|
|
|
|
this.mycropper.getCropperImage((avatar) => {
|
|
|
|
if (avatar) {
|
|
|
|
if (avatar) {
|
|
|
|
wx.showLoading({
|
|
|
|
wx.showLoading({
|
|
|
|
title: '上传中',
|
|
|
|
title: '上传头像中',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.uploadAvartar(avatar)
|
|
|
|
this.uploadAvartar(avatar)
|
|
|
|
.then(res => {
|
|
|
|
.then(res => {
|
|
|
@ -104,6 +131,7 @@ Page({
|
|
|
|
wx.showToast({
|
|
|
|
wx.showToast({
|
|
|
|
title: '更改成功',
|
|
|
|
title: '更改成功',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
setTimeout(()=>{
|
|
|
|
setTimeout(()=>{
|
|
|
|
wx.navigateBack({
|
|
|
|
wx.navigateBack({
|
|
|
|
delta: 1
|
|
|
|
delta: 1
|
|
|
@ -115,12 +143,14 @@ Page({
|
|
|
|
icon: "none"
|
|
|
|
icon: "none"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
wx.showToast({
|
|
|
|
wx.showToast({
|
|
|
|
title: '图片截取失败',
|
|
|
|
title: '图片截取失败',
|
|
|
|
icon: "none"
|
|
|
|
icon: "none"
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setData({submitting:0});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -165,11 +195,11 @@ Page({
|
|
|
|
this.mycropper = new WeCropper(cropperOpt);
|
|
|
|
this.mycropper = new WeCropper(cropperOpt);
|
|
|
|
this.mycropper
|
|
|
|
this.mycropper
|
|
|
|
.on('beforeImageLoad', (ctx) => {
|
|
|
|
.on('beforeImageLoad', (ctx) => {
|
|
|
|
wx.showLoading({title: '上传中'})
|
|
|
|
wx.showLoading({title: '图片加载中'})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.on('imageLoad', (ctx) => {
|
|
|
|
.on('imageLoad', (ctx) => {
|
|
|
|
let {src} = this.mycropper;
|
|
|
|
let {croperTarget} = this.mycropper;
|
|
|
|
this.checkImg({path:src});
|
|
|
|
this.checkImg({path:croperTarget});
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.updateCanvas();
|
|
|
|
.updateCanvas();
|
|
|
|