/** * useAppState —— 跨 composable 共享的全局原始响应式状态(单例)。 * * 设计说明(避免循环依赖与重复实例化): * App.vue 原文件中的逻辑被拆分到多个 composable(useCatalog / useRanking / * useAppDetail / useInstalledApps / useFavorites / useAccountSync / useDownloads)。 * 这些 composable 之间存在大量共享状态(apps / currentApp / installedApps / * favorite* / 各类弹窗开关等)。若各自持有会出现多实例与状态不同步,并引发循环依赖。 * * 故把"贯穿整个应用生命周期的全局原始状态"集中在本模块以单例形式导出, * 所有 composable 与 App.vue 均从本模块取用同一份 ref 实例。 * 这与现有 global/authState.ts、global/storeConfig.ts 的单例风格一致。 * * 本模块**只持有状态与极少量纯派生 computed**,不含任何业务逻辑/副作用, * 确保拆分前后运行时行为完全一致(7 维度审计:功能/状态一致)。 * * 注意:currentApp / currentAppSparkInstalled / currentAppApmInstalled 同时在 * storeConfig 中导出(供其它模块直接引用)。本模块从 storeConfig 再导出以保持单一实例。 */ import { ref, computed } from "vue"; import type { Ref } from "vue"; import type { App, AppJson, CategoryInfo, SidebarEntry, HomeLink, FavoriteFolder, FavoriteItem, InstalledAppInfo, ResolvedFavoriteItem, SystemInfo, DownloadedAppRecord, SyncedAppListItem, AppReview, ReviewUserProfile, DownloadItem, } from "../global/typedefinition"; // ===== 目录数据 ===== export const apps: Ref = ref([]); export const categories: Ref> = ref({}); export const tabCategories: Ref>> = ref({}); export const tabApps: Ref> = ref({}); export const loadingTabs = ref>(new Set()); export const homeListUrls = ref< Record >({}); export const sidebarEntries: Ref = ref([]); export const sparkAvailable = ref(false); export const apmAvailable = ref(false); export const storeFilter = ref<"spark" | "apm" | "both">("both"); export const initialCatalogLoaded = ref(false); export const loading = ref(true); // ===== 首页 / 排行 ===== export const homeLinks = ref([]); export const homeLoading = ref(false); export const homeError = ref(""); export const apmRanking = ref([]); export const sparkRanking = ref([]); export const rankingLoading = ref(false); // ===== 导航 ===== export type MainView = "default" | "favorites"; export const currentView = ref("default"); export const activeTab = ref("home"); export const selectedCategory = ref("all"); export const searchQuery = ref(""); export const isSidebarOpen = ref(false); // ===== 详情弹窗 ===== export { currentApp, currentAppSparkInstalled, currentAppApmInstalled, } from "../global/storeConfig"; export const showModal = ref(false); export const showPreview = ref(false); export const currentScreenIndex = ref(0); export const screenshots = ref([]); // ===== 已安装应用 ===== export const showInstalledModal = ref(false); export const installedApps = ref([]); export const installedLoading = ref(false); export const installedError = ref(""); export const installedWarning = ref(""); export const installedRefreshGeneration = ref(0); export const installedSyncPromptShown = ref(false); // ===== 收藏夹 ===== export const favoriteFolders = ref([]); export const activeFavoriteFolderId = ref(null); export const favoriteItems = ref([]); export const favoriteItemsByFolder = ref>({}); export const showFavoriteSelector = ref(false); export const favoriteTargetApp = ref(null); export const favoriteSelectorDraftFolderIds = ref | null>(null); export const favoriteLoading = ref(false); export const favoriteError = ref(""); export const favoriteRequestGeneration = ref(0); // ===== 账号 / 下载历史 / 云端同步 / 恢复 ===== export const showUserManagementModal = ref(false); export const downloadedApps = ref([]); export const downloadedLoading = ref(false); export const downloadedError = ref(""); export const downloadedRequestGeneration = ref(0); export const syncLoading = ref(false); export const syncStatusMessage = ref(""); export const syncRequestGeneration = ref(0); export const syncCandidateApps = ref([]); export const restoreLoading = ref(false); export const restoreError = ref(""); export const showRestoreModal = ref(false); export const restoreItems = ref([]); export const restoreRequestGeneration = ref(0); export const showLoginModal = ref(false); export const loginLoading = ref(false); export const loginError = ref(""); export const showLoginPrompt = ref(false); export const loginPromptMessage = ref("请登录星火账号后继续操作。"); export const showLoginPromptMessage = loginPromptMessage; export const showReviewUserProfileModal = ref(false); export const selectedReviewUserProfile = ref(null); export const systemInfo = ref({ distro: "unknown" }); // ===== 下载队列 ===== export { downloads } from "../global/downloadStatus"; export const showDownloadDetailModal = ref(false); export const currentDownload: Ref = ref(null); // ===== 其它弹窗 / 卸载 / 更新中心编排 ===== export const showUninstallModal = ref(false); export const uninstallTargetApp: Ref = ref(null); export const showAboutModal = ref(false); export const showSettingsModal = ref(false); export const showApmInstallDialog = ref(false); // 可用来源 computed(供 storeFilter 相关判断复用) export const availableSources = computed(() => ({ spark: sparkAvailable.value, apm: apmAvailable.value, })); // 运算符别名(仅导出类型引用,避免重复定义) export type { App, AppJson, CategoryInfo, SidebarEntry, HomeLink, FavoriteFolder, FavoriteItem, InstalledAppInfo, ResolvedFavoriteItem, SystemInfo, DownloadedAppRecord, SyncedAppListItem, AppReview, ReviewUserProfile, DownloadItem, };