From a376d1d92c17ff68ab8c383e67213f824c202fe4 Mon Sep 17 00:00:00 2001 From: spark Date: Mon, 13 Jan 2025 12:07:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(settings):=20=E6=B7=BB=E5=8A=A0=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD-=20=E5=9C=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=AD=E5=A2=9E=E5=8A=A0=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E5=92=8C=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=97=B4=E9=9A=94=E7=9A=84=E9=85=8D=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=20-=20=E5=AE=9E=E7=8E=B0=E6=A0=B9=E6=8D=AE=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E6=9B=B4=E6=96=B0=E6=95=B0=E6=8D=AE=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=20-=20=E6=B7=BB=E5=8A=A0=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=20-=20=E6=9B=B4=E6=96=B0=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E8=AE=BE=E7=BD=AE=E7=95=8C=E9=9D=A2=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=9F=BA=E7=A1=80=E8=AE=BE=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 7 ++- backend/data/settings_api.go | 24 ++++++---- frontend/src/components/settings.vue | 72 ++++++++++++++++++---------- frontend/wailsjs/go/models.ts | 4 ++ main.go | 11 +++-- 5 files changed, 78 insertions(+), 40 deletions(-) diff --git a/app.go b/app.go index f9c0db5..708cac6 100644 --- a/app.go +++ b/app.go @@ -51,7 +51,12 @@ func (a *App) domReady(ctx context.Context) { // Add your action here //定时更新数据 go func() { - ticker := time.NewTicker(time.Second * 1) + config := data.NewSettingsApi(&data.Settings{}).GetConfig() + interval := config.RefreshInterval + if interval <= 0 { + interval = 1 + } + ticker := time.NewTicker(time.Second * time.Duration(interval)) defer ticker.Stop() for range ticker.C { if isTradingTime(time.Now()) { diff --git a/backend/data/settings_api.go b/backend/data/settings_api.go index c97e8c9..94be27f 100644 --- a/backend/data/settings_api.go +++ b/backend/data/settings_api.go @@ -8,9 +8,11 @@ import ( type Settings struct { gorm.Model - LocalPushEnable bool `json:"localPushEnable"` - DingPushEnable bool `json:"dingPushEnable"` - DingRobot string `json:"dingRobot"` + LocalPushEnable bool `json:"localPushEnable"` + DingPushEnable bool `json:"dingPushEnable"` + DingRobot string `json:"dingRobot"` + UpdateBasicInfoOnStart bool `json:"updateBasicInfoOnStart"` + RefreshInterval int64 `json:"refreshInterval"` } func (receiver Settings) TableName() string { @@ -32,16 +34,20 @@ func (s SettingsApi) UpdateConfig() string { db.Dao.Model(s.Config).Count(&count) if count > 0 { db.Dao.Model(s.Config).Where("id=?", s.Config.ID).Updates(map[string]any{ - "local_push_enable": s.Config.LocalPushEnable, - "ding_push_enable": s.Config.DingPushEnable, - "ding_robot": s.Config.DingRobot, + "local_push_enable": s.Config.LocalPushEnable, + "ding_push_enable": s.Config.DingPushEnable, + "ding_robot": s.Config.DingRobot, + "update_basic_info_on_start": s.Config.UpdateBasicInfoOnStart, + "refresh_interval": s.Config.RefreshInterval, }) } else { logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config) db.Dao.Model(s.Config).Create(&Settings{ - LocalPushEnable: s.Config.LocalPushEnable, - DingPushEnable: s.Config.DingPushEnable, - DingRobot: s.Config.DingRobot, + LocalPushEnable: s.Config.LocalPushEnable, + DingPushEnable: s.Config.DingPushEnable, + DingRobot: s.Config.DingRobot, + UpdateBasicInfoOnStart: s.Config.UpdateBasicInfoOnStart, + RefreshInterval: s.Config.RefreshInterval, }) } return "保存成功!" diff --git a/frontend/src/components/settings.vue b/frontend/src/components/settings.vue index da33b56..f804f4b 100644 --- a/frontend/src/components/settings.vue +++ b/frontend/src/components/settings.vue @@ -8,14 +8,16 @@ const message = useMessage() const formRef = ref(null) const formValue = ref({ - ID:0, + ID:1, dingPush:{ enable:false, dingRobot: '' }, localPush:{ enable:true, - } + }, + updateBasicInfoOnStart:false, + refreshInterval:1 }) onMounted(()=>{ @@ -28,6 +30,8 @@ onMounted(()=>{ formValue.value.localPush = { enable:res.localPushEnable, } + formValue.value.updateBasicInfoOnStart = res.updateBasicInfoOnStart + formValue.value.refreshInterval = res.refreshInterval console.log(res) }) //message.info("加载完成") @@ -40,9 +44,11 @@ function saveConfig(){ dingPushEnable:formValue.value.dingPush.enable, dingRobot:formValue.value.dingPush.dingRobot, localPushEnable:formValue.value.localPush.enable, + updateBasicInfoOnStart:formValue.value.updateBasicInfoOnStart, + refreshInterval:formValue.value.refreshInterval }) - console.log("Settings",config) + //console.log("Settings",config) UpdateConfig(config).then(res=>{ message.success(res) }) @@ -72,30 +78,44 @@ function sendTestNotice(){