Merge pull request #23 from tbphp/fix-version-check

fix: version check
This commit is contained in:
tbphp
2025-07-17 19:06:10 +08:00
committed by GitHub
2 changed files with 23 additions and 23 deletions

View File

@@ -41,9 +41,9 @@ const statusConfig = {
text: "有更新",
},
error: {
color: "#909399",
icon: undefined,
text: "",
color: "#d03050",
icon: WarningOutline,
text: "检查失败",
},
};
@@ -68,7 +68,10 @@ const checkVersion = async () => {
};
const handleVersionClick = () => {
if (versionInfo.value.status === "update-available" && versionInfo.value.releaseUrl) {
if (
(versionInfo.value.status === "update-available" || versionInfo.value.status === "latest") &&
versionInfo.value.releaseUrl
) {
window.open(versionInfo.value.releaseUrl, "_blank", "noopener,noreferrer");
}
};
@@ -95,7 +98,8 @@ onMounted(() => {
<div
class="version-container"
:class="{
'version-clickable': versionInfo.status === 'update-available',
'version-clickable':
versionInfo.status === 'update-available' || versionInfo.status === 'latest',
'version-checking': isChecking,
}"
@click="handleVersionClick"
@@ -110,22 +114,12 @@ onMounted(() => {
<span class="version-text">
{{ formatVersion(versionInfo.currentVersion) }}
-
<template v-if="versionInfo.status === 'latest'">
<span :style="{ color: statusConfig[versionInfo.status].color }">
{{ statusConfig[versionInfo.status].text }}
</span>
</template>
<template v-else-if="versionInfo.status === 'update-available'">
<span :style="{ color: statusConfig[versionInfo.status].color }">
{{ statusConfig[versionInfo.status].text }}
<span :style="{ color: statusConfig[versionInfo.status].color }">
{{ statusConfig[versionInfo.status].text }}
<template v-if="versionInfo.status === 'update-available'">
[{{ formatVersion(versionInfo.latestVersion || "") }}]
</span>
</template>
<template v-else-if="versionInfo.status === 'checking'">
<span :style="{ color: statusConfig[versionInfo.status].color }">
{{ statusConfig[versionInfo.status].text }}
</span>
</template>
</template>
</span>
</span>
</div>

View File

@@ -45,6 +45,12 @@ class VersionService {
return null;
}
// 检查缓存中的版本号是否与当前应用版本号一致
if (versionInfo.currentVersion !== this.currentVersion) {
this.clearCache();
return null;
}
return versionInfo;
} catch (error) {
console.warn("Failed to parse cached version info:", error);
@@ -144,6 +150,9 @@ class VersionService {
versionInfo.isLatest = comparison >= 0;
versionInfo.hasUpdate = comparison < 0;
versionInfo.status = comparison < 0 ? "update-available" : "latest";
// 只在成功时缓存结果
this.setCachedVersionInfo(versionInfo);
} else {
versionInfo.status = "error";
}
@@ -152,9 +161,6 @@ class VersionService {
versionInfo.status = "error";
}
// 缓存结果
this.setCachedVersionInfo(versionInfo);
return versionInfo;
}