🆕 版本检测更新

This commit is contained in:
chaos-zhu 2024-08-09 12:29:27 +08:00
parent b1532ca9da
commit def84a6cae
2 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "web", "name": "web",
"version": "2.1.1", "version": "2.1.2",
"description": "easynode-web", "description": "easynode-web",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@ -31,12 +31,13 @@
> >
<div class="about_content"> <div class="about_content">
<h1>EasyNode</h1> <h1>EasyNode</h1>
<p>Version: {{ currentVersion }}</p> <p>当前版本: {{ currentVersion }}</p>
<p v-if="isNew" style="text-decoration: underline;"> <p v-if="checkVersionErr" class="conspicuous">Error版本更新检测失败(版本检测API需要外网环境)</p>
有新版本可用: {{ latestVersion }} - <a class="link" href="https://github.com/chaos-zhu/easynode/releases" target="_blank">https://github.com/chaos-zhu/easynode/releases</a> <p v-if="isNew" class="conspicuous">
有新版本可用: {{ latestVersion }} -> <a class="link" href="https://github.com/chaos-zhu/easynode/releases" target="_blank">https://github.com/chaos-zhu/easynode/releases</a>
</p> </p>
<p>Author: <a class="link" href="https://github.com/chaos-zhu" target="_blank">ChaosZhu</a></p> <p>作者: <a class="link" href="https://github.com/chaos-zhu" target="_blank">ChaosZhu</a></p>
<p>Source: <a class="link" href="https://github.com/chaos-zhu/easynode" target="_blank">https://github.com/chaos-zhu/easynode</a></p> <p>开源仓库: <a class="link" href="https://github.com/chaos-zhu/easynode" target="_blank">https://github.com/chaos-zhu/easynode</a></p>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@ -50,6 +51,7 @@ import packageJson from '../../package.json'
const { proxy: { $router, $store, $message } } = getCurrentInstance() const { proxy: { $router, $store, $message } } = getCurrentInstance()
let visible = ref(false) let visible = ref(false)
let checkVersionErr = ref(false)
let currentVersion = ref(`v${ packageJson.version }`) let currentVersion = ref(`v${ packageJson.version }`)
let latestVersion = ref(null) let latestVersion = ref(null)
@ -58,18 +60,23 @@ let isNew = computed(() => {
}) })
async function checkLatestVersion() { async function checkLatestVersion() {
const timeout = 3000
try { try {
const response = await fetch('https://production.get-easynode-latest-version.chaoszhu.workers.dev/version') const timeoutPromise = new Promise((_, reject) =>
// const response = await fetch('https://api.github.com/repos/chaos-zhu/easynode/releases/latest') setTimeout(() => reject(new Error('请求超时')), timeout)
)
const fetchPromise = fetch('https://production.get-easynode-latest-version.chaoszhu.workers.dev/version')
const response = await Promise.race([fetchPromise, timeoutPromise,])
if (!response.ok) { if (!response.ok) {
throw new Error('版本信息请求失败: ' + response.statusText) throw new Error('版本信息请求失败: ' + response.statusText)
} }
const data = await response.json() const data = await response.json()
latestVersion.value = data.tag_name latestVersion.value = data.tag_name
} catch (error) { } catch (error) {
checkVersionErr.value = true
console.error('版本信息请求失败:', error.message) console.error('版本信息请求失败:', error.message)
} }
} }
checkLatestVersion() checkLatestVersion()
@ -125,6 +132,9 @@ const handleLogout = () => {
p { p {
line-height: 35px; line-height: 35px;
} }
.conspicuous {
color: red;
}
} }
} }
</style> </style>