chore: initial commit - CloudSearch v0.0.2
This commit is contained in:
100
packages/frontend/src/pages/admin/AdminLogin.vue
Executable file
100
packages/frontend/src/pages/admin/AdminLogin.vue
Executable file
@@ -0,0 +1,100 @@
|
||||
<template>
|
||||
<div class="admin-login-page">
|
||||
<div class="login-card">
|
||||
<h1 class="login-title">{{ siteName || 'CloudSearch' }} 管理后台</h1>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="0" size="large" @keyup.enter="handleLogin">
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="form.username" placeholder="用户名" prefix-icon="User" />
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input v-model="form.password" type="password" placeholder="密码" prefix-icon="Lock" show-password />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="loading" class="login-btn" @click="handleLogin">
|
||||
登录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<p v-if="errorMsg" class="error-msg">{{ errorMsg }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { User, Lock } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { getSiteConfig, adminLogin } from '../../api'
|
||||
import type { ElForm } from 'element-plus'
|
||||
|
||||
const formRef = ref<InstanceType<typeof ElForm>>()
|
||||
const loading = ref(false)
|
||||
const errorMsg = ref('')
|
||||
const siteName = ref('')
|
||||
|
||||
// 获取网站名称
|
||||
getSiteConfig().then(cfg => {
|
||||
if (cfg.site_name) siteName.value = cfg.site_name
|
||||
}).catch(() => {})
|
||||
|
||||
const form = reactive({
|
||||
username: '',
|
||||
password: '',
|
||||
})
|
||||
|
||||
const rules = {
|
||||
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
async function handleLogin() {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
|
||||
loading.value = true
|
||||
errorMsg.value = ''
|
||||
try {
|
||||
const res = await adminLogin(form.username, form.password)
|
||||
localStorage.setItem('admin_token', res.token)
|
||||
ElMessage.success('登录成功')
|
||||
window.location.href = '/admin'
|
||||
} catch (e: any) {
|
||||
errorMsg.value = e?.response?.data?.message || e?.message || '登录失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-login-page {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
.login-card {
|
||||
width: 400px;
|
||||
padding: 40px;
|
||||
background: var(--bg-white);
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
.login-title {
|
||||
text-align: center;
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #303133;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
.login-btn {
|
||||
width: 100%;
|
||||
}
|
||||
.error-msg {
|
||||
text-align: center;
|
||||
color: #f56c6c;
|
||||
font-size: 14px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user