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 @@ }; -