diff --git a/src/api/login/index.ts b/src/api/login/index.ts index b65a90cf..1ffb38d6 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -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({ 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 cc4bb47e..4f95852f 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 d8172d27..f955b36b 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 } }, @@ -333,6 +333,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ { path: '/mall/product', // 商品中心 component: Layout, + name: 'Product', meta: { hidden: true }, @@ -394,6 +395,7 @@ const remainingRouter: AppRouteRecordRaw[] = [ { path: '/mall/trade', // 交易中心 component: Layout, + name: 'Trade', meta: { hidden: true }, diff --git a/src/views/Login/Login.vue b/src/views/Login/Login.vue index 19ffe2d7..d1a5e7f5 100644 --- a/src/views/Login/Login.vue +++ b/src/views/Login/Login.vue @@ -55,7 +55,7 @@ - + @@ -70,7 +70,7 @@ import { useAppStore } from '@/store/modules/app' import { ThemeSwitch } from '@/layout/components/ThemeSwitch' import { LocaleDropdown } from '@/layout/components/LocaleDropdown' -import { LoginForm, MobileForm, QrCodeForm, RegisterForm, SSOLoginVue } from './components' +import { LoginForm, MobileForm, QrCodeForm, RegisterForm } from './components' defineOptions({ name: 'Login' }) 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 a4eb0b92..9bee2523 100644 --- a/src/views/Login/components/LoginForm.vue +++ b/src/views/Login/components/LoginForm.vue @@ -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