From 87c8b4f6f7dc3a6d3e2d7e4a88725c6c08591bb7 Mon Sep 17 00:00:00 2001 From: Tuzki <1720599558@qq.com> Date: Wed, 23 Aug 2023 11:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=B4=E5=83=8F=E6=98=B5=E7=A7=B0=E5=AD=98?= =?UTF-8?q?=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/config.js | 1 + .../personcenter/EditProfile/EditProfile.vue | 55 ++++++++++- pages/personcenter/personcenter.vue | 94 ++++++++++++++----- static/css/common.css | 2 +- 4 files changed, 123 insertions(+), 29 deletions(-) diff --git a/common/config.js b/common/config.js index 88d714c..822d12b 100644 --- a/common/config.js +++ b/common/config.js @@ -91,6 +91,7 @@ module.exports = { getScenicListFormFilter: REAUEST_ROOTPATH + "/mobile/scenic/getScenicListFormFilter" ,//查询景区列表(暂用在热门景区,所返回字段只有目的地详情中热门景区字段) getWeather: REAUEST_ROOTPATH + "/mobile/weather/getweather",//天气 saveUser: REAUEST_ROOTPATH + "/mobile/weixin/saveUserInfo" ,//APP保存微信用户信息 + getUser: REAUEST_ROOTPATH + "/mobile/weixin/getUserByOpenId" ,//获取微信用户信息 getUserInterest: REAUEST_ROOTPATH + "/mobile/interest/getUserInterest.do" ,//根据用户uniid查询用户关注选择的推送数据 addUserInterest: REAUEST_ROOTPATH + "/mobile/interest/addUserInterest.do" ,//保存用户关注选择的推送数据 selectControlListFormFilter : REAUEST_ROOTPATH + "/mobile/complaint/selectControlListFormFilter" ,//投诉列表 diff --git a/pages/personcenter/EditProfile/EditProfile.vue b/pages/personcenter/EditProfile/EditProfile.vue index 5cf337f..4ca4660 100644 --- a/pages/personcenter/EditProfile/EditProfile.vue +++ b/pages/personcenter/EditProfile/EditProfile.vue @@ -26,7 +26,8 @@ export default { data() { return { username: '', - url: '' + url: '', + pic:'', }; }, onShow() { @@ -37,9 +38,39 @@ export default { }, methods: { onChooseAvatar(e) { + console.log(e) let this_ = this; const avatarUrl = e.detail.avatarUrl; this_.url = avatarUrl; + uni.uploadFile({ + url: this_.$config.fileUpload, + filePath: avatarUrl, + name: 'file', + success(res) { + console.log(res,'山川了') + if (res.statusCode != 200) { + uni.showToast({ + title: '上传失败', + icon: 'none' + }); + } + var obj = JSON.parse(res.data); + var flag = this_.$util.isSuccess(obj); + if (!flag) { + return; + } + obj = obj.data; + this_.pic = obj.path + console.log(this_.pic,';') + }, + fail(res) { + console.log('失败了',res) + uni.showToast({ + title: '上传失败', + icon: 'none' + }); + } + }); }, blurname(e) { let this_ = this; @@ -47,9 +78,29 @@ export default { }, saveProfile() { let this_ = this; - uni.setStorageSync('headimgurl', this_.url); + if(this_.pic&&this_.pi!=''){ + uni.setStorageSync('headimgurl', this_.$config.ROOTPATH+this_.pic); + } uni.setStorageSync('nickname', this_.username); uni.setStorageSync('oauthTime', new Date().getTime()); + const obj = { + headimgurl:this_.$config.ROOTPATH+this_.pic, + openid:uni.getStorageSync('unionid'), + nickname:this_.username + } + console.log(obj,'请求参数') + var data = { + "data": JSON.stringify(obj), + userkey:this_.$param.userkey + } + this_.$Request.post(this_.$config.saveUser,data).then(res => { + var flag = this_.$util.isSuccess(res); + if (!flag) { + return; + } + var userid = res.data; + console.log(userid,'保存返回') + }) uni.showToast({ icon: 'success', title: '保存成功!', diff --git a/pages/personcenter/personcenter.vue b/pages/personcenter/personcenter.vue index 6be5140..14c4f36 100644 --- a/pages/personcenter/personcenter.vue +++ b/pages/personcenter/personcenter.vue @@ -4,7 +4,7 @@ - + --> - + @@ -142,6 +142,7 @@ export default { onShow() { if (!uni.getStorageSync('unionid') || uni.getStorageSync('unionid') == '' || uni.getStorageSync('unionid') == null) { this.isLogin = false; + this.headimgurl = '' }else{ this.nickname = uni.getStorageSync('nickname') this.headimgurl = uni.getStorageSync('headimgurl') @@ -247,7 +248,6 @@ export default { setTimeout(function () { wx.login({ success: (res) => { - console.log(res, '登录获取的code'); var datas = { code: res.code }; @@ -257,8 +257,28 @@ export default { method: 'post', success: function (res) { const obj = JSON.parse(res.data.msg); - console.log(obj.openid); this_.isLogin = true; + const da = { + userkey:this_.$param.userkey, + openid:obj.openid + } + this_.$Request.post(this_.$config.getUser,da).then((res)=>{ + if(res.data == null){ + uni.setStorageSync('nickname', '微信用户'); + uni.setStorageSync('headimgurl', 'https://www.lbgjtoa.com/appImg/icon-person-01.png'); + uni.setStorageSync('oauthTime', new Date().getTime()); + this_.nickname = '微信用户'; + this_.headimgurl = 'https://www.lbgjtoa.com/appImg/icon-person-01.png'; + this_.$forceUpdate(); + }else{ + uni.setStorageSync('nickname', res.data.wxNickname); + uni.setStorageSync('headimgurl', res.data.wxHeadimgurl); + uni.setStorageSync('oauthTime', new Date().getTime()); + this_.nickname = res.data.wxNickname; + this_.headimgurl = res.data.wxHeadimgurl; + this_.$forceUpdate(); + } + }) uni.setStorageSync('unionid', obj.openid); }, fail: function (err) { @@ -271,25 +291,7 @@ export default { console.log('login failed ' + error); } }); - wx.getUserInfo({ - provider: 'weixin', - success: (res) => { - uni.setStorageSync('nickname', '微信用户'); - uni.setStorageSync('headimgurl', 'https://www.lbgjtoa.com/appImg/icon-person-01.png'); - uni.setStorageSync('oauthTime', new Date().getTime()); - this_.nickname = '微信用户'; - this_.$forceUpdate(); - this_.headimgurl = 'https://www.lbgjtoa.com/appImg/icon-person-01.png'; - }, - fail: function (error) { - console.log('login failed ' + error); - } - }); - // uni.showToast({ - // title:"授权失败,点击"+that.nickname+"重新授权", - // icon:"none", - // duration: 1500 - // }) + this_.$forceUpdate(); uni.hideLoading(); }, 3000); @@ -299,6 +301,46 @@ export default { // #endif }, + saveProfile:function(){ + let this_ = this + // wx.getUserInfo({ + // provider: 'weixin', + // success: (res) => { + // uni.setStorageSync('nickname', '微信用户'); + // uni.setStorageSync('headimgurl', 'https://www.lbgjtoa.com/appImg/icon-person-01.png'); + // uni.setStorageSync('oauthTime', new Date().getTime()); + // this_.nickname = '微信用户'; + // this_.headimgurl = 'https://www.lbgjtoa.com/appImg/icon-person-01.png'; + // this_.$forceUpdate(); + const obj = { + headimgurl:this_.headimgurl, + openid:uni.getStorageSync('unionid'), + nickname:this_.nickname + } + console.log(obj,'请求参数') + var data = { + "data": JSON.stringify(obj), + userkey:this_.$param.userkey + } + this_.$Request.post(this_.$config.saveUser,data).then(res => { + var flag = this_.$util.isSuccess(res); + if (!flag) { + return; + } + var userid = res.data; + console.log(userid,'保存返回') + }) + // }, + // fail: function (error) { + // console.log('login failed ' + error); + // } + // }); + // uni.showToast({ + // title:"授权失败,点击"+that.nickname+"重新授权", + // icon:"none", + // duration: 1500 + // }) + }, callBackMethod: function () { // clearTimeout(timer); this.isLogin = true; @@ -398,7 +440,7 @@ export default { content: '确定退出登录?', success: function (res) { if (res.confirm) { - that.deleteUserApp(); + // that.deleteUserApp(); (this.scenicGZType = 'NO'), (this.lineGZType = 'NO'), (this.foodGZType = 'NO'), (this.methodGZType = 'NO'), uni.removeStorageSync('nickname'); uni.removeStorageSync('headimgurl'); uni.removeStorageSync('nickname'); @@ -406,7 +448,7 @@ export default { uni.removeStorageSync('openid'); uni.removeStorageSync('unionid'); that.nickname = '点击授权'; - that.headimgurl = ''; + that.headimgurl = 'https://www.lbgjtoa.com/appImg/icon-person-01.png'; that.isLogin = false; } else if (res.cancel) { } @@ -492,7 +534,7 @@ export default { } } } -}; +}