第三方绑定

This commit is contained in:
2020-08-27 12:16:09 +08:00
parent 5f233b8e06
commit 16115ba111
2 changed files with 54 additions and 9 deletions

View File

@@ -2,11 +2,11 @@
<view class="binding">
<view class="binding-item" v-for="(item, index) in bangdingList" :key="index">
<view class="title">{{ item.title }}</view>
<view class="btn unbundling-btn" @click="unbinding" v-if="0">
<view class="btn unbundling-btn" @click="unbinding(item.type)" v-if="userInfo[item.name]">
<image src="/static/image/mine/44.png"></image>
<text>解绑</text>
</view>
<view class="btn bundling-btn" @click="binding(item.provider)" v-else>
<view class="btn bundling-btn" @click="binding(item.provider, item.type)" v-else>
<image src="/static/image/mine/43.png"></image>
<text>绑定</text>
</view>
@@ -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);
})
}
}
};