From 5bf9baf456bb166049ff1720480118ffff63a3ca Mon Sep 17 00:00:00 2001 From: dhb52 Date: Sun, 15 Oct 2023 14:26:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A4=BE=E4=BA=A4=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 4d77d7e1366215930bd4661bc3f94b6e6a306bc8) --- src/api/login/index.ts | 12 + src/api/login/types.ts | 3 + src/locales/zh-CN.ts | 1 + src/router/modules/remaining.ts | 8 +- src/views/Login/SocialLogin.vue | 343 +++++++++++++++++++++++ src/views/Login/components/LoginForm.vue | 7 +- 6 files changed, 369 insertions(+), 5 deletions(-) create mode 100644 src/views/Login/SocialLogin.vue diff --git a/src/api/login/index.ts b/src/api/login/index.ts index 6ab3edc5..8822d2ea 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -47,6 +47,18 @@ export const smsLoginApi = (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 socialAuthRedirectApi = (type: number, redirectUri: string) => { return request.get({ diff --git a/src/api/login/types.ts b/src/api/login/types.ts index b2173f72..fff81225 100644 --- a/src/api/login/types.ts +++ b/src/api/login/types.ts @@ -2,6 +2,9 @@ export type UserLoginVO = { username: string password: string captchaVerification: string + socialType?: string + socialCode?: string + socialState?: string } export type TokenType = { diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 26a7b5ee..c76a9755 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -141,6 +141,7 @@ export default { }, router: { login: '登录', + socialLogin: '社交登录', home: '首页', analysis: '分析页', workplace: '工作台' diff --git a/src/router/modules/remaining.ts b/src/router/modules/remaining.ts index 019cea2d..96abf6ac 100644 --- a/src/router/modules/remaining.ts +++ b/src/router/modules/remaining.ts @@ -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 } }, diff --git a/src/views/Login/SocialLogin.vue b/src/views/Login/SocialLogin.vue new file mode 100644 index 00000000..6bbfc1df --- /dev/null +++ b/src/views/Login/SocialLogin.vue @@ -0,0 +1,343 @@ + + + + + diff --git a/src/views/Login/components/LoginForm.vue b/src/views/Login/components/LoginForm.vue index 777b8aa6..d75dc3ca 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -285,8 +285,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.socialAuthRedirectApi(type, encodeURIComponent(redirectUri)) window.location.href = res