This commit is contained in:
2024-06-28 21:31:48 +08:00
parent 48aced8b6e
commit 06a2ea704e
6 changed files with 175 additions and 34 deletions

View File

@@ -3,6 +3,8 @@ import type { PropType } from 'vue'
import dayjs from 'dayjs'
import { useDownload } from '~/composables/useDownload'
const toast = useToast()
const props = defineProps({
course: {
type: Object as PropType<resp.gen.CourseGenItem>,
@@ -21,9 +23,61 @@ const stateDisplay = computed(() => {
}
return {
color: 'blue',
text: '进行中',
text: !!props.course.progress ? `${ props.course.progress }%` : '队列中',
}
})
const isFailed = computed(() => props.course.progress === -1)
const isDownloadable = computed(() => !isFailed.value && props.course.progress === 100)
const downloadProgress = ref(0)
const startDownload = async (
url: string,
filename: string,
) => {
downloadProgress.value = 0
const {
download,
progressEmitter,
} = useDownload(url, filename)
progressEmitter.on('done', () => {
downloadProgress.value = 100
toast.add({
title: '下载完成',
description: '资源下载已完成',
color: 'green',
icon: 'i-tabler-check',
})
})
progressEmitter.on('progress', (progress) => {
downloadProgress.value = progress
})
progressEmitter.on('error', err => {
downloadProgress.value = 0
toast.add({
title: '下载失败',
description: err.message || '下载失败,未知错误',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
})
download()
}
const copyTaskId = () => {
navigator.clipboard.writeText(props.course.task_id)
toast.add({
title: '复制成功',
description: '已复制任务 ID',
color: 'green',
icon: 'i-tabler-check',
})
}
</script>
<template>
@@ -32,27 +86,33 @@ const stateDisplay = computed(() => {
>
<div class="relative w-full aspect-video">
<NuxtImg
class="w-full aspect-video object-cover pointer-events-none absolute inset-0"
v-if="!!course.video_cover"
:src="course.video_cover"
alt="image"
class="w-full h-full object-cover pointer-events-none absolute inset-0"
loading="lazy"
/>
<div
v-else
class="absolute inset-0 bg-gradient-to-br from-purple-400 to-primary-400 flex justify-center items-center"
>
<Icon class="text-white text-[64px] animate-pulse" name="i-tabler-photo-video"/>
<Icon
v-if="isFailed"
class="text-white text-[64px] opacity-50"
name="i-tabler-alert-triangle"
/>
<Icon v-else class="text-white text-[64px] animate-pulse" name="i-tabler-photo-video"/>
</div>
<div class="absolute inset-2 flex justify-end items-start">
<UTooltip :prevent="course.progress > -1" :text="course.message || ''">
<UBadge
:color="stateDisplay.color"
:variant="stateDisplay.color === 'red' ? 'solid' : 'subtle'"
:variant="isFailed ? 'solid' : 'subtle'"
class="shadow"
size="sm"
>
<Icon
v-if="stateDisplay.color === 'red'"
v-if="isFailed"
class="text-base mr-0.5"
name="i-tabler-alert-triangle"
/>
@@ -63,8 +123,10 @@ const stateDisplay = computed(() => {
</div>
<div class="px-2 pt-1 pb-2 flex justify-between">
<div class="flex-1 overflow-hidden pt-1">
<h1 class="text-sm font-medium overflow-hidden text-ellipsis text-nowrap"
title="课程名字课程名字课程名字课程名字课程名字课程名字课程名字课程名字">
<h1
:title="course.title"
class="text-sm font-medium overflow-hidden text-ellipsis text-nowrap"
>
<Icon class="-mt-0.5 -ml-0.5 text-base" name="i-tabler-book-2"/>
<span class="pl-0.5">{{ course.title }}</span>
</h1>
@@ -74,6 +136,7 @@ const stateDisplay = computed(() => {
class="hover:text-primary font-medium"
tabindex="-1"
:title="course.task_id"
@click="copyTaskId"
>
复制ID
</button>
@@ -83,13 +146,11 @@ const stateDisplay = computed(() => {
<UButtonGroup>
<UButton
color="white"
label="下载"
:disabled="!isDownloadable"
:label="downloadProgress > 0 && downloadProgress < 100 ? `${downloadProgress.toFixed(0)}%` : '下载'"
leading-icon="i-tabler-download"
size="xs"
@click="() => {
const {download} = useDownload(course.video_url, `眩生花微课_${course.title}_${course.task_id}.mp4`)
download()
}"
@click="startDownload(course.video_url, `眩生花微课_${ props.course.title }_${ props.course.task_id }.mp4`)"
/>
<UDropdown
:items="[
@@ -97,19 +158,31 @@ const stateDisplay = computed(() => {
label: '预览课程',
icon: 'i-tabler-play',
shortcuts: ['空格'],
disabled: !isDownloadable,
}, {
label: '查看字幕',
icon: 'i-solar-subtitles-linear',
shortcuts: ['Alt', 'D'],
disabled: !isDownloadable,
}, {
label: '下载字幕',
icon: 'i-tabler-file-download',
shortcuts: ['Alt', 'S'],
disabled: !isDownloadable,
}], [{
label: '删除记录',
icon: 'i-tabler-trash-x',
shortcuts: ['Delete'],
}],
]"
:popper="{ placement: 'bottom-start' }"
:popper="{ placement: 'bottom-end' }"
>
<UButton color="white" size="xs" trailing-icon="i-tabler-dots"/>
<UButton
:disabled="course.progress > 1 && course.progress < 100"
color="white"
size="xs"
trailing-icon="i-tabler-dots"
/>
</UDropdown>
</UButtonGroup>
</div>

View File

@@ -9,6 +9,7 @@ const loginState = useLoginState()
const toast = useToast()
const isCreateCourseModalOpen = ref(false)
const creationPending = ref(false)
const {
data: courseList,
@@ -29,6 +30,7 @@ const {
},
)
const onCreateCourseClick = () => {
isCreateCourseModalOpen.value = true
}
@@ -60,24 +62,55 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
})
return
}
creationPending.value = true
// upload PPTX file
useFileGo(selected_file.value[0]).then(url => {
useFetchWrapped<req.gen.CourseGenCreate & AuthedRequest, resp.gen.CourseGenCreate>('App.Digital_Convert.Create', {
useFetchWrapped<req.gen.CourseGenCreate & AuthedRequest, BaseResponse<resp.gen.CourseGenCreate>>('App.Digital_Convert.Create', {
token: loginState.token!,
user_id: loginState.user.id,
task_title: event.data.task_title,
gen_server: event.data.gen_server as 'main' | 'standby1',
speed: event.data.speed,
speed: 2 - event.data.speed,
ppt_url: url,
digital_human_id: '40696',
digital_human_id: 40696,
custom_video: '[]',
opening_url: '',
ending_url: '',
}).then(res => {
console.log(res)
if (res.data.record_status === 1) {
toast.add({
title: '创建成功',
description: '微课视频已开始生成',
color: 'green',
icon: 'i-tabler-check',
})
refreshCourseList()
isCreateCourseModalOpen.value = false
} else {
toast.add({
title: '创建失败',
description: '未知错误',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
}
creationPending.value = false
}).catch(e => {
creationPending.value = false
toast.add({
title: '创建失败',
description: e.message || '未知错误',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
})
})
}
onMounted(() => {
const i = setInterval(refreshCourseList, 1000 * 5)
onBeforeUnmount(() => clearInterval(i))
})
</script>
<template>
@@ -94,10 +127,10 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
/>
</div>
<div class="p-4">
<div class="relative grid grid-cols-1 sm:grid-cols-2 2xl:grid-cols-4 gap-4">
<div class="relative grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 gap-4">
<CGTaskCard v-for="(course, index) in courseList" :key="index" :course="course"/>
</div>
<pre class="overflow-hidden">{{ JSON.stringify(courseList, null, 2) }}</pre>
<!-- <pre class="overflow-hidden">{{ JSON.stringify(courseList, null, 2) }}</pre>-->
</div>
<UModal
@@ -177,6 +210,7 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
label="提交"
type="submit"
variant="solid"
:loading="creationPending"
/>
</div>
</UForm>