Skip to content

Commit 1cbdbaa

Browse files
ACaiCatclaude
andcommitted
✨ 首页排序切换(下载最多/评分最高/最新收录/名称)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent aa62453 commit 1cbdbaa

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

‎src/api.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ function unwrap<T>(resp: ApiResp<T>): T {
1313
return resp.data as T
1414
}
1515

16+
export type SortKey = 'download' | 'rating' | 'newest' | 'name'
17+
1618
export interface SearchParams {
1719
keyword?: string
1820
page?: number
1921
page_size?: number
22+
sort?: SortKey
2023
}
2124

2225
export async function searchPlugins(params: SearchParams = {}): Promise<PluginListData> {

‎src/views/HomeView.vue‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
<script setup lang="ts">
22
import { computed, onMounted, ref, watch } from 'vue'
3-
import { searchPlugins } from '@/api'
3+
import { searchPlugins, type SortKey } from '@/api'
44
import type { PluginInfo } from '@/plugin'
55
import PluginCard from '@/components/PluginCard.vue'
66
77
const PAGE_SIZE = 12
88
9+
const SORTS: { key: SortKey; label: string }[] = [
10+
{ key: 'download', label: '下载最多' },
11+
{ key: 'rating', label: '评分最高' },
12+
{ key: 'newest', label: '最新收录' },
13+
{ key: 'name', label: '名称' },
14+
]
15+
916
const keyword = ref('')
17+
const sort = ref<SortKey>('download')
1018
const page = ref(1)
1119
const total = ref(0)
1220
const plugins = ref<PluginInfo[]>([])
@@ -21,6 +29,7 @@ async function load() {
2129
try {
2230
const data = await searchPlugins({
2331
keyword: keyword.value || undefined,
32+
sort: sort.value,
2433
page: page.value,
2534
page_size: PAGE_SIZE,
2635
})
@@ -44,6 +53,11 @@ watch(keyword, () => {
4453
4554
watch(page, load)
4655
56+
watch(sort, () => {
57+
page.value = 1
58+
load()
59+
})
60+
4761
onMounted(load)
4862
</script>
4963

@@ -61,6 +75,16 @@ onMounted(load)
6175
</section>
6276

6377
<section class="container list-area">
78+
<div class="sort-bar">
79+
<button
80+
v-for="s in SORTS"
81+
:key="s.key"
82+
class="sort-pill"
83+
:class="{ active: sort === s.key }"
84+
@click="sort = s.key"
85+
>{{ s.label }}</button>
86+
</div>
87+
6488
<p v-if="error" class="error">加载失败: {{ error }}</p>
6589
<p v-else-if="loading && plugins.length === 0" class="hint">加载中...</p>
6690
<p v-else-if="plugins.length === 0" class="hint">没有找到插件捏~</p>
@@ -135,10 +159,39 @@ onMounted(load)
135159
}
136160
137161
.list-area {
138-
padding-top: 1.8rem;
162+
padding-top: 1.4rem;
139163
padding-bottom: 2.5rem;
140164
}
141165
166+
.sort-bar {
167+
display: flex;
168+
gap: 0.5rem;
169+
flex-wrap: wrap;
170+
margin-bottom: 1.1rem;
171+
}
172+
173+
.sort-pill {
174+
padding: 0.32rem 0.95rem;
175+
border: 1px solid var(--color-border);
176+
border-radius: 99px;
177+
background: var(--color-background);
178+
color: var(--color-text);
179+
font-size: 0.85rem;
180+
cursor: pointer;
181+
transition: 0.2s;
182+
}
183+
184+
.sort-pill:hover {
185+
border-color: var(--color-accent);
186+
color: var(--color-accent);
187+
}
188+
189+
.sort-pill.active {
190+
background: var(--color-accent);
191+
border-color: var(--color-accent);
192+
color: #fff;
193+
}
194+
142195
.grid {
143196
display: grid;
144197
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));

0 commit comments

Comments
 (0)