Skip to content

Commit 567414a

Browse files
author
spark
committed
feat(update): 增加新版本详细信息和发布时间
- 获取并显示新版本的 Tag 和 Commit 信息 - 将 UTC 时间转换为本地时间并显示 - 在通知中添加新版本详细信息和发布时间 - 优化股票卡片样式,增加鼠标悬停效果
1 parent 34dc38a commit 567414a

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

app.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ func checkUpdate(a *App) {
6262
}
6363
logger.SugaredLogger.Infof("releaseVersion:%+v", releaseVersion.TagName)
6464
if releaseVersion.TagName != Version {
65+
tag := &models.Tag{}
66+
_, err = resty.New().R().
67+
SetResult(tag).
68+
Get("https://api.github.com/repos/ArvinLovegood/go-stock/git/ref/tags/" + releaseVersion.TagName)
69+
if err == nil {
70+
releaseVersion.Tag = *tag
71+
}
72+
commit := &models.Commit{}
73+
_, err = resty.New().R().
74+
SetResult(commit).
75+
Get(tag.Object.Url)
76+
if err == nil {
77+
releaseVersion.Commit = *commit
78+
}
79+
6580
go runtime.EventsEmit(a.ctx, "updateVersion", releaseVersion)
6681
}
6782
}

backend/models/models.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,51 @@ type GitHubReleaseVersion struct {
8080
TarballUrl string `json:"tarball_url"`
8181
ZipballUrl string `json:"zipball_url"`
8282
Body string `json:"body"`
83+
Tag Tag `json:"tag"`
84+
Commit Commit `json:"commit"`
85+
}
86+
87+
type Tag struct {
88+
Ref string `json:"ref"`
89+
NodeId string `json:"node_id"`
90+
Url string `json:"url"`
91+
Object struct {
92+
Sha string `json:"sha"`
93+
Type string `json:"type"`
94+
Url string `json:"url"`
95+
} `json:"object"`
96+
}
97+
98+
type Commit struct {
99+
Sha string `json:"sha"`
100+
NodeId string `json:"node_id"`
101+
Url string `json:"url"`
102+
HtmlUrl string `json:"html_url"`
103+
Author struct {
104+
Name string `json:"name"`
105+
Email string `json:"email"`
106+
Date time.Time `json:"date"`
107+
} `json:"author"`
108+
Committer struct {
109+
Name string `json:"name"`
110+
Email string `json:"email"`
111+
Date time.Time `json:"date"`
112+
} `json:"committer"`
113+
Tree struct {
114+
Sha string `json:"sha"`
115+
Url string `json:"url"`
116+
} `json:"tree"`
117+
Message string `json:"message"`
118+
Parents []struct {
119+
Sha string `json:"sha"`
120+
Url string `json:"url"`
121+
HtmlUrl string `json:"html_url"`
122+
} `json:"parents"`
123+
Verification struct {
124+
Verified bool `json:"verified"`
125+
Reason string `json:"reason"`
126+
Signature interface{} `json:"signature"`
127+
Payload interface{} `json:"payload"`
128+
VerifiedAt interface{} `json:"verified_at"`
129+
} `json:"verification"`
83130
}

frontend/src/components/stock.vue

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,44 @@ EventsOn("newChatStream",async (msg) => {
160160
})
161161
162162
EventsOn("updateVersion",async (msg) => {
163+
const githubTimeStr = msg.published_at;
164+
// 创建一个 Date 对象
165+
const utcDate = new Date(githubTimeStr);
166+
167+
// 获取本地时间
168+
const date = new Date(utcDate.getTime() + utcDate.getTimezoneOffset() * 60 * 1000);
169+
170+
const year = date.getFullYear();
171+
// getMonth 返回值是 0 - 11,所以要加 1
172+
const month = String(date.getMonth() + 1).padStart(2, '0');
173+
const day = String(date.getDate()).padStart(2, '0');
174+
const hours = String(date.getHours()).padStart(2, '0');
175+
const minutes = String(date.getMinutes()).padStart(2, '0');
176+
const seconds = String(date.getSeconds()).padStart(2, '0');
177+
178+
const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
179+
180+
console.log("GitHub UTC 时间:", utcDate);
181+
console.log("转换后的本地时间:", formattedDate);
163182
notify.info({
164183
avatar: () =>
165184
h(NAvatar, {
166185
size: 'small',
167186
round: false,
168187
src: 'https://github.com/ArvinLovegood/go-stock/raw/master/build/appicon.png'
169188
}),
170-
title: '发现新版本',
171-
content: '请前往发布页下载更新',
189+
title: '发现新版本: ' + msg.tag_name,
190+
content: () => {
191+
//return h(MdPreview, {theme:'dark',modelValue:msg.commit?.message}, null)
192+
return h('div', {
193+
style: {
194+
'text-align': 'left',
195+
'font-size': '14px',
196+
}
197+
}, { default: () => msg.commit?.message })
198+
},
172199
duration: 0,
173-
meta: msg.name,
200+
meta: "发布时间:"+formattedDate,
174201
action: () => {
175202
return h(NButton, {
176203
type: 'primary',
@@ -460,8 +487,8 @@ function getHeight() {
460487
461488
<template>
462489
<n-grid :x-gap="8" :cols="3" :y-gap="8" >
463-
<n-gi v-for="result in sortedResults" >
464-
<n-card :data-code="result['股票代码']" :bordered="false" :title="result['股票名称']" :closable="false" @close="removeMonitor(result['股票代码'],result['股票名称'],result.key)">
490+
<n-gi v-for="result in sortedResults" style="margin-left: 2px" onmouseover="this.style.border='1px solid #3498db' " onmouseout="this.style.border='0px'">
491+
<n-card :data-code="result['股票代码']" :bordered="false" :title="result['股票名称']" :closable="false" @close="removeMonitor(result['股票代码'],result['股票名称'],result.key)">
465492
<n-grid :cols="1" :y-gap="6">
466493
<n-gi>
467494
<n-text :type="result.type" >

0 commit comments

Comments
 (0)