This commit is contained in:
Julian Freeman
2026-03-30 22:00:00 -04:00
parent 5048ef5e76
commit 5717b94c90
2 changed files with 50 additions and 9 deletions

View File

@@ -34,16 +34,26 @@
<span class="id-badge">{{ software.id }}</span>
</div>
<div class="version-info">
<!-- 如果状态是已安装或者是在更新/全部列表中已经有版本号的软件 -->
<template v-if="software.status === 'installed' || (software.status === 'idle' && actionLabel === '更新') || (software.status === 'idle' && !actionLabel && software.version)">
<!-- 情况 1: 已安装软件 (包含待更新状态) -->
<template v-if="isInstalled">
<span class="version-tag">当前: {{ software.version || '--' }}</span>
</template>
<template v-else>
<span class="version-tag recommended">
推荐: {{ software.version || '最新版' }}
<!-- 仅在装机必备且当前版本低于推荐版本时显示 -->
<span
v-if="software.recommended_version && isVersionLower(software.version, software.recommended_version)"
class="version-tag recommended"
>
推荐: {{ software.recommended_version }}
</span>
</template>
<!-- 情况 2: 未安装软件 -->
<template v-else>
<span class="version-tag recommended">
推荐: {{ software.recommended_version || '最新版' }}
</span>
</template>
<!-- 情况 3: WinGet 检测到的仓库最新版本 -->
<span class="version-tag available" v-if="software.available_version">
最新: {{ software.available_version }}
</span>
@@ -126,6 +136,35 @@ const displayProgress = computed(() => {
return Math.round(props.software.progress * 100) + '%';
});
const isInstalled = computed(() => {
return props.software.status === 'installed' ||
(props.software.status === 'idle' && props.actionLabel === '更新') ||
(props.software.status === 'idle' && !props.actionLabel && props.software.installed_version);
});
const isVersionLower = (current: string | undefined | null, target: string | undefined | null) => {
if (!current || !target) return false;
if (current === target) return false;
// 简易的版本比对逻辑:按点分割比对数字
const v1 = current.split('.');
const v2 = target.split('.');
const len = Math.max(v1.length, v2.length);
for (let i = 0; i < len; i++) {
const n1 = parseInt(v1[i] || '0', 10);
const n2 = parseInt(v2[i] || '0', 10);
if (isNaN(n1) || isNaN(n2)) {
// 如果是非数字字符串比对,直接返回字符串比对结果
if (v1[i] !== v2[i]) return v1[i] < v2[i];
continue;
}
if (n1 < n2) return true;
if (n1 > n2) return false;
}
return false;
};
const placeholderColor = computed(() => {
const colors = ['#FF9500', '#FF3B30', '#34C759', '#007AFF', '#5856D6', '#AF52DE'];
let hash = 0;

View File

@@ -39,10 +39,12 @@ export const useSoftwareStore = defineStore('software', {
let displayStatus = item.status;
let actionLabel = '安装';
let currentVersion = item.version; // 默认使用清单中的推荐版本
// 统一字段version 始终代表当前安装的版本recommended_version 代表清单推荐的版本
const currentVersion = installedInfo ? installedInfo.version : null;
const recommendedVersion = item.version;
if (isInstalled) {
currentVersion = installedInfo.version; // 如果已安装,显示本地真实版本
if (hasUpdate) {
actionLabel = '更新';
} else if (displayStatus === 'idle') {
@@ -54,7 +56,7 @@ export const useSoftwareStore = defineStore('software', {
return {
...item,
version: currentVersion,
recommended_version: item.version, // 额外保存一个原始推荐版本字段供前端判断
recommended_version: recommendedVersion,
status: displayStatus,
actionLabel
};