mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-08-07 13:03:56 +08:00
refactor(home): 重构首页与侧边栏,移除旧HomeList类型并支持首页列表侧边栏入口
1. 移除废弃的HomeList类型定义,新增homeList侧边栏类型 2. 重构AppGrid组件,添加showOrigin属性支持自定义显示来源标记 3. 简化HomeView组件,移除旧的列表展示逻辑与相关代码 4. 新增侧边栏首页列表入口加载与应用数据加载逻辑 5. 优化侧边栏计数与应用预加载逻辑,适配新的首页列表类型
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
v-for="(app, index) in apps"
|
||||
:key="index"
|
||||
:app="app"
|
||||
:show-origin="storeFilter === 'both'"
|
||||
:show-origin="effectiveShowOrigin"
|
||||
@open-detail="$emit('open-detail', app)"
|
||||
/>
|
||||
</div>
|
||||
@@ -46,7 +46,7 @@
|
||||
v-for="app in item.apps"
|
||||
:key="app.pkgname"
|
||||
:app="app"
|
||||
:show-origin="storeFilter === 'both'"
|
||||
:show-origin="effectiveShowOrigin"
|
||||
@open-detail="$emit('open-detail', app)"
|
||||
/>
|
||||
</div>
|
||||
@@ -93,8 +93,16 @@ const props = defineProps<{
|
||||
loading: boolean;
|
||||
storeFilter?: "spark" | "apm" | "both";
|
||||
scrollKey?: string;
|
||||
showOrigin?: boolean;
|
||||
}>();
|
||||
|
||||
// 显式传入 showOrigin 时优先使用;否则回退到根据 storeFilter 推断
|
||||
const effectiveShowOrigin = computed(() =>
|
||||
props.showOrigin !== undefined
|
||||
? props.showOrigin
|
||||
: props.storeFilter === "both",
|
||||
);
|
||||
|
||||
defineEmits<{
|
||||
(e: "open-detail", app: App): void;
|
||||
}>();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="space-y-6">
|
||||
<!-- 初始加载状态 - 只有在完全没有数据时显示 -->
|
||||
<div
|
||||
v-if="loading && links.length === 0 && lists.length === 0"
|
||||
v-if="loading && links.length === 0"
|
||||
class="flex flex-col items-center justify-center py-12 text-slate-500 dark:text-slate-400"
|
||||
>
|
||||
<i class="fas fa-spinner fa-spin text-2xl mb-3"></i>
|
||||
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
<!-- 无数据时显示欢迎信息 -->
|
||||
<div
|
||||
v-else-if="links.length === 0 && lists.length === 0"
|
||||
v-else-if="links.length === 0"
|
||||
class="flex flex-col items-center justify-center py-20 text-center"
|
||||
>
|
||||
<img
|
||||
@@ -110,54 +110,22 @@
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- Lists 区域 -->
|
||||
<div v-if="lists.length > 0" class="space-y-6 mt-6">
|
||||
<section v-for="section in lists" :key="section.title">
|
||||
<div class="flex items-center justify-between">
|
||||
<h3
|
||||
class="text-lg font-semibold text-slate-900 dark:text-slate-200"
|
||||
>
|
||||
{{ section.title }}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="mt-3 grid gap-4 app-grid">
|
||||
<AppCard
|
||||
v-for="app in section.apps"
|
||||
:key="app.pkgname"
|
||||
:app="app"
|
||||
@open-detail="handleOpenDetail(app)"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import AppCard from "./AppCard.vue";
|
||||
import { APM_STORE_BASE_URL } from "../global/storeConfig";
|
||||
import { reactive } from "vue";
|
||||
import type { HomeLink, HomeList, App } from "../global/typedefinition";
|
||||
import type { HomeLink } from "../global/typedefinition";
|
||||
|
||||
defineProps<{
|
||||
links: HomeLink[];
|
||||
lists: HomeList[];
|
||||
loading: boolean;
|
||||
error: string;
|
||||
storeFilter?: "spark" | "apm" | "both";
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: "open-detail", app: App | Record<string, unknown>): void;
|
||||
}>();
|
||||
|
||||
// 处理应用卡片点击,添加来自首页的标记
|
||||
const handleOpenDetail = (app: App) => {
|
||||
emit("open-detail", { ...app, _fromHomeView: true });
|
||||
};
|
||||
|
||||
// 图片加载状态跟踪
|
||||
const imageLoaded = reactive<Record<string, boolean>>({});
|
||||
|
||||
@@ -203,16 +171,4 @@ const onLinkClick = (link: HomeLink) => {
|
||||
gap: 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* 应用卡片网格 - 保持原来的样式 */
|
||||
.app-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.app-grid {
|
||||
grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user