diff --git a/src/apis/auth/index.ts b/src/apis/auth/index.ts index 399c8a3..b9c6cdb 100644 --- a/src/apis/auth/index.ts +++ b/src/apis/auth/index.ts @@ -8,6 +8,26 @@ export function accountLogin(req: Auth.AccountLoginReq) { return http.post(`${BASE_URL}/account`, req) } +/** @desc 手机号登录 */ +export function phoneLogin(req: Auth.PhoneLoginReq) { + return http.post(`${BASE_URL}/phone`, req) +} + +/** @desc 邮箱登录 */ +export function emailLogin(req: Auth.EmailLoginReq) { + return http.post(`${BASE_URL}/email`, req) +} + +/** @desc 三方账号登录 */ +export function socialLogin(source: string, req: any) { + return http.post(`/oauth/${source}`, req) +} + +/** @desc 三方账号登录授权 */ +export function socialAuth(source: string) { + return http.get(`/oauth/${source}`) +} + /** @desc 退出登录 */ export function logout() { return http.post(`${BASE_URL}/logout`) @@ -22,8 +42,3 @@ export const getUserInfo = () => { export const getUserRoute = () => { return http.get(`${BASE_URL}/route`) } - -/** @desc 第三方登录授权 */ -export function socialAuth(source: string) { - return http.get(`/oauth/${source}`) -} \ No newline at end of file diff --git a/src/apis/auth/type.ts b/src/apis/auth/type.ts index 7d0b2b1..45b5a2c 100644 --- a/src/apis/auth/type.ts +++ b/src/apis/auth/type.ts @@ -40,6 +40,7 @@ export interface RouteItem { affix: boolean } +/** 账号登录请求参数 */ export interface AccountLoginReq { username: string password: string @@ -47,6 +48,18 @@ export interface AccountLoginReq { uuid: string } +/** 手机号登录请求参数 */ +export interface PhoneLoginReq { + phone: string + captcha: string +} + +/** 邮箱登录请求参数 */ +export interface EmailLoginReq { + email: string + captcha: string +} + // 登录响应类型 export interface LoginResp { token: string diff --git a/src/apis/common/captcha.ts b/src/apis/common/captcha.ts index 4963f0d..1c3c3f1 100644 --- a/src/apis/common/captcha.ts +++ b/src/apis/common/captcha.ts @@ -7,11 +7,13 @@ const BASE_URL = '/captcha' export function getImageCaptcha() { return http.get(`${BASE_URL}/img`) } -/**@desc 获取手机验证码 */ -export function getPhoneCaptcha(query: { phone: string }) { + +/** @desc 获取短信验证码 */ +export function getSmsCaptcha(query: { phone: string }) { return http.get(`${BASE_URL}/sms`, query) } -/**@desc 获取邮箱验证码 */ + +/** @desc 获取邮箱验证码 */ export function getEmailCaptcha(query: { email: string }) { return http.get(`${BASE_URL}/mail`, query) } diff --git a/src/components/GiThemeBtn/index.vue b/src/components/GiThemeBtn/index.vue index 966f7c9..1367cd2 100644 --- a/src/components/GiThemeBtn/index.vue +++ b/src/components/GiThemeBtn/index.vue @@ -1,8 +1,8 @@ diff --git a/src/layout/components/Logo.vue b/src/layout/components/Logo.vue index 48e2f04..719661b 100644 --- a/src/layout/components/Logo.vue +++ b/src/layout/components/Logo.vue @@ -45,10 +45,6 @@ const toHome = () => { display: flex; justify-content: center; align-items: center; - // .logo { - // width: 24px; - // height: 24px; - // } .system-name { display: none; } @@ -62,7 +58,7 @@ const toHome = () => { flex-shrink: 0; } .system-name { - padding-left: 10px; + padding-left: 8px; white-space: nowrap; transition: color 0.3s; &:hover { diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts index acdff91..ee1c58c 100644 --- a/src/stores/modules/user.ts +++ b/src/stores/modules/user.ts @@ -1,8 +1,18 @@ import { defineStore } from 'pinia' import { ref, reactive, computed } from 'vue' import { resetRouter } from '@/router' -import { accountLogin as accountLoginApi, logout as logoutApi, getUserInfo as getUserInfoApi } from '@/apis' -import { socialAuth, type UserInfo } from '@/apis' +import { + accountLogin as accountLoginApi, + phoneLogin as phoneLoginApi, + emailLogin as emailLoginApi, + socialLogin as socialLoginApi, + logout as logoutApi, + getUserInfo as getUserInfoApi, + type AccountLoginReq, + type PhoneLoginReq, + type EmailLoginReq, + type UserInfo +} from '@/apis' import { setToken, clearToken, getToken } from '@/utils/auth' import { resetHasRouteFlag } from '@/router/permission' import getAvatar from '@/utils/avatar' @@ -31,21 +41,33 @@ const storeSetup = () => { } // 登录 - const accountLogin = async (params: any) => { - const res = await accountLoginApi(params) + const accountLogin = async (req: AccountLoginReq) => { + const res = await accountLoginApi(req) setToken(res.data.token) token.value = res.data.token } - // 三方账号身份登录 - const socialLogin = async (source: string, req: any) => { - try { - const res = await socialAuth(source, req) - setToken(res.data.token) - } catch (err) { - clearToken() - throw err - } + + // 邮箱登录 + const emailLogin = async (req: EmailLoginReq) => { + const res = await emailLoginApi(req) + setToken(res.data.token) + token.value = res.data.token } + + // 手机号登录 + const phoneLogin = async (req: PhoneLoginReq) => { + const res = await phoneLoginApi(req) + setToken(res.data.token) + token.value = res.data.token + } + + // 三方账号登录 + const socialLogin = async (source: string, req: any) => { + const res = await socialLoginApi(source, req) + setToken(res.data.token) + token.value = res.data.token + } + // 退出登录 const logout = async () => { try { @@ -88,6 +110,8 @@ const storeSetup = () => { roles, permissions, accountLogin, + emailLogin, + phoneLogin, socialLogin, logout, logoutCallBack, diff --git a/src/views/login/components/account/index.vue b/src/views/login/components/account/index.vue index 6401fd4..10426f9 100644 --- a/src/views/login/components/account/index.vue +++ b/src/views/login/components/account/index.vue @@ -8,20 +8,14 @@ size="large" @submit="handleLogin" > - - - - + + - - - - + + - - - + 验证码 @@ -32,7 +26,7 @@ - 登录 + 立即登录 @@ -70,13 +64,13 @@ const rules: FormInstance['rules'] = { const userStore = useUserStore() const router = useRouter() -const { loading, setLoading } = useLoading() +const loading = ref(false) // 登录 const handleLogin = async () => { try { const isInvalid = await formRef.value?.validate() if (isInvalid) return - setLoading(true) + loading.value = true await userStore.accountLogin({ username: form.username, password: encryptByRsa(form.password) || '', @@ -97,7 +91,7 @@ const handleLogin = async () => { getCaptcha() form.captcha = '' } finally { - setLoading(false) + loading.value = false } } @@ -122,14 +116,23 @@ onMounted(() => { border-radius: 4px; font-size: 13px; } + .arco-input-wrapper.arco-input-error { background-color: rgb(var(--danger-1)); - border-color: rgb(var(--danger-4)); + border-color: rgb(var(--danger-3)); } +.arco-input-wrapper.arco-input-error:hover { + background-color: rgb(var(--danger-1)); + border-color: rgb(var(--danger-6)); +} + .arco-input-wrapper :deep(.arco-input) { font-size: 13px; color: var(--color-text-1); } +.arco-input-wrapper:hover { + border-color: rgb(var(--arcoblue-6)); +} .captcha { width: 111px; diff --git a/src/views/login/components/email/index.vue b/src/views/login/components/email/index.vue new file mode 100644 index 0000000..c0449e3 --- /dev/null +++ b/src/views/login/components/email/index.vue @@ -0,0 +1,156 @@ + + + + + diff --git a/src/views/login/components/phone/index.vue b/src/views/login/components/phone/index.vue new file mode 100644 index 0000000..025d18c --- /dev/null +++ b/src/views/login/components/phone/index.vue @@ -0,0 +1,159 @@ + + + + + diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 57526f7..b1d7be1 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -14,15 +14,21 @@