feat: 完善后端并新增 Vue3 WebUI
后端: - 修复登录校验、DB 并发(单例+WAL+纯Go sqlite)、会话密钥持久化等核心缺陷 - 新增 Timer CRUD/签到/手动触发、执行日志、仪表盘、驱动元数据等 API - 统一驱动接口: 带 context 的执行器、真实错误返回、敏感字段掩码、连通性测试 - 补全钉钉执行器; Timer 触发/提醒去重; 配置支持默认值与环境变量覆盖 前端: - Vite+Vue3+TS+Pinia+Element Plus, 由驱动元数据动态渲染配置表单 - 登录/仪表盘(倒计时环)/定时器/规则/账号/日志/设置页面, 支持暗色模式 - 主题色 #66ccff, 信号波纹 logo, go:embed 单二进制部署 构建: Dockerfile 增加前端构建阶段; 补充各驱动配置文档 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Package response 统一 API 的返回格式
|
||||
//
|
||||
// {"code": 200, "data": ...}
|
||||
//
|
||||
// 出错时 data 为可以直接展示给用户的错误信息。
|
||||
package response
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/ssdomei232/goodBaby/model"
|
||||
)
|
||||
|
||||
// OK 返回成功响应
|
||||
func OK(c *gin.Context, data any) {
|
||||
c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "data": data})
|
||||
}
|
||||
|
||||
// Fail 返回错误响应
|
||||
func Fail(c *gin.Context, code int, msg string) {
|
||||
c.JSON(code, gin.H{"code": code, "data": msg})
|
||||
}
|
||||
|
||||
// AbortWith 返回错误响应并终止后续 handler
|
||||
func AbortWith(c *gin.Context, code int, msg string) {
|
||||
c.AbortWithStatusJSON(code, gin.H{"code": code, "data": msg})
|
||||
}
|
||||
|
||||
// BadRequest 参数错误
|
||||
func BadRequest(c *gin.Context, msg string) { Fail(c, http.StatusBadRequest, msg) }
|
||||
|
||||
// Unauthorized 未登录
|
||||
func Unauthorized(c *gin.Context, msg string) { Fail(c, http.StatusUnauthorized, msg) }
|
||||
|
||||
// NotFound 资源不存在
|
||||
func NotFound(c *gin.Context, msg string) { Fail(c, http.StatusNotFound, msg) }
|
||||
|
||||
// ServerError 服务端错误
|
||||
func ServerError(c *gin.Context, msg string) { Fail(c, http.StatusInternalServerError, msg) }
|
||||
|
||||
// FromError 按错误类型选择合适的状态码:
|
||||
// 参数校验错误返回 400,其余返回 500
|
||||
func FromError(c *gin.Context, err error, fallback string) {
|
||||
var validationErr model.ValidationError
|
||||
if errors.As(err, &validationErr) {
|
||||
BadRequest(c, validationErr.Msg)
|
||||
return
|
||||
}
|
||||
ServerError(c, fallback)
|
||||
}
|
||||
Reference in New Issue
Block a user