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(){