上传头像比例4:5
This commit is contained in:
parent
88c80be724
commit
237ae1e61b
|
@ -2,8 +2,8 @@
|
||||||
"name" : "盛安到家",
|
"name" : "盛安到家",
|
||||||
"appid" : "__UNI__B37C795",
|
"appid" : "__UNI__B37C795",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "2.0.5",
|
"versionName" : "2.1.0",
|
||||||
"versionCode" : "100",
|
"versionCode" : 110,
|
||||||
"transformPx" : false,
|
"transformPx" : false,
|
||||||
/* 5+App特有相关 */
|
/* 5+App特有相关 */
|
||||||
"app-plus" : {
|
"app-plus" : {
|
||||||
|
|
|
@ -125,7 +125,7 @@
|
||||||
</view> -->
|
</view> -->
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="margin-top" @click="addImage(4)" v-if="form.headImg.length<=0">
|
<view class="margin-top" @click="addImagea(4)" v-if="form.headImg.length<=0">
|
||||||
<view style="width: 200rpx;height: 200rpx;background: #f7f8fa;"
|
<view style="width: 200rpx;height: 200rpx;background: #f7f8fa;"
|
||||||
class="flex justify-center align-center">
|
class="flex justify-center align-center">
|
||||||
<view>
|
<view>
|
||||||
|
@ -781,6 +781,75 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
validateImageRatio(imagePath, targetRatio) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.getImageInfo({
|
||||||
|
src: imagePath,
|
||||||
|
success: (info) => {
|
||||||
|
const size = info.size;
|
||||||
|
if (size / 1024 / 1024 > 4) {
|
||||||
|
// 图片大于2MB
|
||||||
|
uni.showToast({
|
||||||
|
icon:'error',
|
||||||
|
title:'图片超出2MB限制,请重新选择'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const { width, height } = info;
|
||||||
|
const actualRatio = width / height;
|
||||||
|
const isValid = Math.abs(actualRatio - targetRatio) < Number.EPSILON;
|
||||||
|
resolve(isValid);
|
||||||
|
console.log("asdasdasd")
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
fail: () => reject(false),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
//上传头像
|
||||||
|
addImagea(e) {
|
||||||
|
let that = this
|
||||||
|
uni.chooseImage({
|
||||||
|
count: 1,
|
||||||
|
sourceType: ['album', 'camera'],
|
||||||
|
success: res => {
|
||||||
|
for (let i = 0; i < res.tempFilePaths.length; i++) {
|
||||||
|
that.$queue.showLoading("上传中...");
|
||||||
|
this.validateImageRatio(res.tempFilePaths[i], 4 / 5).then((isValid) => {
|
||||||
|
if (isValid) {
|
||||||
|
// 图片小于等于2MB
|
||||||
|
uni.uploadFile({ // 上传接口
|
||||||
|
url: websocketUtils.uploadFileUrl(), //真实的接口地址
|
||||||
|
filePath: res.tempFilePaths[i],
|
||||||
|
name: 'file',
|
||||||
|
success: (uploadFileRes) => {
|
||||||
|
if (e == 1) {
|
||||||
|
that.form.front = JSON.parse(uploadFileRes.data).data
|
||||||
|
} else if (e == 2) {
|
||||||
|
that.form.back = JSON.parse(uploadFileRes.data).data
|
||||||
|
} else if (e == 4) {
|
||||||
|
that.form.headImg = JSON.parse(uploadFileRes.data).data
|
||||||
|
console.log(that.form.headImg)
|
||||||
|
}
|
||||||
|
uni.hideLoading();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 继续上传图片的逻辑...
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '图片比例不符合要求,请上传4:5的图片',
|
||||||
|
icon: 'none',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
addImage(e) {
|
addImage(e) {
|
||||||
let that = this
|
let that = this
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
|
|
|
@ -183,6 +183,30 @@
|
||||||
url: '../jifen/myaddress'
|
url: '../jifen/myaddress'
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
validateImageRatio(imagePath, targetRatio) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.getImageInfo({
|
||||||
|
src: imagePath,
|
||||||
|
success: (info) => {
|
||||||
|
const size = info.size;
|
||||||
|
if (size / 1024 / 1024 > 4) {
|
||||||
|
// 图片大于2MB
|
||||||
|
uni.showToast({
|
||||||
|
icon:'error',
|
||||||
|
title:'图片超出2MB限制,请重新选择'
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const { width, height } = info;
|
||||||
|
const actualRatio = width / height;
|
||||||
|
const isValid = Math.abs(actualRatio - targetRatio) < Number.EPSILON;
|
||||||
|
resolve(isValid);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
fail: () => reject(false),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
uploadImg() {
|
uploadImg() {
|
||||||
let token = uni.getStorageSync('token')
|
let token = uni.getStorageSync('token')
|
||||||
|
|
||||||
|
@ -218,26 +242,38 @@
|
||||||
});
|
});
|
||||||
let token = uni.getStorageSync('token');
|
let token = uni.getStorageSync('token');
|
||||||
let userId = uni.getStorageSync('userId');
|
let userId = uni.getStorageSync('userId');
|
||||||
uni.uploadFile({
|
that.validateImageRatio(res.tempFilePaths[0],4 / 5).then((isValid) => {
|
||||||
url: websocketUtils.uploadFileUrl(), //真实的接口地址
|
if (isValid) {
|
||||||
|
// 图片小于等于2MB
|
||||||
filePath: res.tempFilePaths[0],
|
uni.uploadFile({
|
||||||
header: {
|
url: websocketUtils.uploadFileUrl(), //真实的接口地址
|
||||||
token: token
|
filePath: res.tempFilePaths[0],
|
||||||
},
|
header: {
|
||||||
name: 'file',
|
token: token
|
||||||
success: uploadFileRes => {
|
},
|
||||||
url = JSON.parse(uploadFileRes.data);
|
name: 'file',
|
||||||
that.avatar = url.data
|
success: uploadFileRes => {
|
||||||
uni.hideLoading();
|
url = JSON.parse(uploadFileRes.data);
|
||||||
|
that.avatar = url.data
|
||||||
|
uni.hideLoading();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// 继续上传图片的逻辑...
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '图片比例不符合要求,请上传4:5的图片',
|
||||||
|
icon: 'none',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getUserInfo() {
|
getUserInfo() {
|
||||||
let userId = uni.getStorageSync('userId')
|
let userId = uni.getStorageSync('userId')
|
||||||
this.$Request.get("/app/user/selectUserById").then(res => {
|
this.$Request.get("/app/user/selectUserById").then(res => {
|
||||||
|
|
Loading…
Reference in New Issue