79 lines
4.0 KiB
Vue
79 lines
4.0 KiB
Vue
<template>
|
||
<main class="salon-admin-login">
|
||
<section class="login-panel">
|
||
<div class="brand-mark">S</div>
|
||
<p class="eyebrow">SALON PLATFORM</p>
|
||
<h1>Salon 管理后台</h1>
|
||
<p class="intro">平台管理员专用入口,统一查看门店经营与运营事项。</p>
|
||
|
||
<a-form :model="formState" :rules="formRules" layout="vertical" @finish="handleLogin">
|
||
<a-form-item label="管理员账号" name="account">
|
||
<a-input v-model:value="formState.account" size="large" autocomplete="username" placeholder="请输入管理员账号" />
|
||
</a-form-item>
|
||
<a-form-item label="登录密码" name="password">
|
||
<a-input-password v-model:value="formState.password" size="large" autocomplete="current-password" placeholder="请输入登录密码" />
|
||
</a-form-item>
|
||
<a-button type="primary" size="large" html-type="submit" block :loading="loading">进入管理后台</a-button>
|
||
</a-form>
|
||
|
||
</section>
|
||
</main>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { reactive, ref } from 'vue'
|
||
import { useRouter } from 'vue-router'
|
||
import { message } from 'ant-design-vue'
|
||
import { adminAuthApi } from '@/api/admin'
|
||
import { ACCOUNT_REGEX, ACCOUNT_RULE_MESSAGE, sanitizeAccountInput } from '@/utils/account'
|
||
import { runWithGlobalLoading } from '@/utils/action-loading'
|
||
import { resolveAdminLandingPath } from '@/utils/admin-auth-bootstrap'
|
||
|
||
const router = useRouter()
|
||
const loading = ref(false)
|
||
const formState = reactive({ account: '', password: '' })
|
||
const formRules: any = {
|
||
account: [
|
||
{ required: true, message: '请输入管理员账号', trigger: 'blur' },
|
||
{ pattern: ACCOUNT_REGEX, message: ACCOUNT_RULE_MESSAGE, trigger: 'blur' }
|
||
],
|
||
password: [{ required: true, message: '请输入登录密码', trigger: 'blur' }]
|
||
}
|
||
|
||
const handleLogin = async () => {
|
||
formState.account = sanitizeAccountInput(formState.account)
|
||
loading.value = true
|
||
try {
|
||
const response = await runWithGlobalLoading(() => adminAuthApi.login({
|
||
account: formState.account,
|
||
password: formState.password
|
||
})) as any
|
||
localStorage.setItem('adminAccessToken', response.accessToken)
|
||
localStorage.setItem('adminRefreshToken', response.refreshToken)
|
||
localStorage.setItem('adminUserInfo', JSON.stringify(response.userInfo))
|
||
sessionStorage.setItem('adminAccessToken', response.accessToken)
|
||
sessionStorage.setItem('adminRefreshToken', response.refreshToken)
|
||
message.success('管理员登录成功')
|
||
await router.push(resolveAdminLandingPath())
|
||
} catch (error: any) {
|
||
message.error(error?.message || '登录失败,请检查管理员账号和密码')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
</script>
|
||
|
||
<style scoped>
|
||
.salon-admin-login { display: grid; place-items: center; min-height: 100dvh; padding: 32px 20px; background: var(--theme-gradient); color: var(--theme-neutral); }
|
||
.login-panel { position: relative; width: min(100%, 420px); padding: 42px 42px 34px; border: 1px solid rgba(59, 147, 132, .2); border-radius: 24px; background: var(--theme-card-bg); box-shadow: 0 28px 80px rgba(25, 83, 72, .15); backdrop-filter: blur(16px); }
|
||
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #2d9d87; color: #fff; font-size: 23px; font-weight: 800; box-shadow: 0 10px 24px rgba(45, 157, 135, .28); }
|
||
.eyebrow { margin: 22px 0 8px; color: #2d9d87; font-size: 11px; font-weight: 800; letter-spacing: .16em; }
|
||
h1 { margin: 0; font-size: 29px; letter-spacing: -.03em; }
|
||
.intro { margin: 10px 0 30px; color: #6a8580; font-size: 13px; line-height: 1.7; }
|
||
:deep(.ant-form-item-label > label) { color: #476a64; font-size: 12px; font-weight: 700; }
|
||
:deep(.ant-input), :deep(.ant-input-affix-wrapper) { border-color: #dcebe6; border-radius: 10px; background: #fbfefd; }
|
||
:deep(.ant-btn-primary) { height: 46px; border: 0; border-radius: 11px; background: #2d9d87; box-shadow: 0 10px 22px rgba(45, 157, 135, .2); }
|
||
@media (max-width: 520px) { .login-panel { padding: 32px 24px 26px; border-radius: 20px; } h1 { font-size: 25px; } }
|
||
</style>
|