Skip to content

Commit 0993166

Browse files
committed
feat: 重构全部适配新版本 [pub]
1 parent 3418905 commit 0993166

3 files changed

Lines changed: 35 additions & 27 deletions

File tree

src/view/Video.vue

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
<script setup lang="ts">
2-
import { computed, onBeforeUnmount, shallowRef, useTemplateRef } from 'vue'
3-
import { watch } from 'vue'
4-
import type { MediaPlayerElement } from 'vidstack/elements'
5-
import 'vidstack/icons'
2+
import { useFullscreen } from '@delta-comic/core'
3+
import type { uni } from '@delta-comic/model'
4+
import { Inject } from '@delta-comic/plugin'
65
import 'vidstack/bundle'
6+
import 'vidstack/icons'
77
import 'hls.js'
8-
import { ArrowBackIosRound, PauseRound, PlayArrowRound } from '@vicons/material'
8+
import { useQuery } from '@pinia/colada'
99
import { LikeOutlined } from '@vicons/antd'
10+
import { ArrowBackIosRound, PauseRound, PlayArrowRound } from '@vicons/material'
11+
import type { MediaPlayerElement } from 'vidstack/elements'
12+
import { computed, onBeforeUnmount, shallowRef, useTemplateRef } from 'vue'
13+
import { watch } from 'vue'
1014
import { useRouter } from 'vue-router'
11-
import { useFullscreen } from '@delta-comic/core'
12-
import type { ContentVideoPage, VideoConfig } from '@/model'
13-
import { SmartAbortController } from '@delta-comic/request'
14-
import type * as VideoViewInject from './video'
15-
import { Inject } from '@delta-comic/plugin'
15+
1616
import ButtonPopup from '@/components/ButtonPopup.vue'
1717
import Settings from '@/components/Settings.vue'
18+
import { createPageQueryKey } from '@/layout/default'
19+
import type { ContentVideoPage, VideoConfig } from '@/model'
20+
import { useLike } from '@/utils/content'
21+
22+
import * as VideoViewInject from './video'
1823
19-
const $props = defineProps<{ page: ContentVideoPage }>()
24+
const $props = defineProps<{ page: ContentVideoPage; union?: uni.item.Item }>()
2025
2126
const { isFullscreen, ...fc } = useFullscreen()
2227
const setFullscreen = async (isFull: boolean) => (isFull ? fc.entry() : fc.exit())
2328
2429
const player = useTemplateRef<MediaPlayerElement>('player')
25-
const union = computed(() => $props.page.union.value)
26-
const videos = computed(() => $props.page.videos.content.data.value ?? [])
30+
31+
const videosQuery = useQuery({
32+
key: () => [VideoViewInject.QueryKey.Videos, createPageQueryKey($props.page)],
33+
query: async ({ signal }) => await $props.page.fetchVideo(signal)
34+
})
35+
const videos = computed(() => videosQuery.data.value ?? [])
2736
2837
watch(
2938
player,
@@ -84,16 +93,7 @@ watch(
8493
{ immediate: true }
8594
)
8695
87-
const isLiked = shallowRef(union.value?.isLiked ?? false)
88-
const likeSignal = new SmartAbortController()
89-
const handleLike = async () => {
90-
likeSignal.abort()
91-
try {
92-
union.value?.like(likeSignal.signal).then(v => (isLiked.value = v))
93-
} catch (error) {
94-
console.error('liked fail')
95-
}
96-
}
96+
const { likeItem } = useLike()
9797
9898
defineSlots<{
9999
topBar(args: VideoViewInject.BarProps): any
@@ -142,9 +142,15 @@ defineSlots<{
142142
<slot name="topBar" :="{ player, page, isFullscreen }"></slot>
143143
<Inject key="layout::view::video.top-bar" :args="{ player, page, isFullscreen }" />
144144

145-
<DcToggleIcon size="23px" v-model="isLiked" @click="handleLike" :icon="LikeOutlined" />
145+
<DcToggleIcon
146+
size="23px"
147+
v-model="union.isLiked"
148+
@click="likeItem(union)"
149+
v-if="union"
150+
:icon="LikeOutlined"
151+
/>
146152

147-
<FavouriteSelect :item="page.union.value" v-if="page.union.value" plain />
153+
<FavouriteSelect :item="union" v-if="union" plain />
148154

149155
<media-pip-button>
150156
<media-icon

src/view/image.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ export interface ContentProps {
1919
}
2020
export enum QueryKey {
2121
Images = 'layout::view::image'
22-
}
23-
export const createImageQueryKey = () => {}
22+
}

src/view/video.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ export interface BarProps {
66
player: MediaPlayerElement | null
77
page: model.ContentVideoPage
88
isFullscreen: boolean
9+
}
10+
export enum QueryKey {
11+
Videos = 'layout::view::video'
912
}

0 commit comments

Comments
 (0)