feat(settings):增加滚动快讯配置选项

- 在 Settings 结构中添加 EnableNews 字段
- 前端增加滚动快讯配置开关
- 后端逻辑中根据配置决定是否显示滚动快讯
This commit is contained in:
ArvinLovegood 2025-03-20 23:16:37 +08:00
parent ee5c47f2dc
commit f7a2681157
5 changed files with 32 additions and 7 deletions

8
app.go
View File

@ -96,8 +96,8 @@ func (a *App) domReady(ctx context.Context) {
// Add your action here
//定时更新数据
config := data.NewSettingsApi(&data.Settings{}).GetConfig()
go func() {
config := data.NewSettingsApi(&data.Settings{}).GetConfig()
interval := config.RefreshInterval
if interval <= 0 {
interval = 1
@ -123,13 +123,15 @@ func (a *App) domReady(ctx context.Context) {
defer ticker.Stop()
for range ticker.C {
telegraph := refreshTelegraphList()
if telegraph != nil {
if telegraph != nil && config.EnableNews {
go runtime.EventsEmit(a.ctx, "telegraph", telegraph)
}
}
}()
go runtime.EventsEmit(a.ctx, "telegraph", refreshTelegraphList())
if config.EnableNews {
go runtime.EventsEmit(a.ctx, "telegraph", refreshTelegraphList())
}
go MonitorStockPrices(a)
go MonitorFundPrices(a)
go data.NewFundApi().AllFund()

View File

@ -30,6 +30,7 @@ type Settings struct {
KDays int64 `json:"kDays"`
EnableDanmu bool `json:"enableDanmu"`
BrowserPath string `json:"browserPath"`
EnableNews bool `json:"enableNews"`
}
func (receiver Settings) TableName() string {
@ -71,6 +72,7 @@ func (s SettingsApi) UpdateConfig() string {
"k_days": s.Config.KDays,
"enable_danmu": s.Config.EnableDanmu,
"browser_path": s.Config.BrowserPath,
"enable_news": s.Config.EnableNews,
})
} else {
logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config)
@ -95,6 +97,7 @@ func (s SettingsApi) UpdateConfig() string {
KDays: s.Config.KDays,
EnableDanmu: s.Config.EnableDanmu,
BrowserPath: s.Config.BrowserPath,
EnableNews: s.Config.EnableNews,
})
}
return "保存成功!"

View File

@ -8,7 +8,7 @@ import {
WindowSetPosition,
WindowUnfullscreen
} from '../wailsjs/runtime'
import {h, onMounted, ref} from "vue";
import {h, onBeforeMount, onMounted, ref} from "vue";
import { RouterLink } from 'vue-router'
import {darkTheme, NGradientText, NIcon, NText,} from 'naive-ui'
import {
@ -17,7 +17,8 @@ import {
ExpandOutline,
PowerOutline, LogoGithub, MoveOutline, WalletOutline, StarOutline, AlarmOutline, SparklesOutline,
} from '@vicons/ionicons5'
import {GetConfig} from "../wailsjs/go/main/App";
const enableNews= ref(false)
const contentStyle = ref("")
const content = ref('数据来源于网络,仅供参考;投资有风险,入市需谨慎')
const isFullscreen = ref(false)
@ -197,6 +198,15 @@ window.onerror = function (msg, source, lineno, colno, error) {
return true;
};
onBeforeMount(()=>{
GetConfig().then((res)=>{
console.log(res)
if(res.enableNews){
enableNews.value=true
}
})
})
onMounted(()=>{
contentStyle.value="max-height: calc(90vh);overflow: hidden"
})
@ -232,7 +242,7 @@ onMounted(()=>{
-->
<n-gi>
<n-marquee :speed="100" style="position: relative;top:0;z-index: 19;width: 100%" v-if="telegraph.length>0">
<n-marquee :speed="100" style="position: relative;top:0;z-index: 19;width: 100%" v-if="(telegraph.length>0)&&(enableNews)">
<n-tag type="warning" v-for="item in telegraph" style="margin-right: 10px">
{{item}}
</n-tag>

View File

@ -35,6 +35,7 @@ const formValue = ref({
},
enableDanmu:false,
browserPath: '',
enableNews:false,
})
onMounted(()=>{
@ -65,6 +66,8 @@ onMounted(()=>{
}
formValue.value.enableDanmu = res.enableDanmu
formValue.value.browserPath = res.browserPath
formValue.value.enableNews = res.enableNews
console.log(res)
})
//message.info("")
@ -92,7 +95,8 @@ function saveConfig(){
crawlTimeOut:formValue.value.openAI.crawlTimeOut,
kDays:formValue.value.openAI.kDays,
enableDanmu:formValue.value.enableDanmu,
browserPath:formValue.value.browserPath
browserPath:formValue.value.browserPath,
enableNews:formValue.value.enableNews,
})
//console.log("Settings",config)
@ -165,6 +169,7 @@ function importConfig(){
}
formValue.value.enableDanmu = config.enableDanmu
formValue.value.browserPath = config.browserPath
formValue.value.enableNews = config.enableNews
// formRef.value.resetFields()
};
reader.readAsText(file);
@ -227,6 +232,9 @@ window.onerror = function (event, source, lineno, colno, error) {
<n-form-item-gi :span="5" label="弹幕功能:" path="enableDanmu" >
<n-switch v-model:value="formValue.enableDanmu" />
</n-form-item-gi>
<n-form-item-gi :span="5" label="是否显示滚动快讯(重启生效)" path="enableNews" >
<n-switch v-model:value="formValue.enableNews" />
</n-form-item-gi>
<n-form-item-gi :span="22" v-if="formValue.dingPush.enable" label="钉钉机器人接口地址:" path="dingPush.dingRobot" >
<n-input placeholder="请输入钉钉机器人接口地址" v-model:value="formValue.dingPush.dingRobot"/>
<n-button type="primary" @click="sendTestNotice">发送测试通知</n-button>

View File

@ -171,6 +171,7 @@ export namespace data {
kDays: number;
enableDanmu: boolean;
browserPath: string;
enableNews: boolean;
static createFrom(source: any = {}) {
return new Settings(source);
@ -202,6 +203,7 @@ export namespace data {
this.kDays = source["kDays"];
this.enableDanmu = source["enableDanmu"];
this.browserPath = source["browserPath"];
this.enableNews = source["enableNews"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {