feat: add admin login

This commit is contained in:
yanghao05
2025-04-16 20:16:41 +08:00
parent e95fc65f5f
commit 4a9836db68
7 changed files with 88 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
<script setup>
import { authService } from '@/api/authService';
import { useAuthStore } from '@/stores/auth';
import Button from 'primevue/button';
import Card from 'primevue/card';
@@ -10,17 +11,32 @@ import { useRouter } from 'vue-router';
const router = useRouter();
const authStore = useAuthStore();
const username = ref('');
const password = ref('');
const username = ref('admin');
const password = ref('xixi@0202');
const loading = ref(false);
const errorMessage = ref('');
const validateForm = () => {
if (!username.value.trim()) {
errorMessage.value = '请输入用户名';
return false;
}
if (!password.value) {
errorMessage.value = '请输入密码';
return false;
}
return true;
};
const handleLogin = async () => {
if (!validateForm()) return;
loading.value = true;
errorMessage.value = '';
try {
await authStore.login(username.value, password.value);
const token = await authService.login(username.value, password.value);
authStore.setToken(token);
router.push('/');
} catch (error) {
errorMessage.value = error.message || '登录失败';