Skip to content

Commit f701ca5

Browse files
committed
refactor: 完善三方账号登录
1 parent c938028 commit f701ca5

File tree

4 files changed

+52
-26
lines changed

4 files changed

+52
-26
lines changed

src/router/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const constantRoutes: RouteRecordRaw[] = [
4848
},
4949
{
5050
path: '/social/callback',
51-
name: 'SocialCallback',
5251
component: () => import('@/views/login/social/index.vue'),
5352
meta: { hidden: true }
5453
},

src/router/permission.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getToken } from '@/utils/auth'
44
import { isHttp } from '@/utils/validate'
55

66
/** 免登录白名单 */
7-
const whiteList = ['/login', '/register']
7+
const whiteList = ['/login', '/social/callback']
88

99
/** 是否已经生成过路由表 */
1010
let hasRouteFlag = false

src/views/login/index.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
</a-col>
4242
</a-row>
4343

44-
<GiThemeBtn class="theme-btn" />
45-
<Background />
46-
47-
<!-- <div class="footer">
44+
<div v-if="isDesktop" class="footer">
4845
<div class="beian">
4946
<div class="below text" v-html="appStore.getCopyright()"></div>
5047
</div>
51-
</div>-->
48+
</div>
49+
50+
<GiThemeBtn class="theme-btn" />
51+
<Background />
5252
</div>
5353
</template>
5454

@@ -59,9 +59,11 @@ import AccountLogin from './components/account/index.vue'
5959
import PhoneLogin from './components/phone/index.vue'
6060
import EmailLogin from './components/email/index.vue'
6161
import { useAppStore } from '@/stores'
62+
import { useDevice } from '@/hooks'
6263
6364
defineOptions({ name: 'Login' })
6465
66+
const { isDesktop } = useDevice()
6567
const appStore = useAppStore()
6668
const title = computed(() => appStore.getTitle())
6769
const logo = computed(() => appStore.getLogo())
@@ -83,6 +85,7 @@ const onOauth = async (source: string) => {
8385
.login {
8486
height: 100%;
8587
display: flex;
88+
flex-direction: column;
8689
justify-content: center;
8790
align-items: center;
8891
background-color: var(--color-bg-5);
@@ -240,11 +243,11 @@ const onOauth = async (source: string) => {
240243
.footer {
241244
align-items: center;
242245
box-sizing: border-box;
243-
display: flex;
244-
justify-content: center;
246+
position: absolute;
247+
bottom: 10px;
248+
z-index: 999;
245249
.beian {
246250
.text {
247-
color: #41464f;
248251
font-size: 12px;
249252
font-weight: 400;
250253
letter-spacing: 0.2px;

src/views/login/social/index.vue

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,58 @@
33
<div></div>
44
</a-spin>
55
</template>
6+
67
<script setup lang="ts">
7-
import { isLogin } from '@/utils/auth'
88
import { bindSocialAccount } from '@/apis'
9+
import { Message } from '@arco-design/web-vue'
910
import { useRoute, useRouter } from 'vue-router'
10-
import { getCurrentInstance, ref } from 'vue'
11-
const { proxy } = getCurrentInstance() as any
11+
import { isLogin } from '@/utils/auth'
12+
1213
const route = useRoute()
1314
const router = useRouter()
14-
const loading = ref(false)
1515
const source = route.query.source as string
16+
const loading = ref(false)
1617
17-
/**
18-
* 绑定第三方账号
19-
*/
20-
const handleBindSocial = () => {
18+
// 三方账号登录
19+
const handleSocialLogin = () => {
2120
if (loading.value) return
2221
loading.value = true
2322
const { redirect, ...othersQuery } = router.currentRoute.value.query
23+
userStore
24+
.socialLogin(source, othersQuery)
25+
.then(() => {
26+
router.push({
27+
path: (redirect as string) || '/',
28+
query: {
29+
...othersQuery
30+
}
31+
})
32+
Message.success('欢迎使用')
33+
})
34+
.catch(() => {
35+
router.push({
36+
name: 'Login',
37+
query: {
38+
...othersQuery
39+
}
40+
})
41+
})
42+
.finally(() => {
43+
loading.value = false
44+
})
45+
}
46+
47+
// 绑定三方账号
48+
const handleBindSocial = () => {
49+
if (loading.value) return
50+
loading.value = true
51+
const { ...othersQuery } = router.currentRoute.value.query
2452
bindSocialAccount(source, othersQuery)
2553
.then((res) => {
2654
router.push({
2755
path: '/setting/profile',
2856
query: {
29-
tab: 'security-setting'
57+
...othersQuery
3058
}
3159
})
3260
proxy.$message.success(res.msg)
@@ -35,7 +63,7 @@ const handleBindSocial = () => {
3563
router.push({
3664
path: '/setting/profile',
3765
query: {
38-
tab: 'security-setting'
66+
...othersQuery
3967
}
4068
})
4169
})
@@ -46,12 +74,8 @@ const handleBindSocial = () => {
4674
4775
if (isLogin()) {
4876
handleBindSocial()
49-
}
50-
</script>
51-
52-
<script lang="ts">
53-
export default {
54-
name: 'SocialCallback'
77+
} else {
78+
handleSocialLogin()
5579
}
5680
</script>
5781

0 commit comments

Comments
 (0)