Compare commits
3 Commits
9ad60e8925
...
b678ef1f9e
| Author | SHA1 | Date | |
|---|---|---|---|
| b678ef1f9e | |||
| 1cfccc4c39 | |||
| 0eaa1d8e9f |
@@ -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>
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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('登录失败');
|
||||
|
||||
Reference in New Issue
Block a user