Skip to content

Commit

Permalink
fix: 修复第三方登录错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Jun 6, 2024
1 parent 98e8060 commit a775b86
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type RouteRecordRaw, createRouter, createWebHashHistory } from 'vue-router'
import { type RouteRecordRaw, createRouter, createWebHistory } from 'vue-router'
import { useRouteStore } from '@/stores'

/** 默认布局 */
Expand All @@ -19,6 +19,7 @@ export const constantRoutes: RouteRecordRaw[] = [
},
{
path: '/login',
name: 'Login',
component: () => import('@/views/login/index.vue'),
meta: { hidden: true }
},
Expand Down Expand Up @@ -75,7 +76,7 @@ export const constantRoutes: RouteRecordRaw[] = [
]

const router = createRouter({
history: createWebHashHistory(import.meta.env.BASE_URL),
history: createWebHistory(import.meta.env.BASE_URL),
routes: constantRoutes,
scrollBehavior: () => ({ left: 0, top: 0 })
})
Expand Down
12 changes: 9 additions & 3 deletions src/views/login/social/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a-spin :loading="loading" :tip="isLogin() ? '绑定中。。。' : '登录中。。。'">
<a-spin :loading="loading" :tip="isLogin() ? '绑定中...' : '登录中...'">
<div></div>
</a-spin>
</template>
Expand All @@ -8,10 +8,12 @@
import { Message } from '@arco-design/web-vue'
import { useRoute, useRouter } from 'vue-router'
import { bindSocialAccount } from '@/apis'
import { useUserStore } from '@/stores'
import { isLogin } from '@/utils/auth'
const route = useRoute()
const router = useRouter()
const userStore = useUserStore()
const source = route.query.source as string
const loading = ref(false)
Expand Down Expand Up @@ -50,14 +52,14 @@ const handleBindSocial = () => {
loading.value = true
const { ...othersQuery } = router.currentRoute.value.query
bindSocialAccount(source, othersQuery)
.then((res) => {
.then(() => {
router.push({
path: '/setting/profile',
query: {
...othersQuery
}
})
proxy.$message.success(res.msg)
Message.success('绑定成功')
})
.catch(() => {
router.push({
Expand All @@ -80,6 +82,10 @@ if (isLogin()) {
</script>

<style scoped lang="less">
:deep(.arco-spin-mask) {
background-color: transparent;
}
div {
width: 150px;
height: 150px;
Expand Down
61 changes: 29 additions & 32 deletions src/views/setting/profile/Social.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,38 @@
</template>

<script setup lang="ts">
import { Message } from '@arco-design/web-vue'
import type { ModeItem } from '../type'
import VerifyModel from '../components/VerifyModel.vue'
import { listUserSocial, socialAuth, unbindSocialAccount } from '@/apis'
import { useUserStore } from '@/stores'
const userStore = useUserStore()
const socialList = ref<any>([])
const modeList = ref<ModeItem[]>([])
modeList.value = [
{
title: '绑定 Gitee',
icon: 'gitee',
subtitle: `${socialList.value.includes('gitee') ? '' : '绑定后,'}可通过 Gitee 进行登录`,
jumpMode: 'link',
type: 'gitee',
status: socialList.value.includes('gitee')
},
{
title: '绑定 GitHub',
icon: 'github',
subtitle: `${socialList.value.includes('gitee') ? '' : '绑定后,'}可通过 GitHub 进行登录`,
type: 'github',
jumpMode: 'link',
status: socialList.value.includes('github')
}
]
// 初始化数据
const initData = () => {
listUserSocial().then((res) => {
socialList.value = res.data.map((el) => el.source)
modeList.value = [
{
title: '绑定 Gitee',
icon: 'gitee',
subtitle: `${socialList.value.includes('GITEE') ? '' : '绑定后,'}可通过 Gitee 进行登录`,
jumpMode: 'link',
type: 'gitee',
status: socialList.value.includes('GITEE')
},
{
title: '绑定 GitHub',
icon: 'github',
subtitle: `${socialList.value.includes('GITHUB') ? '' : '绑定后,'}可通过 GitHub 进行登录`,
type: 'github',
jumpMode: 'link',
status: socialList.value.includes('GITHUB')
}
]
})
}
// 绑定
const onBinding = (type: string, status: boolean) => {
Expand All @@ -79,10 +84,9 @@ const onBinding = (type: string, status: boolean) => {
window.open(res.data.authorizeUrl, '_self')
})
} else {
unbindSocialAccount(type).then((res) => {
if (res.code === 200) {
userStore.getInfo()
}
unbindSocialAccount(type).then(() => {
initData()
Message.success('解绑成功')
})
}
}
Expand All @@ -93,13 +97,6 @@ const onUpdate = (type: string) => {
verifyModelRef.value?.open(type)
}
// 初始化数据
const initData = () => {
listUserSocial().then((res) => {
socialList.value = res.data.map((el) => el.source)
})
}
onMounted(() => {
initData()
})
Expand Down

0 comments on commit a775b86

Please sign in to comment.