diff --git a/pages/admin.vue b/pages/admin.vue
new file mode 100644
index 0000000..221b74e
--- /dev/null
+++ b/pages/admin.vue
@@ -0,0 +1,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/index.vue b/pages/index.vue
index f61dc48..62a190b 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -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() {
diff --git a/pages/user.vue b/pages/user.vue
new file mode 100644
index 0000000..83ae3f9
--- /dev/null
+++ b/pages/user.vue
@@ -0,0 +1,9 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/server/api/login/admin.post.ts b/server/api/login/admin.post.ts
new file mode 100644
index 0000000..353ae58
--- /dev/null
+++ b/server/api/login/admin.post.ts
@@ -0,0 +1,21 @@
+import { defineEventHandler, readBody, setResponseStatus } from 'h3';
+
+export default defineEventHandler(async (event) => {
+ const body = await readBody(event);
+ const { password } = body;
+
+ if (!password) {
+ setResponseStatus(event, 400);
+ return { message: '请填写密码' };
+ }
+
+ // TODO: Replace with a more secure admin authentication method
+ if (password === 'adminpassword') {
+ return {
+ message: '管理员登录成功!',
+ };
+ } else {
+ setResponseStatus(event, 401);
+ return { message: '密码错误' };
+ }
+});
\ No newline at end of file
diff --git a/server/api/login/user.post.ts b/server/api/login/user.post.ts
new file mode 100644
index 0000000..622aa4c
--- /dev/null
+++ b/server/api/login/user.post.ts
@@ -0,0 +1,22 @@
+import { defineEventHandler, readBody, setResponseStatus } from 'h3';
+
+export default defineEventHandler(async (event) => {
+ const body = await readBody(event);
+ const { contact, password } = body;
+
+ if (!contact || !password) {
+ setResponseStatus(event, 400);
+ return { message: '请填写手机号和密码' };
+ }
+
+ // TODO: Replace with database user lookup and password verification
+ if (contact === '1234567890' && password === 'password') {
+ return {
+ message: '登录成功!',
+ customerId: 'dummy-customer-id-123',
+ };
+ } else {
+ setResponseStatus(event, 401);
+ return { message: '手机号或密码错误' };
+ }
+});
\ No newline at end of file