mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
refactor(app): 重构应用启动和托盘功能
- 移除 App.startup 中的系统托盘创建逻辑 - 在 main.go 中添加系统托盘创建逻辑- 更新前端 App.vue,添加实时盈亏显示和相关事件监听- 调整 stock.vue,引入通知功能
This commit is contained in:
parent
2fcd89ab97
commit
1ea534b3c0
15
app.go
15
app.go
@ -36,14 +36,6 @@ func NewApp() *App {
|
||||
func (a *App) startup(ctx context.Context) {
|
||||
// Perform your setup here
|
||||
a.ctx = ctx
|
||||
|
||||
// 创建系统托盘
|
||||
go systray.Run(func() {
|
||||
onReady(a)
|
||||
}, func() {
|
||||
onExit(a)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// domReady is called after front-end resources have been loaded
|
||||
@ -121,9 +113,10 @@ func MonitorStockPrices(a *App) {
|
||||
}
|
||||
}
|
||||
|
||||
title := "go-stock " + time.Now().Format(time.DateTime) + fmt.Sprintf(" %.2f¥", total)
|
||||
runtime.WindowSetTitle(a.ctx, title)
|
||||
systray.SetTooltip(title)
|
||||
//title := "go-stock " + time.Now().Format(time.DateTime) + fmt.Sprintf(" %.2f¥", total)
|
||||
go runtime.EventsEmit(a.ctx, "realtime_profit", fmt.Sprintf(" %.2f", total))
|
||||
//runtime.WindowSetTitle(a.ctx, title)
|
||||
//systray.SetTooltip(title)
|
||||
|
||||
}
|
||||
func GetStockInfos(follows ...data.FollowedStock) *[]data.StockInfo {
|
||||
|
@ -1,6 +1,7 @@
|
||||
<script setup>
|
||||
import stockInfo from './components/stock.vue'
|
||||
import {
|
||||
EventsOn,
|
||||
Quit,
|
||||
WindowFullscreen, WindowGetPosition,
|
||||
WindowHide,
|
||||
@ -9,18 +10,19 @@ import {
|
||||
} from '../wailsjs/runtime'
|
||||
import {h, ref} from "vue";
|
||||
import { RouterLink } from 'vue-router'
|
||||
import {darkTheme, NIcon, NText} from 'naive-ui'
|
||||
import {darkTheme, NIcon, NText,} from 'naive-ui'
|
||||
import {
|
||||
SettingsOutline,
|
||||
ReorderTwoOutline,
|
||||
ExpandOutline,
|
||||
RefreshOutline, PowerOutline, BarChartOutline, MoveOutline,
|
||||
RefreshOutline, PowerOutline, BarChartOutline, MoveOutline, WalletOutline,
|
||||
} from '@vicons/ionicons5'
|
||||
|
||||
const content = ref('数据来源于网络,仅供参考\n投资有风险,入市需谨慎')
|
||||
const isFullscreen = ref(false)
|
||||
const activeKey = ref('stock')
|
||||
const containerRef= ref({})
|
||||
const realtimeProfit= ref("")
|
||||
const menuOptions = ref([
|
||||
{
|
||||
label: () =>
|
||||
@ -37,7 +39,15 @@ const menuOptions = ref([
|
||||
{ default: () => '我的自选',}
|
||||
),
|
||||
key: 'stock',
|
||||
icon: renderIcon(BarChartOutline)
|
||||
icon: renderIcon(BarChartOutline),
|
||||
children:[
|
||||
{
|
||||
label: ()=> h(NText, {type:realtimeProfit.value>0?'error':'success'},{ default: () => '当日盈亏 '+realtimeProfit.value+"¥"}),
|
||||
key: 'realtimeProfit',
|
||||
show: realtimeProfit.value,
|
||||
icon: renderIcon(WalletOutline),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
label: () =>
|
||||
@ -122,11 +132,18 @@ function dragstart(e) {
|
||||
}
|
||||
}
|
||||
window.addEventListener('mousemove', dragstart)
|
||||
|
||||
EventsOn("realtime_profit",(data)=>{
|
||||
realtimeProfit.value=data
|
||||
})
|
||||
</script>
|
||||
<template>
|
||||
|
||||
|
||||
<n-config-provider :theme="darkTheme" ref="containerRef">
|
||||
<n-message-provider >
|
||||
<n-notification-provider>
|
||||
<n-modal-provider>
|
||||
<n-watermark
|
||||
:content="content"
|
||||
cross
|
||||
@ -141,8 +158,7 @@ window.addEventListener('mousemove', dragstart)
|
||||
style="height: 100%"
|
||||
>
|
||||
<n-flex justify="center">
|
||||
<n-message-provider >
|
||||
<n-modal-provider>
|
||||
|
||||
<n-grid x-gap="12" :cols="1">
|
||||
<n-gi style="padding-bottom: 70px">
|
||||
<RouterView />
|
||||
@ -158,10 +174,12 @@ window.addEventListener('mousemove', dragstart)
|
||||
</n-card>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
</n-modal-provider>
|
||||
</n-message-provider>
|
||||
|
||||
</n-flex>
|
||||
</n-watermark>
|
||||
</n-modal-provider>
|
||||
</n-notification-provider>
|
||||
</n-message-provider>
|
||||
</n-config-provider>
|
||||
</template>
|
||||
<style>
|
||||
|
@ -10,12 +10,13 @@ import {
|
||||
SetCostPriceAndVolume, SetStockSort,
|
||||
UnFollow
|
||||
} from '../../wailsjs/go/main/App'
|
||||
import {NButton, NFlex, NForm, NFormItem, NInputNumber, NText, useMessage, useModal} from 'naive-ui'
|
||||
import {NButton, NFlex, NForm, NFormItem, NInputNumber, NText, useMessage, useModal,useNotification} from 'naive-ui'
|
||||
import {EventsOn, WindowFullscreen, WindowReload, WindowUnfullscreen} from '../../wailsjs/runtime'
|
||||
import {Add, Search,StarOutline} from '@vicons/ionicons5'
|
||||
|
||||
const message = useMessage()
|
||||
const modal = useModal()
|
||||
const notify = useNotification()
|
||||
|
||||
const stocks=ref([])
|
||||
const results=ref({})
|
||||
@ -124,6 +125,8 @@ EventsOn("refreshFollowList",(data)=>{
|
||||
// })
|
||||
})
|
||||
|
||||
|
||||
|
||||
//判断是否是A股交易时间
|
||||
function isTradingTime() {
|
||||
const now = new Date();
|
||||
|
12
main.go
12
main.go
@ -4,6 +4,7 @@ import (
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"github.com/duke-git/lancet/v2/convertor"
|
||||
"github.com/getlantern/systray"
|
||||
"github.com/wailsapp/wails/v2"
|
||||
"github.com/wailsapp/wails/v2/pkg/logger"
|
||||
"github.com/wailsapp/wails/v2/pkg/menu"
|
||||
@ -73,12 +74,23 @@ func main() {
|
||||
FileMenu.AddText("隐藏到托盘区", keys.CmdOrCtrl("h"), func(_ *menu.CallbackData) {
|
||||
runtime.WindowHide(app.ctx)
|
||||
})
|
||||
|
||||
FileMenu.AddText("显示", keys.CmdOrCtrl("v"), func(_ *menu.CallbackData) {
|
||||
runtime.WindowShow(app.ctx)
|
||||
})
|
||||
}
|
||||
|
||||
//FileMenu.AddText("退出", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
|
||||
// runtime.Quit(app.ctx)
|
||||
//})
|
||||
|
||||
// 创建系统托盘
|
||||
go systray.Run(func() {
|
||||
onReady(app)
|
||||
}, func() {
|
||||
onExit(app)
|
||||
})
|
||||
|
||||
// Create application with options
|
||||
err := wails.Run(&options.App{
|
||||
Title: "go-stock",
|
||||
|
Loading…
x
Reference in New Issue
Block a user