1
1
<template >
2
2
<el-table :data =" socialUsers" :show-header =" false" >
3
- <el-table-column type = " seq " title =" 序号" width = " 60 " fixed = " left " />
4
- <el-table-column label = " 社交平台 " align = " left " width =" 120" >
3
+ <el-table-column fixed = " left " title =" 序号" type = " seq " width = " 60 " />
4
+ <el-table-column align = " left " label = " 社交平台 " width =" 120" >
5
5
<template #default =" { row } " >
6
- <img class = " h-5 align-middle " :src =" row.img" alt =" " />
6
+ <img :src =" row.img" alt =" " class = " h-5 align-middle " />
7
7
<p class =" mr-5" >{{ row.title }}</p >
8
8
</template >
9
9
</el-table-column >
10
- <el-table-column label = " 操作 " align = " center " >
10
+ <el-table-column align = " center " label = " 操作 " >
11
11
<template #default =" { row } " >
12
12
<template v-if =" row .openid " >
13
13
已绑定
14
- <XTextButton type = " primary " class =" mr-5" @click = " unbind(row )" title = " (解绑 )" />
14
+ <XTextButton class =" mr-5" title = " (解绑 )" type = " primary " @click = " unbind(row )" />
15
15
</template >
16
16
<template v-else >
17
17
未绑定
18
- <XTextButton type = " primary " class =" mr-5" @click = " bind(row )" title = " (绑定 )" />
18
+ <XTextButton class =" mr-5" title = " (绑定 )" type = " primary " @click = " bind(row )" />
19
19
</template >
20
20
</template >
21
21
</el-table-column >
22
22
</el-table >
23
23
</template >
24
- <script setup lang="ts">
24
+ <script lang="ts" name="UserSocial" setup >
25
25
import { SystemUserSocialTypeEnum } from ' @/utils/constants'
26
26
import { getUserProfile , ProfileVO } from ' @/api/system/user/profile'
27
- import { socialAuthRedirect , socialUnbind } from ' @/api/system/user/socialUser'
27
+ import { socialAuthRedirect , socialBind , socialUnbind } from ' @/api/system/user/socialUser'
28
28
29
29
const message = useMessage ()
30
30
const socialUsers = ref <any []>([])
@@ -46,11 +46,25 @@ const initSocial = async () => {
46
46
}
47
47
}
48
48
}
49
+ const route = useRoute ()
50
+ const bindSocial = () => {
51
+ // 社交绑定
52
+ const type = route .query .type
53
+ const code = route .query .code
54
+ const state = route .query .state
55
+ if (! code ) {
56
+ return
57
+ }
58
+ socialBind (type , code , state ).then (() => {
59
+ message .success (' 绑定成功' )
60
+ initSocial ()
61
+ })
62
+ }
49
63
const bind = (row ) => {
50
64
const redirectUri = location .origin + ' /user/profile?type=' + row .type
51
65
// 进行跳转
52
66
socialAuthRedirect (row .type , encodeURIComponent (redirectUri )).then ((res ) => {
53
- window .location .href = res . data
67
+ window .location .href = res
54
68
})
55
69
}
56
70
const unbind = async (row ) => {
@@ -64,4 +78,15 @@ const unbind = async (row) => {
64
78
onMounted (async () => {
65
79
await initSocial ()
66
80
})
81
+
82
+ watch (
83
+ () => route ,
84
+ (newRoute ) => {
85
+ bindSocial ()
86
+ console .log (newRoute )
87
+ },
88
+ {
89
+ immediate: true
90
+ }
91
+ )
67
92
</script >
0 commit comments