feat: add admin login
This commit is contained in:
@@ -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 || '登录失败';
|
||||
|
||||
Reference in New Issue
Block a user