11<script setup lang="ts">
2- import type { MetaData } from ' ./types'
32import { computed , ref , watchEffect } from ' vue'
4- import Card from ' ./Card.vue'
5- import Pagination from ' ./Pagination.vue'
3+ import StoreCard from ' ./StoreCard.vue'
4+ import StorePagination from ' ./StorePagination.vue'
5+ import type { MetaData } from ' ./types'
66
77enum StoreType {
88 Plugins = ' plugins' ,
@@ -15,53 +15,71 @@ const dataItems = ref<MetaData[]>([])
1515
1616const searchText = ref <string >(' ' )
1717const searchedItems = computed <MetaData []>(() => {
18- if (searchText .value )
19- return dataItems .value .filter (item => item .name .includes (searchText .value ))
18+ if (searchText .value ) {
19+ return dataItems .value .filter ((item ) =>
20+ item .name .includes (searchText .value ),
21+ )
22+ }
2023 return dataItems .value .toSorted ((a , b ) => b .time - a .time )
2124})
2225
2326const pageSize = 10
2427const pageNumber = ref <number >(1 )
25- const pageTotal = computed <number >(() => Math .ceil (searchedItems .value .length / pageSize ))
28+ const pageTotal = computed <number >(() =>
29+ Math .ceil (searchedItems .value .length / pageSize ),
30+ )
2631const pageItems = computed (() => {
27- if (searchedItems .value .length === 0 )
32+ if (searchedItems .value .length === 0 ) {
2833 return []
34+ }
2935 return searchedItems .value .slice (
3036 (pageNumber .value - 1 ) * pageSize ,
3137 pageNumber .value * pageSize ,
3238 )
3339})
3440
3541watchEffect (async () => {
36- dataItems .value = await (await fetch (` https://store.alicebot.dev/${storeType .value }.json ` )).json ()
42+ dataItems .value = await (
43+ await fetch (` https://store.alicebot.dev/${storeType .value }.json ` )
44+ ).json ()
3745 searchText .value = ' '
3846})
3947 </script >
4048
4149<template >
4250 <div >
4351 <div class =" mt-10 flex items-center text-sm text-vp-text-1" >
44- <div class =" mr-8" >
45- 类型
46- </div >
52+ <div class =" mr-8" >类型</div >
4753 <div class =" flex flex-wrap gap-2" >
4854 <button
4955 class =" cursor-pointer rounded bg-vp-bg-soft px-2 py-0.5 hover:bg-vp-brand-soft hover:text-vp-brand-1"
50- :class =" storeType === StoreType.Plugins ? 'bg-vp-brand-soft text-vp-brand-1' : ''"
56+ :class ="
57+ storeType === StoreType.Plugins
58+ ? 'bg-vp-brand-soft text-vp-brand-1'
59+ : ''
60+ "
5161 @click =" storeType = StoreType.Plugins"
5262 >
5363 插件
5464 </button >
5565 <button
5666 class =" cursor-pointer rounded bg-vp-bg-soft px-2 py-0.5 hover:bg-vp-brand-soft hover:text-vp-brand-1"
57- :class =" storeType === StoreType.Adapters ? 'bg-vp-brand-soft text-vp-brand-1' : ''"
67+ :class ="
68+ storeType === StoreType.Adapters
69+ ? 'bg-vp-brand-soft text-vp-brand-1'
70+ : ''
71+ "
5872 @click =" storeType = StoreType.Adapters"
5973 >
6074 适配器
6175 </button >
6276 <button
6377 class =" cursor-pointer rounded bg-vp-bg-soft px-2 py-0.5 hover:bg-vp-brand-soft hover:text-vp-brand-1"
64- :class =" storeType === StoreType.Bots ? 'bg-vp-brand-soft text-vp-brand-1' : ''"
78+ :class ="
79+ storeType === StoreType.Bots
80+ ? 'bg-vp-brand-soft text-vp-brand-1'
81+ : ''
82+ "
6583 @click =" storeType = StoreType.Bots"
6684 >
6785 机器人
@@ -78,14 +96,26 @@ watchEffect(async () => {
7896 type =" text"
7997 role =" search"
8098 placeholder =" Search..."
81- >
99+ / >
82100 </div >
83101 <div class =" h-px bg-neutral-700 opacity-15" />
84102 </div >
85- <Pagination key =" topPagination" v-model =" pageNumber" :total =" pageTotal" />
103+ <StorePagination
104+ key =" topPagination"
105+ v-model =" pageNumber"
106+ :total =" pageTotal"
107+ />
86108 <div class =" grid grid-cols-1 gap-6 md:grid-cols-2" >
87- <Card v-for =" (item, index) in pageItems" :key =" index.toString() + item.name" :item =" item" />
109+ <StoreCard
110+ v-for =" (item, index) in pageItems"
111+ :key =" index.toString() + item.name"
112+ :item =" item"
113+ />
88114 </div >
89- <Pagination key =" bottomPagination" v-model =" pageNumber" :total =" pageTotal" />
115+ <Pagination
116+ key =" bottomPagination"
117+ v-model =" pageNumber"
118+ :total =" pageTotal"
119+ />
90120 </div >
91121</template >
0 commit comments