From 6ad52ff5a9c23d9a64abf2a8024aa26654a1eee7 Mon Sep 17 00:00:00 2001 From: guoapeng Date: Wed, 7 May 2025 15:38:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9D=83=E9=99=90=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.js | 2 ++ server/routes/auth.js | 22 ++++++++++++++++++++++ src/hooks/useApiData.ts | 2 +- src/views/login/index.vue | 6 ++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 server/routes/auth.js diff --git a/server/index.js b/server/index.js index 088ea12..fdbfffa 100644 --- a/server/index.js +++ b/server/index.js @@ -1,5 +1,6 @@ // const express = require('express') import express from 'express' +import { authRoutes } from './routes/auth.js' import { debugRoutes } from './routes/debug.js' import { initWebSocketServer } from './utils/websocket.js' @@ -16,3 +17,4 @@ initWebSocketServer() // 注册路由模块 debugRoutes(app) +authRoutes(app) diff --git a/server/routes/auth.js b/server/routes/auth.js new file mode 100644 index 0000000..dcb31e3 --- /dev/null +++ b/server/routes/auth.js @@ -0,0 +1,22 @@ +const baseUrl = '/api/auth' +export const authRoutes = (app) => { + app.post(`${baseUrl}/login`, (req, res) => { + // const { username, password } = req.body + const mockResponse = { + code: '0', + msg: '成功', + data: { + id: 1, + createTime: '2025-04-27 07:44:01', + updateTime: '2025-04-27 07:44:01', + username: 'admin', + nickname: 'Admin', + password: null, + role: 'ADMIN', + deleted: 'DISABLE', + fixedUser: 'ENABLE', + }, + } + res.json(mockResponse) + }) +} diff --git a/src/hooks/useApiData.ts b/src/hooks/useApiData.ts index ab3d27a..e406940 100644 --- a/src/hooks/useApiData.ts +++ b/src/hooks/useApiData.ts @@ -4,7 +4,7 @@ import { ref } from 'vue' export default function useApiData(url: string, params?: any, init?: boolean) { const data = ref(null) const loading = ref(false) - const error = ref(null) + const error = ref() const fetchData = async () => { loading.value = true error.value = null diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 97b7b7f..b4ef5b9 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,4 +1,5 @@