diff --git a/App.vue b/App.vue index 97234a0..ddd00f5 100644 --- a/App.vue +++ b/App.vue @@ -47,6 +47,7 @@ this.wxLogin(); } else { this.globalData.openId = openid; + this.getUserInfo(); } // #endif }, @@ -63,6 +64,25 @@ }, methods: { ...mapMutations(['setUniverifyErrorMsg', 'setUniverifyLogin']), + //获取用户信息 + getUserInfo() { + uni.request({ + url: this.globalData.baseUrl + '/weChatUser/getWeChatUser?openId=' + this.globalData.openId, + method: 'GET', + success: (res) => { + console.log(res) + if (res.data.code == 200) { + uni.setStorageSync('userInfo', JSON.stringify(res.data.data)); + uni.setStorageSync('phone', res.data.data.phone); + } else { + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + } + } + }) + }, //微信登陆 wxLogin() { uni.login({ diff --git a/pages/pages_zhentou/homePage/homePage.vue b/pages/pages_zhentou/homePage/homePage.vue index 3430224..df4bedc 100644 --- a/pages/pages_zhentou/homePage/homePage.vue +++ b/pages/pages_zhentou/homePage/homePage.vue @@ -6,8 +6,8 @@ - - + + @@ -42,7 +42,8 @@ methods: { // 点击定制 clickCustom() { - console.log('点击定制') + console.log('点击定制'); + // this.doSave(); }, // 填写表单 addForm() { @@ -56,7 +57,6 @@ }, //用户信息 getUserProfile() { - console.log('getuserinfo') uni.getUserProfile({ lang: 'zh_CN', desc: '获取微信用户的昵称和头像', @@ -85,6 +85,30 @@ this.phone = res.data.data; this.hasPhone = true; uni.setStorageSync('phone', res.data.data); + this.doSave(); + } else { + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + } + } + }) + }, + //存储用户信息 + doSave() { + uni.request({ + url: getApp().globalData.baseUrl + '/weChatUser/save', + method: 'POST', + data: { + openId: getApp().globalData.openId, + username: this.userInfo.nickName, + phone: this.phone, + avatar: this.userInfo.avatarUrl + }, + success: (res) => { + if (res.data.code == 200) { + uni.setStorageSync('userInfo', JSON.stringify(res.data.data)); } else { uni.showToast({ title: res.data.msg, @@ -94,7 +118,6 @@ } }) }, - } }