fix:修复混合模式下计数器问题

This commit is contained in:
2026-03-11 08:51:10 +08:00
parent 257065018b
commit 66bf0124bd

View File

@@ -210,7 +210,7 @@ const isDarkTheme = computed(() => {
return themeMode.value === "dark"; return themeMode.value === "dark";
}); });
const categories: Ref<Record<string, string>> = ref({}); const categories: Ref<Record<string, any>> = ref({});
const apps: Ref<App[]> = ref([]); const apps: Ref<App[]> = ref([]);
const activeCategory = ref("home"); const activeCategory = ref("home");
const searchQuery = ref(""); const searchQuery = ref("");
@@ -403,8 +403,9 @@ const openDetail = (app: App | Record<string, unknown>) => {
tags: '', tags: '',
img_urls: [], img_urls: [],
icons: '', icons: '',
origin: (app as any).origin || 'apm',
currentStatus: 'not-installed', currentStatus: 'not-installed',
}; } as App;
} }
// 后续逻辑使用 fullApp // 后续逻辑使用 fullApp
@@ -884,7 +885,7 @@ const loadCategories = async () => {
if (currentStoreMode.value === "hybrid") modes.push("spark", "apm"); if (currentStoreMode.value === "hybrid") modes.push("spark", "apm");
else modes.push(currentStoreMode.value as "spark" | "apm"); else modes.push(currentStoreMode.value as "spark" | "apm");
const categoryData: Record<string, { zh: string; origin: string }> = {}; const categoryData: Record<string, { zh: string; origins: string[] }> = {};
for (const mode of modes) { for (const mode of modes) {
const finalArch = const finalArch =
@@ -897,10 +898,16 @@ const loadCategories = async () => {
const response = await axiosInstance.get(cacheBuster(path)); const response = await axiosInstance.get(cacheBuster(path));
const data = response.data; const data = response.data;
Object.keys(data).forEach((key) => { Object.keys(data).forEach((key) => {
categoryData[key] = { if (categoryData[key]) {
zh: data[key].zh || data[key], if (!categoryData[key].origins.includes(mode)) {
origin: mode, categoryData[key].origins.push(mode);
}; }
} else {
categoryData[key] = {
zh: data[key].zh || data[key],
origins: [mode],
};
}
}); });
} catch (e) { } catch (e) {
logger.error(`读取 ${mode} categories.json 失败: ${e}`); logger.error(`读取 ${mode} categories.json 失败: ${e}`);
@@ -923,58 +930,63 @@ const loadApps = async (onFirstBatch?: () => void) => {
// 并发加载所有分类,每个分类自带重试机制 // 并发加载所有分类,每个分类自带重试机制
await Promise.all( await Promise.all(
categoriesList.map(async (category) => { categoriesList.map(async (category) => {
try { const catInfo = categories.value[category];
const catInfo = categories.value[category]; const origins: string[] = catInfo.origins || (catInfo.origin ? [catInfo.origin] : []);
const mode = catInfo.origin;
const finalArch =
mode === "spark"
? arch.replace("-apm", "-store")
: arch.replace("-store", "-apm");
const path = await Promise.all(
mode === "spark" origins.map(async (mode) => {
? `/store/${category}/applist.json` try {
: `/${finalArch}/${category}/applist.json`; const finalArch =
mode === "spark"
? arch.replace("-apm", "-store")
: arch.replace("-store", "-apm");
logger.info(`加载分类: ${category} (来源: ${mode})`); const path =
const categoryApps = await fetchWithRetry<AppJson[]>( mode === "spark"
cacheBuster(path), ? `/store/${category}/applist.json`
); : `/${finalArch}/${category}/applist.json`;
const normalizedApps = (categoryApps || []).map((appJson) => ({ logger.info(`加载分类: ${category} (来源: ${mode})`);
name: appJson.Name, const categoryApps = await fetchWithRetry<AppJson[]>(
pkgname: appJson.Pkgname, cacheBuster(path),
version: appJson.Version, );
filename: appJson.Filename,
torrent_address: appJson.Torrent_address,
author: appJson.Author,
contributor: appJson.Contributor,
website: appJson.Website,
update: appJson.Update,
size: appJson.Size,
more: appJson.More,
tags: appJson.Tags,
img_urls:
typeof appJson.img_urls === "string"
? JSON.parse(appJson.img_urls)
: appJson.img_urls,
icons: appJson.icons,
category: category,
origin: mode as "spark" | "apm",
currentStatus: "not-installed" as const,
}));
// 增量式更新,让用户尽快看到部分数据 const normalizedApps = (categoryApps || []).map((appJson) => ({
apps.value.push(...normalizedApps); name: appJson.Name,
pkgname: appJson.Pkgname,
version: appJson.Version,
filename: appJson.Filename,
torrent_address: appJson.Torrent_address,
author: appJson.Author,
contributor: appJson.Contributor,
website: appJson.Website,
update: appJson.Update,
size: appJson.Size,
more: appJson.More,
tags: appJson.Tags,
img_urls:
typeof appJson.img_urls === "string"
? JSON.parse(appJson.img_urls)
: appJson.img_urls,
icons: appJson.icons,
category: category,
origin: mode as "spark" | "apm",
currentStatus: "not-installed" as const,
}));
// 只要有一个分类加载成功,就可以考虑关闭整体 loading如果是首批逻辑 // 增量式更新,让用户尽快看到部分数据
if (!firstBatchCallDone && typeof onFirstBatch === "function") { apps.value.push(...normalizedApps);
firstBatchCallDone = true;
onFirstBatch(); // 只要有一个分类加载成功,就可以考虑关闭整体 loading如果是首批逻辑
} if (!firstBatchCallDone && typeof onFirstBatch === "function") {
} catch (error) { firstBatchCallDone = true;
logger.warn(`加载分类 ${category} 最终失败: ${error}`); onFirstBatch();
} }
} catch (error) {
logger.warn(`加载分类 ${category} 来源 ${mode} 最终失败: ${error}`);
}
})
);
}), }),
); );