diff --git a/.gitignore b/.gitignore index d94a68a..7b3fd3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ unpackage/ -.hbuilderx \ No newline at end of file +.hbuilderx +.history \ No newline at end of file diff --git a/components/loginPopup.vue b/components/loginPopup.vue index adab399..528ea0f 100644 --- a/components/loginPopup.vue +++ b/components/loginPopup.vue @@ -54,6 +54,7 @@ export default { "getPlantformInfo", "forceUserInfo", "getUserInfo", + "reloadUserResource", ]), open() { this.$refs["popup"].open("bottom"); @@ -142,16 +143,15 @@ export default { // 一键登录注册 async doWxUserRegisterAndLogin(phoneNumber) { - this.close() const openId = await this.getWxOpenId() - const user = await this.getUserprofile() + const {userInfo:{ nickName, avatarUrl }} = await this.getUserprofile() const that = this this.$.request({ url: this.Config.URL.wx.doWxUserRegisterAndLogin, data: { - nickName: user.userInfo.nickName, - avatarUrl: user.userInfo.avatarUrl, + nickName, + avatarUrl, phoneNumber, openId }, @@ -160,25 +160,43 @@ export default { 'Content-Type': 'application/json;charset=utf-8' }, dataType: "json", - success: function (res) { - if (res.status != 200) { - that.$.confirm(that.__(res.msg || '登录失败,请重试!')); + success: function (data, status, msg, code) { + if (status != 200) { + that.$.confirm(that.__(msg || '登录失败,请重试!')); return } + that.loginSuccess(data) }, }); - // that.$.request({ - // url: that.Config.URL.user.overview, - // success: function (data, status, msg, code) { - // userInfo = Object.assign(userInfo, data.member_info); - - // that.login(userInfo); - - // that.close(); - // }, - // }); }, + + // 成功登录回调 + loginSuccess(data) { + const that = this + + that.$.setStorageSync("uid", data.user_id); + that.$.setStorageSync("ukey", data.key); + + // #ifdef H5 + $cookies.set("uid", data.user_id); + $cookies.set("ukey", data.key); + // #endif + + that.$.request({ + url: that.Config.URL.user.overview, + success: function (data, status, msg, code) { + that.login(data); + that.reloadUserResource(function (user_info) { + that.setData({ + UserInfo: user_info, + }); + }); + + that.close(); + }, + }); + } }, };