Compare commits

...

3 Commits

Author SHA1 Message Date
b678ef1f9e modify logout
Some checks failed
build quyun / Build (push) Failing after 28m54s
2025-12-04 10:05:36 +08:00
1cfccc4c39 fix: trim login info 2025-12-04 10:03:17 +08:00
0eaa1d8e9f fix: Cannot read properties of undefined (reading 'push') 2025-12-04 09:49:27 +08:00
3 changed files with 12 additions and 7 deletions

View File

@@ -60,7 +60,7 @@ const handleLogout = () => {
</div>
</template>
<template #end>
<Button label="Logout" icon="pi pi-power-off" severity="secondary" text @click="handleLogout" />
<Button label="退出登录" icon="pi pi-power-off" severity="secondary" text @click="handleLogout" />
</template>
</Menubar>
</header>

View File

@@ -1,6 +1,6 @@
import { router } from '@/router';
import { useAuthStore } from '@/stores/auth';
import axios from 'axios';
import { useRouter } from 'vue-router';
// Create axios instance with default config
const httpClient = axios.create({
@@ -37,7 +37,6 @@ httpClient.interceptors.response.use(
if (error.response.status === 401) {
const authStore = useAuthStore();
authStore.logout();
const router = useRouter();
// Redirect to login page
router.push('/login');
}

View File

@@ -17,15 +17,18 @@ const loading = ref(false);
const errorMessage = ref('');
const validateForm = () => {
if (!username.value.trim()) {
const trimmedUsername = username.value.trim();
const trimmedPassword = password.value.trim();
if (!trimmedUsername) {
errorMessage.value = '请输入用户名';
return false;
}
if (!password.value) {
if (!trimmedPassword) {
errorMessage.value = '请输入密码';
return false;
}
if (password.value.length < 8) {
if (trimmedPassword.length < 8) {
errorMessage.value = '密码至少需要8个字符';
return false;
}
@@ -38,8 +41,11 @@ const handleLogin = async () => {
loading.value = true;
errorMessage.value = '';
const trimmedUsername = username.value.trim();
const trimmedPassword = password.value.trim();
try {
const resp = await authService.login(username.value, password.value);
const resp = await authService.login(trimmedUsername, trimmedPassword);
const { token } = resp.data;
if (!token) {
alert('登录失败');