170 lines
4.3 KiB
Vue
170 lines
4.3 KiB
Vue
<template>
|
|
<div class="login-wrap">
|
|
<div class="login-lang">
|
|
<n-select
|
|
v-model:value="currentLocale"
|
|
:options="localeOptions"
|
|
size="small"
|
|
style="width: 120px"
|
|
@update:value="changeLocale"
|
|
/>
|
|
</div>
|
|
<div class="login-left">
|
|
<div class="login-left-inner">
|
|
<div class="logo">艺</div>
|
|
<h1>{{ t('pages.login.title') }}</h1>
|
|
<p>{{ t('pages.login.subtitle') }}</p>
|
|
</div>
|
|
</div>
|
|
<div class="login-right">
|
|
<n-card class="login-card" :bordered="false">
|
|
<h2 class="login-card-title">{{ t('pages.login.subtitle') }}</h2>
|
|
<n-form ref="formRef" :model="form" :rules="rules" @keyup.enter="onSubmit">
|
|
<n-form-item path="username" :label="t('pages.login.username')">
|
|
<n-input
|
|
v-model:value="form.username"
|
|
:placeholder="t('pages.login.placeholderUser')"
|
|
size="large"
|
|
>
|
|
<template #prefix><n-icon :component="PersonOutline" /></template>
|
|
</n-input>
|
|
</n-form-item>
|
|
<n-form-item path="password" :label="t('pages.login.password')">
|
|
<n-input
|
|
v-model:value="form.password"
|
|
type="password"
|
|
show-password-on="click"
|
|
:placeholder="t('pages.login.placeholderPass')"
|
|
size="large"
|
|
>
|
|
<template #prefix><n-icon :component="LockClosedOutline" /></template>
|
|
</n-input>
|
|
</n-form-item>
|
|
<n-button type="primary" size="large" block :loading="loading" @click="onSubmit">
|
|
{{ t('pages.login.submit') }}
|
|
</n-button>
|
|
</n-form>
|
|
</n-card>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref } from 'vue';
|
|
import { useRouter } from 'vue-router';
|
|
import { useI18n } from 'vue-i18n';
|
|
import type { FormInst, FormRules } from 'naive-ui';
|
|
import { PersonOutline, LockClosedOutline } from '@vicons/ionicons5';
|
|
import { useAuthStore } from '@/stores/auth';
|
|
import { SUPPORTED_LOCALES, setLocale } from '@/locales';
|
|
import { message } from '@/utils/feedback';
|
|
|
|
const { t, locale } = useI18n();
|
|
const router = useRouter();
|
|
const auth = useAuthStore();
|
|
|
|
const formRef = ref<FormInst | null>(null);
|
|
const form = ref({ username: '', password: '' });
|
|
const loading = ref(false);
|
|
const currentLocale = ref(locale.value);
|
|
const localeOptions = SUPPORTED_LOCALES.map((l) => ({ label: l.label, value: l.value }));
|
|
|
|
const rules: FormRules = {
|
|
username: { required: true, message: () => t('pages.login.placeholderUser'), trigger: 'blur' },
|
|
password: { required: true, message: () => t('pages.login.placeholderPass'), trigger: 'blur' },
|
|
};
|
|
|
|
function changeLocale(val: string) {
|
|
setLocale(val);
|
|
currentLocale.value = val;
|
|
}
|
|
|
|
async function onSubmit() {
|
|
try {
|
|
await formRef.value?.validate();
|
|
} catch {
|
|
return;
|
|
}
|
|
loading.value = true;
|
|
try {
|
|
await auth.login(form.value.username, form.value.password);
|
|
message.success(t('pages.login.success'));
|
|
router.push({ name: 'dashboard' });
|
|
} catch {
|
|
/* 错误已由拦截器提示 */
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.login-wrap {
|
|
position: relative;
|
|
display: flex;
|
|
height: 100vh;
|
|
background: #f0f2f5;
|
|
}
|
|
.login-lang {
|
|
position: absolute;
|
|
top: 20px;
|
|
right: 24px;
|
|
z-index: 2;
|
|
}
|
|
.login-left {
|
|
flex: 1 1 55%;
|
|
background: linear-gradient(135deg, #1f3864 0%, #2e5496 100%);
|
|
color: #fff;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.login-left-inner {
|
|
text-align: center;
|
|
padding: 24px;
|
|
}
|
|
.login-left-inner .logo {
|
|
width: 72px;
|
|
height: 72px;
|
|
margin: 0 auto 24px;
|
|
border-radius: 18px;
|
|
background: rgba(255, 255, 255, 0.16);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 38px;
|
|
font-weight: 700;
|
|
}
|
|
.login-left-inner h1 {
|
|
font-size: 28px;
|
|
margin: 0 0 12px;
|
|
}
|
|
.login-left-inner p {
|
|
font-size: 16px;
|
|
opacity: 0.85;
|
|
margin: 0;
|
|
}
|
|
.login-right {
|
|
flex: 1 1 45%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 24px;
|
|
}
|
|
.login-card {
|
|
width: 100%;
|
|
max-width: 380px;
|
|
}
|
|
.login-card-title {
|
|
margin: 0 0 24px;
|
|
font-size: 22px;
|
|
color: #1f2937;
|
|
text-align: center;
|
|
}
|
|
@media (max-width: 768px) {
|
|
.login-left {
|
|
display: none;
|
|
}
|
|
}
|
|
</style>
|