From 16115ba1115df7dde1cbd6b66dd01c40ba6030c5 Mon Sep 17 00:00:00 2001 From: ghusermoon <2673031505@qq.com> Date: Thu, 27 Aug 2020 12:16:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/api/user.js | 13 ++++++++++ pageE/setting/binding.vue | 50 ++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/common/api/user.js b/common/api/user.js index 459f496..714350d 100644 --- a/common/api/user.js +++ b/common/api/user.js @@ -454,6 +454,19 @@ export default { //获取默认头像 getDefaultAvatar(){ return vm.$u.post("member/getDefaultAvatar") + }, + // 第三方账号绑定【微信|QQ】 + bindingThird({ openid, type }) { + return vm.$u.post("auth/memberBindThird", { + third_openid: openid, + third_type: type, + }) + }, + // 解绑 + unbindingThird({ type }) { + return vm.$u.post("auth/memberUnbindThird", { + third_type: type, + }) } } diff --git a/pageE/setting/binding.vue b/pageE/setting/binding.vue index e085f80..a01be37 100644 --- a/pageE/setting/binding.vue +++ b/pageE/setting/binding.vue @@ -2,11 +2,11 @@ {{ item.title }} - + 解绑 - + 绑定 @@ -17,29 +17,61 @@ export default { data() { return { + userInfo: '', bangdingList: [ { title: 'QQ', - provider: 'qq' + provider: 'qq', // uni 登录 provider + type: 'qq', // 后台需要解绑的参数名 type + name: 'member_qqopenid', // 后台返回是否绑定的字段名 }, { title: '微信', - provider: 'weixin' + provider: 'weixin', + type: 'wechat', + name: 'member_wxopenid', } ] } }, + onLoad() { + this.getMemberInfo(); + }, methods: { - binding(provider) { + getMemberInfo() { + this.$u.api.getMemberInfo().then(res => { + if (res.errCode == 0) { + this.userInfo = res.data.MemberArray; + } + }) + }, + binding(provider, type) { uni.login({ provider: provider, - success: function (loginRes) { - console.log(loginRes.authResult); + success: (loginRes) => { + console.log(loginRes); + uni.getUserInfo({ + provider: provider, + success: (res) => { + console.log(res.userInfo.openId); + this.$u.api.bindingThird({ + openid: res.userInfo.openId, + type: type + }).then(res => { + this.$u.toast(res.message); + }) + } + }) + }, + fail: (e) => { + console.log(e); } }); }, - unbinding() { - + unbinding(type) { + this.$u.api.unbindingThird({ type: type }).then(res => { + this.$u.toast(res.message); + }) } } };