feat: 绿幕视频创建和微课视频创建
This commit is contained in:
@@ -28,7 +28,7 @@ const props = defineProps({
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<div class="flex gap-2.5">
|
||||
<slot name="action"/>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ watchEffect(() => {
|
||||
})
|
||||
|
||||
const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>) => {
|
||||
console.log(event.data)
|
||||
if (!selected_file.value) {
|
||||
toast.add({
|
||||
title: '未选择文件',
|
||||
@@ -167,6 +166,11 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
|
||||
</div>
|
||||
|
||||
<UFormGroup label="PPT 文件" required>
|
||||
<template #help>
|
||||
<p class="text-xs text-neutral-400">
|
||||
仅支持 .pptx 格式
|
||||
</p>
|
||||
</template>
|
||||
<FileDnD
|
||||
accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||
@change="file => selected_file = file"
|
||||
|
||||
198
components/SlideCreateCourseGreen.vue
Normal file
198
components/SlideCreateCourseGreen.vue
Normal file
@@ -0,0 +1,198 @@
|
||||
<script lang="ts" setup>
|
||||
import { type InferType, number, object, string } from 'yup'
|
||||
import ModalDigitalHumanSelect from '~/components/ModalDigitalHumanSelect.vue'
|
||||
import type { FormSubmitEvent } from '#ui/types'
|
||||
import { useFetchWrapped } from '~/composables/useFetchWrapped'
|
||||
|
||||
const emit = defineEmits(['success'])
|
||||
|
||||
const slide = useSlideover()
|
||||
const toast = useToast()
|
||||
const loginState = useLoginState()
|
||||
|
||||
const creationForm = ref<HTMLFormElement>()
|
||||
const creationPending = ref(false)
|
||||
const isDigitalSelectorOpen = ref(false)
|
||||
|
||||
const createCourseSchema = object({
|
||||
title: string().trim().min(4, '标题必须大于4个字符').max(20, '标题不能超过20个字符').required('请输入视频标题'),
|
||||
content: string().trim().min(4, '内容必须大于4个字符').max(1000, '内容不能超过1000个字符').required('请输入驱动文本内容'),
|
||||
digital_human_id: number().not([0], '请选择数字人'),
|
||||
speed: number().default(1.0).min(0.5).max(1.5).required(),
|
||||
})
|
||||
|
||||
type CreateCourseSchema = InferType<typeof createCourseSchema>
|
||||
|
||||
const createCourseState = reactive({
|
||||
title: undefined,
|
||||
content: undefined,
|
||||
digital_human_id: 0,
|
||||
speed: 1.0,
|
||||
})
|
||||
|
||||
const selected_digital_human = ref<DigitalHumanItem | null>(null)
|
||||
|
||||
watchEffect(() => {
|
||||
if (selected_digital_human.value) {
|
||||
createCourseState.digital_human_id = selected_digital_human.value.model_id || selected_digital_human.value.id!
|
||||
}
|
||||
})
|
||||
|
||||
const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSchema>) => {
|
||||
creationPending.value = true
|
||||
useFetchWrapped<req.gen.GBVideoCreate & AuthedRequest, BaseResponse<resp.gen.GBVideoCreate>>('App.Digital_VideoTask.Create', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
title: event.data.title,
|
||||
content: event.data.content,
|
||||
digital_human_id: event.data.digital_human_id,
|
||||
speed: 2 - event.data.speed,
|
||||
device_id: 'XSHAssistant Web',
|
||||
}).then(res => {
|
||||
if (!!res.data.task_id) {
|
||||
toast.add({
|
||||
title: '创建成功',
|
||||
description: '视频已加入生成队列',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
emit('success')
|
||||
slide.close()
|
||||
} else {
|
||||
toast.add({
|
||||
title: '创建失败',
|
||||
description: res.msg || '未知错误',
|
||||
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',
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<USlideover prevent-close>
|
||||
<UCard
|
||||
:ui="{ body: { base: 'flex-1' }, ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }"
|
||||
class="flex flex-col flex-1"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
|
||||
新建绿幕视频
|
||||
</h3>
|
||||
<UButton
|
||||
class="-my-1"
|
||||
color="gray"
|
||||
icon="i-tabler-x"
|
||||
variant="ghost"
|
||||
@click="slide.close()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<UForm
|
||||
ref="creationForm"
|
||||
:schema="createCourseSchema"
|
||||
:state="createCourseState"
|
||||
class="space-y-4"
|
||||
@submit="onCreateCourseGreenSubmit"
|
||||
>
|
||||
<div class="flex justify-between gap-2 *:flex-1">
|
||||
<UFormGroup label="视频标题" name="title" required>
|
||||
<UInput v-model="createCourseState.title" placeholder="请输入视频标题"/>
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
<UFormGroup label="数字人" name="digital_human_id" required>
|
||||
<div
|
||||
:class="{'shadow-inner': !!selected_digital_human}"
|
||||
class="flex items-center gap-2 bg-neutral-100 p-2 rounded-md cursor-pointer select-none transition-all"
|
||||
@click="isDigitalSelectorOpen = true"
|
||||
>
|
||||
<div class="w-12 aspect-square border rounded-md flex justify-center items-center overflow-hidden">
|
||||
<UIcon v-if="!selected_digital_human" class="text-2xl opacity-50" name="i-tabler-user-screen"/>
|
||||
<NuxtImg v-else :src="selected_digital_human?.avatar"/>
|
||||
</div>
|
||||
<div class="flex flex-col text-neutral-400 text-sm font-medium">
|
||||
<span :class="!!selected_digital_human ? 'text-neutral-600' : ''">{{
|
||||
selected_digital_human?.name || '点击选择数字人'
|
||||
}}</span>
|
||||
<span v-if="selected_digital_human?.description" class="text-2xs">
|
||||
{{ selected_digital_human?.description }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<UFormGroup label="驱动内容" name="content" required>
|
||||
<!-- <template #help>-->
|
||||
<!-- <p class="text-xs text-neutral-400">-->
|
||||
<!-- 仅支持 .pptx 格式-->
|
||||
<!-- </p>-->
|
||||
<!-- </template>-->
|
||||
<UTextarea v-model="createCourseState.content" :rows="6" autoresize placeholder="请输入驱动文本内容"/>
|
||||
</UFormGroup>
|
||||
|
||||
<UAccordion :items="[{label: '高级选项'}]" color="gray" size="lg">
|
||||
<template #item>
|
||||
<div class="border rounded-lg space-y-4 p-4 pb-6">
|
||||
<UFormGroup :label="`视频倍速:${createCourseState.speed}`" name="speed">
|
||||
<URange
|
||||
v-model="createCourseState.speed"
|
||||
:max="1.5"
|
||||
:min="0.5"
|
||||
:step="0.1"
|
||||
class="pt-4"
|
||||
size="sm"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</div>
|
||||
</template>
|
||||
</UAccordion>
|
||||
</UForm>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end space-x-4">
|
||||
<UButton
|
||||
color="gray"
|
||||
label="取消"
|
||||
size="lg"
|
||||
variant="ghost"
|
||||
@click="slide.close()"
|
||||
/>
|
||||
<UButton
|
||||
:loading="creationPending"
|
||||
color="primary"
|
||||
label="提交"
|
||||
size="lg"
|
||||
variant="solid"
|
||||
@click="creationForm?.submit()"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</UCard>
|
||||
<ModalDigitalHumanSelect
|
||||
:is-open="isDigitalSelectorOpen"
|
||||
@close="isDigitalSelectorOpen = false"
|
||||
@select="digitalHumans => {
|
||||
selected_digital_human = (digitalHumans as DigitalHumanItem)
|
||||
}"
|
||||
/>
|
||||
</USlideover>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -3,6 +3,7 @@ import type { PropType } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { useDownload } from '~/composables/useDownload'
|
||||
import gsap from 'gsap'
|
||||
import SRTEditor from '~/components/aigc/generation/SRTEditor.vue'
|
||||
|
||||
const toast = useToast()
|
||||
const { metaSymbol } = useShortcuts()
|
||||
@@ -284,7 +285,7 @@ const copyTaskId = (extraMessage?: string) => {
|
||||
/>
|
||||
</UCard>
|
||||
</UModal>
|
||||
<LazyAigcCourseGenerateSRTEditor
|
||||
<SRTEditor
|
||||
ref="srtEditor"
|
||||
:course="course"
|
||||
/>
|
||||
188
components/aigc/generation/GBTaskCard.vue
Normal file
188
components/aigc/generation/GBTaskCard.vue
Normal file
@@ -0,0 +1,188 @@
|
||||
<script lang="ts" setup>
|
||||
import type { PropType } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
video: {
|
||||
type: Object as PropType<GBVideoItem>,
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
const emit = defineEmits({
|
||||
delete: (video: GBVideoItem) => video,
|
||||
})
|
||||
|
||||
const dayjs = useDayjs()
|
||||
const toast = useToast()
|
||||
|
||||
const isFullContentOpen = ref(false)
|
||||
const downloadingState = reactive({
|
||||
subtitle: 0,
|
||||
video: 0,
|
||||
})
|
||||
|
||||
const startDownload = (url: string, filename: string) => {
|
||||
if (url.endsWith('.ass')) {
|
||||
downloadingState.subtitle = 0
|
||||
} else {
|
||||
downloadingState.video = 0
|
||||
}
|
||||
|
||||
const {
|
||||
download,
|
||||
progressEmitter,
|
||||
} = useDownload(url, filename)
|
||||
|
||||
progressEmitter.on('progress', progress => {
|
||||
if (url.endsWith('.ass')) {
|
||||
downloadingState.subtitle = progress
|
||||
} else {
|
||||
downloadingState.video = progress
|
||||
}
|
||||
console.log(downloadingState)
|
||||
})
|
||||
|
||||
progressEmitter.on('done', () => {
|
||||
if (url.endsWith('.ass')) {
|
||||
downloadingState.subtitle = 100
|
||||
} else {
|
||||
downloadingState.video = 100
|
||||
}
|
||||
toast.add({
|
||||
title: '下载完成',
|
||||
description: '资源下载已完成',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
})
|
||||
|
||||
progressEmitter.on('error', err => {
|
||||
if (url.endsWith('.ass')) {
|
||||
downloadingState.subtitle = 0
|
||||
} else {
|
||||
downloadingState.video = 0
|
||||
}
|
||||
toast.add({
|
||||
title: '下载失败',
|
||||
description: err.message || '下载失败,未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
|
||||
download()
|
||||
}
|
||||
|
||||
const onClick = () => {
|
||||
console.log('click delete')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="w-full flex gap-2 rounded-xl border border-neutral-200 dark:border-neutral-700 hover:shadow transition overflow-hidden p-3"
|
||||
>
|
||||
<div class="flex-0 h-48 aspect-[10/16] flex flex-col items-center justify-center rounded-lg shadow overflow-hidden">
|
||||
<div v-if="!video.video_cover" class="w-full h-full bg-primary flex flex-col justify-center items-center gap-2">
|
||||
<UIcon class="animate-spin text-4xl text-white" name="tabler:loader"/>
|
||||
<div class="flex flex-col items-center gap-0.5">
|
||||
<span class="text-sm font-bold text-white/90">火速生成中</span>
|
||||
<span class="text-xs font-medium text-white/50">{{ video.progress }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<NuxtImg v-else :src="video.video_cover" class="brightness-90 object-cover"/>
|
||||
</div>
|
||||
<div class="flex-1 flex flex-col justify-between gap-2">
|
||||
<div class="flex-1 rounded-lg bg-neutral-100 dark:bg-neutral-800 p-2 px-2.5">
|
||||
<ul class="grid grid-cols-2 gap-1.5">
|
||||
<li class="col-span-2">
|
||||
<!-- <h2 class="text-2xs font-medium text-primary-500">标题</h2>-->
|
||||
<p class="text-sm font-bold line-clamp-1">{{ video.title || '无标题' }}</p>
|
||||
</li>
|
||||
<li class="">
|
||||
<h2 class="text-2xs font-medium text-primary-500">完成时间</h2>
|
||||
<p class="text-xs line-clamp-1">{{ dayjs(video.complete_time * 1000).format('YYYY-MM-DD HH:mm:ss') }}</p>
|
||||
</li>
|
||||
<li class="">
|
||||
<h2 class="text-2xs font-medium text-primary-500">生成耗时</h2>
|
||||
<p class="text-xs line-clamp-1">{{ dayjs.duration(video.duration || 0).format('HH:mm:ss') }}</p>
|
||||
</li>
|
||||
<li class="col-span-2 cursor-pointer" @click="isFullContentOpen = true">
|
||||
<h2 class="text-2xs font-medium text-primary-500">驱动文本</h2>
|
||||
<p class="text-xs line-clamp-3 text-justify">{{ video.content }}</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="flex justify-end sm:justify-between items-center group flex-nowrap whitespace-nowrap">
|
||||
<div
|
||||
class="hidden sm:flex items-center gap-1 transition-all group-hover:opacity-0 group-hover:pointer-events-none">
|
||||
<UIcon class="text-primary text-lg" name="i-tabler-user-square-rounded"/>
|
||||
<p class="text-xs">数字人 {{ video.digital_human_id }}</p>
|
||||
</div>
|
||||
<div class="space-x-2">
|
||||
<UButton
|
||||
class="transition-all sm:opacity-0 sm:translate-x-4 sm:pointer-events-none group-hover:opacity-100 group-hover:translate-x-0 group-hover:pointer-events-auto"
|
||||
color="red"
|
||||
icon="i-tabler-trash"
|
||||
size="xs"
|
||||
variant="soft"
|
||||
@click="emit('delete', video)"
|
||||
/>
|
||||
<UButtonGroup size="xs">
|
||||
<UButton
|
||||
:label="downloadingState.subtitle > 0 && downloadingState.subtitle < 100 ? `${downloadingState.subtitle.toFixed(0)}%` : '字幕'"
|
||||
:loading="downloadingState.subtitle > 0 && downloadingState.subtitle < 100"
|
||||
color="primary"
|
||||
leading-icon="i-tabler-file-download"
|
||||
variant="soft"
|
||||
@click="startDownload(video.subtitle!, (video.title || video.task_id) + '.ass')"
|
||||
/>
|
||||
<UButton
|
||||
:label="downloadingState.video > 0 && downloadingState.video < 100 ? `${downloadingState.video.toFixed(0)}%` : '视频'"
|
||||
:loading="downloadingState.video > 0 && downloadingState.video < 100"
|
||||
color="primary"
|
||||
leading-icon="i-tabler-download"
|
||||
variant="soft"
|
||||
@click="startDownload(video.video_url!, (video.title || video.task_id) + '.mp4')"
|
||||
/>
|
||||
</UButtonGroup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Full video content -->
|
||||
<UModal v-model="isFullContentOpen">
|
||||
<UCard :ui="{ ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white">
|
||||
{{ video.title || '无标题' }}
|
||||
<span class="block text-xs text-primary">驱动内容</span>
|
||||
</h3>
|
||||
<UButton
|
||||
color="gray"
|
||||
icon="i-tabler-x"
|
||||
variant="ghost"
|
||||
@click="isFullContentOpen = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div>
|
||||
<article class="prose">
|
||||
<p class="text-justify">{{ video.content }}</p>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex justify-end gap-2">
|
||||
<UButton color="primary" @click="isFullContentOpen = false">关闭</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</UCard>
|
||||
</UModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user