Skip to content

Commit 5e25db3

Browse files
committed
refactor: 重构default布局
1 parent 52c083b commit 5e25db3

4 files changed

Lines changed: 37 additions & 45 deletions

File tree

src/layout/Default.vue

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<script setup lang="ts">
22
import type { uni } from '@delta-comic/model'
33
import { useQuery } from '@pinia/colada'
4+
import { KeyboardArrowDownRound } from '@vicons/material'
45
import { createReusableTemplate, useCssVar } from '@vueuse/core'
6+
import { motion } from 'motion-v'
57
import { computed, shallowRef, useTemplateRef } from 'vue'
68
79
import Comment from '@/components/comment/Comment.vue'
8-
import ItemCard from '@/components/ItemCard.vue'
910
import { createDateString } from '@/utils/date'
1011
1112
import * as LayoutInject from './default'
13+
import Actions from './default/Actions.vue'
14+
import Description from './default/Description.vue'
15+
import EpController from './default/EpController.vue'
16+
import SubscribeList from './default/SubscribeList.vue'
17+
import Tags from './default/Tags.vue'
18+
import ViewBox from './default/ViewBox.vue'
1219
1320
defineSlots<{
1421
subscribeRow(args: LayoutInject.SubscribeRowProps): any
@@ -35,31 +42,10 @@ const safeHeightTop = computed(() => Number(safeHeightTopCss.value?.match(/\d+/)
3542
const isScrolled = shallowRef(false)
3643
const scrollbar = useTemplateRef('scrollbar')
3744
38-
const contentSource = PromiseContent.withResolvers<uni.item.Item>(true)
39-
watch(
40-
$props.page.union,
41-
union => {
42-
if (!union) return
43-
console.log('resolve', union)
44-
contentSource.resolve(union)
45-
},
46-
{ immediate: true }
47-
)
48-
49-
$props.page.detail.content.onError(err => {
50-
console.error('resolve catch', err)
51-
contentSource.reset(false)
52-
contentSource.reject(err)
45+
const { data: shortId } = useQuery({
46+
query: ({ signal }) => $props.page.fetchShortId(signal),
47+
key: () => [LayoutInject.QueryKey.ShortId, LayoutInject.createPageQueryKey($props.page)]
5348
})
54-
$props.page.detail.content.onSuccess(data => {
55-
console.log('resolve then', $props.page.preload.value)
56-
contentSource.reset(false)
57-
contentSource.resolve(data)
58-
})
59-
60-
const config = useConfig()
61-
62-
const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plugin, key])!
6349
</script>
6450

6551
<template>
@@ -88,7 +74,11 @@ const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plu
8874
: 'var(--nui-body-color)'
8975
}"
9076
>
91-
<ViewBox />
77+
<ViewBox :isScrolled :scrollbar>
78+
<template #view>
79+
<slot name="view" />
80+
</template>
81+
</ViewBox>
9282
<VanTabs
9383
shrink
9484
swipeable
@@ -103,13 +93,8 @@ const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plu
10393
title="简介"
10494
name="info"
10595
>
106-
<DcContent
107-
:source="contentSource.content"
108-
retriable
109-
@reset-retry="$props.page.reloadAll"
110-
class="min-h-[60vh]"
111-
>
112-
<SubscribeList />
96+
<div class="min-h-[60vh] w-full">
97+
<SubscribeList :page :union />
11398
<div class="mx-auto mt-2 w-[95%]">
11499
<div class="relative flex h-fit">
115100
<div class="relative w-[89%] text-[17px] font-medium">
@@ -133,17 +118,19 @@ const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plu
133118
{{ union?.title }}
134119
</span>
135120
<Title />
121+
136122
<div
123+
v-if="shortId"
137124
class="mt-0.5 flex justify-start text-xs font-light text-(--van-text-color-2)"
138125
>
139126
<div class="mr-2">
140-
{{ page.pid.content.data.value }}
127+
{{ shortId }}
141128
</div>
142129
</div>
143130

144-
<Description />
131+
<Description :page :union />
145132

146-
<Tags />
133+
<Tags :union />
147134
</NCollapseTransition>
148135
</div>
149136
<NIcon
@@ -156,19 +143,23 @@ const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plu
156143
<KeyboardArrowDownRound />
157144
</NIcon>
158145
</div>
159-
<Actions />
160-
<EpController />
146+
<Actions :page :union>
147+
<template #action="{ item, page }">
148+
<slot name="action" :item :page />
149+
</template>
150+
</Actions>
151+
<EpController :page :union :scrollbar />
161152
</div>
162153
<Recommends />
163-
</DcContent>
154+
</div>
164155
</VanTab>
165156

166-
<VanTab class="van-hairline--top h-full!" title="评论" name="comment">
157+
<VanTab class="van-hairline--top h-full!" title="评论" name="comment" v-if="union">
167158
<template #title>
168159
<span>评论</span>
169160
<span class="ml-0.5 text-xs! font-light">{{ union?.commentNumber ?? '' }}</span>
170161
</template>
171-
<Comment :comments="page.comments" :item="union" class="h-[calc(70vh-38px)]" />
162+
<Comment :fetchComments="page.fetchComments" :item="union" class="h-[calc(70vh-38px)]" />
172163
</VanTab>
173164

174165
<slot name="tab" :="{ page }" />

src/layout/default.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export interface ContentProps {
1919
export enum QueryKey {
2020
Detail = 'layout::default::detail',
2121
Ep = 'layout::default::ep',
22-
Recommends = 'layout::default::recommends'
22+
Recommends = 'layout::default::recommends',
23+
ShortId = 'layout::default::shortId'
2324
}
2425
export const createPageQueryKey = (page: uni.content.ContentPage) => ({
2526
id: page.id,

src/layout/default/EpController.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const $props = defineProps<{
1313
union?: uni.item.Item
1414
page: uni.content.ContentPage
1515
isR18g?: boolean
16-
scrollbar: InstanceType<typeof NScrollbar>
16+
scrollbar: InstanceType<typeof NScrollbar> | null
1717
}>()
1818
1919
const $route = useRoute()
@@ -43,7 +43,7 @@ const nowEpId = $route.params.ep.toString()
4343
const nowEp = computed(() => eps.value.find(ep => ep.id === nowEpId))
4444
const nowEpIndex = computed(() => eps.value.findIndex(ep => ep.id === nowEpId))
4545
const openEpSelectPopup = async () => {
46-
$props.scrollbar.scrollTo(0, 0)
46+
$props.scrollbar?.scrollTo(0, 0)
4747
isShowEpSelectPopup.value = true
4848
await nextTick()
4949
epSelList.value?.listInstance?.scrollTo({

src/layout/default/ViewBox.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { NScrollbar } from 'naive-ui'
66
import { computed, ref } from 'vue'
77
defineProps<{
88
isScrolled: boolean
9-
scrollbar: InstanceType<typeof NScrollbar>
9+
scrollbar: InstanceType<typeof NScrollbar> | null
1010
}>()
1111
1212
const fullscreen = useFullscreen()

0 commit comments

Comments
 (0)