10 Commits

23 changed files with 5076 additions and 931 deletions

226
.github/copilot-instructions.md vendored Normal file
View File

@@ -0,0 +1,226 @@
# XSH Assistant 编码指南
## 项目概览
**xsh-assistant** 是一个基于 Nuxt 3 的 AI 驱动内容生成平台,专注于数字内容创作(微课视频、虚拟讲师、绿幕合成等)。核心特性:
- **前端框架**: Nuxt 3 + Vue 3 + TypeScript + Tailwind CSS + Radix Vue UI
- **状态管理**: Pinia带持久化
- **媒体处理**: FFmpeg WASM客户端视频处理、WebAV视频剪辑
- **API 集成**: 统一的 `useFetchWrapped` 包装器,所有请求都通过 `API_BASE` 代理(`https://service1.fenshenzhike.com/`
- **部署模式**: SPASSR=false
## 核心架构模式
### 1. Composables 设计Pinia + 自定义 Composables
**状态管理采用分层设计**
```
Pinia Stores持久化状态
├── useLoginState: 用户认证、token、个人资料
├── useHistory: AIGC 会话、聊天历史
└── useTourState: 新手引导状态
业务 Composables无状态或短生命周期
├── useFetchWrapped: API 请求包装(自动添加 token、user_id
├── useLLM: LLM API 调用Spark 模型集成)
├── useFFmpeg: FFmpeg WASM 单例管理
├── useVideoBackgroundCompositing: 视频合成(数字人+背景)
├── useVideoSubtitleEmbedding: 字幕嵌入
└── useDownload: 文件下载管理
```
**关键模式**
- **Pinia stores 必须是单一实例**,通过 `storeToRefs()` 获取响应式引用
- **API 请求必须通过 `useFetchWrapped`** 来自动处理认证头token/user_id
- **FFmpeg 采用单例模式**`useFFmpeg()` 返回全局加载的实例),避免重复初始化
### 2. API 请求模式
所有 API 请求使用统一的 `useFetchWrapped` 包装器:
```typescript
// 基础签名
useFetchWrapped<RequestType, ResponseType>(action: string, payload?: RequestType, options?: FetchOptions)
// 请求格式示例(来自 useHistory
useFetchWrapped<AuthedRequest, BaseResponse<resp.xxx>>(
'App.User_User.CheckSession', // action 作为查询参数 ?s=
{ token: loginState.token, user_id: loginState.user.id, ...payload },
{ method: 'POST' } // 默认 POST
)
```
**约定**
- **每个请求必须包含** `token``user_id`(来自 `useLoginState`
- **响应结构统一**: `BaseResponse<T>` 包含 `ret: number` 状态码和 `data: T` 数据
- **API_BASE 在 `nuxt.config.ts` 中定义**,所有请求都相对于此 URL
### 3. 媒体处理架构
#### FFmpeg 初始化流程
- **单例加载**: 首次调用 `useFFmpeg()` 时初始化,后续复用缓存的实例
- **WASM 资源加载**: 从 CDN`cdn.jsdelivr.net`)加载 FFmpeg core、wasm、worker
- **错误恢复**: 调用 `cleanupFFmpeg()` 清理资源并重置单例
#### 视频合成流程(核心用例)
```
输入: 透明通道视频 (WebM) + 背景图 (PNG/File)
1. 获取背景图尺寸
2. 计算等比缩放到 720P
3. 加载文件到 FFmpeg vFS
4. 执行 FFmpeg 滤镜链:
- 背景: scale → ${outputWidth}x${outputHeight}
- 视频: scale → ${outputWidth}x${outputHeight} (保留 alpha)
- overlay: 视频叠加到背景format=auto
5. 使用 VP9 编码(支持 alpha+ Opus 音频编码
6. 返回 Blob → 可直接上传或本地预览
```
### 4. UI 组件架构
#### 内置组件库(`components/uni/`
自定义包装组件,提供统一 API
- `UniButton`: 按钮 + loading 状态
- `UniInput`/`UniTextArea`: 表单输入
- `UniSelect`: 下拉选择
- `UniMessage`: 全局消息通知(通过 provide/inject
- `UniCopyable`: 可复制文本
**消息通知用法**
```typescript
const toast = useToast() // Radix Vue 的 Toast顶部通知
// 或从 provide 注入
const messageApi = inject('uni-message')
messageApi.success('操作成功')
messageApi.error('操作失败', 5000)
```
#### Radix Vue + Nuxt UI 集成
- 使用 Radix Vue for 基础组件button, dialog, select
- Nuxt UI 用于高级组件 + 主题管理
- **颜色方案**: primary='indigo', gray='neutral',详见 `app.config.ts`
### 5. 路由与页面结构
**目录映射**
```
pages/
├── generation.vue (导航枢纽)
└── aigc/
├── chat/index.vue (聊天页,支持多 LLM 模型)
├── draw/index.vue (绘图生成)
└── generation/
├── course.vue (微课生成)
├── green-screen.vue (绿幕视频)
├── avatar-models.vue (数字讲师)
├── materials.vue (片头片尾)
├── ppt-templates.vue (PPT 库)
└── admin/ (管理功能)
```
**导航约定**
- `/generation` → 功能导航页面
- `/aigc/chat` → 聊天/文本生成
- `/generation/course` → 视频生成工作流
- 所有生成功能都需要登录ModalAuthentication 处理)
## 开发工作流
### 启动项目
```bash
ni # 安装依赖
nr dev # 启动 http://localhost:3000
nr generate # 生产构建 (生成静态文件)
```
### 常见任务
**添加新的 API 端点**
1. 定义 Request 和 Response 类型(参考 `typings/llm.ts`
2. 在 composable 中使用 `useFetchWrapped` 调用
3. 自动包含 token/user_id来自 `useLoginState`
**添加新的视频处理功能**
1. 使用 `useFFmpeg()` 获取实例(自动初始化)
2. 写入文件到 vFS: `ffmpeg.writeFile()`
3. 执行命令:`ffmpeg.exec([...filterArgs])`
4. 清理临时文件:`ffmpeg.deleteFile()`
5. 使用 progress callback 通报处理进度
**添加新的 UI 组件**
1. 创建在 `components/` 下(自动注册)
2. 优先使用 Radix Vue + Nuxt UI已集成
3. 使用 Tailwind CSS utility classes + `@apply` 指令
4. 通过 `app.config.ts` 自定义 UI 主题
## 项目特定的约定
### 类型定义位置
- **LLM 相关**: `typings/llm.ts`ChatMessage, ChatSession, ModelTag, LLMModal
- **全局类型**: `typings/types.d.ts`BaseResponse, AuthedRequest, UserSchema
- **组件接口**: 组件目录下的 `index.d.ts`(例 `components/aigc/drawing/index.d.ts`
### 命名规范
- **Composables**: `use` 前缀(`useLoginState`, `useLLM`
- **Stores**: `use` + 功能名(`useHistory`, `useTourState`
- **组件**: PascalCase`ChatItem.vue`, `ModalAuthentication.vue`
- **工具函数**: camelCase放在 `composables/` 或各功能目录
### 响应式数据模式
- **Pinia store 返回值**: 必须通过 `storeToRefs()` 才能保持响应式
- **模板中的 ref**: 直接访问Vue 自动展开)
- **跨组件数据**: 优先使用 Pinia store带持久化
### 进度反馈与错误处理
- **长时间操作** (视频处理): 通过 callback 函数报告 progress0-100
- **错误处理**: 返回 Promise reject上层 catch 处理;可选通过 toast/message 提示
- **FFmpeg 错误**: 捕获 exitCode 非零,记录详细的 FFmpeg 输出
## 依赖与性能优化
### 关键依赖
- **@ffmpeg/ffmpeg@0.12.15**: WASM 视频处理(从 CDN 加载)
- **@webav/av-cliper**: 客户端视频剪辑库
- **markdown-it + highlight.js**: 内容渲染(支持代码高亮)
- **date-fns/dayjs**: 时间处理dayjs-nuxt 提供全局实例)
- **idb-keyval**: IndexedDB 简化操作(缓存大文件)
### Vite 优化设置
```typescript
// nuxt.config.ts 中排除以下包进行优化,避免 bundling WASM
optimizeDeps.exclude: ['@ffmpeg/ffmpeg', 'idb-keyval', '@webav/av-cliper', 'gsap', 'markdown-it']
```
### 构建排除项
Worker 格式设置为 ES Module避免 Vite 默认处理:
```typescript
vite.worker.format = 'es'
```
## 测试与调试
- **开发服务器日志**: 浏览器控制台查看 FFmpeg、API、业务日志
- **FFmpeg 调试**: `[FFmpeg]` 前缀的日志输出包含加载进度、命令执行信息
- **状态调试**: Pinia DevTools启用 `devtools: true`
- **样式调试**: Tailwind 配置在 `tailwind.config.ts`,按需自定义
## 常见陷阱与解决方案
| 问题 | 原因 | 解决方案 |
|------|------|--------|
| API 请求 401 | 缺少 token 或已过期 | 检查 `useLoginState().token`,通过 ModalAuthentication 重新登录 |
| FFmpeg 加载超时 | CDN 资源加载慢 | 检查网络,可切换到本地 `/public/assets/ffmpeg` |
| 视频输出无声音 | 滤镜链未映射音频 | 确保 FFmpeg 命令包含 `-map '1:a?'` 映射音频轨道 |
| 组件未注册 | 文件位置错误 | 确保在 `components/` 目录下,子目录自动扁平化注册 |
| Pinia 状态未持久化 | 未配置 persist 选项 | 在 store 返回语句后添加 persist 配置(参考 `useLoginState` |
## 资源链接
- [Nuxt 3 文档](https://nuxt.com/docs)
- [Pinia 文档](https://pinia.vuejs.org)
- [FFmpeg.wasm 文档](https://ffmpegwasm.netlify.app/)
- [Radix Vue](https://www.radix-vue.com/)
- [Nuxt UI 组件库](https://ui.nuxt.com/):可使用 nuxt-ui MCP 工具

View File

@@ -0,0 +1,476 @@
<script lang="ts" setup>
import { object, string } from 'yup'
import type { FormSubmitEvent } from '#ui/types'
const toast = useToast()
const loginState = useLoginState()
interface Props {
modelValue: boolean
}
interface Emits {
(e: 'update:modelValue', value: boolean): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const isOpen = computed({
get: () => props.modelValue,
set: (value) => emit('update:modelValue', value)
})
// 表单状态
const formState = reactive({
dh_name: '',
organization: '',
})
// 文件上传状态
const videoFile = ref<File | null>(null)
const authVideoFile = ref<File | null>(null)
const isSubmitting = ref(false)
// 上传进度状态
const uploadProgress = reactive({
step: 0,
total: 3,
message: ''
})
// 表单验证
const schema = object({
dh_name: string()
.required('请输入数字人名称')
.max(50, '数字人名称不能超过50个字符'),
organization: string()
.required('请输入单位名称')
.max(100, '单位名称不能超过100个字符'),
})
// 更新上传进度
const updateProgress = (step: number, message: string) => {
uploadProgress.step = step
uploadProgress.message = message
}
// 处理数字人视频上传
const handleVideoUpload = (files: FileList) => {
const file = files[0]
if (!file) return
// 验证文件类型
if (!['video/mp4', 'video/mov'].includes(file.type)) {
toast.add({
title: '文件格式错误',
description: '仅支持MP4和MOV格式的视频文件',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
// 验证文件大小 (1GB)
if (file.size > 1024 * 1024 * 1024) {
toast.add({
title: '文件过大',
description: '视频文件大小不能超过1GB',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
videoFile.value = file
toast.add({
title: '文件上传成功',
description: '数字人视频已选择',
color: 'green',
icon: 'i-tabler-check',
})
}
// 处理授权视频上传
const handleAuthVideoUpload = (files: FileList) => {
const file = files[0]
if (!file) return
// 验证文件类型
if (!['video/mp4', 'video/mov'].includes(file.type)) {
toast.add({
title: '文件格式错误',
description: '仅支持MP4和MOV格式的视频文件',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
// 验证文件大小
if (file.size > 1024 * 1024 * 1024) {
toast.add({
title: '文件过大',
description: '视频文件大小不能超过1GB',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
authVideoFile.value = file
toast.add({
title: '文件上传成功',
description: '授权视频已选择',
color: 'green',
icon: 'i-tabler-check',
})
}
// 提交表单
const onSubmit = async (event: FormSubmitEvent<typeof formState>) => {
// 验证文件是否已上传
if (!videoFile.value) {
toast.add({
title: '请上传数字人视频素材',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
if (!authVideoFile.value) {
toast.add({
title: '请上传形象授权视频',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
if (isSubmitting.value) return
try {
isSubmitting.value = true
updateProgress(0, '开始创建数字人...')
// 上传数字人视频素材
updateProgress(1, '上传数字人视频素材...')
const videoUrl = await useFileGo(videoFile.value, 'material')
// 上传形象授权视频
updateProgress(2, '上传形象授权视频...')
const authVideoUrl = await useFileGo(authVideoFile.value, 'material')
// 创建数字人定制记录
updateProgress(3, '创建数字人定制记录...')
const response = await useFetchWrapped<
{
user_id: number
dh_name: string
organization: string
video_url: string
auth_video_url: string
} & AuthedRequest,
BaseResponse<{ train_id: number }>
>('App.Digital_Train.Create', {
token: loginState.token!,
user_id: loginState.user.id,
dh_name: event.data.dh_name,
organization: event.data.organization,
video_url: videoUrl,
auth_video_url: authVideoUrl,
})
if (response.ret === 200 && response.data.train_id) {
toast.add({
title: '数字人定制提交成功',
description: '您的数字人定制请求已提交,请等待管理员处理',
color: 'green',
icon: 'i-tabler-check',
})
// 重置表单
formState.dh_name = ''
formState.organization = ''
videoFile.value = null
authVideoFile.value = null
uploadProgress.step = 0
uploadProgress.message = ''
// 关闭弹窗
isOpen.value = false
} else {
throw new Error(response.msg || '创建失败')
}
} catch (error) {
console.error('数字人定制失败:', error)
const errorMessage = error instanceof Error ? error.message : '数字人定制失败,请重试'
toast.add({
title: '提交失败',
description: errorMessage,
color: 'red',
icon: 'i-tabler-alert-triangle',
})
} finally {
isSubmitting.value = false
uploadProgress.step = 0
uploadProgress.message = ''
}
}
// 重置表单
const resetForm = () => {
formState.dh_name = ''
formState.organization = ''
videoFile.value = null
authVideoFile.value = null
uploadProgress.step = 0
uploadProgress.message = ''
}
// 监听弹窗关闭事件,重置表单
watch(isOpen, (newValue) => {
if (!newValue) {
resetForm()
}
})
// 显示授权文案弹窗
const showAuthModal = ref(false)
</script>
<template>
<UModal v-model="isOpen" :ui="{ width: 'sm:max-w-6xl' }">
<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-lg font-semibold text-gray-900 dark:text-white">
数字人定制
</h3>
<UButton
color="gray"
variant="ghost"
icon="i-heroicons-x-mark-20-solid"
class="-my-1"
@click="isOpen = false"
/>
</div>
</template>
<div class="grid grid-cols-7 gap-6">
<!-- 左侧表单 -->
<div class="col-span-3 p-4 rounded-lg bg-gray-50 dark:bg-gray-800">
<UForm
:schema="schema"
:state="formState"
class="space-y-4"
@submit="onSubmit"
>
<!-- 数字人视频素材 -->
<UFormGroup label="数字人视频素材" required>
<UniFileDnD
accept="video/mp4,video/mov"
class="h-36"
@change="handleVideoUpload"
>
<template #default>
<div class="text-center">
<UIcon
name="i-heroicons-video-camera"
class="mx-auto h-12 w-12 text-gray-400"
/>
<div class="mt-2">
<span class="text-sm text-gray-600 dark:text-gray-400">
{{ videoFile ? videoFile.name : '点击或拖拽上传视频' }}
</span>
</div>
<p class="text-xs text-gray-500 mt-1">
小于 1GB mov/mp4 格式比例 9:16帧率 25FPS分辨率 1080P时长 3-6 分钟
</p>
</div>
</template>
</UniFileDnD>
</UFormGroup>
<!-- 数字人名称 -->
<UFormGroup label="数字人名称" name="dh_name" required>
<UInput
v-model="formState.dh_name"
placeholder="请输入数字人名称"
/>
</UFormGroup>
<!-- 单位名称 -->
<UFormGroup label="单位名称" name="organization" required>
<UInput
v-model="formState.organization"
placeholder="请输入单位名称"
/>
</UFormGroup>
<!-- 形象授权视频 -->
<UFormGroup label="形象授权视频" required>
<template #description>
<div class="flex items-center justify-between">
<span class="text-xs text-gray-500">
请确保本人进行形象授权视频录制否则脸部比对将不通过导致制作失败
</span>
<UButton
variant="link"
size="xs"
icon="i-heroicons-document-text"
@click="showAuthModal = true"
>
授权文案
</UButton>
</div>
</template>
<UniFileDnD
accept="video/mp4,video/mov"
class="h-36"
@change="handleAuthVideoUpload"
>
<template #default>
<div class="text-center">
<UIcon
name="i-heroicons-shield-check"
class="mx-auto h-12 w-12 text-gray-400"
/>
<div class="mt-2">
<span class="text-sm text-gray-600 dark:text-gray-400">
{{ authVideoFile ? authVideoFile.name : '点击或拖拽上传授权视频' }}
</span>
</div>
</div>
</template>
</UniFileDnD>
</UFormGroup>
<!-- 提交按钮 -->
<UButton
type="submit"
class="w-full"
:loading="isSubmitting"
:disabled="isSubmitting"
color="primary"
>
{{ isSubmitting ? '提交中...' : '确认提交' }}
</UButton>
<!-- 上传进度 -->
<div v-if="isSubmitting" class="mt-4 space-y-2">
<div class="flex justify-between text-sm">
<span>{{ uploadProgress.message }}</span>
<span>{{ uploadProgress.step }}/{{ uploadProgress.total }}</span>
</div>
<UProgress
:value="(uploadProgress.step / uploadProgress.total) * 100"
color="primary"
/>
</div>
</UForm>
</div>
<!-- 右侧教程和提示 -->
<div class="col-span-4 p-4 rounded-lg border dark:border-gray-700">
<div class="flex flex-col h-full gap-6">
<!-- 教程视频 -->
<div class="flex-1">
<h3 class="text-lg font-semibold mb-3 text-gray-800 dark:text-white flex items-center gap-2">
<UIcon name="i-heroicons-video-camera" class="h-5 w-5" />
视频录制教程
</h3>
<div class="w-full aspect-video border rounded-lg bg-gray-100 dark:bg-gray-800 flex items-center justify-center">
<UIcon name="i-heroicons-video-camera" class="h-12 w-12 text-gray-400" />
</div>
</div>
<!-- 联系方式 -->
<div class="bg-blue-50 dark:bg-blue-900/20 rounded-lg p-4 border border-blue-200 dark:border-blue-700">
<div class="flex items-center gap-3">
<div class="bg-blue-100 dark:bg-blue-900 p-2 rounded-lg">
<UIcon name="i-heroicons-chat-bubble-left-right" class="h-5 w-5 text-blue-600 dark:text-blue-400" />
</div>
<div>
<p class="text-sm font-medium text-gray-800 dark:text-white">需要帮助</p>
<p class="text-sm text-gray-600 dark:text-gray-300">
客服微信<span class="font-mono text-blue-600 dark:text-blue-400">xxxxxx</span>
</p>
</div>
</div>
</div>
<!-- 录制指南 -->
<div class="bg-amber-50 dark:bg-amber-900/20 rounded-lg p-4 border border-amber-200 dark:border-amber-700">
<div class="flex items-start gap-3">
<div class="bg-amber-100 dark:bg-amber-900 p-2 rounded-lg mt-0.5">
<UIcon name="i-heroicons-light-bulb" class="h-5 w-5 text-amber-600 dark:text-amber-400" />
</div>
<div class="flex-1">
<h4 class="text-sm font-semibold text-gray-800 dark:text-white mb-3">录制注意事项</h4>
<div class="space-y-2">
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-sun" class="h-4 w-4 text-amber-500 mt-0.5 flex-shrink-0" />
<span class="text-xs text-gray-600 dark:text-gray-300">确保光线充足避免背光</span>
</div>
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-speaker-wave" class="h-4 w-4 text-green-500 mt-0.5 flex-shrink-0" />
<span class="text-xs text-gray-600 dark:text-gray-300">选择安静环境减少噪音干扰</span>
</div>
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-viewfinder-circle" class="h-4 w-4 text-blue-500 mt-0.5 flex-shrink-0" />
<span class="text-xs text-gray-600 dark:text-gray-300">人脸占画面比例控制在 1/4 以内</span>
</div>
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-face-smile" class="h-4 w-4 text-purple-500 mt-0.5 flex-shrink-0" />
<span class="text-xs text-gray-600 dark:text-gray-300">保持自然表情使用恰当手势</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</UCard>
<!-- 授权文案弹窗 -->
<UModal v-model="showAuthModal">
<UCard>
<template #header>
<div class="flex items-center justify-between">
<h3 class="text-lg font-semibold text-gray-900 dark:text-white">
授权视频文案
</h3>
<UButton
color="gray"
variant="ghost"
icon="i-heroicons-x-mark-20-solid"
class="-my-1"
@click="showAuthModal = false"
/>
</div>
</template>
<div class="p-4">
<p class="text-sm text-gray-600 dark:text-gray-400 mb-4">
请确保您是视频中人物的合法授权人在授权视频中朗读以下文案
</p>
<div class="bg-gray-100 dark:bg-gray-800 rounded-lg p-4">
<p class="text-sm leading-relaxed text-gray-800 dark:text-gray-200">
我是在"AI智慧职教平台"定制上传视频的模特本人我承诺已经按照平台规则进行合法授权特此承诺
</p>
</div>
</div>
</UCard>
</UModal>
</UModal>
</template>
<style scoped></style>

View File

@@ -33,10 +33,10 @@ const toast = useToast()
const page = ref(1) const page = ref(1)
const sourceTypeList = [ const sourceTypeList = [
{ label: 'TX', value: 1, color: 'blue' }, { label: 'xsh_wm', value: 1, color: 'blue' }, // 万木(腾讯)
{ label: 'XSH', value: 2, color: 'green' }, { label: 'xsh_zy', value: 2, color: 'green' }, // XSH 自有
{ label: 'GJ', value: 3, color: 'purple' }, { label: 'xsh_fh', value: 3, color: 'purple' }, // 硅基(泛化数字人)
{ label: 'XB', value: 4, color: 'indigo' }, { label: 'xsh_bb', value: 4, color: 'indigo' }, // 百度小冰
] ]
// const sourceType = ref(sourceTypeList[0]) // const sourceType = ref(sourceTypeList[0])

View File

@@ -15,8 +15,16 @@ const creationPending = ref(false)
const isDigitalSelectorOpen = ref(false) const isDigitalSelectorOpen = ref(false)
const createCourseSchema = object({ const createCourseSchema = object({
title: string().trim().min(4, '标题必须大于4个字符').max(20, '标题不能超过20个字符').required('请输入视频标题'), title: string()
content: string().trim().min(4, '内容必须大于4个字符').max(1000, '内容不能超过1000个字符').required('请输入驱动文本内容'), .trim()
.min(4, '标题必须大于4个字符')
.max(20, '标题不能超过20个字符')
.required('请输入视频标题'),
content: string()
.trim()
.min(4, '内容必须大于4个字符')
.max(1000, '内容不能超过1000个字符')
.required('请输入驱动文本内容'),
digital_human_id: number().not([0], '请选择数字人'), digital_human_id: number().not([0], '请选择数字人'),
source_type: number().default(0).required(), source_type: number().default(0).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(),
@@ -31,40 +39,46 @@ const createCourseState = reactive({
digital_human_id: 0, digital_human_id: 0,
source_type: 0, source_type: 0,
speed: 1.0, speed: 1.0,
bg_img: undefined, bg_img: '',
}) })
const selected_digital_human = ref<DigitalHumanItem | null>(null) const selected_digital_human = ref<DigitalHumanItem | null>(null)
const selected_bg_img = ref<File | undefined>(); const selected_bg_img = ref<File | undefined>()
const enableBackgroundCompositing = ref(false)
watchEffect(() => { watchEffect(() => {
if (selected_digital_human.value) { if (selected_digital_human.value) {
// 2025.02.26 使用内部数字人 ID // 2025.02.26 使用内部数字人 ID
createCourseState.digital_human_id = createCourseState.digital_human_id =
selected_digital_human.value.digital_human_id ?? selected_digital_human.value.id ?? 0 selected_digital_human.value.digital_human_id ??
selected_digital_human.value.id ??
0
createCourseState.source_type = selected_digital_human.value.type! createCourseState.source_type = selected_digital_human.value.type!
} }
}) })
const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSchema>) => { watchEffect(() => {
// 根据背景合成开关更新 bg_img
createCourseState.bg_img = enableBackgroundCompositing.value
? 'https://service1.fenshenzhike.com/default_background.png'
: ''
})
const onCreateCourseGreenSubmit = async (
event: FormSubmitEvent<CreateCourseSchema>
) => {
creationPending.value = true creationPending.value = true
let bgImgUrl = undefined
if (selected_bg_img.value) {
bgImgUrl = await useFileGo(selected_bg_img.value, 'tmp')
}
let payload: { let payload: {
token: string; token: string
user_id: number; user_id: number
title: string; title: string
content: string; content: string
digital_human_id: any; digital_human_id: any
speed: number; speed: number
device_id: string; device_id: string
source_type: 1 | 2 | undefined; source_type: 1 | 2 | undefined
bg_img?: string; bg_img?: string
} = { } = {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
@@ -74,66 +88,60 @@ const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSche
speed: 2 - event.data.speed, speed: 2 - event.data.speed,
device_id: 'XSHAssistant Web', device_id: 'XSHAssistant Web',
source_type: event.data.source_type as 1 | 2 | undefined, source_type: event.data.source_type as 1 | 2 | undefined,
bg_img: event.data.bg_img,
} }
if (selected_bg_img.value) { useFetchWrapped<
if (!bgImgUrl) { req.gen.GBVideoCreate & AuthedRequest,
toast.add({ BaseResponse<resp.gen.GBVideoCreate>
title: '上传失败', >('App.Digital_VideoTask.Create', payload)
description: '背景图片上传失败,请重试', .then((res) => {
color: 'red', if (!!res.data.task_id) {
icon: 'i-tabler-alert-triangle', toast.add({
}) title: '创建成功',
selected_bg_img.value = undefined 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 creationPending.value = false
return
}
payload = {
...payload,
bg_img: bgImgUrl,
}
}
useFetchWrapped<req.gen.GBVideoCreate & AuthedRequest, BaseResponse<resp.gen.GBVideoCreate>>('App.Digital_VideoTask.Create', payload).then(res => {
if (!!res.data.task_id) {
toast.add({
title: '创建成功',
description: '视频已加入生成队列',
color: 'green',
icon: 'i-tabler-check',
})
emit('success')
slide.close()
} else {
toast.add({ toast.add({
title: '创建失败', title: '创建失败',
description: res.msg || '未知错误', description: e.message || '未知错误',
color: 'red', color: 'red',
icon: 'i-tabler-alert-triangle', 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> </script>
<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
@@ -154,28 +162,52 @@ const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSche
@submit="onCreateCourseGreenSubmit" @submit="onCreateCourseGreenSubmit"
> >
<div class="flex justify-between gap-2 *:flex-1"> <div class="flex justify-between gap-2 *:flex-1">
<UFormGroup label="视频标题" name="title" required> <UFormGroup
<UInput v-model="createCourseState.title" placeholder="请输入视频标题"/> label="视频标题"
name="title"
required
>
<UInput
v-model="createCourseState.title"
placeholder="请输入视频标题"
/>
</UFormGroup> </UFormGroup>
</div> </div>
<div class="grid grid-cols-1 sm:grid-cols-2 gap-2"> <div class="grid grid-cols-1 sm: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>
@@ -183,23 +215,44 @@ const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSche
</UFormGroup> </UFormGroup>
</div> </div>
<UFormGroup label="背景图片" name="bg_img" help="可以上传图片作为视频背景,留空则为绿幕背景"> <!-- <UFormGroup label="背景图片" name="bg_img" help="可以上传图片作为视频背景,留空则为绿幕背景">
<UInput type="file" accept="image/jpg,image/png" placeholder="选择背景图片" @change="selected_bg_img = $event?.[0] || undefined"/> <UInput type="file" accept="image/jpg,image/png" placeholder="选择背景图片" @change="selected_bg_img = $event?.[0] || undefined"/>
</UFormGroup> -->
<UFormGroup
label="驱动内容"
name="content"
required
>
<UTextarea
v-model="createCourseState.content"
:rows="6"
autoresize
placeholder="请输入驱动文本内容"
/>
</UFormGroup> </UFormGroup>
<UFormGroup label="驱动内容" name="content" required> <UFormGroup
<!-- <template #help>--> label="启用背景合成"
<!-- <p class="text-xs text-neutral-400">--> name="bg_img"
<!-- 仅支持 .pptx 格式--> help="开启后生成透明通道,可在视频生成完毕后选择自定义背景合成;关闭则使用绿幕背景。"
<!-- </p>--> >
<!-- </template>--> <UToggle v-model="enableBackgroundCompositing" />
<UTextarea v-model="createCourseState.content" :rows="6" autoresize placeholder="请输入驱动文本内容"/>
</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="`视频倍速:${createCourseState.speed}`" name="speed"> class="border dark:border-neutral-700 rounded-lg space-y-4 p-4 pb-6"
>
<UFormGroup
:label="`视频倍速:${createCourseState.speed}`"
name="speed"
>
<URange <URange
v-model="createCourseState.speed" v-model="createCourseState.speed"
:max="1.5" :max="1.5"
@@ -244,6 +297,4 @@ const onCreateCourseGreenSubmit = async (event: FormSubmitEvent<CreateCourseSche
</USlideover> </USlideover>
</template> </template>
<style scoped> <style scoped></style>
</style>

View File

@@ -145,10 +145,24 @@ const copyTaskId = (extraMessage?: string) => {
const isCombinationModalOpen = ref(false) const isCombinationModalOpen = ref(false)
const combinationState = ref<0 | 1 | undefined>(0) const combinationState = ref<0 | 1 | undefined>(0)
const onCombination = () => { const onCombination = async () => {
isCombinationModalOpen.value = true isCombinationModalOpen.value = true
combinationState.value = undefined combinationState.value = undefined
useVideoSubtitleEmbedding(props.course.video_url, props.course.subtitle_url) const srtResponse = await (
await fetch(await fetchCourseSubtitleUrl(props.course))
).blob()
if (!srtResponse) {
toast.add({
title: '获取字幕失败',
description: '无法获取字幕文件,请稍后重试',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
const srtBlob = new Blob([srtResponse], { type: 'text/plain' })
const srtUrl = URL.createObjectURL(srtBlob)
useVideoSubtitleEmbedding(props.course.video_url, srtUrl)
.then((src) => { .then((src) => {
startDownload( startDownload(
src, src,

View File

@@ -15,13 +15,132 @@ const emit = defineEmits({
const dayjs = useDayjs() const dayjs = useDayjs()
const toast = useToast() const toast = useToast()
const isFailed = computed(() => {
return props.video.progress === -1
})
const isPreviewModalOpen = ref(false) const isPreviewModalOpen = ref(false)
const isVideoBackgroundPreviewOpen = ref(false)
const isFullContentOpen = ref(false) const isFullContentOpen = ref(false)
const downloadingState = reactive({ const downloadingState = reactive({
subtitle: 0, subtitle: 0,
video: 0, video: 0,
}) })
// 背景选择相关状态
const selectedBackgroundFile = ref<File | null>(null)
const selectedBackgroundPreview = ref<string>('')
const isCombinatorLoading = ref(false)
const compositingProgress = ref(0)
const compositingPhase = ref<'loading' | 'analyzing' | 'preparing' | 'executing' | 'finalizing'>('loading')
const combinatorError = ref<string>('')
const fileInputRef = ref<HTMLInputElement | null>(null)
const compositedVideoBlob = ref<Blob | null>(null)
// 阶段显示文本
const phaseText = computed(() => {
const phaseMap: Record<typeof compositingPhase.value, string> = {
'loading': '加载资源...',
'analyzing': '分析图片...',
'preparing': '准备合成...',
'executing': '合成中...',
'finalizing': '完成处理...',
}
return phaseMap[compositingPhase.value]
})
const handleBackgroundFileSelect = (event: Event) => {
const target = event.target as HTMLInputElement
const file = target.files?.[0]
if (!file) return
// 验证文件类型
if (!file.type.startsWith('image/')) {
toast.add({
title: '文件类型错误',
description: '请选择一个图片文件',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
selectedBackgroundFile.value = file
const reader = new FileReader()
reader.onload = (e) => {
selectedBackgroundPreview.value = e.target?.result as string
}
reader.readAsDataURL(file)
combinatorError.value = ''
compositedVideoBlob.value = null
}
const composeBackgroundVideo = async () => {
if (!selectedBackgroundFile.value) {
toast.add({
title: '未选择图片',
description: '请先选择一个背景图片',
color: 'orange',
icon: 'i-tabler-alert-circle',
})
return
}
try {
isCombinatorLoading.value = true
compositingProgress.value = 0
combinatorError.value = ''
// 使用 FFmpeg WASM 进行视频背景合成
const resultBlob = await useVideoBackgroundCompositing(
props.video.video_alpha_url!,
selectedBackgroundFile.value,
{
onProgress: (info) => {
compositingProgress.value = info.progress
compositingPhase.value = info.phase
}
}
)
compositedVideoBlob.value = resultBlob
toast.add({
title: '合成成功',
description: '背景已成功合成,可预览或下载',
color: 'green',
icon: 'i-tabler-check',
})
} catch (err: any) {
combinatorError.value = err.message || '合成失败,请重试'
toast.add({
title: '合成失败',
description: combinatorError.value,
color: 'red',
icon: 'i-tabler-alert-triangle',
})
} finally {
isCombinatorLoading.value = false
}
}
const downloadCompositedVideo = () => {
if (!compositedVideoBlob.value) return
const url = URL.createObjectURL(compositedVideoBlob.value)
const link = document.createElement('a')
link.href = url
link.download = `${props.video.title || props.video.task_id}_composited.mp4`
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
}
const compositedVideoUrl = computed(() => {
return compositedVideoBlob.value ? URL.createObjectURL(compositedVideoBlob.value) : ''
})
const startDownload = (url: string, filename: string) => { const startDownload = (url: string, filename: string) => {
if (url.endsWith('.ass')) { if (url.endsWith('.ass')) {
downloadingState.subtitle = 0 downloadingState.subtitle = 0
@@ -73,10 +192,6 @@ const startDownload = (url: string, filename: string) => {
download() download()
} }
const onClick = () => {
console.log('click delete')
}
</script> </script>
<template> <template>
@@ -84,11 +199,14 @@ const onClick = () => {
class="w-full flex gap-2 rounded-xl border border-neutral-200 dark:border-neutral-700 hover:shadow transition overflow-hidden p-3" 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 relative group"> <div class="flex-0 h-48 aspect-[10/16] flex flex-col items-center justify-center rounded-lg shadow overflow-hidden relative group">
<div v-if="!video.video_cover" class="w-full h-full bg-primary flex flex-col justify-center items-center gap-2"> <div v-if="!video.video_cover" class="w-full h-full flex flex-col justify-center items-center gap-2" :class="!isFailed ? 'bg-primary' : 'bg-rose-400'">
<UIcon class="animate-spin text-4xl text-white" name="tabler:loader"/> <UIcon v-if="!isFailed" class="animate-spin text-4xl text-white" name="tabler:loader"/>
<UIcon v-else class="text-4xl text-white" name="tabler:alert-triangle"/>
<div class="flex flex-col items-center gap-0.5"> <div class="flex flex-col items-center gap-0.5">
<span class="text-sm font-bold text-white/90">火速生成中</span> <span class="text-sm font-bold text-white/90">
<span class="text-xs font-medium text-white/50">{{ video.progress }}%</span> {{ isFailed ? '生成失败' : '火速生成中...' }}
</span>
<span v-if="!isFailed" class="text-xs font-medium text-white/50">{{ video.progress }}%</span>
</div> </div>
</div> </div>
<NuxtImg v-else :src="video.video_cover" class="w-full h-full brightness-90 object-cover"/> <NuxtImg v-else :src="video.video_cover" class="w-full h-full brightness-90 object-cover"/>
@@ -148,15 +266,36 @@ const onClick = () => {
variant="soft" variant="soft"
@click="startDownload(video.subtitle!, (video.title || video.task_id) + '.ass')" @click="startDownload(video.subtitle!, (video.title || video.task_id) + '.ass')"
/> />
<UButton <UDropdown
:label="downloadingState.video > 0 && downloadingState.video < 100 ? `${downloadingState.video.toFixed(0)}%` : '视频'" :items="[
:loading="downloadingState.video > 0 && downloadingState.video < 100" [
:disabled="!video.video_url" {
color="primary" label: '绿幕视频下载',
leading-icon="i-tabler-download" icon: 'tabler:download',
variant="soft" click: () => {
@click="startDownload(video.video_url!, (video.title || video.task_id) + '.mp4')" startDownload(video.video_url!, (video.title || video.task_id) + '.mp4')
/> }
},
{
label: '合成背景图片',
icon: 'tabler:background',
click: () => {
isVideoBackgroundPreviewOpen = true
},
disabled: !video.video_alpha_url
},
],
]"
>
<UButton
:label="downloadingState.video > 0 && downloadingState.video < 100 ? `${downloadingState.video.toFixed(0)}%` : '视频'"
:loading="downloadingState.video > 0 && downloadingState.video < 100"
:disabled="!video.video_url"
color="primary"
leading-icon="i-tabler-download"
variant="soft"
/>
</UDropdown>
</UButtonGroup> </UButtonGroup>
</div> </div>
</div> </div>
@@ -209,6 +348,132 @@ const onClick = () => {
<video class="w-full rounded shadow" controls autoplay :src="video.video_url" /> <video class="w-full rounded shadow" controls autoplay :src="video.video_url" />
</UCard> </UCard>
</UModal> </UModal>
<UModal v-model="isVideoBackgroundPreviewOpen">
<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">
{{ video.title }}
</p>
</div>
<UButton class="-my-1" color="gray" icon="i-tabler-x" variant="ghost" @click="isVideoBackgroundPreviewOpen = false" />
</div>
</template>
<div class="space-y-4">
<!-- 背景图片选择区域 -->
<div v-if="!compositedVideoBlob && !isCombinatorLoading" class="border-2 border-dashed border-neutral-200 dark:border-neutral-700 rounded-lg p-4">
<div class="space-y-3">
<div class="text-sm font-medium text-gray-900 dark:text-white">选择背景图片</div>
<!-- 预览区域 -->
<!-- <div v-if="selectedBackgroundPreview" class="relative w-full aspect-video rounded-lg overflow-hidden bg-neutral-100 dark:bg-neutral-800">
<img :src="selectedBackgroundPreview" alt="背景预览" class="w-full h-full object-cover" />
</div>
<div v-else class="w-full aspect-video rounded-lg overflow-hidden bg-neutral-100 dark:bg-neutral-800 flex flex-col items-center justify-center gap-2">
<UIcon class="text-3xl text-neutral-400" name="tabler:photo" />
<span class="text-xs text-neutral-400">点击选择图片</span>
</div> -->
<!-- 文件输入 -->
<input
ref="fileInputRef"
type="file"
accept="image/*"
class="hidden"
@change="handleBackgroundFileSelect"
/>
<!-- 选择按钮 -->
<UButton
block
color="primary"
icon="i-tabler-photo-plus"
label="选择图片"
variant="soft"
@click="fileInputRef?.click()"
/>
<!-- 选中的文件名 -->
<div v-if="selectedBackgroundFile" class="text-xs text-neutral-500 dark:text-neutral-400">
已选择: {{ selectedBackgroundFile.name }}
</div>
</div>
</div>
<!-- 错误提示 -->
<UAlert
v-if="combinatorError"
color="red"
icon="i-tabler-alert-triangle"
title="合成失败"
:description="combinatorError"
/>
<!-- 合成进度 -->
<div v-if="isCombinatorLoading" class="space-y-2">
<div class="flex justify-between items-center">
<span class="text-sm font-medium text-gray-900 dark:text-white">{{ phaseText }}</span>
<span class="text-xs text-neutral-500">{{ compositingProgress }}%</span>
</div>
<UProgress :value="compositingProgress" />
</div>
<!-- 合成预览 -->
<div v-if="compositedVideoBlob" class="space-y-2">
<div class="text-sm font-medium text-gray-900 dark:text-white">视频预览</div>
<video
class="w-full rounded-lg shadow bg-black"
controls
autoplay
muted
:src="compositedVideoUrl"
/>
</div>
</div>
<template #footer>
<div class="flex justify-end gap-2">
<UButton
color="gray"
label="取消"
:disabled="isCombinatorLoading"
@click="isVideoBackgroundPreviewOpen = false"
/>
<UButton
v-if="compositedVideoBlob"
color="gray"
label="重新选择"
@click="() => {
selectedBackgroundFile = null
selectedBackgroundPreview = ''
compositedVideoBlob = null
combinatorError = ''
isCombinatorLoading = false
}"
/>
<UButton
v-if="compositedVideoBlob"
color="green"
icon="i-tabler-download"
label="下载合成视频"
@click="downloadCompositedVideo"
/>
<UButton
v-else
:disabled="!selectedBackgroundFile || isCombinatorLoading"
:loading="isCombinatorLoading"
color="primary"
icon="i-tabler-wand"
:label="isCombinatorLoading ? '合成中' : '开始合成'"
@click="composeBackgroundVideo"
/>
</div>
</template>
</UCard>
</UModal>
</div> </div>
</template> </template>

View File

@@ -1,12 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import type { PropType } from 'vue' import type { PropType } from 'vue'
import { encode } from '@monosky/base64' import { encode } from '@monosky/base64'
import { object, string, number, type InferType } from 'yup'; import { object, string, number, type InferType } from 'yup'
interface Subtitle { interface Subtitle {
start: string; start: string
end: string; end: string
text: string; text: string
active?: boolean active?: boolean
} }
@@ -70,7 +70,7 @@ const parseSrt = (srt: string) => {
const regex = /(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/ const regex = /(\d{2}:\d{2}:\d{2},\d{3}) --> (\d{2}:\d{2}:\d{2},\d{3})/
let subtitle: Subtitle | null = null let subtitle: Subtitle | null = null
lines.forEach(line => { lines.forEach((line) => {
if (/^\d+$/.test(line.trim())) return if (/^\d+$/.test(line.trim())) return
const match = line.match(regex) const match = line.match(regex)
@@ -84,7 +84,7 @@ const parseSrt = (srt: string) => {
text: '', text: '',
} }
} else if (subtitle) { } else if (subtitle) {
subtitle.text += (line.trim() ? line : '') subtitle.text += line.trim() ? line : ''
} }
}) })
@@ -94,9 +94,13 @@ const parseSrt = (srt: string) => {
} }
const generateSrt = () => { const generateSrt = () => {
return subtitles.value.map((subtitle, index) => { return subtitles.value
return `${index + 1}\n${subtitle.start} --> ${subtitle.end}\n${subtitle.text}\n` .map((subtitle, index) => {
}).join('\n') return `${index + 1}\n${subtitle.start} --> ${subtitle.end}\n${
subtitle.text
}\n`
})
.join('\n')
} }
const formatTime = (time: string) => { const formatTime = (time: string) => {
@@ -113,7 +117,11 @@ const formatTime = (time: string) => {
const formatTimeToDayjs = (time: string) => { const formatTimeToDayjs = (time: string) => {
const parts = time.split(',') const parts = time.split(',')
const timeParts = parts[0].split(':') const timeParts = parts[0].split(':')
return dayjs().hour(parseInt(timeParts[0])).minute(parseInt(timeParts[1])).second(parseInt(timeParts[2])).millisecond(parseInt(parts[1])) return dayjs()
.hour(parseInt(timeParts[0]))
.minute(parseInt(timeParts[1]))
.second(parseInt(timeParts[2]))
.millisecond(parseInt(parts[1]))
} }
const syncSubtitles = () => { const syncSubtitles = () => {
@@ -121,17 +129,23 @@ const syncSubtitles = () => {
const currentTime = videoElement.value.currentTime * 1000 // convert to milliseconds const currentTime = videoElement.value.currentTime * 1000 // convert to milliseconds
subtitles.value.forEach(subtitle => { subtitles.value.forEach((subtitle) => {
const start = formatTime(subtitle.start) const start = formatTime(subtitle.start)
const end = formatTime(subtitle.end) const end = formatTime(subtitle.end)
const startTime = (start.hours * 3600 + start.minutes * 60 + start.seconds) * 1000 + start.milliseconds const startTime =
const endTime = (end.hours * 3600 + end.minutes * 60 + end.seconds) * 1000 + end.milliseconds (start.hours * 3600 + start.minutes * 60 + start.seconds) * 1000 +
start.milliseconds
const endTime =
(end.hours * 3600 + end.minutes * 60 + end.seconds) * 1000 +
end.milliseconds
subtitle.active = currentTime >= startTime && currentTime <= endTime subtitle.active = currentTime >= startTime && currentTime <= endTime
// scroll active subtitle into view // scroll active subtitle into view
if (subtitle.active) { if (subtitle.active) {
const element = document.getElementById(`subtitle-${subtitles.value.indexOf(subtitle)}`)! const element = document.getElementById(
`subtitle-${subtitles.value.indexOf(subtitle)}`
)!
const parent = element?.parentElement const parent = element?.parentElement
// scroll element to the center of parent // scroll element to the center of parent
parent?.scrollTo({ parent?.scrollTo({
@@ -144,9 +158,11 @@ const syncSubtitles = () => {
const onSubtitleInputClick = (subtitle: Subtitle) => { const onSubtitleInputClick = (subtitle: Subtitle) => {
if (!videoElement.value) return if (!videoElement.value) return
if (!subtitle.active) { if (!subtitle.active) {
videoElement.value.currentTime = formatTime(subtitle.start).hours * 3600 + videoElement.value.currentTime =
formatTime(subtitle.start).hours * 3600 +
formatTime(subtitle.start).minutes * 60 + formatTime(subtitle.start).minutes * 60 +
formatTime(subtitle.start).seconds + 1 formatTime(subtitle.start).seconds +
1
} }
videoElement.value.pause() videoElement.value.pause()
} }
@@ -163,42 +179,63 @@ const saveNewSubtitle = () => {
sub_type: 1, sub_type: 1,
sub_content: encodedSubtitle, sub_content: encodedSubtitle,
task_id: props.course?.task_id, task_id: props.course?.task_id,
}).then(_ => {
modified.value = false
toast.add({
color: 'green',
title: '字幕已保存',
description: '修改后的字幕文件已保存',
})
}).finally(() => {
isSaving.value = false
}) })
.then((_) => {
modified.value = false
toast.add({
color: 'green',
title: '字幕已保存',
description: '修改后的字幕文件已保存',
})
})
.finally(() => {
isSaving.value = false
})
} }
const exportVideo = () => { const exportVideo = async () => {
isExporting.value = true isExporting.value = true
useVideoSubtitleEmbedding(props.course.video_url, props.course.subtitle_url, { const srtResponse = await (
await fetch(await fetchCourseSubtitleUrl(props.course))
).blob()
if (!srtResponse) {
toast.add({
title: '获取字幕失败',
description: '无法获取字幕文件,请稍后重试',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
const srtBlob = new Blob([srtResponse], { type: 'text/plain' })
const srtUrl = URL.createObjectURL(srtBlob)
useVideoSubtitleEmbedding(props.course.video_url, srtUrl, {
color: subtitleStyleState.color, color: subtitleStyleState.color,
fontSize: subtitleStyleState.fontSize, fontSize: subtitleStyleState.fontSize,
textShadow: subtitleStyleState.effect === 'shadow' ? { textShadow:
offsetX: 2, subtitleStyleState.effect === 'shadow'
offsetY: 2, ? {
blur: 6, offsetX: 2,
color: "rgba(0, 0, 0, 0.35)", offsetY: 2,
} : { blur: 6,
offsetX: 0, color: 'rgba(0, 0, 0, 0.35)',
offsetY: 0, }
blur: 0, : {
color: 'transparent', offsetX: 0,
}, offsetY: 0,
blur: 0,
color: 'transparent',
},
strokeStyle: subtitleStyleState.effect === 'stroke' ? '#000 2px' : 'none', strokeStyle: subtitleStyleState.effect === 'stroke' ? '#000 2px' : 'none',
bottomOffset: subtitleStyleState.bottomOffset, bottomOffset: subtitleStyleState.bottomOffset,
}).then(blobUrl => {
const { download } = useDownload(blobUrl, 'combined_video.mp4')
download()
}).finally(() => {
isExporting.value = false
}) })
.then((blobUrl) => {
const { download } = useDownload(blobUrl, 'combined_video.mp4')
download()
})
.finally(() => {
isExporting.value = false
})
} }
onMounted(() => { onMounted(() => {
@@ -220,133 +257,308 @@ defineExpose({
<template> <template>
<div> <div>
<USlideover v-model="isDrawerActive" :prevent-close="modified" :ui="{ width: 'max-w-lg' }"> <USlideover
<UCard class="flex flex-col flex-1 overflow-hidden" :ui="{ v-model="isDrawerActive"
body: { base: 'overflow-auto flex-1' }, :prevent-close="modified"
ring: '', :ui="{ width: 'max-w-lg' }"
divide: 'divide-y divide-gray-100 dark:divide-gray-800' >
}"> <UCard
class="flex flex-col flex-1 overflow-hidden"
:ui="{
body: { base: 'overflow-auto flex-1' },
ring: '',
divide: 'divide-y divide-gray-100 dark:divide-gray-800',
}"
>
<template #header> <template #header>
<UButton color="gray" variant="ghost" size="sm" icon="tabler:x" <UButton
class="flex sm:hidden absolute end-5 top-5 z-10" square padded @click="isDrawerActive = false" /> color="gray"
variant="ghost"
size="sm"
icon="tabler:x"
class="flex sm:hidden absolute end-5 top-5 z-10"
square
padded
@click="isDrawerActive = false"
/>
<div class="flex flex-col"> <div class="flex flex-col">
<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>
<h3 class="text-xs font-semibold text-blue-500" v-if="course.title"> <h3
class="text-xs font-semibold text-blue-500"
v-if="course.title"
>
{{ course.title }} {{ course.title }}
</h3> </h3>
</div> </div>
</template> </template>
<div v-if="isLoading" class="flex justify-center items-center text-primary"> <div
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"> v-if="isLoading"
class="flex justify-center items-center text-primary"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="32"
height="32"
viewBox="0 0 24 24"
>
<defs> <defs>
<filter id="svgSpinnersGooeyBalls20"> <filter id="svgSpinnersGooeyBalls20">
<feGaussianBlur in="SourceGraphic" result="y" stdDeviation="1" /> <feGaussianBlur
<feColorMatrix in="y" result="z" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7" /> in="SourceGraphic"
<feBlend in="SourceGraphic" in2="z" /> result="y"
stdDeviation="1"
/>
<feColorMatrix
in="y"
result="z"
values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -7"
/>
<feBlend
in="SourceGraphic"
in2="z"
/>
</filter> </filter>
</defs> </defs>
<g filter="url(#svgSpinnersGooeyBalls20)"> <g filter="url(#svgSpinnersGooeyBalls20)">
<circle cx="5" cy="12" r="4" fill="currentColor"> <circle
<animate attributeName="cx" calcMode="spline" dur="2s" keySplines=".36,.62,.43,.99;.79,0,.58,.57" cx="5"
repeatCount="indefinite" values="5;8;5" /> cy="12"
r="4"
fill="currentColor"
>
<animate
attributeName="cx"
calcMode="spline"
dur="2s"
keySplines=".36,.62,.43,.99;.79,0,.58,.57"
repeatCount="indefinite"
values="5;8;5"
/>
</circle> </circle>
<circle cx="19" cy="12" r="4" fill="currentColor"> <circle
<animate attributeName="cx" calcMode="spline" dur="2s" keySplines=".36,.62,.43,.99;.79,0,.58,.57" cx="19"
repeatCount="indefinite" values="19;16;19" /> cy="12"
r="4"
fill="currentColor"
>
<animate
attributeName="cx"
calcMode="spline"
dur="2s"
keySplines=".36,.62,.43,.99;.79,0,.58,.57"
repeatCount="indefinite"
values="19;16;19"
/>
</circle> </circle>
<animateTransform attributeName="transform" dur="0.75s" repeatCount="indefinite" type="rotate" <animateTransform
values="0 12 12;360 12 12" /> attributeName="transform"
dur="0.75s"
repeatCount="indefinite"
type="rotate"
values="0 12 12;360 12 12"
/>
</g> </g>
</svg> </svg>
</div> </div>
<div v-else class="flex flex-col h-full gap-2 overflow-hidden overscroll-y-none overshadow"> <div
v-else
class="flex flex-col h-full gap-2 overflow-hidden overscroll-y-none overshadow"
>
<div class="relative w-full aspect-video flex-1"> <div class="relative w-full aspect-video flex-1">
<div class="absolute w-fit mx-auto inset-x-0 font-sans font-bold subtitle" :class="{ <div
'stroke': subtitleStyleState.effect === 'stroke', class="absolute w-fit mx-auto inset-x-0 font-sans font-bold subtitle"
}" :style="{ :class="{
lineHeight: '1', stroke: subtitleStyleState.effect === 'stroke',
color: subtitleStyleState.color, }"
fontSize: subtitleStyleState.fontSize / 1.5 + 'px', :style="{
bottom: subtitleStyleState.bottomOffset / 1.5 + 'px', lineHeight: '1',
textShadow: subtitleStyleState.effect === 'shadow' ? '2px 2px 4px rgba(0, 0, 0, 0.25)' : undefined color: subtitleStyleState.color,
}"> fontSize: subtitleStyleState.fontSize / 1.5 + 'px',
{{ subtitles.find(sub => sub.active)?.text }} bottom: subtitleStyleState.bottomOffset / 1.5 + 'px',
textShadow:
subtitleStyleState.effect === 'shadow'
? '2px 2px 4px rgba(0, 0, 0, 0.25)'
: undefined,
}"
>
{{ subtitles.find((sub) => sub.active)?.text }}
</div> </div>
<video controls ref="videoElement" class="rounded" style="-webkit-user-drag: none;" :src="course.video_url" <video
@timeupdate="syncSubtitles" /> controls
ref="videoElement"
class="rounded"
style="-webkit-user-drag: none"
:src="course.video_url"
@timeupdate="syncSubtitles"
/>
</div> </div>
<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
class="border dark:border-neutral-700 rounded-lg space-y-4 p-4 pb-6"
>
<div class="w-full flex flex-col justify-center"> <div class="w-full flex flex-col justify-center">
<div class="rounded-md w-full aspect-video relative overflow-hidden"> <div
<img class="object-cover w-full h-full rounded-md" class="rounded-md w-full aspect-video relative overflow-hidden"
src="https://static-xsh.oss-cn-chengdu.aliyuncs.com/file/2024-08-04/9ed1e5c0133824f0bcf79d1ad9e9ecbb.png" /> >
<span class="absolute font-sans font-bold bottom-0 left-1/2 transform -translate-x-1/2 subtitle" <img
class="object-cover w-full h-full rounded-md"
src="https://static-xsh.oss-cn-chengdu.aliyuncs.com/file/2024-08-04/9ed1e5c0133824f0bcf79d1ad9e9ecbb.png"
/>
<span
class="absolute font-sans font-bold bottom-0 left-1/2 transform -translate-x-1/2 subtitle"
:class="{ :class="{
'stroke': subtitleStyleState.effect === 'stroke', stroke: subtitleStyleState.effect === 'stroke',
}" :style="{ }"
:style="{
lineHeight: '1', lineHeight: '1',
color: subtitleStyleState.color, color: subtitleStyleState.color,
fontSize: subtitleStyleState.fontSize / 1.5 + 'px', fontSize: subtitleStyleState.fontSize / 1.5 + 'px',
bottom: subtitleStyleState.bottomOffset / 1.5 + 'px', bottom: subtitleStyleState.bottomOffset / 1.5 + 'px',
textShadow: subtitleStyleState.effect === 'shadow' ? '2px 2px 4px rgba(0, 0, 0, 0.25)' : undefined, textShadow:
}"> subtitleStyleState.effect === 'shadow'
? '2px 2px 4px rgba(0, 0, 0, 0.25)'
: undefined,
}"
>
字幕样式预览 字幕样式预览
</span> </span>
</div> </div>
<span class="text-sm italic opacity-50">字幕预览仅供参考以实际渲染效果为准</span> <span class="text-sm italic opacity-50">
字幕预览仅供参考以实际渲染效果为准
</span>
</div> </div>
<UForm :schema="subtitleStyleSchema" :state="subtitleStyleState" class="flex flex-col gap-4"> <UForm
:schema="subtitleStyleSchema"
:state="subtitleStyleState"
class="flex flex-col gap-4"
>
<div class="flex gap-4"> <div class="flex gap-4">
<UFormGroup label="字幕颜色" name="fontColor" class="w-full" size="xs"> <UFormGroup
<USelectMenu :options="[{ label="字幕颜色"
label: '黑色', name="fontColor"
value: '#000', class="w-full"
}, { size="xs"
label: '白色', >
value: '#fff', <USelectMenu
}]" option-attribute="label" value-attribute="value" v-model="subtitleStyleState.color" /> :options="[
{
label: '黑色',
value: '#000',
},
{
label: '白色',
value: '#fff',
},
]"
option-attribute="label"
value-attribute="value"
v-model="subtitleStyleState.color"
/>
</UFormGroup> </UFormGroup>
<UFormGroup label="字幕效果" name="effect" class="w-full" size="xs"> <UFormGroup
<USelectMenu :options="[{ label="字幕效果"
label: '阴影', name="effect"
value: 'shadow', class="w-full"
}, { size="xs"
label: '描边', >
value: 'stroke', <USelectMenu
}]" option-attribute="label" value-attribute="value" v-model="subtitleStyleState.effect" /> :options="[
{
label: '阴影',
value: 'shadow',
},
{
label: '描边',
value: 'stroke',
},
]"
option-attribute="label"
value-attribute="value"
v-model="subtitleStyleState.effect"
/>
</UFormGroup> </UFormGroup>
</div> </div>
<UFormGroup :label="`字幕大小 ${subtitleStyleState.fontSize}px`" name="fontSize" size="xs"> <UFormGroup
<URange :max="64" :min="20" :step="2" size="sm" v-model="subtitleStyleState.fontSize" /> :label="`字幕大小 ${subtitleStyleState.fontSize}px`"
name="fontSize"
size="xs"
>
<URange
:max="64"
:min="20"
:step="2"
size="sm"
v-model="subtitleStyleState.fontSize"
/>
</UFormGroup> </UFormGroup>
<UFormGroup :label="`字幕偏移量 ${subtitleStyleState.bottomOffset}px`" name="offset" size="xs"> <UFormGroup
<URange :max="30" :min="0" :step="1" size="sm" v-model="subtitleStyleState.bottomOffset" /> :label="`字幕偏移量 ${subtitleStyleState.bottomOffset}px`"
name="offset"
size="xs"
>
<URange
:max="30"
:min="0"
:step="1"
size="sm"
v-model="subtitleStyleState.bottomOffset"
/>
</UFormGroup> </UFormGroup>
</UForm> </UForm>
</div> </div>
</template> </template>
</UAccordion> </UAccordion>
<ul class="flex-1 px-0.5 pb-[100%] overflow-y-auto space-y-0.5 scroll-smooth relative"> <ul
<li v-for="(subtitle, index) in subtitles" :key="index" :id="'subtitle-' + index"> class="flex-1 px-0.5 pb-[100%] overflow-y-auto space-y-0.5 scroll-smooth relative"
>
<li
v-for="(subtitle, index) in subtitles"
:key="index"
:id="'subtitle-' + index"
>
<div :class="{ 'text-primary': subtitle.active }"> <div :class="{ 'text-primary': subtitle.active }">
<span class="text-xs font-medium opacity-60"> <span class="text-xs font-medium opacity-60">
{{ formatTimeToDayjs(subtitle.start).format('HH:mm:ss') }} {{ formatTimeToDayjs(subtitle.start).format('HH:mm:ss') }}
- -
{{ formatTimeToDayjs(subtitle.end).format('HH:mm:ss') }} {{ formatTimeToDayjs(subtitle.end).format('HH:mm:ss') }}
<span class="opacity-50"> <span class="opacity-50">
[{{ formatTimeToDayjs(subtitle.end).diff(formatTimeToDayjs(subtitle.start), 'second') }}s] [{{
formatTimeToDayjs(subtitle.end).diff(
formatTimeToDayjs(subtitle.start),
'second'
)
}}s]
</span> </span>
</span> </span>
<UInput v-model="subtitle.text" class="w-full" placeholder="请输入字幕内容" :name="'subtitle-' + index" <UInput
:autofocus="false" :color="subtitle.active ? 'primary' : undefined" v-model="subtitle.text"
@click="onSubtitleInputClick(subtitle)" @input="() => { if (!modified) modified = true }"> class="w-full"
placeholder="请输入字幕内容"
:name="'subtitle-' + index"
:autofocus="false"
:color="subtitle.active ? 'primary' : undefined"
@click="onSubtitleInputClick(subtitle)"
@input="
() => {
if (!modified) modified = true
}
"
>
<template #trailing> <template #trailing>
<UIcon v-show="subtitle.active" name="tabler:keyframe-align-vertical-filled" /> <UIcon
v-show="subtitle.active"
name="tabler:keyframe-align-vertical-filled"
/>
</template> </template>
</UInput> </UInput>
</div> </div>
@@ -356,12 +568,26 @@ defineExpose({
<template #footer> <template #footer>
<div class="flex justify-end items-center gap-2"> <div class="flex justify-end items-center gap-2">
<span v-if="modified" class="text-sm text-yellow-500 font-medium">已更改但未保存</span> <span
<UButton :loading="isExporting" variant="soft" icon="i-tabler-file-export" @click="exportVideo"> v-if="modified"
class="text-sm text-yellow-500 font-medium"
>
已更改但未保存
</span>
<UButton
:loading="isExporting"
variant="soft"
icon="i-tabler-file-export"
@click="exportVideo"
>
导出视频 导出视频
</UButton> </UButton>
<UButton :disabled="isExporting || !modified" :loading="isSaving" icon="i-tabler-device-floppy" <UButton
@click="saveNewSubtitle"> :disabled="isExporting || !modified"
:loading="isSaving"
icon="i-tabler-device-floppy"
@click="saveNewSubtitle"
>
保存{{ isSaving ? '中' : '' }} 保存{{ isSaving ? '中' : '' }}
</UButton> </UButton>
</div> </div>
@@ -377,16 +603,14 @@ defineExpose({
} }
.overshadow:after { .overshadow:after {
content: ""; content: '';
inset: 80% 0 0; inset: 80% 0 0;
position: absolute; position: absolute;
@apply bg-gradient-to-b from-transparent to-white dark:to-neutral-950 pointer-events-none; @apply bg-gradient-to-b from-transparent to-white dark:to-neutral-950 pointer-events-none;
} }
.subtitle.stroke { .subtitle.stroke {
text-shadow: 1px 1px 0 #000, text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000,
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000; -1px 1px 0 #000;
} }

103
composables/useFFmpeg.ts Normal file
View File

@@ -0,0 +1,103 @@
import { FFmpeg } from '@ffmpeg/ffmpeg'
import { toBlobURL } from '@ffmpeg/util'
let ffmpegInstance: FFmpeg | null = null
let loadPromise: Promise<FFmpeg> | null = null
/**
* 获取或初始化 FFmpeg 实例(单例模式)
*/
export const useFFmpeg = async () => {
// 如果已经加载过,直接返回
if (ffmpegInstance && ffmpegInstance.loaded) {
return ffmpegInstance
}
// 如果正在加载中,等待加载完成
if (loadPromise) {
return loadPromise
}
loadPromise = initializeFFmpeg()
return loadPromise
}
async function initializeFFmpeg(enableMT: boolean = false): Promise<FFmpeg> {
try {
const ffmpeg = new FFmpeg()
ffmpeg.on('log', ({ message, type }) => {
console.log(`[ffmpeg - ${type}]`, message)
})
ffmpeg.on('progress', ({ progress, time }) => {
console.log(`[ffmpeg] P: ${(progress * 100).toFixed(2)}%, T: ${time}ms`)
})
const baseURL = enableMT
? 'https://cdn.jsdelivr.net/npm/@ffmpeg/core-mt@0.12.10/dist/esm'
: 'https://cdn.jsdelivr.net/npm/@ffmpeg/core@0.12.10/dist/esm'
const coreURL = await toBlobURL(
`${baseURL}/ffmpeg-core.js`,
'text/javascript'
)
const wasmURL = await toBlobURL(
`${baseURL}/ffmpeg-core.wasm`,
'application/wasm'
)
let loadPayload = {
coreURL,
wasmURL,
}
if (enableMT) {
const workerURL = await toBlobURL(
`${baseURL}/ffmpeg-core.worker.js`,
'text/javascript'
)
Object.assign(loadPayload, { workerURL })
}
const isLoaded = await ffmpeg.load(loadPayload)
console.log('[FFmpeg] FFmpeg 加载完成isLoaded:', isLoaded)
ffmpegInstance = ffmpeg
loadPromise = null
return ffmpeg
} catch (error) {
console.error('[FFmpeg] 初始化失败:', error)
loadPromise = null
throw error
}
}
/**
* 清理 FFmpeg 资源
*/
export const cleanupFFmpeg = () => {
if (ffmpegInstance && ffmpegInstance.loaded) {
console.log('[FFmpeg] 清理 FFmpeg 资源...')
ffmpegInstance.terminate()
ffmpegInstance = null
loadPromise = null
}
}
/**
* 将 Blob/File 转换为 Uint8Array
*/
export const fileToUint8Array = async (
file: File | Blob
): Promise<Uint8Array> => {
return new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onload = (e) => {
const arrayBuffer = e.target?.result as ArrayBuffer
resolve(new Uint8Array(arrayBuffer))
}
reader.onerror = reject
reader.readAsArrayBuffer(file)
})
}

View File

@@ -0,0 +1,6 @@
/**
* 已废弃:使用 useVideoBackgroundCompositing 替代
* 该文件保留用于向后兼容
*/
export { useVideoBackgroundCompositing as useVideoBackgroundCombinator } from './useVideoBackgroundCompositing'

View File

@@ -0,0 +1,166 @@
import { fetchFile } from '@ffmpeg/util'
import { useFFmpeg, fileToUint8Array } from './useFFmpeg'
/**
* 获取图片的宽高信息
*/
const getImageDimensions = async (
imageData: Uint8Array
): Promise<{ width: number; height: number }> => {
return new Promise((resolve, reject) => {
const blob = new Blob([imageData], { type: 'image/png' })
const url = URL.createObjectURL(blob)
const img = new Image()
img.onload = () => {
URL.revokeObjectURL(url)
resolve({ width: img.width, height: img.height })
}
img.onerror = () => {
URL.revokeObjectURL(url)
reject(new Error('Failed to load image'))
}
img.src = url
})
}
/**
* 计算等比缩放到720P的尺寸
* 720P 指高度为720宽度按原宽高比计算
*/
const calculateScaledDimensions = (
width: number,
height: number
): { width: number; height: number } => {
const targetHeight = 720
// 如果原始高度小于等于720保持原始尺寸
if (height <= targetHeight) {
return { width, height }
}
// 计算缩放比例
const scale = targetHeight / height
const scaledWidth = Math.round(width * scale)
// 确保宽度为偶数(视频编码要求)
const finalWidth = scaledWidth % 2 === 0 ? scaledWidth : scaledWidth - 1
return { width: finalWidth, height: targetHeight }
}
export type CompositingPhase =
| 'loading'
| 'analyzing'
| 'preparing'
| 'executing'
| 'finalizing'
export type CompositingProgressCallback = (info: {
progress: number
phase: CompositingPhase
}) => void
/**
* 使用 FFmpeg WASM 将透明通道的视频与背景图片进行合成
* @param videoUrl - WebM 视频 URL带透明通道的数字人视频
* @param backgroundImage - 背景图片File 对象或 URL 字符串)
* @param options - 额外选项
* @returns 合成后的视频 Blob
*/
export const useVideoBackgroundCompositing = async (
videoUrl: string,
backgroundImage: File | string,
options?: {
onProgress?: CompositingProgressCallback
}
) => {
const ffmpeg = await useFFmpeg()
const progressCallback = options?.onProgress
const videoFileName = 'input_video.webm'
const backgroundFileName = 'background.png'
const outputFileName = 'output.mp4'
try {
progressCallback?.({ progress: 10, phase: 'loading' })
const videoData = await fetchFile(videoUrl)
const backgroundData = await fetchFile(backgroundImage)
progressCallback?.({ progress: 15, phase: 'analyzing' })
const { width: bgWidth, height: bgHeight } = await getImageDimensions(
backgroundData
)
console.log(
`[Compositing] Background image dimensions: ${bgWidth}x${bgHeight}`
)
const { width: outputWidth, height: outputHeight } =
calculateScaledDimensions(bgWidth, bgHeight)
console.log(
`[Compositing] Output dimensions: ${outputWidth}x${outputHeight}`
)
progressCallback?.({ progress: 20, phase: 'preparing' })
await ffmpeg.writeFile(videoFileName, videoData)
await ffmpeg.writeFile(backgroundFileName, backgroundData)
progressCallback?.({ progress: 25, phase: 'preparing' })
// HACK: 不明原因导致首次执行合成时会报 memory access out of bounds 错误,先执行一次空命令能够规避
await ffmpeg.exec(['-i', 'not-found'])
// 设置 progress 事件监听,映射 FFmpeg 进度到 30-95% 范围
const executingProgressHandler = ({ progress }: { progress: number }) => {
// progress 范围是 0-1映射到 30-95
const mappedProgress = Math.round(30 + progress * 65)
progressCallback?.({ progress: mappedProgress, phase: 'executing' })
}
ffmpeg.on('progress', executingProgressHandler)
progressCallback?.({ progress: 30, phase: 'executing' })
// prettier-ignore
const exitCode = await ffmpeg.exec([
'-i', backgroundFileName,
'-c:v', 'libvpx-vp9',
'-i', videoFileName,
'-filter_complex', 'overlay=(W-w)/2:H-h',
'-c:v', 'libx264',
outputFileName
])
ffmpeg.off('progress', executingProgressHandler)
if (exitCode !== 0) {
throw new Error(`FFmpeg command failed with exit code ${exitCode}`)
}
progressCallback?.({ progress: 95, phase: 'finalizing' })
const outputData = await ffmpeg.readFile(outputFileName)
let outputArray: Uint8Array
if (outputData instanceof Uint8Array) {
outputArray = outputData
} else if (typeof outputData === 'string') {
outputArray = new TextEncoder().encode(outputData)
} else {
outputArray = new Uint8Array(outputData as ArrayBufferLike)
}
const outputBlob = new Blob([outputArray], { type: 'video/mp4' })
progressCallback?.({ progress: 100, phase: 'finalizing' })
return outputBlob
} catch (error) {
console.error('Video compositing failed:', error)
throw error
} finally {
await ffmpeg.deleteFile(videoFileName)
await ffmpeg.deleteFile(backgroundFileName)
await ffmpeg.deleteFile(outputFileName)
}
}

View File

@@ -58,4 +58,23 @@ export default defineNuxtConfig({
}, },
compatibilityDate: '2024-07-28', compatibilityDate: '2024-07-28',
vite: {
worker: {
format: 'es',
},
optimizeDeps: {
exclude: [
'@ffmpeg/ffmpeg',
'idb-keyval',
'@uniiem/uuid',
'@uniiem/object-trim',
'gsap',
'@monosky/base64',
'markdown-it',
'highlight.js',
'driver.js',
],
},
},
}) })

View File

@@ -10,8 +10,10 @@
"preview": "nuxt preview", "preview": "nuxt preview",
"postinstall": "nuxt prepare" "postinstall": "nuxt prepare"
}, },
"packageManager": "pnpm@9.1.3", "packageManager": "pnpm@10.22.0",
"dependencies": { "dependencies": {
"@ffmpeg/ffmpeg": "^0.12.15",
"@ffmpeg/util": "^0.12.2",
"@iconify-json/line-md": "^1.1.38", "@iconify-json/line-md": "^1.1.38",
"@iconify-json/solar": "^1.1.9", "@iconify-json/solar": "^1.1.9",
"@iconify-json/svg-spinners": "^1.1.2", "@iconify-json/svg-spinners": "^1.1.2",
@@ -20,7 +22,7 @@
"@nuxt/image": "^1.7.0", "@nuxt/image": "^1.7.0",
"@uniiem/object-trim": "^0.2.0", "@uniiem/object-trim": "^0.2.0",
"@uniiem/uuid": "^0.2.1", "@uniiem/uuid": "^0.2.1",
"@webav/av-cliper": "^1.0.10", "@webav/av-cliper": "^1.2.7",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"events": "^3.3.0", "events": "^3.3.0",
"gsap": "^3.12.5", "gsap": "^3.12.5",

View File

@@ -39,9 +39,9 @@ const navList = ref<
to: '/generation/ppt-templates', to: '/generation/ppt-templates',
}, },
{ {
label: '用户管理', label: '管理中心',
icon: 'tabler:users', icon: 'tabler:home-cog',
to: '/generation/admin/users', to: '/generation/admin',
admin: true, admin: true,
}, },
]) ])

View File

@@ -0,0 +1,574 @@
<script lang="ts" setup>
import { object, string, number } from 'yup'
import type { FormSubmitEvent } from '#ui/types'
useHead({
title: '数字人定制管理 | 管理员',
})
const toast = useToast()
const loginState = useLoginState()
// 定制记录列表
const pagination = reactive({
page: 1,
pageSize: 20,
})
const {
data: trainListResp,
status: trainListStatus,
refresh: refreshTrainList,
} = useAsyncData(
'digital-train-list',
() =>
useFetchWrapped<
PagedDataRequest & AuthedRequest,
BaseResponse<PagedData<DigitalHumanTrainItem>>
>('App.Digital_Train.GetList', {
token: loginState.token!,
user_id: loginState.user.id,
to_user_id: loginState.user.id,
page: pagination.page,
perpage: pagination.pageSize,
}),
{
watch: [pagination],
}
)
const trainList = computed(() => trainListResp.value?.data.items || [])
// 表格列定义
const columns = [
{
key: 'id',
label: 'ID',
},
{
key: 'dh_name',
label: '数字人名称',
},
{
key: 'organization',
label: '单位名称',
},
{
key: 'user_id',
label: '用户ID',
},
{
key: 'create_time',
label: '创建时间',
},
{
key: 'video_url',
label: '数字人视频',
},
{
key: 'auth_video_url',
label: '授权视频',
},
{
key: 'actions',
label: '操作',
},
]
// 录入数字人相关状态
const isProcessModalOpen = ref(false)
const currentTrainItem = ref<DigitalHumanTrainItem | null>(null)
const processFormState = reactive({
name: '',
model_id: undefined as number | undefined,
description: '',
type: 2, // 默认为XSH自有
})
const processFormSchema = object({
name: string().required('请输入名称'),
model_id: number().required('请输入数字人ID'),
description: string().required('请输入描述'),
type: number().required('请选择类型'),
})
const sourceTypeList = [
{ label: 'xsh_wm', value: 1, color: 'blue' }, // 万木(腾讯)
{ label: 'xsh_zy', value: 2, color: 'green' }, // XSH 自有
{ label: 'xsh_fh', value: 3, color: 'purple' }, // 硅基(泛化数字人)
{ label: 'xsh_bb', value: 4, color: 'indigo' }, // 百度小冰
]
const avatarFile = ref<File | null>(null)
const isProcessing = ref(false)
// 处理训练素材:录入系统数字人并分配给用户
const handleProcessTrain = (item: DigitalHumanTrainItem) => {
currentTrainItem.value = item
// 预填充表单数据
processFormState.name = item.dh_name
processFormState.model_id = undefined
processFormState.description = `基于${item.organization}提交的训练素材创建`
processFormState.type = 2
isProcessModalOpen.value = true
}
// 处理文件上传
const handleAvatarUpload = (files: FileList) => {
const file = files[0]
if (!file) return
// 验证文件类型
if (!file.type.startsWith('image/')) {
toast.add({
title: '文件格式错误',
description: '请上传图片文件',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
// 验证文件大小 (10MB)
if (file.size > 10 * 1024 * 1024) {
toast.add({
title: '文件过大',
description: '图片文件大小不能超过10MB',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
avatarFile.value = file
}
// 提交录入表单
const onProcessSubmit = async (event: FormSubmitEvent<typeof processFormState>) => {
if (!currentTrainItem.value) return
if (!avatarFile.value) {
toast.add({
title: '请上传数字人预览图',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
return
}
if (isProcessing.value) return
try {
isProcessing.value = true
// 1. 上传预览图
const avatarUrl = await useFileGo(avatarFile.value, 'material')
// 2. 创建系统数字人
const createSystemResult = await useFetchWrapped<
{
name: string
model_id: number
type: number
description: string
avatar: string
} & AuthedRequest,
BaseResponse<{ digital_human_id: number }>
>('App.Digital_Human.Create', {
token: loginState.token!,
user_id: loginState.user.id,
name: event.data.name,
model_id: event.data.model_id!,
type: event.data.type,
description: event.data.description,
avatar: avatarUrl,
})
if (createSystemResult.ret !== 200 || !createSystemResult.data.digital_human_id) {
throw new Error(createSystemResult.msg || '创建系统数字人失败')
}
// 3. 分配数字人给提交素材的用户
const createUserResult = await useFetchWrapped<
{
to_user_id: number
digital_human_array: number[]
} & AuthedRequest,
BaseResponse<{
total: number
success: number
failed: number
}>
>('App.User_UserDigital.CreateConnArr', {
token: loginState.token!,
user_id: loginState.user.id,
to_user_id: currentTrainItem.value.user_id,
digital_human_array: [createSystemResult.data.digital_human_id],
})
if (createUserResult.ret !== 200 || createUserResult.data.success === 0) {
throw new Error(createUserResult.msg || '分配用户数字人失败')
}
toast.add({
title: '录入成功',
description: `数字人"${event.data.name}"已成功录入并分配给用户 ${currentTrainItem.value.user_id}${
createUserResult.data.failed ? `,失败 ${createUserResult.data.failed}` : ''
}`,
color: 'green',
icon: 'i-tabler-check',
})
// 删除定制记录
await handleDeleteTrain(currentTrainItem.value)
// 重置表单和状态
processFormState.name = ''
processFormState.model_id = undefined
processFormState.description = ''
processFormState.type = 2
avatarFile.value = null
currentTrainItem.value = null
isProcessModalOpen.value = false
// 刷新列表
await refreshTrainList()
} catch (error) {
console.error('录入数字人失败:', error)
const errorMessage = error instanceof Error ? error.message : '录入失败,请重试'
toast.add({
title: '录入失败',
description: errorMessage,
color: 'red',
icon: 'i-tabler-alert-triangle',
})
} finally {
isProcessing.value = false
}
}
// 删除定制记录
const handleDeleteTrain = async (item: DigitalHumanTrainItem) => {
try {
const result = await useFetchWrapped<
{ train_id: number } & AuthedRequest,
BaseResponse<{ code: 0 | 1 }>
>('App.Digital_Train.Delete', {
token: loginState.token!,
user_id: loginState.user.id,
train_id: item.id,
})
if (result.ret === 200 && result.data.code === 1) {
toast.add({
title: '删除成功',
description: '定制记录已删除',
color: 'green',
icon: 'i-tabler-check',
})
await refreshTrainList()
} else {
throw new Error(result.msg || '删除失败')
}
} catch (error) {
console.error('删除定制记录失败:', error)
const errorMessage = error instanceof Error ? error.message : '删除失败,请重试'
toast.add({
title: '删除失败',
description: errorMessage,
color: 'red',
icon: 'i-tabler-alert-triangle',
})
}
}
// 格式化时间
const formatTime = (timestamp: number) => {
return new Date(timestamp * 1000).toLocaleString('zh-CN')
}
// 预览视频
const previewVideo = (videoUrl: string, title: string) => {
// 创建一个简单的视频预览弹窗
const videoModal = document.createElement('div')
videoModal.className = 'fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50'
const videoContainer = document.createElement('div')
videoContainer.className = 'bg-white dark:bg-gray-800 rounded-lg p-4 max-w-4xl max-h-[80vh] overflow-auto'
const titleElement = document.createElement('h3')
titleElement.textContent = title
titleElement.className = 'text-lg font-semibold mb-4 text-gray-900 dark:text-white'
const video = document.createElement('video')
video.src = videoUrl
video.controls = true
video.className = 'w-full max-h-[60vh]'
const closeButton = document.createElement('button')
closeButton.textContent = '关闭'
closeButton.className = 'mt-4 px-4 py-2 bg-gray-500 text-white rounded hover:bg-gray-600'
closeButton.onclick = () => {
document.body.removeChild(videoModal)
}
videoContainer.appendChild(titleElement)
videoContainer.appendChild(video)
videoContainer.appendChild(closeButton)
videoModal.appendChild(videoContainer)
videoModal.onclick = (e) => {
if (e.target === videoModal) {
document.body.removeChild(videoModal)
}
}
document.body.appendChild(videoModal)
}
</script>
<template>
<div>
<div class="p-4 pb-0">
<BubbleTitle
title="数字人定制管理"
subtitle="Digital Human Training Management"
>
<template #action>
<UButton
color="gray"
variant="soft"
icon="i-tabler-refresh"
label="刷新"
@click="refreshTrainList"
/>
</template>
</BubbleTitle>
<GradientDivider />
</div>
<div class="p-4">
<UAlert
v-if="loginState.user.auth_code === 2"
icon="i-tabler-user-shield"
title="管理员功能"
description="当前正在管理用户提交的数字人定制请求,仅管理员可见"
class="mb-4"
/>
<div class="flex flex-col gap-4">
<UTable
:rows="trainList"
:columns="columns"
:loading="trainListStatus === 'pending'"
:progress="{ color: 'amber', animation: 'carousel' }"
class="border dark:border-neutral-800 rounded-md"
>
<template #create_time-data="{ row }">
<span class="text-sm">{{ formatTime(row.create_time) }}</span>
</template>
<template #video_url-data="{ row }">
<div class="flex gap-2">
<UButton
color="blue"
variant="soft"
size="xs"
icon="i-tabler-download"
:to="row.video_url"
target="_blank"
label="下载"
/>
<UButton
color="green"
variant="soft"
size="xs"
icon="i-tabler-eye"
label="预览"
@click="previewVideo(row.video_url, '数字人视频')"
/>
</div>
</template>
<template #auth_video_url-data="{ row }">
<div class="flex gap-2">
<UButton
color="blue"
variant="soft"
size="xs"
icon="i-tabler-download"
:to="row.auth_video_url"
target="_blank"
label="下载"
/>
<UButton
color="green"
variant="soft"
size="xs"
icon="i-tabler-eye"
label="预览"
@click="previewVideo(row.auth_video_url, '授权视频')"
/>
</div>
</template>
<template #actions-data="{ row }">
<div class="flex gap-2">
<UButton
color="amber"
variant="soft"
size="xs"
icon="i-tabler-user-cog"
label="录入"
@click="handleProcessTrain(row)"
/>
<UButton
color="red"
variant="soft"
size="xs"
icon="i-tabler-trash"
label="删除"
@click="handleDeleteTrain(row)"
/>
</div>
</template>
</UTable>
<div class="flex justify-end">
<UPagination
v-model="pagination.page"
:max="9"
:page-count="pagination.pageSize"
:total="trainListResp?.data.total || 0"
/>
</div>
</div>
</div>
<!-- 录入数字人弹窗 -->
<USlideover v-model="isProcessModalOpen">
<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>
<UButton
class="flex absolute end-5 top-5 z-10"
color="gray"
icon="i-tabler-x"
padded
size="sm"
square
variant="ghost"
@click="isProcessModalOpen = false"
/>
<div>
<h3 class="text-lg font-semibold">录入数字人</h3>
<p class="text-sm text-gray-500 mt-1">
"{{ currentTrainItem?.dh_name }}"创建系统数字人并分配给用户 {{ currentTrainItem?.user_id }}
</p>
</div>
</template>
<UForm
class="space-y-4"
:schema="processFormSchema"
:state="processFormState"
@submit="onProcessSubmit"
>
<UFormGroup
label="名称"
name="name"
>
<UInput v-model="processFormState.name" />
</UFormGroup>
<UFormGroup
label="数字人ID"
name="model_id"
description="请输入五位数字人ID"
>
<UInput
v-model="processFormState.model_id"
type="number"
placeholder="请输入数字人ID"
/>
</UFormGroup>
<UFormGroup
label="描述"
name="description"
>
<UTextarea
v-model="processFormState.description"
rows="3"
/>
</UFormGroup>
<UFormGroup
label="供应商类型"
name="type"
>
<USelectMenu
v-model="processFormState.type"
value-attribute="value"
:options="sourceTypeList"
/>
</UFormGroup>
<UFormGroup
label="数字人预览图"
required
>
<UniFileDnD
accept="image/png,image/jpeg,image/jpg"
@change="handleAvatarUpload"
>
<template #default>
<div class="text-center">
<UIcon
name="i-heroicons-photo"
class="mx-auto h-12 w-12 text-gray-400"
/>
<div class="mt-2">
<span class="text-sm text-gray-600 dark:text-gray-400">
{{ avatarFile ? avatarFile.name : '点击或拖拽上传图片' }}
</span>
</div>
</div>
</template>
</UniFileDnD>
</UFormGroup>
<div class="flex justify-end gap-2 pt-4">
<UButton
type="button"
color="gray"
variant="soft"
@click="isProcessModalOpen = false"
>
取消
</UButton>
<UButton
type="submit"
color="primary"
:loading="isProcessing"
:disabled="isProcessing"
>
{{ isProcessing ? '录入中...' : '录入并分配' }}
</UButton>
</div>
</UForm>
</UCard>
</USlideover>
</div>
</template>
<style scoped></style>

View File

@@ -0,0 +1,110 @@
<script lang="ts" setup>
const router = useRouter()
const loginState = useLoginState()
// 检查用户权限
if (loginState.user.auth_code !== 2) {
throw createError({
statusCode: 403,
statusMessage: '无权访问管理页面',
})
}
useHead({
title: '管理中心',
})
const adminPages = [
{
title: '用户管理',
description: '管理系统用户、权限和服务配额',
icon: 'i-tabler-users',
path: '/generation/admin/users',
color: 'blue',
},
{
title: '数字人定制管理',
description: '管理用户提交的数字人定制请求',
icon: 'i-tabler-user-cog',
path: '/generation/admin/digital-human-train',
color: 'amber',
},
{
title: '片头片尾管理',
description: '管理用户提交的片头片尾制作请求',
icon: 'i-tabler-movie',
path: '/generation/admin/materials',
color: 'green',
},
]
const navigateToPage = (path: string) => {
router.push(path)
}
</script>
<template>
<div>
<div class="p-4 pb-0">
<BubbleTitle
title="管理中心"
subtitle="Administrator Panel"
/>
<GradientDivider />
</div>
<div class="p-4">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<div
v-for="page in adminPages"
:key="page.path"
class="group cursor-pointer"
@click="navigateToPage(page.path)"
>
<UCard
class="hover:shadow-lg transition-all duration-200 group-hover:scale-105"
:ui="{
ring: 'ring-1 ring-gray-200 dark:ring-gray-700 group-hover:ring-gray-300 dark:group-hover:ring-gray-600',
}"
>
<div class="flex flex-col items-center text-center p-6">
<div
class="w-16 h-16 rounded-full flex items-center justify-center mb-4 transition-colors"
:class="{
'bg-blue-100 dark:bg-blue-900/30': page.color === 'blue',
'bg-amber-100 dark:bg-amber-900/30': page.color === 'amber',
'bg-green-100 dark:bg-green-900/30': page.color === 'green',
}"
>
<UIcon
:name="page.icon"
class="w-8 h-8"
:class="{
'text-blue-600 dark:text-blue-400': page.color === 'blue',
'text-amber-600 dark:text-amber-400': page.color === 'amber',
'text-green-600 dark:text-green-400': page.color === 'green',
}"
/>
</div>
<h3 class="text-lg font-semibold text-gray-900 dark:text-white mb-2">
{{ page.title }}
</h3>
<p class="text-sm text-gray-600 dark:text-gray-400 leading-relaxed">
{{ page.description }}
</p>
<div class="mt-4 flex items-center text-sm text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-300 transition-colors">
<span>进入管理</span>
<UIcon name="i-heroicons-arrow-right" class="ml-1 w-4 h-4" />
</div>
</div>
</UCard>
</div>
</div>
</div>
</div>
</template>
<style scoped></style>

File diff suppressed because it is too large Load Diff

View File

@@ -226,7 +226,7 @@ const onDigitalHumansSelected = (digitalHumans: DigitalHumanItem[]) => {
user_id: loginState.user.id!, user_id: loginState.user.id!,
to_user_id: viewingUser.value?.id || 0, to_user_id: viewingUser.value?.id || 0,
digital_human_array: digitalHumans.map( digital_human_array: digitalHumans.map(
(row) => row.id || row.digital_human_id (row) => row.id || row.digital_human_id || 0
), ),
}).then((res) => { }).then((res) => {
if (res.ret === 200) { if (res.ret === 200) {

View File

@@ -61,6 +61,25 @@ const {
} }
) )
const {
data: avatarTrainList,
status: avatarTrainStatus,
refresh: refreshAvatarTrainList,
} = useAsyncData(
() =>
useFetchWrapped<
PagedDataRequest & AuthedRequest,
BaseResponse<PagedData<DigitalHumanTrainItem>>
>('App.Digital_Train.GetList', {
token: loginState.token!,
user_id: loginState.user.id,
to_user_id: loginState.user.id,
page: 1,
perpage: 20,
}),
{}
)
const onSystemAvatarDelete = (row: DigitalHumanItem) => { const onSystemAvatarDelete = (row: DigitalHumanItem) => {
useFetchWrapped< useFetchWrapped<
{ digital_human_id: number } & AuthedRequest, { digital_human_id: number } & AuthedRequest,
@@ -125,13 +144,14 @@ const columns = [
] ]
const sourceTypeList = [ const sourceTypeList = [
{ label: 'TX', value: 1, color: 'blue' }, { label: 'xsh_wm', value: 1, color: 'blue' }, // 万木(腾讯)
{ label: 'XSH', value: 2, color: 'green' }, { label: 'xsh_zy', value: 2, color: 'green' }, // XSH 自有
{ label: 'GJ', value: 3, color: 'purple' }, { label: 'xsh_fh', value: 3, color: 'purple' }, // 硅基(泛化数字人)
{ label: 'XB', value: 4, color: 'indigo' }, { label: 'xsh_bb', value: 4, color: 'indigo' }, // 百度小冰
] ]
const isCreateSlideOpen = ref(false) const isCreateSlideOpen = ref(false)
const isTrainCreatorOpen = ref(false)
const createAvatarState = reactive({ const createAvatarState = reactive({
name: '', name: '',
@@ -230,13 +250,6 @@ const onAvatarUpload = async (files: FileList) => {
:label="showSystemAvatar ? '显示用户数字人' : '显示系统数字人'" :label="showSystemAvatar ? '显示用户数字人' : '显示系统数字人'"
@click="showSystemAvatar = !showSystemAvatar" @click="showSystemAvatar = !showSystemAvatar"
/> />
<UButton
v-if="loginState.user.auth_code === 2"
color="amber"
variant="soft"
label="创建数字人"
@click="isCreateSlideOpen = true"
/>
<UButton <UButton
:icon=" :icon="
data_layout === 'grid' data_layout === 'grid'
@@ -248,6 +261,29 @@ const onAvatarUpload = async (files: FileList) => {
@click="data_layout = data_layout === 'grid' ? 'list' : 'grid'" @click="data_layout = data_layout === 'grid' ? 'list' : 'grid'"
:label="data_layout === 'grid' ? '列表视图' : '宫格视图'" :label="data_layout === 'grid' ? '列表视图' : '宫格视图'"
/> />
<UButton
v-if="loginState.user.auth_code === 2"
color="amber"
variant="soft"
icon="tabler:user-cog"
label="定制管理"
:to="'/generation/admin/digital-human-train'"
/>
<UButton
color="blue"
variant="soft"
icon="tabler:user-plus"
label="定制数字人"
@click="isTrainCreatorOpen = true"
/>
<UButton
v-if="loginState.user.auth_code === 2"
color="amber"
variant="soft"
icon="tabler:plus"
label="创建数字人"
@click="isCreateSlideOpen = true"
/>
</template> </template>
</BubbleTitle> </BubbleTitle>
<GradientDivider /> <GradientDivider />
@@ -473,6 +509,9 @@ const onAvatarUpload = async (files: FileList) => {
</UForm> </UForm>
</UCard> </UCard>
</USlideover> </USlideover>
<!-- 数字人定制对话框 -->
<DigitalHumanTrainCreator v-model="isTrainCreatorOpen" />
</div> </div>
</template> </template>

View File

@@ -18,8 +18,11 @@ const userPagination = reactive({
pageSize: 15, pageSize: 15,
}) })
const { data: systemTitlesTemplate, status: systemTitlesTemplateStatus } = const {
useAsyncData( data: systemTitlesTemplate,
status: systemTitlesTemplateStatus,
refresh: refreshSystemTitlesTemplate,
} = useAsyncData(
'systemTitlesTemplate', 'systemTitlesTemplate',
() => () =>
useFetchWrapped< useFetchWrapped<
@@ -93,6 +96,46 @@ const onUserTitlesRequest = (titles: TitlesTemplate) => {
isUserTitlesRequestModalActive.value = true isUserTitlesRequestModalActive.value = true
} }
const onSystemTitlesDelete = (titles: TitlesTemplate) => {
useFetchWrapped<
{ title_id: number } & AuthedRequest,
BaseResponse<{ code: 0 | 1 }>
>('App.Digital_Titles.Delete', {
token: loginState.token!,
user_id: loginState.user.id,
title_id: titles.id,
})
.then((res) => {
if (res.ret === 200 && res.data.code === 1) {
toast.add({
title: '删除成功',
description: '已删除系统片头模板',
color: 'green',
icon: 'i-tabler-check',
})
} else {
toast.add({
title: '删除失败',
description: res.msg || '未知错误',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
}
})
.catch((error) => {
toast.add({
title: '删除失败',
description: error instanceof Error ? error.message : '未知错误',
color: 'red',
icon: 'i-tabler-alert-triangle',
})
})
.finally(() => {
systemPagination.page = 1
refreshSystemTitlesTemplate()
})
}
const onUserTitlesDelete = (titles: TitlesTemplate) => { const onUserTitlesDelete = (titles: TitlesTemplate) => {
useFetchWrapped< useFetchWrapped<
Pick<req.gen.TitlesTemplateRequest, 'to_user_id'> & { Pick<req.gen.TitlesTemplateRequest, 'to_user_id'> & {
@@ -217,6 +260,7 @@ const onUserTitlesSubmit = (event: FormSubmitEvent<UserTitlesSchema>) => {
type="system" type="system"
:key="titles.id" :key="titles.id"
@user-titles-request="onUserTitlesRequest" @user-titles-request="onUserTitlesRequest"
@system-titles-delete="onSystemTitlesDelete"
/> />
</div> </div>
</div> </div>

View File

@@ -15,7 +15,7 @@ const { data: pptCategories, refresh: refreshPPTCategories } = useAsyncData(
useFetchWrapped< useFetchWrapped<
PagedDataRequest & AuthedRequest, PagedDataRequest & AuthedRequest,
BaseResponse<PagedData<PPTCategory>> BaseResponse<PagedData<PPTCategory>>
>('App.Digital_PowerPointCat.GetList', { >('App.PowerPoint_Category.GetList', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
page: 1, page: 1,
@@ -35,7 +35,7 @@ const { data: pptTemplates, refresh: refreshPptTemplates } = useAsyncData(
useFetchWrapped< useFetchWrapped<
PagedDataRequest & { type: string | number } & AuthedRequest, PagedDataRequest & { type: string | number } & AuthedRequest,
BaseResponse<PagedData<PPTTemplate>> BaseResponse<PagedData<PPTTemplate>>
>('App.Digital_PowerPoint.GetList', { >('App.PowerPoint_SysPowerPoint.GetList', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
page: pagination.page, page: pagination.page,
@@ -87,7 +87,7 @@ const onCreateSubmit = (event: FormSubmitEvent<PPTCreateSchema>) => {
file_url: string file_url: string
} & AuthedRequest, } & AuthedRequest,
BaseResponse<{ powerpoint_id: number }> BaseResponse<{ powerpoint_id: number }>
>('App.Digital_PowerPoint.Create', { >('App.PowerPoint_SysPowerPoint.Create', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
title: event.data.title, title: event.data.title,
@@ -127,7 +127,7 @@ const onCreateSubmit = (event: FormSubmitEvent<PPTCreateSchema>) => {
} }
const onFileSelect = async (files: FileList, type: 'preview' | 'ppt') => { const onFileSelect = async (files: FileList, type: 'preview' | 'ppt') => {
const url = await useFileGo(files[0]) const url = await useFileGo(files[0], 'material')
if (type === 'preview') { if (type === 'preview') {
pptCreateState.preview_url = url pptCreateState.preview_url = url
} else { } else {
@@ -145,7 +145,7 @@ const onDeletePPT = (ppt: PPTTemplate) => {
useFetchWrapped< useFetchWrapped<
{ powerpoint_id: number } & AuthedRequest, { powerpoint_id: number } & AuthedRequest,
BaseResponse<{ code: number }> BaseResponse<{ code: number }>
>('App.Digital_PowerPoint.Delete', { >('App.PowerPoint_SysPowerPoint.Delete', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
powerpoint_id: ppt.id, powerpoint_id: ppt.id,
@@ -185,7 +185,7 @@ const onCreateCat = () => {
useFetchWrapped< useFetchWrapped<
{ type: string } & AuthedRequest, { type: string } & AuthedRequest,
BaseResponse<{ ppt_cat_id: number }> BaseResponse<{ ppt_cat_id: number }>
>('App.Digital_PowerPointCat.Create', { >('App.PowerPoint_SysPowerPoint.Create', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
type: createCatInput.value, type: createCatInput.value,
@@ -217,7 +217,7 @@ const onDeleteCat = (cat: PPTCategory) => {
useFetchWrapped< useFetchWrapped<
{ ppt_cat_id: number } & AuthedRequest, { ppt_cat_id: number } & AuthedRequest,
BaseResponse<{ code: number }> BaseResponse<{ code: number }>
>('App.Digital_PowerPointCat.Delete', { >('App.PowerPoint_SysPowerPoint.Delete', {
token: loginState.token!, token: loginState.token!,
user_id: loginState.user.id, user_id: loginState.user.id,
ppt_cat_id: cat.id, ppt_cat_id: cat.id,
@@ -359,7 +359,7 @@ const onDeleteCat = (cat: PPTCategory) => {
<div class="w-full flex justify-end"> <div class="w-full flex justify-end">
<UPagination <UPagination
v-if="pptTemplates?.data.total > pagination.perpage" v-if="(pptTemplates?.data.total || 0) > pagination.perpage"
:total="pptTemplates?.data.total" :total="pptTemplates?.data.total"
:page-count="pagination.perpage" :page-count="pagination.perpage"
:max="9" :max="9"

View File

@@ -341,12 +341,12 @@ onMounted(() => {
.updateProfile() .updateProfile()
.then(() => { .then(() => {
loginState.checkSession() loginState.checkSession()
toast.add({ // toast.add({
title: '登录成功', // title: '登录成功',
description: `合作渠道认证成功`, // description: `合作渠道认证成功`,
color: 'primary', // color: 'primary',
icon: 'i-tabler-login-2', // icon: 'i-tabler-login-2',
}) // })
router.replace('/') router.replace('/')
}) })
.catch((err) => { .catch((err) => {

1687
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

23
typings/types.d.ts vendored
View File

@@ -87,6 +87,20 @@ interface DigitalHumanItem {
digital_human_id?: number digital_human_id?: number
} }
/**
* 数字人定制训练记录
*/
interface DigitalHumanTrainItem {
id: number
user_id: number
dh_name: string
organization: string
video_url: string
auth_video_url: string
create_time: number
status?: number // 0: 待处理, 1: 已处理
}
interface GBVideoItem { interface GBVideoItem {
id: number id: number
user_id: number user_id: number
@@ -99,6 +113,7 @@ interface GBVideoItem {
title: string title: string
content: string content: string
bg_img: string bg_img: string
video_alpha_url?: string
video_url?: string video_url?: string
video_cover?: string video_cover?: string
subtitle?: string subtitle?: string
@@ -233,6 +248,14 @@ namespace req {
source_type?: number source_type?: number
} }
interface AvatarTrainCreate {
user_id: number
dh_name: string
organization: string
video_url: string
auth_video_url: string
}
/** /**
* @param title 任务标题筛选 * @param title 任务标题筛选
*/ */