Skip to content

Commit 6103dcb

Browse files
committed
feat: support mp-baidu
1 parent 7f54886 commit 6103dcb

3 files changed

Lines changed: 46 additions & 37 deletions

File tree

‎pages/API/get-user-info/get-user-info.vue‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<view style="background:#FFF; padding:40upx;">
66
<block v-if="hasUserInfo === false">
77
<view class="uni-hello-text uni-center">
8-
<text>请点击蓝色按钮获取用户头像及昵称</text>
8+
<text>请点击下方按钮获取用户头像及昵称</text>
99
</view>
1010
</block>
1111
<block v-if="hasUserInfo === true">
@@ -20,7 +20,10 @@
2020
<button type="primary" @tap="getUserInfo">获取用户信息</button>
2121
<!-- #endif -->
2222
<!-- #ifdef MP-WEIXIN -->
23-
<button type="primary" open-type="getUserInfo" @getuserinfo="wxGetUserInfo">获取用户信息</button>
23+
<button type="primary" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">获取用户信息</button>
24+
<!-- #endif -->
25+
<!-- #ifdef MP-BAIDU -->
26+
<button type="primary" open-type="getUserInfo" @getuserinfo="mpGetUserInfo">获取用户信息</button>
2427
<!-- #endif -->
2528
<button @tap="clear">清空</button>
2629
</view>
@@ -46,7 +49,7 @@
4649
loginProvider: state => state.loginProvider
4750
})
4851
},
49-
onLoad: function () {},
52+
onLoad: function() {},
5053
methods: {
5154
getUserInfo() { //获取用户信息api在微信小程序可直接使用,在5+app里面需要先登录才能调用
5255
uni.getUserInfo({
@@ -63,29 +66,29 @@
6366
content = "请在登录页面完成登录操作"
6467
}
6568
uni.showModal({
66-
title:"获取用户信息失败",
67-
content:"错误原因"+content,
69+
title: "获取用户信息失败",
70+
content: "错误原因" + content,
6871
showCancel: false
6972
})
7073
}
7174
})
7275
},
73-
wxGetUserInfo(e){
76+
mpGetUserInfo(e) {
7477
console.log("得到用户信息", e);
75-
if(e.detail.errMsg !== 'getUserInfo:ok'){
78+
if (e.detail.errMsg !== 'getUserInfo:ok') {
7679
uni.showModal({
77-
title:"获取用户信息失败",
78-
content:"错误原因"+e.detail.errMsg,
79-
showCancel:false
80+
title: "获取用户信息失败",
81+
content: "错误原因" + e.detail.errMsg,
82+
showCancel: false
8083
});
8184
return;
8285
}
8386
this.hasUserInfo = true;
8487
this.userInfo = e.detail.userInfo
8588
},
8689
clear() {
87-
this.hasUserInfo = false,
88-
this.userInfo = {}
90+
this.hasUserInfo = false;
91+
this.userInfo = {};
8992
}
9093
}
9194
}
@@ -97,4 +100,4 @@
97100
width: 128upx;
98101
height: 128upx;
99102
}
100-
</style>
103+
</style>

‎pages/API/login/login.vue‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</block>
1818
</view>
1919
<view class="uni-btn-v uni- uni-common-mt">
20-
<button type="primary" class="page-body-button" v-for="(value,key) in providerList" @tap="bindLogin(value)" :key="key">{{value.name}}</button>
20+
<button type="primary" class="page-body-button" v-for="(value,key) in providerList" @click="tologin(value)" :key="key">{{value.name}}</button>
2121
</view>
2222
</view>
2323
</view>
@@ -42,28 +42,29 @@
4242
uni.getProvider({
4343
service: "oauth",
4444
success: (e) => {
45+
console.log('oauth..........');
4546
this.providerList = e.provider.map((value) => {
47+
let providerName = '';
4648
switch (value) {
4749
case 'weixin':
48-
return {
49-
name: '微信登录',
50-
id: value
51-
}
50+
providerName = '微信登录'
51+
break;
5252
case 'qq':
53-
return {
54-
name: 'QQ登录',
55-
id: value
56-
}
53+
providerName = 'QQ登录'
54+
break;
5755
case 'sinaweibo':
58-
return {
59-
name: '新浪微博登录',
60-
id: value
61-
}
56+
providerName = '新浪微博登录'
57+
break;
6258
case 'xiaomi':
63-
return {
64-
name: '小米登录',
65-
id: value
66-
}
59+
providerName = '小米登录'
60+
break;
61+
case 'baidu':
62+
providerName = '百度登录'
63+
break;
64+
}
65+
return {
66+
name: providerName,
67+
id: value
6768
}
6869
})
6970
},
@@ -74,15 +75,15 @@
7475
},
7576
methods: {
7677
...mapMutations(['login']),
77-
bindLogin(e) {
78+
tologin(provider) {
7879
uni.login({
79-
provider: e.id,
80+
provider: provider.id,
8081
success: (res) => {
81-
console.log("登录", res);
82-
this.login(e.id); //改变保存在store里的登录状态
82+
console.log('login success:', res);
83+
this.login(provider.id); //改变保存在store里的登录状态
8384
},
84-
fail: (e) => {
85-
console.log("fail", e);
85+
fail: (err) => {
86+
console.log('login fail:', err);
8687
}
8788
})
8889
}
@@ -95,4 +96,4 @@
9596
background-color: #007aff;
9697
color: #ffffff;
9798
}
98-
</style>
99+
</style>

‎pages/API/share/share.vue‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<button type="primary" open-type="share">分享</button>
4141
</view>
4242
<!-- #endif -->
43+
<!-- #ifdef MP-BAIDU -->
44+
<view class="uni-btn-v uni-common-mt">
45+
<button type="primary" open-type="share">分享</button>
46+
</view>
47+
<!-- #endif -->
4348
</view>
4449
</view>
4550
</template>

0 commit comments

Comments
 (0)