Skip to content

Commit 10c0b3a

Browse files
committed
refactor: 重构Ep选择
1 parent 5f737d9 commit 10c0b3a

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/layout/default.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export interface ContentProps {
1818

1919
export enum QueryKey {
2020
Detail = 'layout::default::detail',
21-
Ep = 'layout::default::ep'
21+
Ep = 'layout::default::ep',
22+
Recommends = 'layout::default::recommends'
2223
}
2324
export const createPageQueryKey = (page: uni.content.ContentPage) => ({
2425
id: page.id,

src/layout/default/EpController.vue

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { SharedFunction } from '@delta-comic/core'
33
import { uni } from '@delta-comic/model'
44
import { useConfig } from '@delta-comic/plugin'
5-
import { shallowRef, useTemplateRef } from 'vue'
5+
import { useInfiniteQuery } from '@pinia/colada'
6+
import { computed, nextTick, shallowRef, useTemplateRef } from 'vue'
67
import { useRoute } from 'vue-router'
78
89
import * as LayoutInject from '../default'
@@ -25,27 +26,25 @@ const routeToContent = (preload: uni.item.RawItem) =>
2526
2627
const config = useConfig()
2728
28-
const queryEps = useInfQuery({
29+
const queryEps = useInfiniteQuery({
2930
key: () => [LayoutInject.QueryKey.Ep, LayoutInject.createPageQueryKey($props.page)],
30-
query: () => $props.page
31+
query: async ({ signal, pageParam }) => await $props.page.fetchEps(pageParam, signal),
32+
initialPageParam: $props.page.fetchEps.initialPageParam,
33+
getNextPageParam: lp => lp.nextPage
3134
})
35+
const eps = computed(() => queryEps.data.value?.pages.flat() ?? [])
3236
3337
const epSelList = useTemplateRef('epSelList')
3438
const isShowEpSelectPopup = shallowRef(false)
35-
const eps = computedAsync(
36-
async () => sortBy(await $props.page.eps.content, v => Number(v.index)),
37-
[]
38-
)
3939
4040
const nowEpId = $route.params.ep.toString()
41-
const nowEp = computed(() => eps.value.find(ep => ep.index === nowEpId))
42-
const nowEpIndex = computed(() => eps.value.findIndex(ep => ep.index === nowEpId))
41+
const nowEp = computed(() => eps.value.find(ep => ep.id === nowEpId))
42+
const nowEpIndex = computed(() => eps.value.findIndex(ep => ep.id === nowEpId))
4343
const openEpSelectPopup = async () => {
44-
scrollbar.value?.scrollTo(0, 0)
4544
isShowEpSelectPopup.value = true
4645
await nextTick()
4746
epSelList.value?.listInstance?.scrollTo({
48-
index: eps.value.findIndex(ep => ep.index === nowEpId)
47+
index: eps.value.findIndex(ep => ep.id === nowEpId)
4948
})
5049
}
5150
</script>
@@ -84,16 +83,17 @@ const openEpSelectPopup = async () => {
8483
<div class="flex h-10 w-full items-center pt-2 pl-8 text-lg font-bold">选集</div>
8584
<DcList
8685
class="h-full w-full"
87-
:source="{ data: PromiseContent.resolve(eps), isEnd: true }"
86+
:source="{ type: 'infinite', value: queryEps }"
8887
:itemHeight="40"
8988
v-slot="{ data: { item: ep, index }, height }"
9089
ref="epSelList"
9190
>
9291
<VanCell
92+
v-if="union"
9393
clickable
9494
@click="routeToContent({ ...union.toJSON(), thisEp: ep.toJSON() })"
9595
:title="ep.name || `第${index + 1}话`"
96-
:title-class="[nowEpId === ep.index && 'font-bold text-(--p-color)!']"
96+
:title-class="[nowEpId === ep.id && 'font-bold text-(--p-color)!']"
9797
class="flex w-full items-center"
9898
:style="{ height: `${height}px !important` }"
9999
>

src/layout/default/Recommends.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import { uni } from '@delta-comic/model'
3+
import { useQuery } from '@pinia/colada'
4+
5+
import ItemCard from '@/components/ItemCard'
6+
7+
import * as LayoutInject from '../default'
8+
9+
const $props = defineProps<{
10+
union?: uni.item.Item
11+
page: uni.content.ContentPage
12+
}>()
13+
14+
const getItemCard = (contentType: uni.content.ContentType_) =>
15+
uni.item.Item.itemCards.get(contentType) ?? ItemCard
16+
17+
const recommendsQuery = useQuery({
18+
key: () => [LayoutInject.QueryKey.Recommends]
19+
})
20+
</script>
221

322
<template>
423
<div class="van-hairline--top w-full *:bg-transparent">

0 commit comments

Comments
 (0)