@@ -27,12 +27,15 @@ import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
27
27
import { socialAuthRedirect , socialBind , socialUnbind } from ' @/api/system/user/socialUser'
28
28
29
29
defineOptions ({ name: ' UserSocial' })
30
-
30
+ defineProps <{
31
+ activeName: string
32
+ }>()
31
33
const message = useMessage ()
32
34
const socialUsers = ref <any []>([])
33
35
const userInfo = ref <ProfileVO >()
34
36
35
37
const initSocial = async () => {
38
+ socialUsers .value = [] // 重置避免无限增长
36
39
const res = await getUserProfile ()
37
40
userInfo .value = res
38
41
for (const i in SystemUserSocialTypeEnum ) {
@@ -49,21 +52,33 @@ const initSocial = async () => {
49
52
}
50
53
}
51
54
const route = useRoute ()
55
+ const emit = defineEmits <{
56
+ (e : ' update:activeName' , v : string ): void
57
+ }>()
52
58
const bindSocial = () => {
53
59
// 社交绑定
54
- const type = route . query . type
60
+ const type = getUrlValue ( ' type' )
55
61
const code = route .query .code
56
62
const state = route .query .state
57
63
if (! code ) {
58
64
return
59
65
}
60
66
socialBind (type , code , state ).then (() => {
61
67
message .success (' 绑定成功' )
68
+ emit (' update:activeName' , ' userSocial' )
62
69
initSocial ()
63
70
})
64
71
}
72
+
73
+ // 双层 encode 需要在回调后进行 decode
74
+ function getUrlValue(key : string ): string {
75
+ const url = new URL (decodeURIComponent (location .href ))
76
+ return url .searchParams .get (key ) ?? ' '
77
+ }
78
+
65
79
const bind = (row ) => {
66
- const redirectUri = location .origin + ' /user/profile?type=' + row .type
80
+ // 双层 encode 解决钉钉回调 type 参数丢失的问题
81
+ const redirectUri = location .origin + ' /user/profile?' + encodeURIComponent (` type=${row .type } ` )
67
82
// 进行跳转
68
83
socialAuthRedirect (row .type , encodeURIComponent (redirectUri )).then ((res ) => {
69
84
window .location .href = res
@@ -83,9 +98,8 @@ onMounted(async () => {
83
98
84
99
watch (
85
100
() => route ,
86
- (newRoute ) => {
101
+ () => {
87
102
bindSocial ()
88
- console .log (newRoute )
89
103
},
90
104
{
91
105
immediate: true
0 commit comments