diff --git a/src/api/download.ts b/src/api/download.ts index c7fb288..b75e6cf 100644 --- a/src/api/download.ts +++ b/src/api/download.ts @@ -10,6 +10,7 @@ export interface DownloadResource { file_hash: string | null file_size: string | null is_active: boolean | null + is_test?: boolean package_type: string version: string } @@ -36,6 +37,20 @@ export function getLatestVersionApi(): Promise { }) } +/** + * 获取测试版本 + * GET /download-resources?is_test=true + */ +export function getTestVersionApi(): Promise { + return request({ + url: '/download-resources', + method: 'get', + params: { + is_test: true + } + }) +} + /** * 获取资源列表(包含未激活的) * GET /web-api/download-resources @@ -86,6 +101,7 @@ export interface CreateResourceRequest { file_size?: string | null file_hash?: string | null is_active?: boolean | null + is_test?: boolean } /** 创建资源响应数据类型 */ diff --git a/src/views/download-manager/index.vue b/src/views/download-manager/index.vue index 2014ba1..d8acaf0 100644 --- a/src/views/download-manager/index.vue +++ b/src/views/download-manager/index.vue @@ -231,6 +231,14 @@ /> + + + + + + + + ({ file_size: '', file_hash: '', is_active: true, + is_test: false, }) const createRules: FormRules = { @@ -410,6 +427,7 @@ const editForm = reactive({ file_size: '', file_hash: '', is_active: true, + is_test: false, }) const editRules: FormRules = { @@ -499,6 +517,7 @@ function handleCreate() { file_size: '', file_hash: '', is_active: true, + is_test: false, }) createDialogVisible.value = true } @@ -543,6 +562,7 @@ function handleEdit(resource: DownloadResource) { file_size: resource.file_size || '', file_hash: resource.file_hash || '', is_active: resource.is_active ?? true, + is_test: resource.is_test ?? false, }) editDialogVisible.value = true } diff --git a/src/views/download/index.vue b/src/views/download/index.vue index d59880b..d831e34 100644 --- a/src/views/download/index.vue +++ b/src/views/download/index.vue @@ -13,12 +13,51 @@ 下载中心

选择适合您的安装包,立即开始使用 Snap Hutao
系统要求:新版本Windows10及Windows11

+ + +
+ + + + + + + + + + + +

测试版可能存在未知的 Bug 和稳定性问题,仅供测试和体验新功能使用。如需稳定使用,请下载正式版。

+
+
- 最新版本 + + {{ versionType === 'test' ? '最新测试版本' : '最新版本' }} +

{{ latestVersion.version }}

@@ -70,16 +109,18 @@
- 历史版本 + + 历史版本 -
-
+ +

暂无历史版本

-
+ +
+ + +
+ +

暂无测试版本

+
@@ -147,7 +194,7 @@ import { FolderOpened, } from '@element-plus/icons-vue' import Header from '@/components/Header.vue' -import { getDownloadResourcesApi } from '@/api/download' +import { getDownloadResourcesApi, getTestVersionApi } from '@/api/download' const router = useRouter() @@ -200,6 +247,7 @@ const latestVersion = ref(null) const historyVersions = ref([]) const loading = ref(false) const downloading = ref(false) +const versionType = ref<'stable' | 'test'>('stable') /** * 格式化日期 @@ -261,7 +309,7 @@ function getTooltipText(item: VersionInfo, packageType: 'msi' | 'msix') { } /** - * 加载所有版本 + * 加载正式版本 */ async function loadAllVersions() { try { @@ -324,6 +372,91 @@ async function loadAllVersions() { } } +/** + * 加载测试版本 + */ +async function loadTestVersion() { + try { + loading.value = true + const data = await getTestVersionApi() + if (!data || data.length === 0) { + latestVersion.value = null + historyVersions.value = [] + return + } + + // 按版本号分组 + const versionMap = new Map() + + data.forEach((item) => { + if (!versionMap.has(item.version)) { + // 首次遇到该版本,创建新记录 + versionMap.set(item.version, { + version: item.version, + created_at: item.created_at, + created_by: item.created_by, + features: item.features, + file_hash: item.file_hash, + file_size: item.file_size, + is_active: item.is_active, + packages: { + msi: null, + msix: null, + msi_size: null, + msix_size: null, + }, + }) + } + + // 添加包类型的下载链接和大小 + const versionInfo = versionMap.get(item.version) + if (versionInfo) { + if (item.package_type === 'msi') { + versionInfo.packages.msi = item.download_url + versionInfo.packages.msi_size = item.file_size + } else if (item.package_type === 'msix') { + versionInfo.packages.msix = item.download_url + versionInfo.packages.msix_size = item.file_size + } + } + }) + + // 转换为数组并按创建时间倒序排序 + const versions = Array.from(versionMap.values()).sort((a, b) => + new Date(b.created_at).getTime() - new Date(a.created_at).getTime() + ) + + if (versions.length > 0) { + latestVersion.value = versions[0] ?? null + // 测试版本只显示最新版本,不显示历史版本 + historyVersions.value = [] + } else { + latestVersion.value = null + historyVersions.value = [] + } + } catch (error) { + console.error('加载测试版本失败:', error) + ElMessage.error('加载测试版本失败') + } finally { + loading.value = false + } +} + +/** + * 切换版本类型 + */ +function switchVersionType(type: 'stable' | 'test') { + versionType.value = type + latestVersion.value = null + historyVersions.value = [] + + if (type === 'stable') { + loadAllVersions() + } else { + loadTestVersion() + } +} + onMounted(() => { loadAllVersions() }) @@ -365,7 +498,42 @@ onMounted(() => { font-size: 16px; color: var(--text-color); opacity: 0.8; - margin-bottom: 10px; + margin-bottom: 20px; +} + +/* 版本类型切换 */ +.version-tabs { + margin-bottom: 32px; +} + +.version-tabs :deep(.el-tabs__header) { + margin: 0; +} + +.version-tabs :deep(.el-tabs__nav-wrap::after) { + display: none; +} + +.version-tabs :deep(.el-tabs__item) { + font-size: 16px; + padding: 0 24px; +} + +.version-tabs .tab-label { + display: flex; + align-items: center; + gap: 6px; +} + +.version-tabs :deep(.el-alert) { + margin-top: 16px; + padding: 12px 16px; +} + +.version-tabs :deep(.el-alert__description) { + margin-top: 8px; + font-size: 14px; + line-height: 1.5; } /* 最新版本卡片 */