feat: tweened generate progress
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
import type { PropType } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { useDownload } from '~/composables/useDownload'
|
||||
import gsap from 'gsap'
|
||||
|
||||
const toast = useToast()
|
||||
const { metaSymbol } = useShortcuts()
|
||||
|
||||
const props = defineProps({
|
||||
course: {
|
||||
@@ -11,6 +13,36 @@ const props = defineProps({
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
const emit = defineEmits([
|
||||
'delete',
|
||||
])
|
||||
|
||||
defineShortcuts({
|
||||
'p': {
|
||||
handler: () => {
|
||||
if (isDropdownOpen.value && isDownloadable.value) {
|
||||
isPreviewModalOpen.value = true
|
||||
}
|
||||
},
|
||||
},
|
||||
'meta_s': {
|
||||
handler: () => {
|
||||
if (isDropdownOpen.value && isDownloadable.value) {
|
||||
startDownload(props.course.subtitle_url, `眩生花微课_${ props.course.title }_${ props.course.task_id }.srt`)
|
||||
}
|
||||
},
|
||||
},
|
||||
'delete': {
|
||||
handler: () => {
|
||||
if (isDropdownOpen.value) {
|
||||
emit('delete', props.course.task_id)
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const isDropdownOpen = ref(false)
|
||||
const isPreviewModalOpen = ref(false)
|
||||
|
||||
const stateDisplay = computed(() => {
|
||||
if (props.course.progress === -1) return {
|
||||
@@ -23,12 +55,28 @@ const stateDisplay = computed(() => {
|
||||
}
|
||||
return {
|
||||
color: 'blue',
|
||||
text: !!props.course.progress ? `${ props.course.progress }%` : '队列中',
|
||||
text: !!props.course.progress ? `${ tweenedGenerateProgress.value.toFixed(0) }%` : '队列中',
|
||||
}
|
||||
})
|
||||
const isFailed = computed(() => props.course.progress === -1)
|
||||
const isDownloadable = computed(() => !isFailed.value && props.course.progress === 100)
|
||||
|
||||
const generateProgress = computed(() => {
|
||||
return props.course.progress || 0
|
||||
})
|
||||
const tweenedGenerateProgress = ref(0)
|
||||
watch(generateProgress, (newValue) => {
|
||||
gsap.to(tweenedGenerateProgress, {
|
||||
duration: 5,
|
||||
value: newValue,
|
||||
})
|
||||
}, {
|
||||
immediate: true,
|
||||
})
|
||||
watch(tweenedGenerateProgress, val => {
|
||||
console.log(val)
|
||||
})
|
||||
|
||||
const downloadProgress = ref(0)
|
||||
|
||||
const startDownload = async (
|
||||
@@ -147,32 +195,39 @@ const copyTaskId = () => {
|
||||
<UButton
|
||||
color="white"
|
||||
:disabled="!isDownloadable"
|
||||
:loading="downloadProgress > 0 && downloadProgress < 100"
|
||||
:label="downloadProgress > 0 && downloadProgress < 100 ? `${downloadProgress.toFixed(0)}%` : '下载'"
|
||||
leading-icon="i-tabler-download"
|
||||
size="xs"
|
||||
@click="startDownload(course.video_url, `眩生花微课_${ props.course.title }_${ props.course.task_id }.mp4`)"
|
||||
/>
|
||||
<UDropdown
|
||||
v-model:open="isDropdownOpen"
|
||||
:items="[
|
||||
[{
|
||||
label: '预览课程',
|
||||
icon: 'i-tabler-play',
|
||||
shortcuts: ['空格'],
|
||||
shortcuts: ['P'],
|
||||
disabled: !isDownloadable,
|
||||
click: () => isPreviewModalOpen = true,
|
||||
}, {
|
||||
label: '查看字幕',
|
||||
icon: 'i-solar-subtitles-linear',
|
||||
shortcuts: ['Alt', 'D'],
|
||||
shortcuts: [metaSymbol, 'D'],
|
||||
disabled: !isDownloadable,
|
||||
}, {
|
||||
label: '下载字幕',
|
||||
icon: 'i-tabler-file-download',
|
||||
shortcuts: ['Alt', 'S'],
|
||||
shortcuts: [metaSymbol, 'S'],
|
||||
disabled: !isDownloadable,
|
||||
click: () => {
|
||||
startDownload(course.subtitle_url, `眩生花微课_${ props.course.title }_${ props.course.task_id }.srt`)
|
||||
}
|
||||
}], [{
|
||||
label: '删除记录',
|
||||
icon: 'i-tabler-trash-x',
|
||||
shortcuts: ['Delete'],
|
||||
click: () => emit('delete', course.task_id)
|
||||
}],
|
||||
]"
|
||||
:popper="{ placement: 'bottom-end' }"
|
||||
@@ -187,6 +242,36 @@ const copyTaskId = () => {
|
||||
</UButtonGroup>
|
||||
</div>
|
||||
</div>
|
||||
<UModal
|
||||
v-model="isPreviewModalOpen"
|
||||
>
|
||||
<UCard :ui="{ ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="text-base font-semibold leading-6 text-gray-900 dark:text-white overflow-hidden">
|
||||
<p>微课视频预览</p>
|
||||
<p class="text-xs text-blue-500 w-full overflow-hidden text-nowrap text-ellipsis">
|
||||
{{ course.title }}
|
||||
</p>
|
||||
</div>
|
||||
<UButton
|
||||
class="-my-1"
|
||||
color="gray"
|
||||
icon="i-tabler-x"
|
||||
variant="ghost"
|
||||
@click="isPreviewModalOpen = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<video
|
||||
class="w-full rounded shadow"
|
||||
controls
|
||||
autoplay
|
||||
:src="course.video_url"
|
||||
/>
|
||||
</UCard>
|
||||
</UModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user