From 30526b4694e8b8123664c105687715e3edc8bf42 Mon Sep 17 00:00:00 2001 From: "Mr.jiang" <714156421@qq.com> Date: Mon, 19 Aug 2024 14:42:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E5=90=8E=E5=85=B3=E9=97=AD=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/my/userinfo.vue | 139 ++++++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 52 deletions(-) diff --git a/pages/my/userinfo.vue b/pages/my/userinfo.vue index 26f6f13..e25974f 100644 --- a/pages/my/userinfo.vue +++ b/pages/my/userinfo.vue @@ -14,7 +14,7 @@ - + @@ -76,6 +76,24 @@ 保存 + + + + + + + 查看头像 + + + 从相册选择图片 + + + + 取消 + + + + @@ -101,7 +119,8 @@ zhiFuBaoName: '', sex: 1, age: 0, - url:'' + url:'', + upUrl:'' }; }, onLoad(e) { @@ -199,7 +218,7 @@ let userId = uni.getStorageSync('userId'); uni.uploadFile({ url: websocketUtils.uploadFileUrl(), //真实的接口地址 - filePath:that.url, + filePath:that.upUrl, header: { token: token }, @@ -207,6 +226,7 @@ success: uploadFileRes => { url = JSON.parse(uploadFileRes.data); // that.avatar = url.data + that.$refs.popup.close('bottom') uni.hideLoading(); } }); @@ -216,62 +236,56 @@ // url设置为空,隐藏控件 this.url = ""; }, - uploadImg() { + quxiao(){ + this.$refs.popup.close('bottom') + }, + toggle(type) { + this.$refs.popup.open('bottom') + }, + uploadImg(index) { let token = uni.getStorageSync('token') - if (!token) { this.goLoginInfo(); return; } let that = this; var url = null; - uni.showActionSheet({ - // itemList按钮的文字接受的是数组 - itemList: ["查看头像", "从相册选择图片"], - success(e) { - var index = e.tapIndex - if (index === 0) { - // 用户点击了预览当前图片 - // 可以自己实现当前头像链接的读取 - let url = that.avatar; - let arr = [] - arr.push(url) - uni.previewImage({ - // 预览功能图片也必须是数组的 - urls: arr - }) - } else if (index === 1) { - uni.chooseImage({ - count: 1, //默认9 - sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 - sourceType: ['album'], //从相册选择 - success: function(res) { - uni.getImageInfo({ - src: res.tempFilePaths[0], - success: (info) => { - const size = info.size; - if (size / 1024 / 1024 > 4) { - // 图片大于2MB - uni.showToast({ - icon:'error', - title:'图片超出4MB限制,请重新选择' - }) - } else { - that.url = res.tempFilePaths[0]; - } - - } - }); - - - - } + if (index === 0) { + // 用户点击了预览当前图片 + // 可以自己实现当前头像链接的读取 + let url = that.avatar; + let arr = [] + arr.push(url) + uni.previewImage({ + // 预览功能图片也必须是数组的 + urls: arr + }) + } else if (index === 1) { + uni.chooseImage({ + count: 1, //默认9 + sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有 + sourceType: ['album'], //从相册选择 + success: function(res) { + uni.getImageInfo({ + src: res.tempFilePaths[0], + success: (info) => { + const size = info.size; + if (size / 1024 / 1024 > 4) { + // 图片大于2MB + uni.showToast({ + icon:'error', + title:'图片超出4MB限制,请重新选择' + }) + } else { + that.url = res.tempFilePaths[0]; + that.upUrl=res.tempFilePaths[0]; + } + + } }); } - }, fail: function (err) { - console.log('showActionSheet失败', err); - } - }) + }); + } }, getUserInfo() { @@ -356,7 +370,28 @@ }; -