feat: implement user and admin login flow

This commit is contained in:
2025-06-18 16:03:28 +08:00
parent 0d98d4f0c2
commit 6652953b1a
5 changed files with 88 additions and 2 deletions

View File

@ -113,8 +113,33 @@ function showLogin() {
}
async function handleLogin() {
// TODO: Implement login logic
console.log('Logging in with role:', role.value, 'and credentials:', loginForm);
try {
if (role.value === 'user') {
const response = await $fetch('/api/login/user', {
method: 'POST',
body: {
contact: loginForm.contact,
password: loginForm.password
}
});
message.value = response.message;
if (response.customerId) {
localStorage.setItem('customerId', response.customerId);
await navigateTo('/user');
}
} else { // admin
const response = await $fetch('/api/login/admin', {
method: 'POST',
body: {
password: loginForm.password
}
});
message.value = response.message;
await navigateTo('/admin');
}
} catch (error: any) {
message.value = error.data?.message || '登录失败';
}
}
async function handleRegister() {