Skip to content

Commit 2c9c478

Browse files
committed
refactor: 重构view的layout
1 parent 10c0b3a commit 2c9c478

5 files changed

Lines changed: 94 additions & 57 deletions

File tree

src/layout/Default.vue

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<script setup lang="ts">
2+
import type { uni } from '@delta-comic/model'
3+
import { useQuery } from '@pinia/colada'
4+
import { createReusableTemplate, useCssVar } from '@vueuse/core'
5+
import { computed, shallowRef, useTemplateRef } from 'vue'
6+
27
import Comment from '@/components/comment/Comment.vue'
38
import ItemCard from '@/components/ItemCard.vue'
49
import { createDateString } from '@/utils/date'
@@ -14,13 +19,8 @@ defineSlots<{
1419
view(): any
1520
}>()
1621
17-
const $router = useRouter()
18-
const $route = useRoute()
1922
const $props = defineProps<{ page: uni.content.ContentPage; isR18g?: boolean }>()
2023
21-
const fullscreen = useFullscreen()
22-
const setFullscreen = async (isFull: boolean) => (isFull ? fullscreen.entry() : fullscreen.exit())
23-
2424
const { data: detail } = useQuery({
2525
query: ({ signal }) => $props.page.fetchDetail(signal),
2626
key: () => [LayoutInject.QueryKey.Detail, LayoutInject.createPageQueryKey($props.page)]
@@ -35,20 +35,6 @@ const safeHeightTop = computed(() => Number(safeHeightTopCss.value?.match(/\d+/)
3535
const isScrolled = shallowRef(false)
3636
const scrollbar = useTemplateRef('scrollbar')
3737
38-
const getItemCard = (contentType: uni.content.ContentType_) =>
39-
uni.item.Item.itemCard.get(contentType) ?? ItemCard
40-
41-
const isLiked = shallowRef(union.value?.isLiked ?? false)
42-
const likeSignal = new SmartAbortController()
43-
const handleLike = async () => {
44-
likeSignal.abort()
45-
try {
46-
union.value?.like(likeSignal.signal).then(v => (isLiked.value = v))
47-
} catch (error) {
48-
console.error('liked fail')
49-
}
50-
}
51-
5238
const contentSource = PromiseContent.withResolvers<uni.item.Item>(true)
5339
watch(
5440
$props.page.union,
@@ -74,34 +60,6 @@ $props.page.detail.content.onSuccess(data => {
7460
const config = useConfig()
7561
7662
const getActionInfo = (key: string) => Global.userActions.get([union.value.$$plugin, key])!
77-
78-
const getIsSubscribe = (author: uni.item.Author) =>
79-
db.value
80-
.selectFrom('subscribe')
81-
.where('key', '=', `${author.$$plugin}:${author.label}`)
82-
.selectAll()
83-
.execute()
84-
.then(v => v.length != 0)
85-
86-
const showDetailUsers = shallowRef(false)
87-
88-
const addSubscribe = (author: uni.item.Author) =>
89-
createLoadingMessage('关注中').bind(
90-
SubscribeDB.upsert({
91-
type: 'author',
92-
author,
93-
plugin: author.$$plugin,
94-
key: SubscribeDB.key.toString([author.$$plugin, author.label]),
95-
itemKey: null
96-
})
97-
)
98-
const removeSubscribe = (author: uni.item.Author) =>
99-
createLoadingMessage('取消中').bind(
100-
db.value
101-
.deleteFrom('subscribe')
102-
.where('key', '=', SubscribeDB.key.toString([author.$$plugin, author.label]))
103-
.execute()
104-
)
10563
</script>
10664

10765
<template>

src/layout/default/EpController.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SharedFunction } from '@delta-comic/core'
33
import { uni } from '@delta-comic/model'
44
import { useConfig } from '@delta-comic/plugin'
55
import { useInfiniteQuery } from '@pinia/colada'
6+
import type { NScrollbar } from 'naive-ui'
67
import { computed, nextTick, shallowRef, useTemplateRef } from 'vue'
78
import { useRoute } from 'vue-router'
89
@@ -12,6 +13,7 @@ const $props = defineProps<{
1213
union?: uni.item.Item
1314
page: uni.content.ContentPage
1415
isR18g?: boolean
16+
scrollbar: InstanceType<typeof NScrollbar>
1517
}>()
1618
1719
const $route = useRoute()
@@ -41,6 +43,7 @@ const nowEpId = $route.params.ep.toString()
4143
const nowEp = computed(() => eps.value.find(ep => ep.id === nowEpId))
4244
const nowEpIndex = computed(() => eps.value.findIndex(ep => ep.id === nowEpId))
4345
const openEpSelectPopup = async () => {
46+
$props.scrollbar.scrollTo(0, 0)
4447
isShowEpSelectPopup.value = true
4548
await nextTick()
4649
epSelList.value?.listInstance?.scrollTo({

src/layout/default/SubscribeRow.vue

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
11
<script setup lang="ts">
2+
import { SubscribeDB } from '@delta-comic/db'
23
import type { uni } from '@delta-comic/model'
4+
import { Global } from '@delta-comic/plugin'
5+
import { createLoadingMessage } from '@delta-comic/ui'
6+
import { createReusableTemplate } from '@vueuse/core'
37
4-
defineProps<{
8+
const $props = defineProps<{
9+
page: uni.content.ContentPage
510
author: uni.item.Author
611
isSmall?: boolean
712
}>()
813
914
const [DefineAvatar, Avatar] = createReusableTemplate<{ author: uni.item.Author }>()
15+
16+
const getIsSubscribe = (author: uni.item.Author) =>
17+
SubscribeDB.useQuery(db =>
18+
db
19+
.where('key', '=', `${author.$$plugin}:${author.label}`)
20+
.selectAll()
21+
.execute()
22+
.then(v => v.length != 0)
23+
)
24+
25+
const addSubscribe = (author: uni.item.Author) =>
26+
createLoadingMessage('关注中').bind(
27+
SubscribeDB.upsert({
28+
type: 'author',
29+
author,
30+
plugin: author.$$plugin,
31+
key: SubscribeDB.key.toString([author.$$plugin, author.label]),
32+
itemKey: null
33+
})
34+
)
35+
const removeSubscribe = (author: uni.item.Author) =>
36+
createLoadingMessage('取消中').bind(
37+
db.value
38+
.deleteFrom('subscribe')
39+
.where('key', '=', SubscribeDB.key.toString([author.$$plugin, author.label]))
40+
.execute()
41+
)
42+
43+
const getActionInfo = (key: string) => Global.userActions.get([$props.page.plugin, key])!
1044
</script>
1145

1246
<template>
1347
<div class="relative w-full" v-if="isSmall">
1448
<Avatar :author />
15-
<DcAwait :promise="() => getIsSubscribe(author)" v-slot="{ result: isSubscribe }">
49+
<DcVar
50+
:value="getIsSubscribe(author)"
51+
v-slot="{
52+
value: {
53+
data: { value: isSubscribe }
54+
}
55+
}"
56+
>
1657
<slot name="subscribeRow" :="{ page, author, isSubscribe, type: 'small' }" />
1758
<Inject
1859
key="layout::layout::default.subscribe-row"
@@ -33,11 +74,18 @@ const [DefineAvatar, Avatar] = createReusableTemplate<{ author: uni.item.Author
3374
</NIcon>
3475
</template>
3576
</NButton>
36-
</DcAwait>
77+
</DcVar>
3778
</div>
3879
<div class="relative w-full" v-else>
3980
<Avatar :author />
40-
<DcAwait :promise="() => getIsSubscribe(author)" v-slot="{ result: isSubscribe }">
81+
<DcVar
82+
:value="getIsSubscribe(author)"
83+
v-slot="{
84+
value: {
85+
data: { value: isSubscribe }
86+
}
87+
}"
88+
>
4189
<slot name="subscribeRow" :="{ page, author, isSubscribe, type: 'common' }" />
4290
<Inject
4391
key="layout::layout::default.subscribe-row"
@@ -61,7 +109,7 @@ const [DefineAvatar, Avatar] = createReusableTemplate<{ author: uni.item.Author
61109
{{ isSubscribe ? '取关' : '关注' }}
62110
</template>
63111
</NButton>
64-
</DcAwait>
112+
</DcVar>
65113
</div>
66114
<DefineAvatar v-slot="{ author }">
67115
<VanPopover

src/layout/default/Tags.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import { SharedFunction } from '@delta-comic/core'
3+
import type { uni } from '@delta-comic/model'
4+
5+
defineProps<{
6+
union?: uni.item.Item
7+
}>()
8+
</script>
29

310
<template>
411
<div
@@ -23,7 +30,7 @@
2330
SharedFunction.call(
2431
'routeToSearch',
2532
category.search.keyword,
26-
[page.plugin, category.search.source],
33+
[category.$$plugin, category.search.source],
2734
category.search.sort
2835
)
2936
"

src/layout/default/ViewBox.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
<script setup lang="ts"></script>
1+
<script setup lang="ts">
2+
import { useFullscreen } from '@delta-comic/core'
3+
import { usePreventBack } from '@delta-comic/ui'
4+
import { ArrowBackRound, FullscreenRound, PlayArrowRound } from '@vicons/material'
5+
import type { NScrollbar } from 'naive-ui'
6+
import { computed, ref } from 'vue'
7+
defineProps<{
8+
isScrolled: boolean
9+
scrollbar: InstanceType<typeof NScrollbar>
10+
}>()
11+
12+
const fullscreen = useFullscreen()
13+
const isFullscreen = computed({
14+
get: () => fullscreen.isFullscreen.value,
15+
set: isFull => (isFull ? fullscreen.entry() : fullscreen.exit())
16+
})
17+
usePreventBack(isFullscreen, ref(true))
18+
19+
defineSlots<{
20+
view(): any
21+
}>()
22+
</script>
223

324
<template>
425
<div class="relative flex h-[30vh] justify-center bg-black text-white">
@@ -46,14 +67,14 @@
4667
</div>
4768
</VanSticky>
4869
</div>
49-
<Teleport to="#cover" :disabled="!fullscreen.isFullscreen.value">
70+
<Teleport to="#cover" :disabled="!isFullscreen">
5071
<slot name="view" />
5172
</Teleport>
5273
<VanRow class="pointer-events-none absolute bottom-0 z-2 w-full">
5374
<VanCol span="1" offset="21">
5475
<NButton
5576
class="pointer-events-auto text-3xl!"
56-
@click="setFullscreen(true)"
77+
@click="isFullscreen = true"
5778
text
5879
color="#fff"
5980
>

0 commit comments

Comments
 (0)