Commit 4d77d7e1 by dhb52

feat: 社交平台登录

parent 889334bc
......@@ -47,6 +47,18 @@ export const smsLogin = (data: SmsLoginVO) => {
return request.post({ url: '/system/auth/sms-login', data })
}
// 社交快捷登录,使用 code 授权码
export function socialLogin(type: string, code: string, state: string) {
return request.post({
url: '/system/auth/social-login',
data: {
type,
code,
state
}
})
}
// 社交授权的跳转
export const socialAuthRedirect = (type: number, redirectUri: string) => {
return request.get({
......
......@@ -2,6 +2,9 @@ export type UserLoginVO = {
username: string
password: string
captchaVerification: string
socialType?: string
socialCode?: string
socialState?: string
}
export type TokenType = {
......
......@@ -141,6 +141,7 @@ export default {
},
router: {
login: '登录',
socialLogin: '社交登录',
home: '首页',
analysis: '分析页',
workplace: '工作台'
......
......@@ -186,12 +186,12 @@ const remainingRouter: AppRouteRecordRaw[] = [
}
},
{
path: '/sso',
component: () => import('@/views/Login/Login.vue'),
name: 'SSOLogin',
path: '/social-login',
component: () => import('@/views/Login/SocialLogin.vue'),
name: 'SocialLogin',
meta: {
hidden: true,
title: t('router.login'),
title: t('router.socialLogin'),
noTagsView: true
}
},
......
......@@ -284,8 +284,13 @@ const doSocialLogin = async (type: number) => {
})
}
// 计算 redirectUri
// tricky: type、redirect需要先encode一次,否则钉钉回调会丢失。
// 配合 Login/SocialLogin.vue#getUrlValue() 使用
const redirectUri =
location.origin + '/social-login?type=' + type + '&redirect=' + (redirect.value || '/')
location.origin +
'/social-login?' +
encodeURIComponent(`type=${type}&redirect=${redirect.value || '/'}`)
// 进行跳转
const res = await LoginApi.socialAuthRedirect(type, encodeURIComponent(redirectUri))
window.location.href = res
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment