feat:增加个人中心:60% 支持右侧的社交绑定

pull/76/MERGE
YunaiV 2025-04-20 19:49:16 +08:00
parent a6dcd8c200
commit 555dc1c063
2 changed files with 59 additions and 9 deletions

View File

@ -13,8 +13,7 @@ import { getUserProfile } from '#/api/system/user/profile';
import { useAuthStore } from '#/store'; import { useAuthStore } from '#/store';
const authStore = useAuthStore(); const authStore = useAuthStore();
// const activeName = ref('basicInfo'); const activeName = ref('basicInfo');
const activeName = ref('userSocial');
/** 加载个人信息 */ /** 加载个人信息 */
const profile = ref<SystemUserProfileApi.UserProfileRespVO>(); const profile = ref<SystemUserProfileApi.UserProfileRespVO>();
@ -52,9 +51,10 @@ onMounted(loadProfile);
<Tabs.TabPane key="resetPwd" tab="密码设置"> <Tabs.TabPane key="resetPwd" tab="密码设置">
<ResetPwd /> <ResetPwd />
</Tabs.TabPane> </Tabs.TabPane>
<Tabs.TabPane key="userSocial" tab="社交绑定"> <Tabs.TabPane key="userSocial" tab="社交绑定" force-render>
<UserSocial /> <UserSocial @update:active-name="activeName = $event" />
</Tabs.TabPane> </Tabs.TabPane>
<!-- TODO @芋艿在线设备 -->
</Tabs> </Tabs>
</Card> </Card>
</div> </div>

View File

@ -4,13 +4,20 @@ import type { SystemSocialUserApi } from '#/api/system/social/user';
import { Button, Card, Image, message, Modal } from 'ant-design-vue'; import { Button, Card, Image, message, Modal } from 'ant-design-vue';
import { computed, ref } from 'vue'; import { computed, ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getBindSocialUserList, socialUnbind } from '#/api/system/social/user'; import { getBindSocialUserList, socialUnbind, socialBind } from '#/api/system/social/user';
import { socialAuthRedirect } from '#/api/core/auth';
import { DICT_TYPE, getDictLabel } from '#/utils/dict'; import { DICT_TYPE, getDictLabel } from '#/utils/dict';
import { SystemUserSocialTypeEnum } from '#/utils/constants'; import { SystemUserSocialTypeEnum } from '#/utils/constants';
const route = useRoute()
const emit = defineEmits<{
(e: 'update:activeName', v: string): void
}>()
/** 已经绑定的平台 */ /** 已经绑定的平台 */
const bindList = ref<SystemSocialUserApi.SystemSocialUser[]>([]); const bindList = ref<SystemSocialUserApi.SystemSocialUser[]>([]);
const allBindList = computed<any[]>(() => { const allBindList = computed<any[]>(() => {
@ -101,10 +108,53 @@ function onUnbind(row: SystemSocialUserApi.SystemSocialUser) {
}); });
} }
/** 绑定账号 */ /** 绑定账号(跳转授权页面) */
function onBind(bind: any) { async function onBind(bind: any) {
alert('待实现!'); const type = bind.type;
if (type <= 0) {
return;
}
try {
// redirectUri
// tricky: type encode getUrlValue() 使
const redirectUri = location.origin + '/profile?' + encodeURIComponent(`type=${type}`)
//
window.location.href = await socialAuthRedirect(type, redirectUri)
} catch (error) {
console.error('社交绑定处理失败:', error);
}
} }
/** 监听路由变化,处理社交绑定回调 */
async function bindSocial() {
//
const type = Number(getUrlValue('type'))
const code = route.query.code as string
const state = route.query.state as string
if (!code) {
return
}
await socialBind({ type, code, state })
//
message.success('绑定成功')
emit('update:activeName', 'userSocial')
await gridApi.reload();
// URL
window.history.replaceState({}, '', location.pathname)
}
// TODO @ util
// encode decode
function getUrlValue(key: string): string {
const url = new URL(decodeURIComponent(location.href))
return url.searchParams.get(key) ?? ''
}
/** 初始化 */
onMounted(() => {
bindSocial()
})
</script> </script>
<template> <template>