From d62e607292a2bd12eafe5ad97fafcc726c99a019 Mon Sep 17 00:00:00 2001 From: puhui999 <puhui999@163.com> Date: Fri, 14 Apr 2023 21:47:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=BB=91=E5=AE=9A=E7=AC=AC?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E8=B7=B3=E8=BD=AC=E6=89=AB=E7=A0=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Profile/components/UserSocial.vue | 43 ++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/views/Profile/components/UserSocial.vue b/src/views/Profile/components/UserSocial.vue index da88d993..5d1664ea 100644 --- a/src/views/Profile/components/UserSocial.vue +++ b/src/views/Profile/components/UserSocial.vue @@ -1,30 +1,30 @@ <template> <el-table :data="socialUsers" :show-header="false"> - <el-table-column type="seq" title="序号" width="60" fixed="left" /> - <el-table-column label="社交平台" align="left" width="120"> + <el-table-column fixed="left" title="序号" type="seq" width="60" /> + <el-table-column align="left" label="社交平台" width="120"> <template #default="{ row }"> - <img class="h-5 align-middle" :src="row.img" alt="" /> + <img :src="row.img" alt="" class="h-5 align-middle" /> <p class="mr-5">{{ row.title }}</p> </template> </el-table-column> - <el-table-column label="操作" align="center"> + <el-table-column align="center" label="操作"> <template #default="{ row }"> <template v-if="row.openid"> 已绑定 - <XTextButton type="primary" class="mr-5" @click="unbind(row)" title="(解绑)" /> + <XTextButton class="mr-5" title="(解绑)" type="primary" @click="unbind(row)" /> </template> <template v-else> 未绑定 - <XTextButton type="primary" class="mr-5" @click="bind(row)" title="(绑定)" /> + <XTextButton class="mr-5" title="(绑定)" type="primary" @click="bind(row)" /> </template> </template> </el-table-column> </el-table> </template> -<script setup lang="ts"> +<script lang="ts" name="UserSocial" setup> import { SystemUserSocialTypeEnum } from '@/utils/constants' import { getUserProfile, ProfileVO } from '@/api/system/user/profile' -import { socialAuthRedirect, socialUnbind } from '@/api/system/user/socialUser' +import { socialAuthRedirect, socialBind, socialUnbind } from '@/api/system/user/socialUser' const message = useMessage() const socialUsers = ref<any[]>([]) @@ -46,11 +46,25 @@ const initSocial = async () => { } } } +const route = useRoute() +const bindSocial = () => { + // 社交绑定 + const type = route.query.type + const code = route.query.code + const state = route.query.state + if (!code) { + return + } + socialBind(type, code, state).then(() => { + message.success('绑定成功') + initSocial() + }) +} const bind = (row) => { const redirectUri = location.origin + '/user/profile?type=' + row.type // 进行跳转 socialAuthRedirect(row.type, encodeURIComponent(redirectUri)).then((res) => { - window.location.href = res.data + window.location.href = res }) } const unbind = async (row) => { @@ -64,4 +78,15 @@ const unbind = async (row) => { onMounted(async () => { await initSocial() }) + +watch( + () => route, + (newRoute) => { + bindSocial() + console.log(newRoute) + }, + { + immediate: true + } +) </script>