From a2fee361e742e9bf6bd6726e5b082446d3bf7843 Mon Sep 17 00:00:00 2001 From: ArvinLovegood Date: Wed, 18 Jun 2025 14:23:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=E5=AE=9E=E6=97=B6=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E8=B5=84=E8=AE=AF=E4=BF=A1=E6=81=AF=E6=8F=90=E9=86=92?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 NewsPush 函数用于推送市场资讯 - 在 App.vue 中添加新闻推送的事件监听 - 在 settings 中增加启用新闻推送的选项 - 修改 README.md,添加实时市场资讯信息提醒的更新说明 --- README.md | 2 +- app.go | 15 +++++++++++++++ backend/data/settings_api.go | 3 +++ frontend/src/App.vue | 16 ++++++++++++++-- frontend/src/components/settings.vue | 19 +++++++++++++------ frontend/wailsjs/go/main/App.d.ts | 2 ++ frontend/wailsjs/go/main/App.js | 4 ++++ frontend/wailsjs/go/models.ts | 2 ++ 8 files changed, 54 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 071402d..6895a4a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ ## 👀 更新日志 -### 2025.06.18 更新内置股票基础数据 +### 2025.06.18 更新内置股票基础数据,软件内实时市场资讯信息提醒 ### 2025.06.15 添加公司公告信息搜索/查看功能 ### 2025.06.15 添加个股研报到弹出菜单 ### 2025.06.13 添加个股研报功能 diff --git a/app.go b/app.go index a4049d9..147c0de 100644 --- a/app.go +++ b/app.go @@ -178,6 +178,9 @@ func (a *App) domReady(ctx context.Context) { } entryID, err := a.cron.AddFunc(fmt.Sprintf("@every %ds", interval+10), func() { news := data.NewMarketNewsApi().GetNewTelegraph(30) + if config.EnablePushNews { + go a.NewsPush(news) + } go runtime.EventsEmit(a.ctx, "newTelegraph", news) }) if err != nil { @@ -188,6 +191,9 @@ func (a *App) domReady(ctx context.Context) { entryIDSina, err := a.cron.AddFunc(fmt.Sprintf("@every %ds", interval+10), func() { news := data.NewMarketNewsApi().GetSinaNews(30) + if config.EnablePushNews { + go a.NewsPush(news) + } go runtime.EventsEmit(a.ctx, "newSinaNews", news) }) if err != nil { @@ -292,6 +298,15 @@ func (a *App) domReady(ctx context.Context) { } +func (a *App) NewsPush(news *[]models.Telegraph) { + for _, telegraph := range *news { + //if telegraph.IsRed { + go runtime.EventsEmit(a.ctx, "newsPush", telegraph) + go data.NewAlertWindowsApi("go-stock", telegraph.Source+" "+telegraph.Time, telegraph.Content, string(icon)).SendNotification() + //} + } +} + func (a *App) AddCronTask(follow data.FollowedStock) func() { return func() { go runtime.EventsEmit(a.ctx, "warnMsg", "开始自动分析"+follow.Name+"_"+follow.StockCode) diff --git a/backend/data/settings_api.go b/backend/data/settings_api.go index 5ca4bb6..5134c45 100644 --- a/backend/data/settings_api.go +++ b/backend/data/settings_api.go @@ -34,6 +34,7 @@ type Settings struct { DarkTheme bool `json:"darkTheme"` BrowserPoolSize int `json:"browserPoolSize"` EnableFund bool `json:"enableFund"` + EnablePushNews bool `json:"enablePushNews"` } func (receiver Settings) TableName() string { @@ -78,6 +79,7 @@ func (s SettingsApi) UpdateConfig() string { "enable_news": s.Config.EnableNews, "dark_theme": s.Config.DarkTheme, "enable_fund": s.Config.EnableFund, + "enable_push_news": s.Config.EnablePushNews, }) } else { logger.SugaredLogger.Infof("未找到配置,创建默认配置:%+v", s.Config) @@ -105,6 +107,7 @@ func (s SettingsApi) UpdateConfig() string { EnableNews: s.Config.EnableNews, DarkTheme: s.Config.DarkTheme, EnableFund: s.Config.EnableFund, + EnablePushNews: s.Config.EnablePushNews, }) } return "保存成功!" diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 760e45c..aed2fd3 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -10,7 +10,7 @@ import { } from '../wailsjs/runtime' import {h, onBeforeMount, onBeforeUnmount, onMounted, ref} from "vue"; import {RouterLink, useRouter} from 'vue-router' -import {darkTheme, NIcon, NText,dateZhCN,zhCN} from 'naive-ui' +import {createDiscreteApi,darkTheme,lightTheme , NIcon, NText,dateZhCN,zhCN} from 'naive-ui' import { AlarmOutline, AnalyticsOutline, @@ -29,6 +29,9 @@ import { } from '@vicons/ionicons5' import {GetConfig, GetGroupList} from "../wailsjs/go/main/App"; + + + const router = useRouter() const loading = ref(true) const loadingMsg = ref("加载数据中...") @@ -430,6 +433,7 @@ onBeforeUnmount(() => { EventsOff("realtime_profit") EventsOff("loadingMsg") EventsOff("telegraph") + EventsOff("newsPush") }) window.onerror = function (msg, source, lineno, colno, error) { @@ -515,9 +519,17 @@ onMounted(() => { enableNews.value = true } enableFund.value = res.enableFund + const {notification } =createDiscreteApi(["notification"], { + configProviderProps: { + theme: enableDarkTheme.value ? darkTheme : lightTheme , + max: 3, + }, + }) + EventsOn("newsPush", (data) => { + notification.create({ title: data.time, content: data.content,duration:1000*60 }) + }) }) }) -