Skip to content

Commit af602fb

Browse files
committed
feat: migrate the ranking page
1 parent ba208b3 commit af602fb

15 files changed

Lines changed: 417 additions & 291 deletions

File tree

components/kun/top-bar/Avatar.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ const statusClasses = computed(() => {
3030

3131
<template>
3232
<div class="flex items-center space-x-1">
33-
<KunButton
34-
:is-icon-only="true"
35-
variant="light"
36-
color="default"
37-
size="xl"
38-
href="/search"
39-
>
40-
<KunIcon name="lucide:search" />
41-
</KunButton>
33+
<KunTooltip text="Ctrl + K 以快速搜索" position="bottom">
34+
<KunButton
35+
:is-icon-only="true"
36+
variant="light"
37+
color="default"
38+
size="xl"
39+
href="/search"
40+
>
41+
<KunIcon name="lucide:search" />
42+
</KunButton>
43+
</KunTooltip>
4244

4345
<KunButton
4446
:is-icon-only="true"

components/ranking/Galgame.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script setup lang="ts">
2+
import { galgameSortItem } from '~/constants/ranking'
3+
import { galgameRankingPageData } from './pageData'
4+
5+
const { data } = await useFetch(`/api/ranking/galgame`, {
6+
method: 'GET',
7+
query: galgameRankingPageData,
8+
...kungalgameResponseHandler
9+
})
10+
</script>
11+
12+
<template>
13+
<KunLink
14+
color="default"
15+
underline="none"
16+
v-for="(galgame, index) in data"
17+
:key="galgame.id"
18+
:to="`/user/${galgame.id}/info`"
19+
class-name="hover:bg-default-100 flex cursor-pointer items-center justify-between rounded-lg p-3 transition-colors"
20+
>
21+
<div class="flex items-center">
22+
<span class="text-default-500 w-12 text-xl font-bold">
23+
{{ index + 1 }}
24+
</span>
25+
{{ getPreferredLanguageText(galgame.name) }}
26+
</div>
27+
28+
<div class="flex items-center space-x-2">
29+
<KunIcon
30+
:name="
31+
galgameSortItem.find((i) => i.sortField === galgame.sortField)
32+
?.icon || ''
33+
"
34+
class="text-primary h-5 w-5"
35+
/>
36+
<span class="font-medium">{{ galgame.value }}</span>
37+
</div>
38+
</KunLink>
39+
</template>

components/ranking/Topic.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { topicIconMap } from '~/constants/ranking'
2+
import { topicSortItem } from '~/constants/ranking'
33
import { topicRankingPageData } from './pageData'
44
55
const { data } = await useFetch(`/api/ranking/topic`, {
@@ -14,8 +14,8 @@ const { data } = await useFetch(`/api/ranking/topic`, {
1414
color="default"
1515
underline="none"
1616
v-for="(topic, index) in data"
17-
:key="topic.tid"
18-
:to="`/topic/${topic.tid}`"
17+
:key="topic.id"
18+
:to="`/topic/${topic.id}`"
1919
class-name="hover:bg-default-100 flex cursor-pointer items-center justify-between rounded-lg p-3 transition-colors"
2020
>
2121
<div class="flex items-center">
@@ -29,10 +29,12 @@ const { data } = await useFetch(`/api/ranking/topic`, {
2929

3030
<div class="flex items-center space-x-2">
3131
<KunIcon
32-
:name="topicIconMap[topicRankingPageData.sortField]"
32+
:name="
33+
topicSortItem.find((i) => i.sortField === topic.sortField)?.icon || ''
34+
"
3335
class="text-primary h-5 w-5"
3436
/>
35-
<span class="font-medium">{{ topic.field }}</span>
37+
<span class="font-medium">{{ topic.value }}</span>
3638
</div>
3739
</KunLink>
3840
</template>

components/ranking/User.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { userIconMap } from '~/constants/ranking'
2+
import { userSortItem } from '~/constants/ranking'
33
import { userRankingPageData } from './pageData'
44
55
const { data } = await useFetch(`/api/ranking/user`, {
@@ -14,8 +14,8 @@ const { data } = await useFetch(`/api/ranking/user`, {
1414
color="default"
1515
underline="none"
1616
v-for="(user, index) in data"
17-
:key="user.uid"
18-
:to="`/user/${user.uid}/info`"
17+
:key="user.id"
18+
:to="`/user/${user.id}/info`"
1919
class-name="hover:bg-default-100 flex cursor-pointer items-center justify-between rounded-lg p-3 transition-colors"
2020
>
2121
<div class="flex items-center">
@@ -28,10 +28,12 @@ const { data } = await useFetch(`/api/ranking/user`, {
2828

2929
<div class="flex items-center space-x-2">
3030
<KunIcon
31-
:name="userIconMap[userRankingPageData.sortField]"
31+
:name="
32+
userSortItem.find((i) => i.sortField === user.sortField)?.icon || ''
33+
"
3234
class="text-primary h-5 w-5"
3335
/>
34-
<span class="font-medium">{{ user.field }}</span>
36+
<span class="font-medium">{{ user.value }}</span>
3537
</div>
3638
</KunLink>
3739
</template>

components/ranking/pageData.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
import type {
2-
RankingGetTopicsRequestData,
3-
RankingGetUserRequestData
4-
} from '~/types/api/ranking'
2+
getTopicRankingSchema,
3+
getGalgameRankingSchema,
4+
getUserRankingSchema
5+
} from '~/validations/ranking'
6+
import type { z } from 'zod'
57

6-
export const topicRankingPageData = reactive<RankingGetTopicsRequestData>({
7-
page: '1',
8-
limit: '100',
9-
sortField: 'views',
8+
type Topic = z.infer<typeof getTopicRankingSchema>
9+
type Galgame = z.infer<typeof getGalgameRankingSchema>
10+
type User = z.infer<typeof getUserRankingSchema>
11+
12+
export const topicRankingPageData = reactive<Topic>({
13+
page: 1,
14+
limit: 100,
15+
sortField: 'view',
16+
sortOrder: 'desc'
17+
})
18+
19+
export const galgameRankingPageData = reactive<Galgame>({
20+
page: 1,
21+
limit: 100,
22+
sortField: 'view',
1023
sortOrder: 'desc'
1124
})
1225

13-
export const userRankingPageData = reactive<RankingGetUserRequestData>({
14-
page: '1',
15-
limit: '100',
26+
export const userRankingPageData = reactive<User>({
27+
page: 1,
28+
limit: 100,
1629
sortField: 'moemoepoint',
1730
sortOrder: 'desc'
1831
})

constants/layout.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export const kunLayoutItem: KunLayoutItem[] = [
8080
router: '/ranking/topic',
8181
label: '话题排行'
8282
},
83+
{
84+
name: 'galgame',
85+
router: '/ranking/galgame',
86+
label: 'Galgame 排行'
87+
},
8388
{
8489
name: 'ranking',
8590
router: '/ranking/user',

0 commit comments

Comments
 (0)