24
24
25
25
import {SystemUserSocialTypeEnum } from " @/utils/constants" ;
26
26
import {socialAuthRedirect } from " @/api/login" ;
27
- import {socialBind , socialUnbind } from " @/api/system/socialUser" ;
27
+ import {socialBind , socialUnbind , getBindSocialUserList } from " @/api/system/socialUser" ;
28
28
29
29
export default {
30
30
props: {
@@ -40,27 +40,15 @@ export default {
40
40
},
41
41
data () {
42
42
return {
43
+ socialUsers: []
43
44
};
44
45
},
45
46
computed: {
46
- socialUsers (){
47
- const socialUsers = [];
48
- for (const i in SystemUserSocialTypeEnum) {
49
- const socialUser = {... SystemUserSocialTypeEnum[i]};
50
- socialUsers .push (socialUser);
51
- if (this .user .socialUsers ) {
52
- for (const j in this .user .socialUsers ) {
53
- if (socialUser .type === this .user .socialUsers [j].type ) {
54
- socialUser .openid = this .user .socialUsers [j].openid ;
55
- break ;
56
- }
57
- }
58
- }
59
- }
60
- return socialUsers;
61
- }
62
47
},
63
- created () {
48
+ async created () {
49
+ // 初始化社交用户列表
50
+ await this .initSocial ();
51
+
64
52
// 社交绑定
65
53
const type = this .$route .query .type ;
66
54
const code = this .$route .query .code ;
@@ -72,17 +60,35 @@ export default {
72
60
this .$modal .msgSuccess (" 绑定成功" );
73
61
this .$router .replace (' /user/profile' );
74
62
// 调用父组件, 刷新
75
- this .getUser ();
76
63
this .setActiveTab (' userSocial' );
64
+ // 重新初始化社交用户列表
65
+ this .initSocial ();
77
66
});
78
67
},
79
68
methods: {
69
+ async initSocial () {
70
+ this .socialUsers = []; // 重置避免无限增长
71
+ // 获取已绑定的社交用户列表
72
+ const bindSocialUserList = await getBindSocialUserList ();
73
+ // 检查该社交平台是否已绑定
74
+ for (const i in SystemUserSocialTypeEnum) {
75
+ const socialUser = { ... SystemUserSocialTypeEnum[i] };
76
+ this .socialUsers .push (socialUser);
77
+ if (bindSocialUserList && bindSocialUserList .data && bindSocialUserList .data .length > 0 ) {
78
+ for (const bindUser of bindSocialUserList .data ) {
79
+ if (socialUser .type === bindUser .type ) {
80
+ socialUser .openid = bindUser .openid ;
81
+ break ;
82
+ }
83
+ }
84
+ }
85
+ }
86
+ },
80
87
bind (socialUser ) {
81
88
// 计算 redirectUri
82
89
const redirectUri = location .origin + ' /user/profile?type=' + socialUser .type ;
83
90
// 进行跳转
84
91
socialAuthRedirect (socialUser .type , encodeURIComponent (redirectUri)).then ((res ) => {
85
- // console.log(res.url);
86
92
window .location .href = res .data ;
87
93
});
88
94
},
0 commit comments