fix: 微课生成片头模板选择

This commit is contained in:
2025-02-10 18:45:00 +08:00
parent 3f10018144
commit 4f7e206e42
2 changed files with 354 additions and 59 deletions

View File

@@ -0,0 +1,187 @@
<script lang="ts" setup>
const props = defineProps({
isOpen: {
type: Boolean,
required: false,
},
})
const emit = defineEmits({
close: () => true,
select: (titles: TitlesTemplate) => titles,
})
const toast = useToast()
const modal = useModal()
const loginState = useLoginState()
const pagination = reactive({
page: 1,
pageSize: 15,
})
const selectedTitle = ref<TitlesTemplate | null>(null)
const {
data: userTitlesTemplate,
status: userTitlesTemplateStatus,
refresh: refreshUserTitlesTemplate,
} = useAsyncData(
'userTitlesTemplate',
() =>
useFetchWrapped<
PagedDataRequest & AuthedRequest & { process_status: 0 | 1 },
BaseResponse<PagedData<TitlesTemplate>>
>('App.User_UserTitles.GetList', {
token: loginState.token!,
user_id: loginState.user.id,
to_user_id: loginState.user.id,
page: pagination.page,
perpage: pagination.pageSize,
process_status: 1,
}),
{
watch: [pagination],
}
)
const handleClose = () => {
if (props.isOpen) {
emit('close')
} else {
modal.close()
}
}
const handleSubmit = () => {
if (!selectedTitle.value) {
toast.add({
title: '请选择片头',
description: '请选择一个片头',
color: 'red',
icon: 'i-tabler-circle-x',
})
return
}
emit('select', selectedTitle.value)
handleClose()
}
</script>
<template>
<UModal
:model-value="isOpen"
:ui="{ width: 'w-full sm:max-w-3xl' }"
@close="handleClose"
>
<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"
>
视频片头选择器
</h3>
<UButton
class="-my-1"
color="gray"
icon="i-tabler-x"
variant="ghost"
@click="handleClose"
/>
</div>
</template>
<div>
<div class="w-full grid grid-cols-2 sm:grid-cols-3 gap-4">
<div
v-for="(titles, i) in userTitlesTemplate?.data.items"
:key="`user-titles-${titles.id}`"
:class="{
'border-primary shadow-md': selectedTitle?.id === titles.id,
'border-neutral-200 dark:border-neutral-700':
selectedTitle?.id !== titles.id,
}"
class="relative flex flex-col justify-center items-center gap-2 overflow-hidden w-full bg-white dark:bg-neutral-800 rounded-md border dark:border-2 cursor-pointer transition-all duration-150 select-none"
@click="selectedTitle = titles"
>
<div
:class="{
'bg-primary-50': selectedTitle?.id === titles.id,
}"
class="relative bg-neutral-100 dark:bg-neutral-800 border-b dark:border-neutral-700 w-full aspect-video object-cover overflow-hidden transition-all duration-150"
>
<NuxtImg :src="titles.opening_url" />
<UIcon
v-if="selectedTitle?.id === titles.id"
class="absolute top-1 right-1 text-lg text-primary"
name="i-tabler-check"
/>
</div>
<div class="w-full flex flex-col gap-1 px-2 pb-2">
<div class="flex justify-between items-center">
<span
class="text-sm text-neutral-800 dark:text-neutral-300 font-medium line-clamp-1"
>
{{ titles.title }}
</span>
<span
class="text-xs text-neutral-300 dark:text-neutral-500 font-medium"
>
ID:{{ titles.id }}
</span>
</div>
</div>
</div>
</div>
<div class="flex justify-end">
<UPagination
v-if="(userTitlesTemplate?.data.total || 0) > 0"
v-model="pagination.page"
:page-count="pagination.pageSize"
:total="userTitlesTemplate?.data.total || 0"
class="pt-4"
/>
</div>
</div>
<template #footer>
<div class="flex justify-between items-center">
<div>
<p class="text-xs font-medium opacity-50 select-none">
如果此处没有您的片头请在
<a
class="text-primary"
href="/generation/materials"
target="_blank"
>
片头模版库
</a>
页面确认已经制作完毕
</p>
</div>
<div class="flex items-center gap-4">
<UButton
color="gray"
label="取消"
variant="ghost"
@click="handleClose"
/>
<UButton
color="primary"
label="选择"
variant="solid"
@click="handleSubmit"
/>
</div>
</div>
</template>
</UCard>
</UModal>
</template>
<style scoped></style>

View File

@@ -14,10 +14,17 @@ const loginState = useLoginState()
const creationForm = ref<HTMLFormElement>() const creationForm = ref<HTMLFormElement>()
const creationPending = ref(false) const creationPending = ref(false)
const isDigitalSelectorOpen = ref(false) const isDigitalSelectorOpen = ref(false)
const isTitlesSelectorOpen = ref(false)
const createCourseSchema = object({ const createCourseSchema = object({
task_title: string().trim().min(4, '标题必须大于4个字符').max(20, '标题不能超过20个字符').required('请输入微课标题'), task_title: string()
.trim()
.min(4, '标题必须大于4个字符')
.max(20, '标题不能超过20个字符')
.required('请输入微课标题'),
digital_human_id: number().not([0], '请选择数字人'), digital_human_id: number().not([0], '请选择数字人'),
opening_url: string().url().notRequired().default(''),
ending_url: string().url().notRequired().default(''),
gen_server: string().required(), gen_server: string().required(),
speed: number().default(1.0).min(0.5).max(1.5).required(), speed: number().default(1.0).min(0.5).max(1.5).required(),
}) })
@@ -27,20 +34,30 @@ type CreateCourseSchema = InferType<typeof createCourseSchema>
const createCourseState = reactive({ const createCourseState = reactive({
task_title: undefined, task_title: undefined,
digital_human_id: 0, digital_human_id: 0,
opening_url: '',
ending_url: '',
gen_server: 'main', gen_server: 'main',
speed: 1.0, speed: 1.0,
}) })
const selected_file = ref<File[] | null>(null) const selected_file = ref<File[] | null>(null)
const selected_digital_human = ref<DigitalHumanItem | null>(null) const selected_digital_human = ref<DigitalHumanItem | null>(null)
const selected_titles = ref<TitlesTemplate | null>(null)
watchEffect(() => { watchEffect(() => {
if (selected_digital_human.value) { if (selected_digital_human.value) {
createCourseState.digital_human_id = selected_digital_human.value.model_id || selected_digital_human.value.id! createCourseState.digital_human_id =
selected_digital_human.value.model_id || selected_digital_human.value.id!
}
if (selected_titles.value) {
createCourseState.opening_url = selected_titles.value.opening_file
createCourseState.ending_url = selected_titles.value.ending_file
} }
}) })
const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>) => { const onCreateCourseSubmit = async (
event: FormSubmitEvent<CreateCourseSchema>
) => {
if (!selected_file.value) { if (!selected_file.value) {
toast.add({ toast.add({
title: '未选择文件', title: '未选择文件',
@@ -52,8 +69,11 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
} }
creationPending.value = true creationPending.value = true
// upload PPTX file // upload PPTX file
useFileGo(selected_file.value[0]).then(url => { useFileGo(selected_file.value[0]).then((url) => {
useFetchWrapped<req.gen.CourseGenCreate & AuthedRequest, BaseResponse<resp.gen.CourseGenCreate>>('App.Digital_Convert.Create', { useFetchWrapped<
req.gen.CourseGenCreate & AuthedRequest,
BaseResponse<resp.gen.CourseGenCreate>
>('App.Digital_Convert.Create', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
task_title: event.data.task_title, task_title: event.data.task_title,
@@ -62,9 +82,10 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
ppt_url: url, ppt_url: url,
digital_human_id: event.data.digital_human_id, digital_human_id: event.data.digital_human_id,
custom_video: '[]', custom_video: '[]',
opening_url: '', opening_url: event.data.opening_url || '',
ending_url: '', ending_url: event.data.opening_url || '',
}).then(res => { })
.then((res) => {
if (res.data.record_status === 1) { if (res.data.record_status === 1) {
toast.add({ toast.add({
title: '创建成功', title: '创建成功',
@@ -83,7 +104,8 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
}) })
} }
creationPending.value = false creationPending.value = false
}).catch(e => { })
.catch((e) => {
creationPending.value = false creationPending.value = false
toast.add({ toast.add({
title: '创建失败', title: '创建失败',
@@ -99,12 +121,18 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
<template> <template>
<USlideover prevent-close> <USlideover prevent-close>
<UCard <UCard
:ui="{ body: { base: 'flex-1' }, ring: '', divide: 'divide-y divide-gray-100 dark:divide-gray-800' }" :ui="{
body: { base: 'flex-1' },
ring: '',
divide: 'divide-y divide-gray-100 dark:divide-gray-800',
}"
class="flex flex-col flex-1" class="flex flex-col flex-1"
> >
<template #header> <template #header>
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<h3 class="text-base font-semibold leading-6 text-gray-900 dark:text-white"> <h3
class="text-base font-semibold leading-6 text-gray-900 dark:text-white"
>
新建微课视频 新建微课视频
</h3> </h3>
<UButton <UButton
@@ -125,34 +153,93 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
@submit="onCreateCourseSubmit" @submit="onCreateCourseSubmit"
> >
<div class="flex justify-between gap-2 *:flex-1"> <div class="flex justify-between gap-2 *:flex-1">
<UFormGroup label="微课标题" name="task_title" required> <UFormGroup
<UInput v-model="createCourseState.task_title" placeholder="请输入微课标题"/> label="微课标题"
name="task_title"
required
>
<UInput
v-model="createCourseState.task_title"
placeholder="请输入微课标题"
/>
</UFormGroup> </UFormGroup>
</div> </div>
<div class="grid grid-cols-2 gap-2"> <div class="grid grid-cols-2 gap-2">
<UFormGroup label="数字人" name="digital_human_id" required> <UFormGroup
label="数字人"
name="digital_human_id"
required
>
<div <div
:class="{'shadow-inner': !!selected_digital_human}" :class="{ 'shadow-inner': !!selected_digital_human }"
class="flex items-center gap-2 bg-neutral-100 dark:bg-neutral-800 p-2 rounded-md cursor-pointer select-none transition-all" class="flex items-center gap-2 bg-neutral-100 dark:bg-neutral-800 p-2 rounded-md cursor-pointer select-none transition-all"
@click="isDigitalSelectorOpen = true" @click="isDigitalSelectorOpen = true"
> >
<div <div
class="w-12 aspect-square border dark:border-neutral-700 rounded-md flex justify-center items-center overflow-hidden"> class="w-12 aspect-square border dark:border-neutral-700 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"/> <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>
<div class="flex flex-col text-neutral-400 text-sm font-medium"> <div class="flex flex-col text-neutral-400 text-sm font-medium">
<span :class="!!selected_digital_human ? 'text-neutral-600' : ''">{{ <span
selected_digital_human?.name || '点击选择数字人' :class="!!selected_digital_human ? 'text-neutral-600' : ''"
}}</span> >
<span v-if="selected_digital_human?.description" class="text-2xs"> {{ selected_digital_human?.name || '点击选择数字人' }}
</span>
<span
v-if="selected_digital_human?.description"
class="text-2xs"
>
{{ selected_digital_human?.description }} {{ selected_digital_human?.description }}
</span> </span>
</div> </div>
</div> </div>
</UFormGroup> </UFormGroup>
<UFormGroup label="视频片头片尾" name="opening"> <UFormGroup
label="视频片头片尾"
name="opening"
>
<div
:class="{ 'shadow-inner': !!selected_titles }"
class="flex items-center gap-2 bg-neutral-100 dark:bg-neutral-800 p-2 rounded-md cursor-pointer select-none transition-all"
@click="isTitlesSelectorOpen = true"
>
<div
class="w-12 aspect-square border dark:border-neutral-700 rounded-md flex justify-center items-center overflow-hidden"
>
<UIcon
v-if="!selected_titles"
class="text-2xl opacity-50"
name="i-tabler-brackets-contain"
/>
<NuxtImg
v-else
:src="selected_titles?.opening_url"
/>
</div>
<div class="flex flex-col text-neutral-400 text-sm font-medium">
<span :class="!!selected_titles ? 'text-neutral-600' : ''">
{{ selected_titles?.title || '点击选择片头' }}
</span>
<span
v-if="selected_titles?.description"
class="text-2xs"
>
{{ selected_titles?.description }}
</span>
</div>
</div>
</UFormGroup>
<!-- <UFormGroup label="视频片头片尾" name="opening">
<div <div
class="flex items-center gap-2 bg-neutral-100 dark:bg-neutral-800 p-2 rounded-md cursor-pointer select-none transition-all" class="flex items-center gap-2 bg-neutral-100 dark:bg-neutral-800 p-2 rounded-md cursor-pointer select-none transition-all"
> >
@@ -164,39 +251,55 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
<span>点击选择</span> <span>点击选择</span>
</div> </div>
</div> </div>
</UFormGroup> </UFormGroup> -->
</div> </div>
<UFormGroup label="PPT 文件" required> <UFormGroup
label="PPT 文件"
required
>
<template #help> <template #help>
<p class="text-xs text-neutral-400"> <p class="text-xs text-neutral-400">仅支持 .pptx 格式</p>
仅支持 .pptx 格式
</p>
</template> </template>
<FileDnD <FileDnD
accept="application/vnd.openxmlformats-officedocument.presentationml.presentation" accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"
@change="file => selected_file = file" @change="(file) => (selected_file = file)"
/> />
</UFormGroup> </UFormGroup>
<UAccordion :items="[{label: '高级选项'}]" color="gray" size="lg"> <UAccordion
:items="[{ label: '高级选项' }]"
color="gray"
size="lg"
>
<template #item> <template #item>
<div class="border dark:border-neutral-700 rounded-lg space-y-4 p-4 pb-6"> <div
<UFormGroup label="生成线路" name="gen_server"> class="border dark:border-neutral-700 rounded-lg space-y-4 p-4 pb-6"
>
<UFormGroup
label="生成线路"
name="gen_server"
>
<USelectMenu <USelectMenu
v-model="createCourseState.gen_server" v-model="createCourseState.gen_server"
:options="[{ :options="[
{
label: '主线路', label: '主线路',
value: 'main', value: 'main',
}, { },
{
label: '备用线路', label: '备用线路',
value: 'standby1', value: 'standby1',
}]" },
]"
option-attribute="label" option-attribute="label"
value-attribute="value" value-attribute="value"
/> />
</UFormGroup> </UFormGroup>
<UFormGroup :label="`视频倍速:${createCourseState.speed}`" name="speed"> <UFormGroup
:label="`视频倍速:${createCourseState.speed}`"
name="speed"
>
<URange <URange
v-model="createCourseState.speed" v-model="createCourseState.speed"
:max="1.5" :max="1.5"
@@ -238,9 +341,14 @@ const onCreateCourseSubmit = async (event: FormSubmitEvent<CreateCourseSchema>)
selected_digital_human = (digitalHumans as DigitalHumanItem) selected_digital_human = (digitalHumans as DigitalHumanItem)
}" }"
/> />
<ModalVideoTitleSelect
:is-open="isTitlesSelectorOpen"
@close="isTitlesSelectorOpen = false"
@select="titles => {
selected_titles = (titles as TitlesTemplate)
}"
/>
</USlideover> </USlideover>
</template> </template>
<style scoped> <style scoped></style>
</style>