1. 前端改为vue单体程序

2. 增加设备管理相关接口
This commit is contained in:
2025-09-08 18:16:40 +08:00
parent e5383ce268
commit 7112a16ca8
853 changed files with 546690 additions and 620 deletions

View File

@@ -178,6 +178,26 @@ func (a *API) setupRoutes() {
userGroup.POST("/login", a.userController.Login)
}
// 配置静态文件服务
a.engine.Static("/assets/", "./frontend/dist/assets/")
// 使用NoRoute处理器处理前端路由
a.engine.NoRoute(func(c *gin.Context) {
path := c.Request.URL.Path
// 判断是否为API路径
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/ws/") || path == "/health" {
// API路径返回404
c.JSON(http.StatusNotFound, gin.H{
"error": "API路径未找到",
})
return
}
// 对于前端路由提供index.html支持Vue Router的history模式
c.File("./frontend/dist/index.html")
})
// 需要鉴权的路由组
protectedGroup := a.engine.Group("/api/v1")
protectedGroup.Use(a.authMiddleware.Handle())
@@ -194,6 +214,10 @@ func (a *API) setupRoutes() {
deviceGroup := protectedGroup.Group("/device")
{
deviceGroup.POST("/switch", a.deviceController.Switch)
deviceGroup.GET("/list", a.deviceController.List)
deviceGroup.POST("/create", a.deviceController.Create)
deviceGroup.POST("/update", a.deviceController.Update)
deviceGroup.POST("/delete", a.deviceController.Delete)
}
// 远程控制相关路由
@@ -204,26 +228,6 @@ 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: 添加更多路由
}