114 lines
2.6 KiB
Vue
114 lines
2.6 KiB
Vue
<template>
|
|||
|
|
<div class="login-container">
|
||
|
|
<el-card class="login-card">
|
||
|
|
<template #header>
|
||
|
|
<div class="card-header">
|
||
|
|
<h2>CC Cloud</h2>
|
||
|
|
<p>Claude Code 管理平台</p>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<el-form :model="loginForm" :rules="rules" ref="formRef" @submit.prevent="handleLogin">
|
||
|
|
<el-form-item prop="username">
|
||
|
|
<el-input
|
||
|
|
v-model="loginForm.username"
|
||
|
|
placeholder="用户名"
|
||
|
|
prefix-icon="User"
|
||
|
|
size="large"
|
||
|
|
/>
|
||
|
|
</el-form-item>
|
||
|
|
|
||
|
|
<el-form-item prop="password">
|
||
|
|
<el-input
|
||
|
|
v-model="loginForm.password"
|
||
|
|
type="password"
|
||
|
|
placeholder="密码"
|
||
|
|
prefix-icon="Lock"
|
||
|
|
size="large"
|
||
|
|
@keyup.enter="handleLogin"
|
||
|
|
/>
|
||
|
|
</el-form-item>
|
||
|
|
|
||
|
|
<el-form-item>
|
||
|
|
<el-button type="primary" size="large" style="width: 100%" :loading="loading" @click="handleLogin">
|
||
|
|
登录
|
||
|
|
</el-button>
|
||
|
|
</el-form-item>
|
||
|
|
</el-form>
|
||
|
|
</el-card>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<script setup lang="ts">
|
||
|
|
import { reactive, ref } from 'vue';
|
||
|
|
import { useRouter } from 'vue-router';
|
||
|
|
import { ElMessage } from 'element-plus';
|
||
|
|
import type { FormInstance, FormRules } from 'element-plus';
|
||
|
|
import { useAuthStore } from '@/stores/auth';
|
||
|
|
|
||
|
|
const router = useRouter();
|
||
|
|
const authStore = useAuthStore();
|
||
|
|
|
||
|
|
const formRef = ref<FormInstance>();
|
||
|
|
const loading = ref(false);
|
||
|
|
|
||
|
|
const loginForm = reactive({
|
||
|
|
username: '',
|
||
|
|
password: '',
|
||
|
|
});
|
||
|
|
|
||
|
|
const rules: FormRules = {
|
||
|
|
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
||
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
||
|
|
};
|
||
|
|
|
||
|
|
const handleLogin = async () => {
|
||
|
|
if (!formRef.value) return;
|
||
|
|
|
||
|
|
await formRef.value.validate(async (valid) => {
|
||
|
|
if (!valid) return;
|
||
|
|
|
||
|
|
loading.value = true;
|
||
|
|
try {
|
||
|
|
await authStore.login(loginForm);
|
||
|
|
ElMessage.success('登录成功');
|
||
|
|
router.push('/');
|
||
|
|
} catch (error: any) {
|
||
|
|
ElMessage.error(error.message || '登录失败');
|
||
|
|
} finally {
|
||
|
|
loading.value = false;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<style scoped>
|
||
|
|
.login-container {
|
||
|
|
display: flex;
|
||
|
|
justify-content: center;
|
||
|
|
align-items: center;
|
||
|
|
width: 100%;
|
||
|
|
height: 100vh;
|
||
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||
|
|
}
|
||
|
|
|
||
|
|
.login-card {
|
||
|
|
width: 400px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.card-header {
|
||
|
|
text-align: center;
|
||
|
|
}
|
||
|
|
|
||
|
|
.card-header h2 {
|
||
|
|
margin: 0;
|
||
|
|
font-size: 24px;
|
||
|
|
color: #303133;
|
||
|
|
}
|
||
|
|
|
||
|
|
.card-header p {
|
||
|
|
margin: 8px 0 0;
|
||
|
|
font-size: 14px;
|
||
|
|
color: #909399;
|
||
|
|
}
|
||
|
|
</style>
|