Compare commits
3 Commits
9ad60e8925
...
b678ef1f9e
| Author | SHA1 | Date | |
|---|---|---|---|
| b678ef1f9e | |||
| 1cfccc4c39 | |||
| 0eaa1d8e9f |
@@ -60,7 +60,7 @@ const handleLogout = () => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template #end>
|
<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>
|
</template>
|
||||||
</Menubar>
|
</Menubar>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import { router } from '@/router';
|
||||||
import { useAuthStore } from '@/stores/auth';
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
// Create axios instance with default config
|
// Create axios instance with default config
|
||||||
const httpClient = axios.create({
|
const httpClient = axios.create({
|
||||||
@@ -37,7 +37,6 @@ httpClient.interceptors.response.use(
|
|||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
authStore.logout();
|
authStore.logout();
|
||||||
const router = useRouter();
|
|
||||||
// Redirect to login page
|
// Redirect to login page
|
||||||
router.push('/login');
|
router.push('/login');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,18 @@ const loading = ref(false);
|
|||||||
const errorMessage = ref('');
|
const errorMessage = ref('');
|
||||||
|
|
||||||
const validateForm = () => {
|
const validateForm = () => {
|
||||||
if (!username.value.trim()) {
|
const trimmedUsername = username.value.trim();
|
||||||
|
const trimmedPassword = password.value.trim();
|
||||||
|
|
||||||
|
if (!trimmedUsername) {
|
||||||
errorMessage.value = '请输入用户名';
|
errorMessage.value = '请输入用户名';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!password.value) {
|
if (!trimmedPassword) {
|
||||||
errorMessage.value = '请输入密码';
|
errorMessage.value = '请输入密码';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (password.value.length < 8) {
|
if (trimmedPassword.length < 8) {
|
||||||
errorMessage.value = '密码至少需要8个字符';
|
errorMessage.value = '密码至少需要8个字符';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -38,8 +41,11 @@ const handleLogin = async () => {
|
|||||||
loading.value = true;
|
loading.value = true;
|
||||||
errorMessage.value = '';
|
errorMessage.value = '';
|
||||||
|
|
||||||
|
const trimmedUsername = username.value.trim();
|
||||||
|
const trimmedPassword = password.value.trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const resp = await authService.login(username.value, password.value);
|
const resp = await authService.login(trimmedUsername, trimmedPassword);
|
||||||
const { token } = resp.data;
|
const { token } = resp.data;
|
||||||
if (!token) {
|
if (!token) {
|
||||||
alert('登录失败');
|
alert('登录失败');
|
||||||
|
|||||||
Reference in New Issue
Block a user