From e5383ce2687ca6c59b92f2eaa42bc3a2ede850db Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Mon, 8 Sep 2025 17:15:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=95=8C=E9=9D=A2=202.=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=BE=93=E5=87=BA=E6=97=A5=E5=BF=97=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/dashboard.html | 336 +++++++++++++++++++++++++++++++++++ frontend/index.html | 272 ++++++++++++++++++++++++++++ internal/api/api.go | 21 +++ internal/core/application.go | 4 +- 4 files changed, 631 insertions(+), 2 deletions(-) create mode 100644 frontend/dashboard.html create mode 100644 frontend/index.html diff --git a/frontend/dashboard.html b/frontend/dashboard.html new file mode 100644 index 0000000..5328d08 --- /dev/null +++ b/frontend/dashboard.html @@ -0,0 +1,336 @@ + + + + + + 猪场管理系统 - 控制台 + + + +
+

🐷 猪场管理系统

+
+ 用户 + +
+
+ +
+
+
+

📊 系统状态

+

当前系统运行正常

+

连接设备: 0

+

今日操作: 0

+
+ +
+

🌡️ 环境监控

+

温度: 25.6°C

+

湿度: 65%

+

空气质量: 良好

+
+ +
+

📡 设备连接

+

中继设备: 在线

+

风扇设备: 在线

+

水帘设备: 离线

+
+
+ +
+

⚙️ 设备控制

+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+ + + + \ No newline at end of file diff --git a/frontend/index.html b/frontend/index.html new file mode 100644 index 0000000..0e7e52b --- /dev/null +++ b/frontend/index.html @@ -0,0 +1,272 @@ + + + + + + 猪场管理系统 - 登录 + + + +
+ +

猪场管理系统

+

请登录您的账户

+ +
+
+ + +
+ +
+ + +
+ + +
+ +
+
+

登录中...

+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/internal/api/api.go b/internal/api/api.go index 68e0e71..39c9d30 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "net/http" + "strings" "time" "git.huangwc.com/pig/pig-farm-controller/internal/api/middleware" @@ -203,6 +204,26 @@ func (a *API) setupRoutes() { } } + // 使用NoRoute处理器处理前端路由 + a.engine.NoRoute(func(c *gin.Context) { + path := c.Request.URL.Path + + // 判断是否为API路径 + if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/ws/") { + // API路径返回404 + c.JSON(http.StatusNotFound, gin.H{ + "error": "API路径未找到", + }) + return + } + + // 其他路径提供前端静态文件服务 + c.File("./frontend/index.html") + }) + + // 静态文件服务 - 提供前端静态资源 + a.engine.Static("/static", "./frontend/static") + // TODO: 添加更多路由 } diff --git a/internal/core/application.go b/internal/core/application.go index aacc36d..d902bb5 100644 --- a/internal/core/application.go +++ b/internal/core/application.go @@ -108,8 +108,8 @@ func (app *Application) Start() error { app.logger.Info("API启动成功") // 启动任务执行器组件 + app.logger.Info("启动任务执行器") app.TaskExecutor.Start() - app.logger.Info("任务执行器启动成功") return nil } @@ -123,8 +123,8 @@ func (app *Application) Stop() error { } // 停止任务执行器组件 + app.logger.Info("停止任务执行器") app.TaskExecutor.Stop() - app.logger.Info("任务执行器已停止") // 停止存储组件 if err := app.Storage.Disconnect(); err != nil {