From e710fab2f602fc66b89a409f7c1ed09323d5ed84 Mon Sep 17 00:00:00 2001 From: kuaileWu <1432334894@qq.com> Date: Mon, 6 May 2024 17:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3=E8=81=94=E8=B0=83=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/user_modify/user_modify.vue | 75 +++++++++++++++++++++------------------ pages/usercenter/usercenter.vue | 5 ++- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/pages/user_modify/user_modify.vue b/pages/user_modify/user_modify.vue index 268902a..5ecf4f0 100644 --- a/pages/user_modify/user_modify.vue +++ b/pages/user_modify/user_modify.vue @@ -5,8 +5,8 @@ 头像 - - + + 点击上传照片 @@ -39,7 +39,8 @@ cssUrl:this.cssUrl, avator:this.cssUrl+'default_avator.svg', uinfo:{}, - nick:'' + nick:'', + tempFilePaths:'', } }, onLoad() { @@ -47,19 +48,45 @@ }, methods: { getUser(){ - this.$http.req('client/user/info', {}, 'POST').then(data=>{ + this.$http.req('get_userinfo', {}, 'GET').then(data=>{ if(data == -1) return this.uinfo = data - this.nick = this.uinfo.nickname + this.nick = this.uinfo.nick }); }, save(){ var param = new Object() - param.name = this.nick - this.$http.req('client/user/info', param, 'PUT').then(data=>{ - if(data == -1) return - this.$pop.modelShow('保存成功') - }) + param.nick = this.nick + var that = this + var token = uni.getStorageSync('token') + console.log(that.tempFilePaths) + uni.uploadFile({ + url: '/api/user/setting_user/', + filePath: that.tempFilePaths, + name: that.tempFilePaths ? 'avator':'empty', + header: { + 'Authorization': token + }, + formData:{nick:param.nick}, + success: function(res){ + try{ + var data = JSON.parse(res.data) + if(data.code != 0){ + that.$pop.modelShow(data.msg) + return + } + uni.showToast({ + title:data.msg + }) + if(that.tempFilePaths) that.uinfo.avator = that.tempFilePaths + }catch(e){ + that.$pop.modelShow('保存失败~'+e.message) + } + }, + fail: function(res){ + that.$pop.modelShow('保存失败') + } + }); }, copyUid(uid) { var that = this @@ -71,34 +98,12 @@ }, upload() { var that = this - var token = uni.getStorageSync('token') uni.chooseImage({ count: 1, success: function(res) { - var tempFilePaths = res.tempFilePaths; - uni.uploadFile({ - url: '/api/client/common/avatar/', - filePath: tempFilePaths[0], - name: 'file', - header: { - 'Authorization': token - }, - success: function(res){ - try{ - var data = JSON.parse(res.data) - if(data.code != 2000){ - that.$pop.modelShow('上传失败:'+data.msg) - return - } - that.uinfo.avatar = data.data.url - }catch(e){ - that.$pop.modelShow('上传失败~'+e.message) - } - }, - fail: function(res){ - that.$pop.modelShow('上传失败') - } - }); + var tempFilePaths = res.tempFilePaths + that.tempFilePaths = tempFilePaths[0] + that.uinfo.avator = that.tempFilePaths } }); } diff --git a/pages/usercenter/usercenter.vue b/pages/usercenter/usercenter.vue index 909ebac..af736e0 100644 --- a/pages/usercenter/usercenter.vue +++ b/pages/usercenter/usercenter.vue @@ -1,7 +1,7 @@