fix: trim login info
This commit is contained in:
@@ -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