Skip to content

Commit

Permalink
feat(frontend): 添加窗口移动功能并优化错误处理
Browse files Browse the repository at this point in the history
- 在 App.vue 中添加移动窗口功能
- 优化全屏切换逻辑
- 在 stock_data_api.go 中改进错误处理
- 移除 app.go 中的冗余日志
  • Loading branch information
sparkmemory committed Jan 11, 2025
1 parent 9dc8fa9 commit 1fd149b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
1 change: 0 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func getStockInfo(follow data.FollowedStock) *data.StockInfo {
stockCode := follow.StockCode
stockDatas, err := data.NewStockDataApi().GetStockCodeRealTimeData(stockCode)
if err != nil || len(*stockDatas) == 0 {
logger.SugaredLogger.Errorf("get stock code real time data error:%s", err.Error())
return &data.StockInfo{}
}
stockData := (*stockDatas)[0]
Expand Down
2 changes: 1 addition & 1 deletion backend/data/stock_data_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (receiver StockDataApi) GetStockCodeRealTimeData(StockCodes ...string) (*[]
Get(fmt.Sprintf(sina_stook_url, time.Now().Unix(), slice.Join(StockCodes, ",")))
if err != nil {
logger.SugaredLogger.Error(err.Error())
return &[]StockInfo{}, nil
return &[]StockInfo{}, err
}

stockInfos := make([]StockInfo, 0)
Expand Down
39 changes: 30 additions & 9 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import stockInfo from './components/stock.vue'
import {
Quit,
WindowFullscreen,
WindowFullscreen, WindowGetPosition,
WindowHide,
WindowIsFullscreen,
WindowIsFullscreen, WindowSetPosition,
WindowUnfullscreen
} from '../wailsjs/runtime'
import {h, ref} from "vue";
Expand All @@ -14,7 +14,7 @@ import {
SettingsOutline,
ReorderTwoOutline,
ExpandOutline,
RefreshOutline, PowerOutline, BarChartOutline,
RefreshOutline, PowerOutline, BarChartOutline, MoveOutline,
} from '@vicons/ionicons5'
const content = ref('数据来源于网络,仅供参考\n投资有风险,入市需谨慎')
Expand Down Expand Up @@ -71,7 +71,15 @@ const menuOptions = ref([
}, { default: () => '隐藏到托盘区' }),
key: 'hide',
icon: renderIcon(ReorderTwoOutline),
},
{
label: ()=> h("a", {
href: 'javascript:void(0)',
style: 'cursor: move;',
onClick: toggleStartMoveWindow,
}, { default: () => '移动' }),
key: 'move',
icon: renderIcon(MoveOutline),
},
{
label: ()=> h("a", {
Expand All @@ -87,18 +95,31 @@ function renderIcon(icon) {
}
function toggleFullscreen(e) {
console.log(e)
WindowIsFullscreen().then((isFull) => {
isFullscreen.value = isFull
if (isFull) {
isFullscreen.value=!isFullscreen.value
if (isFullscreen.value) {
WindowUnfullscreen()
e.target.innerHTML = '全屏'
} else {
WindowFullscreen()
e.target.innerHTML = '取消全屏'
}
})
}
const drag = ref(false)
const lastPos= ref({x:0,y:0})
function toggleStartMoveWindow(e) {
drag.value=!drag.value
lastPos.value={x:e.clientX,y:e.clientY}
}
function dragstart(e) {
if (drag.value) {
let x=e.clientX-lastPos.value.x
let y=e.clientY-lastPos.value.y
WindowGetPosition().then((pos) => {
WindowSetPosition(pos.x+x,pos.y+y)
})
}
}
window.addEventListener('mousemove', dragstart)
</script>
<template>

Expand Down

0 comments on commit 1fd149b

Please sign in to comment.