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:
mei
2026-07-26 22:19:41 +08:00
co-authored by Claude Fable 5
parent 89e8b7fd66
commit 79774070fc
110 changed files with 8936 additions and 849 deletions
+31 -5
View File
@@ -1,9 +1,35 @@
package model
// Account 保存执行规则时需要用到的第三方凭据
type Account struct {
ID uint `gorm:"primaryKey" json:"id"`
UID uint `json:"uid"`
Name string `json:"name"` // 账号名称
Type string `json:"type"` // 账号类型,如 "bilibili"
Config string `json:"config"` // 存储账号相关配置,如cookie等
ID uint `gorm:"primaryKey" json:"id"`
UID uint `gorm:"index" json:"uid"`
Name string `json:"name"` // 账号名称
Type string `json:"type"` // 账号类型,如 "bilibili"
Config string `json:"config"` // 存储账号相关配置,如 cookie 等
CreateAt int64 `json:"create_at"`
}
// AccountRequest 创建/编辑账号的请求体
type AccountRequest struct {
Name string `json:"name"`
Type string `json:"type"`
Config string `json:"config"`
}
// Validate 校验账号请求中与类型无关的通用部分
func (r *AccountRequest) Validate() error {
if r.Name == "" {
return ErrValidation("账号名称不能为空")
}
if len(r.Name) > 64 {
return ErrValidation("账号名称过长")
}
if r.Type == "" {
return ErrValidation("账号类型不能为空")
}
if r.Config == "" {
return ErrValidation("账号配置不能为空")
}
return nil
}
+11
View File
@@ -0,0 +1,11 @@
package model
// ValidationError 表示一个可以直接展示给用户的参数校验错误
type ValidationError struct {
Msg string
}
func (e ValidationError) Error() string { return e.Msg }
// ErrValidation 构造一个参数校验错误
func ErrValidation(msg string) error { return ValidationError{Msg: msg} }
+22
View File
@@ -0,0 +1,22 @@
package model
// 执行日志的触发来源
const (
TriggerTimer = "timer" // Timer 到期自动触发
TriggerManual = "manual" // 用户在 WebUI 手动测试
TriggerRemind = "remind" // 提醒通知
)
// ExecutionLog 记录每一次规则执行/提醒的结果,供 WebUI 展示
type ExecutionLog struct {
ID uint `gorm:"primaryKey" json:"id"`
UID uint `gorm:"index" json:"uid"`
RuleID uint `json:"rule_id"`
RuleName string `json:"rule_name"`
RuleType string `json:"rule_type"`
TimerID uint `json:"timer_id"`
Trigger string `json:"trigger"`
Success bool `json:"success"`
Message string `json:"message"`
CreateAt int64 `gorm:"index" json:"create_at"`
}
+39 -3
View File
@@ -1,11 +1,47 @@
package model
// Rule 描述一个 Timer 到期后要执行的动作
type Rule struct {
ID uint `json:"id" gorm:"primaryKey"`
UID uint `json:"uid"`
TimerID uint `json:"timer_id"`
ID uint `json:"id" gorm:"primaryKey"`
UID uint `gorm:"index" json:"uid"`
TimerID uint `gorm:"index" json:"timer_id"`
Name string `json:"name"`
// 关联账号,部分规则类型(如钉钉)不需要账号,此时为 0
AccountID uint `json:"account_id"`
// 规则类型,见 internal/ruleConfigChecker 注册表
Type string `json:"type"`
// 规则配置,JSON 字符串
ConfigJson string `json:"config_json"`
Enabled bool `gorm:"default:true" json:"enabled"`
CreateAt int64 `json:"create_at"`
}
// RuleRequest 创建/编辑规则的请求体
type RuleRequest struct {
Name string `json:"name"`
TimerID uint `json:"timer_id"`
AccountID uint `json:"account_id"`
Type string `json:"type"`
ConfigJson string `json:"config_json"`
Enabled *bool `json:"enabled"`
}
// Validate 校验规则请求中与类型无关的通用部分
func (r *RuleRequest) Validate() error {
if r.Name == "" {
return ErrValidation("规则名称不能为空")
}
if len(r.Name) > 64 {
return ErrValidation("规则名称过长")
}
if r.Type == "" {
return ErrValidation("规则类型不能为空")
}
if r.TimerID == 0 {
return ErrValidation("必须关联一个 Timer")
}
if r.ConfigJson == "" {
return ErrValidation("规则配置不能为空")
}
return nil
}
+58 -4
View File
@@ -1,10 +1,64 @@
package model
// Timer 是摇篮系统的核心:用户需要在 SignDerationSeconds 内完成一次签到,
// 否则挂在这个 Timer 下的所有规则都会被触发。
type Timer struct {
ID uint `gorm:"primaryKey" json:"id"`
UID uint `json:"uid"`
ID uint `gorm:"primaryKey" json:"id"`
UID uint `gorm:"index" json:"uid"`
Name string `json:"name"`
Description string `json:"description"`
// 是否启用,停用后不再提醒也不会触发
Enabled bool `gorm:"default:true" json:"enabled"`
// 签到有效期(秒),超过这个时间没有签到就会触发规则
SignDerationSeconds int64 `json:"sign_deration_seconds"`
// 上次签到时间(Unix 秒)
LastSign int64 `json:"last_sign"`
// 提前多少秒提醒
RemindTimeSeconds int64 `json:"remind_time_seconds"`
// 上次发送提醒时对应的签到周期,用于避免重复提醒
LastRemind int64 `json:"last_remind"`
// 是否已经触发过,触发后进入静默状态直到用户重新签到
Triggered bool `json:"triggered"`
// 上次触发时间
LastTrigger int64 `json:"last_trigger"`
CreateAt int64 `json:"create_at"`
}
// NextSignTime 下次必须完成签到的时间点
func (t *Timer) NextSignTime() int64 {
return t.LastSign + t.SignDerationSeconds
}
// RemindAt 应该发送提醒的时间点
func (t *Timer) RemindAt() int64 {
return t.NextSignTime() - t.RemindTimeSeconds
}
// TimerRequest 创建/编辑 Timer 的请求体
type TimerRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Enabled *bool `json:"enabled"`
SignDerationSeconds int64 `json:"sign_deration_seconds"`
LastSign int64 `json:"last_sign"`
RemindTimeSeconds int64 `json:"remind_time_seconds"` // 提前多少秒提醒
RemindTimeSeconds int64 `json:"remind_time_seconds"`
}
// Validate 校验 Timer 请求参数
func (r *TimerRequest) Validate() error {
if r.Name == "" {
return ErrValidation("Timer 名称不能为空")
}
if len(r.Name) > 64 {
return ErrValidation("Timer 名称过长")
}
if r.SignDerationSeconds < 60 {
return ErrValidation("签到周期不能小于 60 秒")
}
if r.RemindTimeSeconds < 0 {
return ErrValidation("提醒提前量不能为负数")
}
if r.RemindTimeSeconds >= r.SignDerationSeconds {
return ErrValidation("提醒提前量必须小于签到周期")
}
return nil
}
+17 -24
View File
@@ -1,21 +1,29 @@
package model
import (
"fmt"
"github.com/ssdomei232/goodBaby/handler/db"
)
import "fmt"
type UserRegistryReuest struct {
Username string `json:"username"`
Password string `json:"password"`
}
// ChangePasswordRequest 修改密码请求
type ChangePasswordRequest struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
}
// NotifyConfigRequest 修改提醒渠道配置的请求
type NotifyConfigRequest struct {
DingTalkConfig *string `json:"dingtalk_config"`
}
type User struct {
ID uint `json:"id" gorm:"primaryKey"`
CreateAt int64 `json:"create_at"`
Username string `json:"username"`
Password string `json:"-"`
ID uint `json:"id" gorm:"primaryKey"`
CreateAt int64 `json:"create_at"`
Username string `gorm:"uniqueIndex" json:"username"`
Password string `json:"-"`
// 钉钉机器人配置(JSON 字符串),用于接收提醒
DingTalkConfig *string `json:"dingtalk_config"`
}
@@ -31,18 +39,3 @@ func (u *User) IsValid() error {
}
return nil
}
func (u *User) IsExist() bool {
db, err := db.GetGormDB()
if err != nil {
return false
}
var count int64
result := db.Where("username = ?", u.Username).Count(&count)
if result.Error != nil {
return false
}
return count > 0
}