11<script setup lang="ts">
22import { computed , onMounted , ref , watch } from ' vue'
3- import { searchPlugins } from ' @/api'
3+ import { searchPlugins , type SortKey } from ' @/api'
44import type { PluginInfo } from ' @/plugin'
55import PluginCard from ' @/components/PluginCard.vue'
66
77const 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+
916const keyword = ref (' ' )
17+ const sort = ref <SortKey >(' download' )
1018const page = ref (1 )
1119const total = ref (0 )
1220const 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
4554watch (page , load )
4655
56+ watch (sort , () => {
57+ page .value = 1
58+ load ()
59+ })
60+
4761onMounted (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.8 rem ;
162+ padding-top : 1.4 rem ;
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