Skip to content

Commit

Permalink
refactor: 完善三方账号登录
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Apr 27, 2024
1 parent c938028 commit f701ca5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const constantRoutes: RouteRecordRaw[] = [
},
{
path: '/social/callback',
name: 'SocialCallback',
component: () => import('@/views/login/social/index.vue'),
meta: { hidden: true }
},
Expand Down
2 changes: 1 addition & 1 deletion src/router/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getToken } from '@/utils/auth'
import { isHttp } from '@/utils/validate'

/** 免登录白名单 */
const whiteList = ['/login', '/register']
const whiteList = ['/login', '/social/callback']

/** 是否已经生成过路由表 */
let hasRouteFlag = false
Expand Down
19 changes: 11 additions & 8 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
</a-col>
</a-row>

<GiThemeBtn class="theme-btn" />
<Background />

<!-- <div class="footer">
<div v-if="isDesktop" class="footer">
<div class="beian">
<div class="below text" v-html="appStore.getCopyright()"></div>
</div>
</div>-->
</div>

<GiThemeBtn class="theme-btn" />
<Background />
</div>
</template>

Expand All @@ -59,9 +59,11 @@ import AccountLogin from './components/account/index.vue'
import PhoneLogin from './components/phone/index.vue'
import EmailLogin from './components/email/index.vue'
import { useAppStore } from '@/stores'
import { useDevice } from '@/hooks'
defineOptions({ name: 'Login' })
const { isDesktop } = useDevice()
const appStore = useAppStore()
const title = computed(() => appStore.getTitle())
const logo = computed(() => appStore.getLogo())
Expand All @@ -83,6 +85,7 @@ const onOauth = async (source: string) => {
.login {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: var(--color-bg-5);
Expand Down Expand Up @@ -240,11 +243,11 @@ const onOauth = async (source: string) => {
.footer {
align-items: center;
box-sizing: border-box;
display: flex;
justify-content: center;
position: absolute;
bottom: 10px;
z-index: 999;
.beian {
.text {
color: #41464f;
font-size: 12px;
font-weight: 400;
letter-spacing: 0.2px;
Expand Down
56 changes: 40 additions & 16 deletions src/views/login/social/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,58 @@
<div></div>
</a-spin>
</template>

<script setup lang="ts">
import { isLogin } from '@/utils/auth'
import { bindSocialAccount } from '@/apis'
import { Message } from '@arco-design/web-vue'
import { useRoute, useRouter } from 'vue-router'
import { getCurrentInstance, ref } from 'vue'
const { proxy } = getCurrentInstance() as any
import { isLogin } from '@/utils/auth'
const route = useRoute()
const router = useRouter()
const loading = ref(false)
const source = route.query.source as string
const loading = ref(false)
/**
* 绑定第三方账号
*/
const handleBindSocial = () => {
// 三方账号登录
const handleSocialLogin = () => {
if (loading.value) return
loading.value = true
const { redirect, ...othersQuery } = router.currentRoute.value.query
userStore
.socialLogin(source, othersQuery)
.then(() => {
router.push({
path: (redirect as string) || '/',
query: {
...othersQuery
}
})
Message.success('欢迎使用')
})
.catch(() => {
router.push({
name: 'Login',
query: {
...othersQuery
}
})
})
.finally(() => {
loading.value = false
})
}
// 绑定三方账号
const handleBindSocial = () => {
if (loading.value) return
loading.value = true
const { ...othersQuery } = router.currentRoute.value.query
bindSocialAccount(source, othersQuery)
.then((res) => {
router.push({
path: '/setting/profile',
query: {
tab: 'security-setting'
...othersQuery
}
})
proxy.$message.success(res.msg)
Expand All @@ -35,7 +63,7 @@ const handleBindSocial = () => {
router.push({
path: '/setting/profile',
query: {
tab: 'security-setting'
...othersQuery
}
})
})
Expand All @@ -46,12 +74,8 @@ const handleBindSocial = () => {
if (isLogin()) {
handleBindSocial()
}
</script>

<script lang="ts">
export default {
name: 'SocialCallback'
} else {
handleSocialLogin()
}
</script>

Expand Down

0 comments on commit f701ca5

Please sign in to comment.