diff --git a/.env.development b/.env.development index a05742f..c77c0df 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,4 @@ # VITE_APP_URL = http://192.168.31.82:8771 # VITE_APP_URL = http://18.167.251.121:10095 -VITE_APP_URL = https://www.lc-api.aida.com.hk \ No newline at end of file +VITE_APP_URL = https://www.lc-api.aida.com.hk +VITE_GOOGLE_CLIENT_ID = 216037134725-7q8vqp0ohtmohlosltkfg7bd2v29rm5a.apps.googleusercontent.com diff --git a/.env.production b/.env.production index 3e65b04..54a50e7 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,3 @@ -VITE_APP_URL = https://www.lc-api.aida.com.hk \ No newline at end of file +VITE_APP_URL = https://www.lc-api.aida.com.hk +# VITE_APP_URL = http://18.167.251.121:10095 +VITE_GOOGLE_CLIENT_ID = 29310152396-nnsd3h533fld665oguu8ovrt1nukmt46.apps.googleusercontent.com diff --git a/src/api/login.ts b/src/api/login.ts index 85b6b34..efa60dc 100644 --- a/src/api/login.ts +++ b/src/api/login.ts @@ -47,3 +47,15 @@ export const LogOut = (): Promise => { method: 'get' }) } + +// Google登录/注册参数类型 +interface GoogleAuthParamsType { + credential?: string // Google ID Token (用于One Tap登录) +} +export const googleAuth = (data: GoogleAuthParamsType): Promise => { + return request({ + url: '/api/auth/parseGoogleCredential', + method: 'get', + params: data + }) +} diff --git a/src/views/login/LoginPage.vue b/src/views/login/LoginPage.vue index 0e62376..c7c9060 100644 --- a/src/views/login/LoginPage.vue +++ b/src/views/login/LoginPage.vue @@ -28,10 +28,11 @@
Forgot password?
-
+ +
@@ -48,9 +49,9 @@ import { ref, reactive, computed } from 'vue' import { useRouter } from 'vue-router' import { useUserInfoStore } from '@/stores' import { showToast } from 'vant' -import { google } from '@/assets/base64' -import { fetchRegisterOrLogin } from '@/api/login' +import { fetchRegisterOrLogin, googleAuth } from '@/api/login' import { encryptPassword } from '@/utils/tools' +import GoogleLogin from './components/GoogleLogin.vue' const router = useRouter() const userInfoStore = useUserInfoStore() @@ -111,13 +112,15 @@ const handleLogin = async () => { isLoading.value = true const encryptedPassword = encryptPassword(formData.password) - fetchRegisterOrLogin({ ...formData, password: encryptedPassword, operationType: 'LOGIN' }).then((response) => { - console.log('登录成功', response) - userInfoStore.setToken(response.token) - userInfoStore.setUserInfo(response.user) - showToast('login success') - router.replace('/stylist/customer') - }) + fetchRegisterOrLogin({ ...formData, password: encryptedPassword, operationType: 'LOGIN' }).then( + (response) => { + console.log('登录成功', response) + userInfoStore.setToken(response.token) + userInfoStore.setUserInfo(response.user) + showToast('login success') + router.replace('/stylist/customer') + } + ) } // 处理忘记密码 @@ -127,13 +130,15 @@ const handleForgotPassword = () => { } // 处理Google登录 -const handleGoogleLogin = async () => { +const handleGoogleLogin = async (credential: string) => { try { isLoading.value = true - showToast('Google login is not available yet') - - // 这里添加Google OAuth登录逻辑 - // const response = await googleLoginAPI() + const result = await googleAuth({ credential }) + // console.log('result', result) + userInfoStore.setToken(result.token) + userInfoStore.setUserInfo(result.user) + showToast('Google login successful') + router.replace('/stylist/customer') } catch (error) { console.error('Google登录失败:', error) showToast('Google login failed, please try again') @@ -234,12 +239,12 @@ const handleSignup = () => { -moz-backdrop-filter: blur(35px); -ms-backdrop-filter: blur(35px); -o-backdrop-filter: blur(35px); - border: .2rem solid rgba(255, 255, 255, 0.15); + border: 0.2rem solid rgba(255, 255, 255, 0.15); border-radius: 4.79rem; padding: 11.2rem 8.62rem 14.28rem 7.18rem; box-shadow: 0 0.8rem 3.2rem rgba(0, 0, 0, 0.1); overflow: hidden; - border: .2rem solid #fff; + border: 0.2rem solid #fff; font-size: 3.83rem; } @@ -247,7 +252,7 @@ const handleSignup = () => { width: 100%; height: 10rem; padding: 1.6rem 2rem; - border: .2rem solid #fff; + border: 0.2rem solid #fff; background: transparent; border-radius: 7.1rem; color: white; @@ -293,7 +298,7 @@ const handleSignup = () => { .google-button { width: 100%; padding: 1.6rem; - border: .2rem solid #fff; + border: 0.2rem solid #fff; border-radius: 7rem; font-size: 3.83rem; cursor: pointer; @@ -303,6 +308,12 @@ const handleSignup = () => { column-gap: 3.1rem; margin-bottom: 1.67rem; } + +.google-icon { + width: 4.8rem; + height: 4.8rem; +} + .sign-up-button { font-family: 'satoshiRegular'; font-size: 2.39rem; @@ -310,11 +321,6 @@ const handleSignup = () => { text-align: center; } -.google-icon { - width: 4.8rem; - height: 4.8rem; -} - .footer { position: relative; text-align: center; diff --git a/src/views/login/SignupPage.vue b/src/views/login/SignupPage.vue index ceecb34..ab0b56e 100644 --- a/src/views/login/SignupPage.vue +++ b/src/views/login/SignupPage.vue @@ -30,10 +30,7 @@ -
- - Sign up with Google -
+ @@ -48,11 +45,13 @@ import { ref, reactive } from 'vue' import { useRouter } from 'vue-router' import { showToast } from 'vant' -import { google } from '@/assets/base64' -import { fetchRegisterOrLogin } from '@/api/login' +import { fetchRegisterOrLogin, googleAuth } from '@/api/login' import { encryptPassword } from '@/utils/tools' +import { useUserInfoStore } from '@/stores' +import GoogleLogin from './components/GoogleLogin.vue' const router = useRouter() +const userInfoStore = useUserInfoStore() // 表单数据 const formData = reactive({ @@ -120,10 +119,11 @@ const handleConfirm = async () => { fetchRegisterOrLogin({ ...formData, password: encryptedPassword, operationType: 'REGISTER' }) .then((res) => { console.log('res', res) - showToast('register success') + showToast('Register successful') router.push('/login') }) .catch((err) => { + console.log('err', err) showToast(err.message) }) .finally(() => { @@ -131,16 +131,17 @@ const handleConfirm = async () => { }) } -// 处理Google登录 -const handleSignupByGoogle = async () => { +// 处理Google注册 +const handleGoogleSignup = async (credential: string) => { try { isLoading.value = true - showToast('Google sign up is not available yet') - - // 这里添加Google OAuth登录逻辑 - // const response = await googleLoginAPI() + const result = await googleAuth({ credential }) + userInfoStore.setToken(result.token) + userInfoStore.setUserInfo(result.user) + showToast('Google sign up successful') + router.replace('/stylist/customer') } catch (error) { - console.error('Google登录失败:', error) + console.error('Google注册失败:', error) showToast(error?.message || 'Google sign up failed, please try again') } finally { isLoading.value = false @@ -232,12 +233,12 @@ const handleSignupByGoogle = async () => { -moz-backdrop-filter: blur(35px); -ms-backdrop-filter: blur(35px); -o-backdrop-filter: blur(35px); - border: .2rem solid rgba(255, 255, 255, 0.15); + border: 0.2rem solid rgba(255, 255, 255, 0.15); border-radius: 4.79rem; padding: 11.2rem 8.62rem 14.28rem 7.18rem; box-shadow: 0 0.8rem 3.2rem rgba(0, 0, 0, 0.1); overflow: hidden; - border: .2rem solid #fff; + border: 0.2rem solid #fff; font-size: 3.83rem; } @@ -245,7 +246,7 @@ const handleSignupByGoogle = async () => { width: 100%; height: 10rem; padding: 1.6rem 2rem; - border: .2rem solid #fff; + border: 0.2rem solid #fff; background: transparent; border-radius: 7.1rem; color: white; @@ -277,23 +278,6 @@ const handleSignupByGoogle = async () => { } } -.google-button { - width: 100%; - padding: 1.6rem; - border: .2rem solid #fff; - border-radius: 7rem; - font-size: 3.83rem; - cursor: pointer; - display: flex; - align-items: center; - justify-content: center; - column-gap: 3.1rem; -} - -.google-icon { - width: 4.8rem; - height: 4.8rem; -} .footer { position: relative; diff --git a/src/views/login/components/GoogleLogin.vue b/src/views/login/components/GoogleLogin.vue new file mode 100644 index 0000000..8562882 --- /dev/null +++ b/src/views/login/components/GoogleLogin.vue @@ -0,0 +1,189 @@ + + +