更新
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://json.schemastore.org/prettierrc",
|
"$schema": "https://json.schemastore.org/prettierrc",
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"printWidth": 260,
|
"printWidth": 260,
|
||||||
"useTabs": true,
|
"useTabs": true,
|
||||||
"tabWidth": 4
|
"tabWidth": 4
|
||||||
}
|
}
|
||||||
@@ -5,23 +5,23 @@ import pluginVue from 'eslint-plugin-vue'
|
|||||||
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
|
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
|
||||||
|
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
{
|
{
|
||||||
name: 'app/files-to-lint',
|
name: 'app/files-to-lint',
|
||||||
files: ['**/*.{vue,js,mjs,jsx}'],
|
files: ['**/*.{vue,js,mjs,jsx}'],
|
||||||
},
|
},
|
||||||
|
|
||||||
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
|
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**']),
|
||||||
|
|
||||||
{
|
{
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: {
|
globals: {
|
||||||
...globals.browser,
|
...globals.browser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
js.configs.recommended,
|
js.configs.recommended,
|
||||||
...pluginVue.configs['flat/essential'],
|
...pluginVue.configs['flat/essential'],
|
||||||
|
|
||||||
skipFormatting,
|
skipFormatting,
|
||||||
])
|
])
|
||||||
|
|||||||
3860
package-lock.json
generated
Normal file
3860
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -14,10 +14,10 @@
|
|||||||
"format": "prettier --write --experimental-cli src/"
|
"format": "prettier --write --experimental-cli src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.2",
|
"@ant-design/icons-vue": "^7.0.1",
|
||||||
|
"ant-design-vue": "^4.2.6",
|
||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"element-plus": "^2.13.1",
|
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"pinia": "^3.0.4",
|
"pinia": "^3.0.4",
|
||||||
"pinia-plugin-persistedstate": "^4.7.1",
|
"pinia-plugin-persistedstate": "^4.7.1",
|
||||||
|
|||||||
@@ -1,154 +0,0 @@
|
|||||||
/* 认证页面统一样式 */
|
|
||||||
.auth-container {
|
|
||||||
min-height: 100vh;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
||||||
padding: 20px;
|
|
||||||
position: relative;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-container::before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
top: -50%;
|
|
||||||
left: -50%;
|
|
||||||
width: 200%;
|
|
||||||
height: 200%;
|
|
||||||
background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 50%);
|
|
||||||
animation: rotate 20s linear infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes rotate {
|
|
||||||
from {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-card {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 420px;
|
|
||||||
background: rgba(255, 255, 255, 0.95);
|
|
||||||
backdrop-filter: blur(10px);
|
|
||||||
border-radius: 16px;
|
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
||||||
padding: 40px;
|
|
||||||
position: relative;
|
|
||||||
z-index: 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-header {
|
|
||||||
text-align: center;
|
|
||||||
margin-bottom: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-header .logo {
|
|
||||||
font-size: 48px;
|
|
||||||
margin-bottom: 16px;
|
|
||||||
color: #667eea;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-header h1 {
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #2c3e50;
|
|
||||||
margin: 0 0 8px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-header p {
|
|
||||||
font-size: 14px;
|
|
||||||
color: #7f8c8d;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-form {
|
|
||||||
margin-bottom: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-actions {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 24px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-actions .forgot-link {
|
|
||||||
color: #667eea;
|
|
||||||
text-decoration: none;
|
|
||||||
font-size: 14px;
|
|
||||||
transition: color 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-actions .forgot-link:hover {
|
|
||||||
color: #764ba2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-footer {
|
|
||||||
text-align: center;
|
|
||||||
padding-top: 24px;
|
|
||||||
border-top: 1px solid #eaeaea;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-footer .link {
|
|
||||||
color: #667eea;
|
|
||||||
text-decoration: none;
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: 500;
|
|
||||||
transition: color 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-footer .link:hover {
|
|
||||||
color: #764ba2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-footer .text {
|
|
||||||
color: #7f8c8d;
|
|
||||||
font-size: 14px;
|
|
||||||
margin: 0 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-button {
|
|
||||||
width: 100%;
|
|
||||||
height: 44px;
|
|
||||||
border-radius: 8px;
|
|
||||||
border: 1px solid #667eea;
|
|
||||||
background: transparent;
|
|
||||||
color: #667eea;
|
|
||||||
font-size: 14px;
|
|
||||||
transition: all 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-button:hover:not(:disabled) {
|
|
||||||
background: rgba(102, 126, 234, 0.05);
|
|
||||||
color: #764ba2;
|
|
||||||
border-color: #764ba2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.code-button:disabled {
|
|
||||||
border-color: #dcdfe6;
|
|
||||||
color: #c0c4cc;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.language-switcher {
|
|
||||||
position: absolute;
|
|
||||||
top: 20px;
|
|
||||||
right: 20px;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 响应式设计 */
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.auth-card {
|
|
||||||
padding: 30px 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.auth-header h1 {
|
|
||||||
font-size: 24px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/* 自定义 NProgress 样式 */
|
|
||||||
#nprogress {
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
#nprogress .bar {
|
|
||||||
background: linear-gradient(90deg, #00d4ff 0%, #7c4dff 100%);
|
|
||||||
position: fixed;
|
|
||||||
z-index: 9999;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 3px;
|
|
||||||
box-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 螺旋加载器样式 */
|
|
||||||
#nprogress .peg {
|
|
||||||
display: block;
|
|
||||||
position: absolute;
|
|
||||||
right: 0;
|
|
||||||
width: 100px;
|
|
||||||
height: 100%;
|
|
||||||
box-shadow:
|
|
||||||
0 0 10px #00d4ff,
|
|
||||||
0 0 5px #7c4dff;
|
|
||||||
opacity: 1;
|
|
||||||
transform: rotate(3deg) translate(0px, -4px);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 进度条动画 */
|
|
||||||
@keyframes nprogress-spinner {
|
|
||||||
0% {
|
|
||||||
transform: rotate(0deg);
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
transform: rotate(360deg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 如果启用加载器时的样式 */
|
|
||||||
#nprogress .spinner {
|
|
||||||
display: block;
|
|
||||||
position: fixed;
|
|
||||||
z-index: 9999;
|
|
||||||
top: 15px;
|
|
||||||
right: 15px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#nprogress .spinner-icon {
|
|
||||||
width: 18px;
|
|
||||||
height: 18px;
|
|
||||||
box-sizing: border-box;
|
|
||||||
border: solid 2px transparent;
|
|
||||||
border-top-color: #00d4ff;
|
|
||||||
border-left-color: #7c4dff;
|
|
||||||
border-radius: 50%;
|
|
||||||
animation: nprogress-spinner 400ms linear infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 进度条闪烁效果 */
|
|
||||||
@keyframes nprogress-flicker {
|
|
||||||
0% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
50% {
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
100% {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#nprogress .bar {
|
|
||||||
animation: nprogress-flicker 0.5s ease-in-out;
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ const userRoutes = [
|
|||||||
component: 'home',
|
component: 'home',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'dashboard',
|
title: 'dashboard',
|
||||||
icon: 'el-icon-odometer',
|
icon: 'DashboardOutlined',
|
||||||
role: ['admin']
|
role: ['admin']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
|
|
||||||
import ElementPlus from 'element-plus'
|
import Antd from 'ant-design-vue'
|
||||||
import 'element-plus/dist/index.css'
|
import 'ant-design-vue/dist/reset.css'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import pinia from './stores'
|
import pinia from './stores'
|
||||||
@@ -9,7 +9,7 @@ import i18n from './i18n'
|
|||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
|
|
||||||
app.use(ElementPlus)
|
app.use(Antd)
|
||||||
app.use(router)
|
app.use(router)
|
||||||
app.use(pinia)
|
app.use(pinia)
|
||||||
app.use(i18n)
|
app.use(i18n)
|
||||||
|
|||||||
@@ -1,147 +1,173 @@
|
|||||||
<script setup>
|
|
||||||
import { ref, reactive, onBeforeUnmount } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { useI18n } from '@/hooks/useI18n'
|
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { User, Lock } from '@element-plus/icons-vue'
|
|
||||||
import LanguageSwitcher from '@/layouts/components/LanguageSwitcher.vue'
|
|
||||||
import '@/assets/css/auth.css'
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
const router = useRouter()
|
|
||||||
const userStore = useUserStore()
|
|
||||||
|
|
||||||
const loginFormRef = ref(null)
|
|
||||||
const loading = ref(false)
|
|
||||||
|
|
||||||
const loginForm = reactive({
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
remember: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const loginRules = {
|
|
||||||
username: [
|
|
||||||
{ required: true, message: t('login.usernamePlaceholder'), trigger: 'blur' },
|
|
||||||
{ min: 3, max: 20, message: t('form.minLength', { min: 3, max: 20 }), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
password: [
|
|
||||||
{ required: true, message: t('login.passwordPlaceholder'), trigger: 'blur' },
|
|
||||||
{ min: 6, max: 20, message: t('form.minLength', { min: 6 }), trigger: 'blur' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleLogin = async () => {
|
|
||||||
if (!loginFormRef.value) return
|
|
||||||
|
|
||||||
await loginFormRef.value.validate(async (valid) => {
|
|
||||||
if (valid) {
|
|
||||||
loading.value = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 模拟登录请求
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1000))
|
|
||||||
|
|
||||||
// 模拟登录成功
|
|
||||||
const mockUserInfo = {
|
|
||||||
id: 1,
|
|
||||||
username: loginForm.username,
|
|
||||||
nickname: '管理员',
|
|
||||||
email: 'admin@example.com',
|
|
||||||
role: ['admin'],
|
|
||||||
avatar: ''
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockToken = 'mock-token-' + Date.now()
|
|
||||||
const mockRefreshToken = 'mock-refresh-token-' + Date.now()
|
|
||||||
|
|
||||||
userStore.setToken(mockToken)
|
|
||||||
userStore.setRefreshToken(mockRefreshToken)
|
|
||||||
userStore.setUserInfo(mockUserInfo)
|
|
||||||
|
|
||||||
ElMessage.success(t('login.loginSuccess'))
|
|
||||||
|
|
||||||
// 跳转到首页或重定向页面
|
|
||||||
const redirect = router.currentRoute.value.query.redirect || '/'
|
|
||||||
router.push(redirect)
|
|
||||||
} catch (error) {
|
|
||||||
ElMessage.error(error.message || t('login.loginFailed'))
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const goToRegister = () => {
|
|
||||||
router.push('/register')
|
|
||||||
}
|
|
||||||
|
|
||||||
const goToResetPassword = () => {
|
|
||||||
router.push('/reset-password')
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
if (loginFormRef.value) {
|
|
||||||
loginFormRef.value.clearValidate()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="auth-container">
|
<div class="login-container">
|
||||||
<div class="language-switcher">
|
<div class="login-wrapper">
|
||||||
<LanguageSwitcher />
|
<div class="login-card">
|
||||||
</div>
|
<div class="login-header">
|
||||||
|
<div class="login-logo">
|
||||||
<div class="auth-card">
|
<h1>Vue Admin</h1>
|
||||||
<div class="auth-header">
|
</div>
|
||||||
<div class="logo">
|
<p class="login-subtitle">欢迎回来</p>
|
||||||
<el-icon :size="48">
|
|
||||||
<User />
|
|
||||||
</el-icon>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>{{ t('login.title') }}</h1>
|
|
||||||
<p>{{ t('login.subtitle') }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-form ref="loginFormRef" :model="loginForm" :rules="loginRules" class="auth-form" size="large">
|
<a-form :model="formState" @finish="handleLogin" layout="vertical" class="login-form">
|
||||||
<el-form-item prop="username">
|
<a-form-item name="username" :rules="[{ required: true, message: '请输入用户名' }]">
|
||||||
<el-input v-model="loginForm.username" :placeholder="t('login.usernamePlaceholder')"
|
<a-input v-model:value="formState.username" placeholder="用户名" size="large"
|
||||||
:prefix-icon="User" />
|
:prefix="h(UserOutlined)" />
|
||||||
</el-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="password">
|
<a-form-item name="password" :rules="[{ required: true, message: '请输入密码' }]">
|
||||||
<el-input v-model="loginForm.password" type="password" :placeholder="t('login.passwordPlaceholder')"
|
<a-input-password v-model:value="formState.password" placeholder="密码" size="large"
|
||||||
:prefix-icon="Lock" show-password @keyup.enter="handleLogin" />
|
:prefix="h(LockOutlined)" />
|
||||||
</el-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<div class="form-options">
|
||||||
<el-checkbox v-model="loginForm.remember">
|
<a-checkbox v-model:checked="formState.remember">记住密码</a-checkbox>
|
||||||
{{ t('login.rememberMe') }}
|
<router-link to="/reset-password" class="forgot-password">
|
||||||
</el-checkbox>
|
忘记密码?
|
||||||
</el-form-item>
|
</router-link>
|
||||||
|
</div>
|
||||||
|
|
||||||
<el-form-item>
|
<a-form-item>
|
||||||
<el-button type="primary" :loading="loading" @click="handleLogin">
|
<a-button type="primary" html-type="submit" size="large" block :loading="loading">
|
||||||
{{ t('login.loginButton') }}
|
登录
|
||||||
</el-button>
|
</a-button>
|
||||||
</el-form-item>
|
</a-form-item>
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<div class="auth-actions">
|
<div class="form-footer">
|
||||||
<el-link type="primary" @click="goToResetPassword">
|
<span>还没有账号?</span>
|
||||||
{{ t('login.forgotPassword') }}
|
<router-link to="/register" class="register-link">
|
||||||
</el-link>
|
立即注册
|
||||||
</div>
|
</router-link>
|
||||||
|
</div>
|
||||||
<div class="auth-footer">
|
</a-form>
|
||||||
<span class="text">{{ t('login.noAccount') }}</span>
|
|
||||||
<router-link to="/register" class="link">
|
|
||||||
{{ t('login.registerNow') }}
|
|
||||||
</router-link>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { reactive, ref, h } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue';
|
||||||
|
|
||||||
|
// 定义组件名称(多词命名)
|
||||||
|
defineOptions({
|
||||||
|
name: 'LoginPage'
|
||||||
|
});
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const formState = reactive({
|
||||||
|
username: '',
|
||||||
|
password: '',
|
||||||
|
remember: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleLogin = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
// TODO: 实现登录逻辑
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
message.success('登录成功');
|
||||||
|
router.push('/');
|
||||||
|
} catch {
|
||||||
|
message.error('登录失败,请检查用户名和密码');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.login-container {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 40px;
|
||||||
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-logo h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 700;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
background-clip: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-subtitle {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-form-item) {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-input-affix-wrapper),
|
||||||
|
.login-form :deep(.ant-input) {
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-options {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forgot-password {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.forgot-password:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,196 +1,210 @@
|
|||||||
<script setup>
|
|
||||||
import { ref, reactive, onBeforeUnmount } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { useI18n } from '@/hooks/useI18n'
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { Lock, Message } from '@element-plus/icons-vue'
|
|
||||||
import LanguageSwitcher from '@/layouts/components/LanguageSwitcher.vue'
|
|
||||||
import '@/assets/css/auth.css'
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const resetFormRef = ref(null)
|
|
||||||
const loading = ref(false)
|
|
||||||
const countdown = ref(0)
|
|
||||||
const timer = ref(null)
|
|
||||||
|
|
||||||
const resetForm = reactive({
|
|
||||||
email: '',
|
|
||||||
code: '',
|
|
||||||
newPassword: '',
|
|
||||||
confirmPassword: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
const validatePass2 = (rule, value, callback) => {
|
|
||||||
if (value === '') {
|
|
||||||
callback(new Error(t('form.passwordMismatch')))
|
|
||||||
} else if (value !== resetForm.newPassword) {
|
|
||||||
callback(new Error(t('form.passwordMismatch')))
|
|
||||||
} else {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const resetRules = {
|
|
||||||
email: [
|
|
||||||
{ required: true, message: t('resetPassword.emailPlaceholder'), trigger: 'blur' },
|
|
||||||
{ type: 'email', message: t('resetPassword.emailRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
code: [
|
|
||||||
{ required: true, message: t('resetPassword.codePlaceholder'), trigger: 'blur' },
|
|
||||||
{ len: 6, message: t('resetPassword.codeRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
newPassword: [
|
|
||||||
{ required: true, message: t('resetPassword.newPasswordPlaceholder'), trigger: 'blur' },
|
|
||||||
{ min: 6, max: 20, message: t('resetPassword.passwordRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
confirmPassword: [
|
|
||||||
{ required: true, validator: validatePass2, trigger: 'blur' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const sendCode = () => {
|
|
||||||
if (!resetForm.email) {
|
|
||||||
ElMessage.warning(t('resetPassword.sendCodeFirst'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(resetForm.email)) {
|
|
||||||
ElMessage.warning(t('resetPassword.emailRule'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 模拟发送验证码
|
|
||||||
countdown.value = 60
|
|
||||||
timer.value = setInterval(() => {
|
|
||||||
countdown.value--
|
|
||||||
if (countdown.value <= 0) {
|
|
||||||
clearInterval(timer.value)
|
|
||||||
timer.value = null
|
|
||||||
}
|
|
||||||
}, 1000)
|
|
||||||
|
|
||||||
ElMessage.success(t('resetPassword.codeSent'))
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleReset = async () => {
|
|
||||||
if (!resetFormRef.value) return
|
|
||||||
|
|
||||||
await resetFormRef.value.validate(async (valid) => {
|
|
||||||
if (valid) {
|
|
||||||
loading.value = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 模拟重置密码请求
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
||||||
|
|
||||||
ElMessage.success(t('resetPassword.resetSuccess'))
|
|
||||||
|
|
||||||
// 清除定时器
|
|
||||||
if (timer.value) {
|
|
||||||
clearInterval(timer.value)
|
|
||||||
timer.value = null
|
|
||||||
countdown.value = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// 跳转到登录页
|
|
||||||
router.push('/login')
|
|
||||||
} catch (error) {
|
|
||||||
ElMessage.error(error.message || t('resetPassword.resetFailed'))
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const goToLogin = () => {
|
|
||||||
// 清除定时器
|
|
||||||
if (timer.value) {
|
|
||||||
clearInterval(timer.value)
|
|
||||||
timer.value = null
|
|
||||||
countdown.value = 0
|
|
||||||
}
|
|
||||||
router.push('/login')
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
if (resetFormRef.value) {
|
|
||||||
resetFormRef.value.clearValidate()
|
|
||||||
}
|
|
||||||
if (timer.value) {
|
|
||||||
clearInterval(timer.value)
|
|
||||||
timer.value = null
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="auth-container">
|
<div class="login-container">
|
||||||
<div class="language-switcher">
|
<div class="login-wrapper">
|
||||||
<LanguageSwitcher />
|
<div class="login-card">
|
||||||
</div>
|
<div class="login-header">
|
||||||
|
<div class="login-logo">
|
||||||
<div class="auth-card">
|
<h1>Vue Admin</h1>
|
||||||
<div class="auth-header">
|
</div>
|
||||||
<div class="logo">
|
<p class="login-subtitle">重置密码</p>
|
||||||
<el-icon :size="48">
|
|
||||||
<Lock />
|
|
||||||
</el-icon>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>{{ t('resetPassword.title') }}</h1>
|
|
||||||
<p>{{ t('resetPassword.subtitle') }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-form ref="resetFormRef" :model="resetForm" :rules="resetRules" class="auth-form" size="large">
|
<a-form :model="formState" @finish="handleReset" layout="vertical" class="login-form">
|
||||||
<el-form-item prop="email">
|
<a-form-item name="email" :rules="[
|
||||||
<el-input v-model="resetForm.email" :placeholder="t('resetPassword.emailPlaceholder')"
|
{ required: true, message: '请输入邮箱' },
|
||||||
:prefix-icon="Message" />
|
{ type: 'email', message: '请输入有效的邮箱地址' },
|
||||||
</el-form-item>
|
]">
|
||||||
|
<a-input v-model:value="formState.email" placeholder="邮箱地址" size="large"
|
||||||
|
:prefix="h(MailOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="code">
|
<a-form-item name="verificationCode" :rules="[{ required: true, message: '请输入验证码' }]">
|
||||||
<el-row :gutter="10">
|
<a-input v-model:value="formState.verificationCode" placeholder="验证码" size="large"
|
||||||
<el-col :span="14">
|
:prefix="h(SafetyOutlined)">
|
||||||
<el-input v-model="resetForm.code" :placeholder="t('resetPassword.codePlaceholder')"
|
<template #suffix>
|
||||||
:prefix-icon="Lock" maxlength="6" />
|
<a-button type="link" :disabled="countdown > 0" @click="sendCode" class="code-btn">
|
||||||
</el-col>
|
{{ countdown > 0 ? `${countdown}秒后重试` : '发送验证码' }}
|
||||||
<el-col :span="10">
|
</a-button>
|
||||||
<el-button class="code-button" :disabled="countdown > 0" @click="sendCode">
|
</template>
|
||||||
{{
|
</a-input>
|
||||||
countdown > 0
|
</a-form-item>
|
||||||
? t('resetPassword.resendCode', { seconds: countdown })
|
|
||||||
: t('resetPassword.sendCode')
|
|
||||||
}}
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item prop="newPassword">
|
<a-form-item name="newPassword" :rules="[
|
||||||
<el-input v-model="resetForm.newPassword" type="password"
|
{ required: true, message: '请输入新密码' },
|
||||||
:placeholder="t('resetPassword.newPasswordPlaceholder')" :prefix-icon="Lock" show-password />
|
{ min: 6, message: '密码至少6个字符' },
|
||||||
</el-form-item>
|
]">
|
||||||
|
<a-input-password v-model:value="formState.newPassword" placeholder="新密码" size="large"
|
||||||
|
:prefix="h(LockOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="confirmPassword">
|
<a-form-item name="confirmPassword" :rules="[
|
||||||
<el-input v-model="resetForm.confirmPassword" type="password"
|
{ required: true, message: '请确认新密码' },
|
||||||
:placeholder="t('resetPassword.confirmPasswordPlaceholder')" :prefix-icon="Lock" show-password
|
{ validator: validateConfirmPassword },
|
||||||
@keyup.enter="handleReset" />
|
]">
|
||||||
</el-form-item>
|
<a-input-password v-model:value="formState.confirmPassword" placeholder="确认新密码" size="large"
|
||||||
|
:prefix="h(LockOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<a-form-item>
|
||||||
<el-button type="primary" :loading="loading" @click="handleReset">
|
<a-button type="primary" html-type="submit" size="large" block :loading="loading">
|
||||||
{{ t('resetPassword.resetButton') }}
|
重置密码
|
||||||
</el-button>
|
</a-button>
|
||||||
</el-form-item>
|
</a-form-item>
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<div class="auth-footer">
|
<div class="form-footer">
|
||||||
<span class="text">{{ t('common.back') }}</span>
|
<span>记得密码了?</span>
|
||||||
<el-link type="primary" @click="goToLogin">
|
<router-link to="/login" class="register-link">
|
||||||
{{ t('resetPassword.backToLogin') }}
|
立即登录
|
||||||
</el-link>
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { reactive, ref, h } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
import {
|
||||||
|
MailOutlined,
|
||||||
|
SafetyOutlined,
|
||||||
|
LockOutlined,
|
||||||
|
} from '@ant-design/icons-vue';
|
||||||
|
|
||||||
|
// 定义组件名称(多词命名)
|
||||||
|
defineOptions({
|
||||||
|
name: 'ResetPasswordPage'
|
||||||
|
});
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const loading = ref(false);
|
||||||
|
const countdown = ref(0);
|
||||||
|
|
||||||
|
const formState = reactive({
|
||||||
|
email: '',
|
||||||
|
verificationCode: '',
|
||||||
|
newPassword: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const validateConfirmPassword = async (rule, value) => {
|
||||||
|
if (value !== formState.newPassword) {
|
||||||
|
return Promise.reject('两次输入的密码不一致');
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
const sendCode = () => {
|
||||||
|
if (!formState.email) {
|
||||||
|
message.warning('请先输入邮箱地址');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 实现发送验证码逻辑
|
||||||
|
message.success('验证码已发送');
|
||||||
|
countdown.value = 60;
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
countdown.value--;
|
||||||
|
if (countdown.value <= 0) {
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleReset = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
// TODO: 实现重置密码逻辑
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
message.success('密码重置成功,请登录');
|
||||||
|
router.push('/login');
|
||||||
|
} catch {
|
||||||
|
message.error('密码重置失败,请稍后重试');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.login-container {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 40px;
|
||||||
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-logo h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 700;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
background-clip: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-subtitle {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-form-item) {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-input-affix-wrapper),
|
||||||
|
.login-form :deep(.ant-input) {
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-btn {
|
||||||
|
padding: 0;
|
||||||
|
height: auto;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,162 +1,203 @@
|
|||||||
<script setup>
|
|
||||||
import { ref, reactive, onBeforeUnmount } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { useI18n } from '@/hooks/useI18n'
|
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
|
||||||
import { ElMessage } from 'element-plus'
|
|
||||||
import { User, Lock, Message } from '@element-plus/icons-vue'
|
|
||||||
import LanguageSwitcher from '@/layouts/components/LanguageSwitcher.vue'
|
|
||||||
import '@/assets/css/auth.css'
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
|
||||||
const router = useRouter()
|
|
||||||
const userStore = useUserStore()
|
|
||||||
|
|
||||||
const registerFormRef = ref(null)
|
|
||||||
const loading = ref(false)
|
|
||||||
|
|
||||||
const registerForm = reactive({
|
|
||||||
username: '',
|
|
||||||
email: '',
|
|
||||||
password: '',
|
|
||||||
confirmPassword: '',
|
|
||||||
agree: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const validatePass2 = (rule, value, callback) => {
|
|
||||||
if (value === '') {
|
|
||||||
callback(new Error(t('form.passwordMismatch')))
|
|
||||||
} else if (value !== registerForm.password) {
|
|
||||||
callback(new Error(t('form.passwordMismatch')))
|
|
||||||
} else {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const registerRules = {
|
|
||||||
username: [
|
|
||||||
{ required: true, message: t('register.usernamePlaceholder'), trigger: 'blur' },
|
|
||||||
{ min: 3, max: 20, message: t('register.usernameRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
email: [
|
|
||||||
{ required: true, message: t('register.emailPlaceholder'), trigger: 'blur' },
|
|
||||||
{ type: 'email', message: t('register.emailRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
password: [
|
|
||||||
{ required: true, message: t('register.passwordPlaceholder'), trigger: 'blur' },
|
|
||||||
{ min: 6, max: 20, message: t('register.passwordRule'), trigger: 'blur' }
|
|
||||||
],
|
|
||||||
confirmPassword: [
|
|
||||||
{ required: true, validator: validatePass2, trigger: 'blur' }
|
|
||||||
],
|
|
||||||
agree: [
|
|
||||||
{
|
|
||||||
validator: (rule, value, callback) => {
|
|
||||||
if (!value) {
|
|
||||||
callback(new Error(t('register.agreeRule')))
|
|
||||||
} else {
|
|
||||||
callback()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
trigger: 'change'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleRegister = async () => {
|
|
||||||
if (!registerFormRef.value) return
|
|
||||||
|
|
||||||
await registerFormRef.value.validate(async (valid) => {
|
|
||||||
if (valid) {
|
|
||||||
loading.value = true
|
|
||||||
|
|
||||||
try {
|
|
||||||
// 模拟注册请求
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 1500))
|
|
||||||
|
|
||||||
ElMessage.success(t('register.registerSuccess'))
|
|
||||||
|
|
||||||
// 跳转到登录页
|
|
||||||
router.push('/login')
|
|
||||||
} catch (error) {
|
|
||||||
ElMessage.error(error.message || t('register.registerFailed'))
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const goToLogin = () => {
|
|
||||||
router.push('/login')
|
|
||||||
}
|
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
if (registerFormRef.value) {
|
|
||||||
registerFormRef.value.clearValidate()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="auth-container">
|
<div class="login-container">
|
||||||
<div class="language-switcher">
|
<div class="login-wrapper">
|
||||||
<LanguageSwitcher />
|
<div class="login-card">
|
||||||
</div>
|
<div class="login-header">
|
||||||
|
<div class="login-logo">
|
||||||
<div class="auth-card">
|
<h1>Vue Admin</h1>
|
||||||
<div class="auth-header">
|
</div>
|
||||||
<div class="logo">
|
<p class="login-subtitle">创建新账号</p>
|
||||||
<el-icon :size="48">
|
|
||||||
<User />
|
|
||||||
</el-icon>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>{{ t('register.title') }}</h1>
|
|
||||||
<p>{{ t('register.subtitle') }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-form ref="registerFormRef" :model="registerForm" :rules="registerRules" class="auth-form" size="large">
|
<a-form :model="formState" @finish="handleRegister" layout="vertical" class="login-form">
|
||||||
<el-form-item prop="username">
|
<a-form-item name="username" :rules="[
|
||||||
<el-input v-model="registerForm.username" :placeholder="t('register.usernamePlaceholder')"
|
{ required: true, message: '请输入用户名' },
|
||||||
:prefix-icon="User" />
|
{ min: 3, message: '用户名至少3个字符' },
|
||||||
</el-form-item>
|
]">
|
||||||
|
<a-input v-model:value="formState.username" placeholder="用户名" size="large"
|
||||||
|
:prefix="h(UserOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="email">
|
<a-form-item name="email" :rules="[
|
||||||
<el-input v-model="registerForm.email" :placeholder="t('register.emailPlaceholder')"
|
{ required: true, message: '请输入邮箱' },
|
||||||
:prefix-icon="Message" />
|
{ type: 'email', message: '请输入有效的邮箱地址' },
|
||||||
</el-form-item>
|
]">
|
||||||
|
<a-input v-model:value="formState.email" placeholder="邮箱地址" size="large"
|
||||||
|
:prefix="h(MailOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="password">
|
<a-form-item name="password" :rules="[
|
||||||
<el-input v-model="registerForm.password" type="password"
|
{ required: true, message: '请输入密码' },
|
||||||
:placeholder="t('register.passwordPlaceholder')" :prefix-icon="Lock" show-password />
|
{ min: 6, message: '密码至少6个字符' },
|
||||||
</el-form-item>
|
]">
|
||||||
|
<a-input-password v-model:value="formState.password" placeholder="密码" size="large"
|
||||||
|
:prefix="h(LockOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="confirmPassword">
|
<a-form-item name="confirmPassword" :rules="[
|
||||||
<el-input v-model="registerForm.confirmPassword" type="password"
|
{ required: true, message: '请确认密码' },
|
||||||
:placeholder="t('register.confirmPasswordPlaceholder')" :prefix-icon="Lock" show-password
|
{ validator: validateConfirmPassword },
|
||||||
@keyup.enter="handleRegister" />
|
]">
|
||||||
</el-form-item>
|
<a-input-password v-model:value="formState.confirmPassword" placeholder="确认密码" size="large"
|
||||||
|
:prefix="h(LockOutlined)" />
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item prop="agree">
|
<a-form-item>
|
||||||
<el-checkbox v-model="registerForm.agree">
|
<a-checkbox v-model:checked="formState.agree">
|
||||||
<span v-html="t('register.agreeTerms')"></span>
|
我已阅读并同意
|
||||||
<el-link type="primary">{{ t('register.terms') }}</el-link>
|
<a href="#" class="link">用户协议</a>
|
||||||
</el-checkbox>
|
和
|
||||||
</el-form-item>
|
<a href="#" class="link">隐私政策</a>
|
||||||
|
</a-checkbox>
|
||||||
|
</a-form-item>
|
||||||
|
|
||||||
<el-form-item>
|
<a-form-item>
|
||||||
<el-button type="primary" :loading="loading" @click="handleRegister">
|
<a-button type="primary" html-type="submit" size="large" block :loading="loading"
|
||||||
{{ t('register.registerButton') }}
|
:disabled="!formState.agree">
|
||||||
</el-button>
|
注册
|
||||||
</el-form-item>
|
</a-button>
|
||||||
</el-form>
|
</a-form-item>
|
||||||
|
|
||||||
<div class="auth-footer">
|
<div class="form-footer">
|
||||||
<span class="text">{{ t('register.hasAccount') }}</span>
|
<span>已有账号?</span>
|
||||||
<router-link to="/login" class="link">
|
<router-link to="/login" class="register-link">
|
||||||
{{ t('register.loginNow') }}
|
立即登录
|
||||||
</router-link>
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</a-form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { reactive, ref, h } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { message } from 'ant-design-vue';
|
||||||
|
import {
|
||||||
|
UserOutlined,
|
||||||
|
MailOutlined,
|
||||||
|
LockOutlined,
|
||||||
|
} from '@ant-design/icons-vue';
|
||||||
|
|
||||||
|
// 定义组件名称(多词命名)
|
||||||
|
defineOptions({
|
||||||
|
name: 'RegisterPage'
|
||||||
|
});
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const formState = reactive({
|
||||||
|
username: '',
|
||||||
|
email: '',
|
||||||
|
password: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
agree: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const validateConfirmPassword = async (rule, value) => {
|
||||||
|
if (value !== formState.password) {
|
||||||
|
return Promise.reject('两次输入的密码不一致');
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRegister = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
// TODO: 实现注册逻辑
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
message.success('注册成功,请登录');
|
||||||
|
router.push('/login');
|
||||||
|
} catch {
|
||||||
|
message.error('注册失败,请稍后重试');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.login-container {
|
||||||
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-wrapper {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 40px;
|
||||||
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-header {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-logo h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 700;
|
||||||
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||||
|
-webkit-background-clip: text;
|
||||||
|
-webkit-text-fill-color: transparent;
|
||||||
|
background-clip: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-subtitle {
|
||||||
|
margin: 8px 0 0;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form {
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-form-item) {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.login-form :deep(.ant-input-affix-wrapper),
|
||||||
|
.login-form :deep(.ant-input) {
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
color: #666;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link {
|
||||||
|
color: #667eea;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 500;
|
||||||
|
margin-left: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.register-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -97,16 +97,6 @@ function transformMenusToRoutes(menus) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加路由到路由器
|
|
||||||
* @param {Array} routes - 要添加的路由数组
|
|
||||||
*/
|
|
||||||
function addRoutes(routes) {
|
|
||||||
routes.forEach(route => {
|
|
||||||
router.addRoute(route)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由守卫
|
* 路由守卫
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import config from '@/config'
|
import config from '@/config'
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
import { ElMessage } from 'element-plus'
|
import { message } from 'ant-design-vue'
|
||||||
import router from '@/router'
|
import router from '@/router'
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
@@ -45,7 +45,7 @@ http.interceptors.response.use(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 其他错误码处理
|
// 其他错误码处理
|
||||||
ElMessage.error(message || '请求失败')
|
message.error(message || '请求失败')
|
||||||
return Promise.reject(new Error(message || '请求失败'))
|
return Promise.reject(new Error(message || '请求失败'))
|
||||||
},
|
},
|
||||||
async (error) => {
|
async (error) => {
|
||||||
@@ -54,7 +54,7 @@ http.interceptors.response.use(
|
|||||||
|
|
||||||
// 无响应(网络错误、超时等)
|
// 无响应(网络错误、超时等)
|
||||||
if (!response) {
|
if (!response) {
|
||||||
ElMessage.error('网络错误,请检查网络连接')
|
message.error('网络错误,请检查网络连接')
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ http.interceptors.response.use(
|
|||||||
requests = []
|
requests = []
|
||||||
userStore.logout()
|
userStore.logout()
|
||||||
router.push('/login')
|
router.push('/login')
|
||||||
ElMessage.error('登录已过期,请重新登录')
|
message.error('登录已过期,请重新登录')
|
||||||
return Promise.reject(refreshError)
|
return Promise.reject(refreshError)
|
||||||
} finally {
|
} finally {
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
@@ -104,25 +104,25 @@ http.interceptors.response.use(
|
|||||||
|
|
||||||
// 403 禁止访问
|
// 403 禁止访问
|
||||||
if (status === 403) {
|
if (status === 403) {
|
||||||
ElMessage.error('没有权限访问该资源')
|
message.error('没有权限访问该资源')
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 404 资源不存在
|
// 404 资源不存在
|
||||||
if (status === 404) {
|
if (status === 404) {
|
||||||
ElMessage.error('请求的资源不存在')
|
message.error('请求的资源不存在')
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 500 服务器错误
|
// 500 服务器错误
|
||||||
if (status >= 500) {
|
if (status >= 500) {
|
||||||
ElMessage.error('服务器错误,请稍后重试')
|
message.error('服务器错误,请稍后重试')
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其他错误
|
// 其他错误
|
||||||
const errorMessage = data?.message || error.message || '请求失败'
|
const errorMessage = data?.message || error.message || '请求失败'
|
||||||
ElMessage.error(errorMessage)
|
message.error(errorMessage)
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user