From 237ae1e61b5bea7b6ed8c6b078891e7b63a77c6f Mon Sep 17 00:00:00 2001 From: "Mr.jiang" <714156421@qq.com> Date: Mon, 19 Aug 2024 10:20:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F=E6=AF=94?= =?UTF-8?q?=E4=BE=8B4:5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 4 +-- my/renzheng/index.vue | 71 ++++++++++++++++++++++++++++++++++++++++++- pages/my/userinfo.vue | 60 ++++++++++++++++++++++++++++-------- 3 files changed, 120 insertions(+), 15 deletions(-) diff --git a/manifest.json b/manifest.json index 8397946..bf8fffc 100644 --- a/manifest.json +++ b/manifest.json @@ -2,8 +2,8 @@ "name" : "盛安到家", "appid" : "__UNI__B37C795", "description" : "", - "versionName" : "2.0.5", - "versionCode" : "100", + "versionName" : "2.1.0", + "versionCode" : 110, "transformPx" : false, /* 5+App特有相关 */ "app-plus" : { diff --git a/my/renzheng/index.vue b/my/renzheng/index.vue index e056d7f..62d7f32 100644 --- a/my/renzheng/index.vue +++ b/my/renzheng/index.vue @@ -125,7 +125,7 @@ --> - + @@ -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) { let that = this uni.chooseImage({ diff --git a/pages/my/userinfo.vue b/pages/my/userinfo.vue index 6c353d0..5a80645 100644 --- a/pages/my/userinfo.vue +++ b/pages/my/userinfo.vue @@ -183,6 +183,30 @@ 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() { let token = uni.getStorageSync('token') @@ -218,26 +242,38 @@ }); let token = uni.getStorageSync('token'); let userId = uni.getStorageSync('userId'); - uni.uploadFile({ - url: websocketUtils.uploadFileUrl(), //真实的接口地址 - - filePath: res.tempFilePaths[0], - header: { - token: token - }, - name: 'file', - success: uploadFileRes => { - url = JSON.parse(uploadFileRes.data); - that.avatar = url.data - uni.hideLoading(); + that.validateImageRatio(res.tempFilePaths[0],4 / 5).then((isValid) => { + if (isValid) { + // 图片小于等于2MB + uni.uploadFile({ + url: websocketUtils.uploadFileUrl(), //真实的接口地址 + filePath: res.tempFilePaths[0], + header: { + token: token + }, + name: 'file', + success: uploadFileRes => { + url = JSON.parse(uploadFileRes.data); + that.avatar = url.data + uni.hideLoading(); + } + }); + // 继续上传图片的逻辑... + } else { + uni.showToast({ + title: '图片比例不符合要求,请上传4:5的图片', + icon: 'none', + }); } }); + } }); } } }) }, + getUserInfo() { let userId = uni.getStorageSync('userId') this.$Request.get("/app/user/selectUserById").then(res => {