mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-10-25 18:57:15 +08:00
refactor: 完善三方账号登录
This commit is contained in:
@@ -48,7 +48,6 @@ export const constantRoutes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/social/callback',
|
path: '/social/callback',
|
||||||
name: 'SocialCallback',
|
|
||||||
component: () => import('@/views/login/social/index.vue'),
|
component: () => import('@/views/login/social/index.vue'),
|
||||||
meta: { hidden: true }
|
meta: { hidden: true }
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { getToken } from '@/utils/auth'
|
|||||||
import { isHttp } from '@/utils/validate'
|
import { isHttp } from '@/utils/validate'
|
||||||
|
|
||||||
/** 免登录白名单 */
|
/** 免登录白名单 */
|
||||||
const whiteList = ['/login', '/register']
|
const whiteList = ['/login', '/social/callback']
|
||||||
|
|
||||||
/** 是否已经生成过路由表 */
|
/** 是否已经生成过路由表 */
|
||||||
let hasRouteFlag = false
|
let hasRouteFlag = false
|
||||||
|
|||||||
@@ -41,14 +41,14 @@
|
|||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
|
|
||||||
<GiThemeBtn class="theme-btn" />
|
<div v-if="isDesktop" class="footer">
|
||||||
<Background />
|
|
||||||
|
|
||||||
<!-- <div class="footer">
|
|
||||||
<div class="beian">
|
<div class="beian">
|
||||||
<div class="below text" v-html="appStore.getCopyright()"></div>
|
<div class="below text" v-html="appStore.getCopyright()"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>-->
|
</div>
|
||||||
|
|
||||||
|
<GiThemeBtn class="theme-btn" />
|
||||||
|
<Background />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -59,9 +59,11 @@ import AccountLogin from './components/account/index.vue'
|
|||||||
import PhoneLogin from './components/phone/index.vue'
|
import PhoneLogin from './components/phone/index.vue'
|
||||||
import EmailLogin from './components/email/index.vue'
|
import EmailLogin from './components/email/index.vue'
|
||||||
import { useAppStore } from '@/stores'
|
import { useAppStore } from '@/stores'
|
||||||
|
import { useDevice } from '@/hooks'
|
||||||
|
|
||||||
defineOptions({ name: 'Login' })
|
defineOptions({ name: 'Login' })
|
||||||
|
|
||||||
|
const { isDesktop } = useDevice()
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const title = computed(() => appStore.getTitle())
|
const title = computed(() => appStore.getTitle())
|
||||||
const logo = computed(() => appStore.getLogo())
|
const logo = computed(() => appStore.getLogo())
|
||||||
@@ -83,6 +85,7 @@ const onOauth = async (source: string) => {
|
|||||||
.login {
|
.login {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: var(--color-bg-5);
|
background-color: var(--color-bg-5);
|
||||||
@@ -240,11 +243,11 @@ const onOauth = async (source: string) => {
|
|||||||
.footer {
|
.footer {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
display: flex;
|
position: absolute;
|
||||||
justify-content: center;
|
bottom: 10px;
|
||||||
|
z-index: 999;
|
||||||
.beian {
|
.beian {
|
||||||
.text {
|
.text {
|
||||||
color: #41464f;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
letter-spacing: 0.2px;
|
letter-spacing: 0.2px;
|
||||||
|
|||||||
@@ -3,30 +3,58 @@
|
|||||||
<div></div>
|
<div></div>
|
||||||
</a-spin>
|
</a-spin>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { isLogin } from '@/utils/auth'
|
|
||||||
import { bindSocialAccount } from '@/apis'
|
import { bindSocialAccount } from '@/apis'
|
||||||
|
import { Message } from '@arco-design/web-vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { getCurrentInstance, ref } from 'vue'
|
import { isLogin } from '@/utils/auth'
|
||||||
const { proxy } = getCurrentInstance() as any
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const loading = ref(false)
|
|
||||||
const source = route.query.source as string
|
const source = route.query.source as string
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
/**
|
// 三方账号登录
|
||||||
* 绑定第三方账号
|
const handleSocialLogin = () => {
|
||||||
*/
|
|
||||||
const handleBindSocial = () => {
|
|
||||||
if (loading.value) return
|
if (loading.value) return
|
||||||
loading.value = true
|
loading.value = true
|
||||||
const { redirect, ...othersQuery } = router.currentRoute.value.query
|
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)
|
bindSocialAccount(source, othersQuery)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
router.push({
|
router.push({
|
||||||
path: '/setting/profile',
|
path: '/setting/profile',
|
||||||
query: {
|
query: {
|
||||||
tab: 'security-setting'
|
...othersQuery
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
proxy.$message.success(res.msg)
|
proxy.$message.success(res.msg)
|
||||||
@@ -35,7 +63,7 @@ const handleBindSocial = () => {
|
|||||||
router.push({
|
router.push({
|
||||||
path: '/setting/profile',
|
path: '/setting/profile',
|
||||||
query: {
|
query: {
|
||||||
tab: 'security-setting'
|
...othersQuery
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -46,12 +74,8 @@ const handleBindSocial = () => {
|
|||||||
|
|
||||||
if (isLogin()) {
|
if (isLogin()) {
|
||||||
handleBindSocial()
|
handleBindSocial()
|
||||||
}
|
} else {
|
||||||
</script>
|
handleSocialLogin()
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
export default {
|
|
||||||
name: 'SocialCallback'
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user