refactor(deps): migrate to nuxt v4
This commit is contained in:
588
app/pages/generation/admin/digital-human-train.vue
Normal file
588
app/pages/generation/admin/digital-human-train.vue
Normal file
@@ -0,0 +1,588 @@
|
||||
<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>
|
||||
121
app/pages/generation/admin/index.vue
Normal file
121
app/pages/generation/admin/index.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<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>
|
||||
1672
app/pages/generation/admin/materials.vue
Normal file
1672
app/pages/generation/admin/materials.vue
Normal file
File diff suppressed because it is too large
Load Diff
883
app/pages/generation/admin/users.vue
Normal file
883
app/pages/generation/admin/users.vue
Normal file
@@ -0,0 +1,883 @@
|
||||
<script lang="ts" setup>
|
||||
const route = useRoute()
|
||||
const toast = useToast()
|
||||
const dayjs = useDayjs()
|
||||
const loginState = useLoginState()
|
||||
|
||||
const systemServices: ServiceType[] = [
|
||||
{
|
||||
tag: 'PPTToVideo',
|
||||
name: '微课视频(PPT驱动)',
|
||||
},
|
||||
{
|
||||
tag: 'TextToVideo',
|
||||
name: '绿幕视频(文字驱动)',
|
||||
},
|
||||
{
|
||||
tag: 'SparkChat15',
|
||||
name: '讯飞星火大模型 1.5',
|
||||
},
|
||||
{
|
||||
tag: 'SparkChat30',
|
||||
name: '讯飞星火大模型 3.0',
|
||||
},
|
||||
{
|
||||
tag: 'SparkChat35',
|
||||
name: '讯飞星火大模型 3.5',
|
||||
},
|
||||
{
|
||||
tag: 'TenImgToImg',
|
||||
name: '腾讯混元 - 图生图',
|
||||
},
|
||||
{
|
||||
tag: 'TenTextToImg',
|
||||
name: '腾讯混元 - 文生图',
|
||||
},
|
||||
]
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key: 'id',
|
||||
label: 'ID',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: 'avatar',
|
||||
label: '头像',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: 'username',
|
||||
label: '账户名/姓名',
|
||||
disabled: true,
|
||||
},
|
||||
{
|
||||
key: 'company',
|
||||
label: '单位',
|
||||
},
|
||||
{
|
||||
key: 'mobile',
|
||||
label: '手机号',
|
||||
},
|
||||
{
|
||||
key: 'sex',
|
||||
label: '性别',
|
||||
},
|
||||
{
|
||||
key: 'auth_code',
|
||||
label: '角色',
|
||||
},
|
||||
{
|
||||
key: 'actions',
|
||||
label: '操作',
|
||||
},
|
||||
]
|
||||
|
||||
const selectedColumns = ref([
|
||||
...columns.filter((row) => {
|
||||
return !['auth_code'].includes(row.key)
|
||||
}),
|
||||
])
|
||||
const page = ref(1)
|
||||
const pageCount = ref(15)
|
||||
const state_filter = ref<'verified' | 'unverified'>('verified')
|
||||
const is_verified = ref(true)
|
||||
const viewingUser = ref<UserSchema | null>(null)
|
||||
const isSlideOpen = computed({
|
||||
get: () => !!viewingUser.value,
|
||||
set: () => (viewingUser.value = null),
|
||||
})
|
||||
|
||||
watch([is_verified, pageCount], () => (page.value = 1))
|
||||
watch(
|
||||
state_filter,
|
||||
() => (is_verified.value = state_filter.value === 'verified')
|
||||
)
|
||||
|
||||
const {
|
||||
data: usersData,
|
||||
refresh: refreshUsersData,
|
||||
status: usersDataStatus,
|
||||
} = useAsyncData(
|
||||
'systemUsers',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
req.user.UserList & AuthedRequest,
|
||||
BaseResponse<PagedData<UserSchema>>
|
||||
>('App.User_User.ListUser', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id!,
|
||||
page: page.value,
|
||||
perpage: pageCount.value,
|
||||
is_verify: is_verified.value,
|
||||
}),
|
||||
{
|
||||
watch: [page, pageCount, is_verified],
|
||||
transform: (res) => {
|
||||
res.data.items.unshift(loginState.user)
|
||||
return res
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
const isDigitalSelectorOpen = ref(false)
|
||||
const dhPage = ref(1)
|
||||
const dhPageCount = ref(10)
|
||||
|
||||
watch(dhPageCount, () => (dhPage.value = 1))
|
||||
|
||||
onMounted(() => {
|
||||
if (!!route.query?.unverified) {
|
||||
state_filter.value = 'unverified'
|
||||
}
|
||||
})
|
||||
|
||||
const {
|
||||
data: digitalHumansData,
|
||||
refresh: refreshDigitalHumansData,
|
||||
status: digitalHumansDataStatus,
|
||||
} = useAsyncData(
|
||||
'currentUserDigitalHumans',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
PagedDataRequest & AuthedRequest,
|
||||
BaseResponse<PagedData<DigitalHumanItem>>
|
||||
>('App.User_UserDigital.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id!,
|
||||
to_user_id: viewingUser.value?.id || 0,
|
||||
page: dhPage.value,
|
||||
perpage: dhPageCount.value,
|
||||
}),
|
||||
{
|
||||
watch: [viewingUser, dhPage, dhPageCount],
|
||||
}
|
||||
)
|
||||
|
||||
const {
|
||||
data: userBalances,
|
||||
status: userBalancesStatus,
|
||||
refresh: refreshUserBalances,
|
||||
} = useAsyncData(
|
||||
'userServiceBalances',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
PagedDataRequest & AuthedRequest,
|
||||
BaseResponse<PagedData<ServiceBalance>>
|
||||
>('App.User_UserBalance.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: viewingUser.value?.id || 0,
|
||||
page: 1,
|
||||
perpage: 20,
|
||||
}),
|
||||
{
|
||||
watch: [viewingUser],
|
||||
}
|
||||
)
|
||||
|
||||
const getBalanceByTag = (tag: ServiceTag): ServiceBalance | null => {
|
||||
return (
|
||||
userBalances?.value?.data.items.find((row) => row.request_type === tag) ||
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
const items = (row: UserSchema) => [
|
||||
[
|
||||
{
|
||||
label: '服务和用量',
|
||||
icon: 'tabler:server-cog',
|
||||
click: () => openSlide(row),
|
||||
disabled: row.auth_code === 0,
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
disabled: row.id === loginState.user.id,
|
||||
label: row.auth_code !== 0 ? '停用账号' : '启用账号',
|
||||
icon: row.auth_code !== 0 ? 'tabler:cancel' : 'tabler:shield-check',
|
||||
click: () => setUserStatus(row.id, row.auth_code === 0),
|
||||
},
|
||||
],
|
||||
]
|
||||
|
||||
const openSlide = (user: UserSchema) => {
|
||||
viewingUser.value = user
|
||||
}
|
||||
|
||||
const closeSlide = () => {
|
||||
viewingUser.value = null
|
||||
}
|
||||
|
||||
const onDigitalHumansSelected = (digitalHumans: DigitalHumanItem[]) => {
|
||||
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: viewingUser.value?.id || 0,
|
||||
digital_human_array: digitalHumans.map(
|
||||
(row) => row.id || row.digital_human_id || 0
|
||||
),
|
||||
}).then((res) => {
|
||||
if (res.ret === 200) {
|
||||
toast.add({
|
||||
title: '授权成功',
|
||||
description: `成功授权 ${res.data.success} 个数字人${
|
||||
res.data.failed ? `,失败 ${res.data.failed} 个` : ''
|
||||
}`,
|
||||
color: 'green',
|
||||
icon: 'tabler:check',
|
||||
})
|
||||
refreshDigitalHumansData()
|
||||
} else {
|
||||
toast.add({
|
||||
title: '授权失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'tabler:alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const revokeDigitalHuman = (uid: number, digitalHumanId: number) => {
|
||||
useFetchWrapped<
|
||||
{
|
||||
to_user_id: number
|
||||
digital_human_id: number
|
||||
} & AuthedRequest,
|
||||
BaseResponse<{
|
||||
code: number // 1: success, 0: failed
|
||||
}>
|
||||
>('App.User_UserDigital.DeleteConn', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id!,
|
||||
to_user_id: uid,
|
||||
digital_human_id: digitalHumanId,
|
||||
}).then((res) => {
|
||||
if (res.ret === 200 && res.data.code === 1) {
|
||||
toast.add({
|
||||
title: '撤销成功',
|
||||
description: '已撤销数字人授权',
|
||||
color: 'green',
|
||||
icon: 'tabler:check',
|
||||
})
|
||||
refreshDigitalHumansData()
|
||||
} else {
|
||||
toast.add({
|
||||
title: '撤销失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'tabler:alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const setUserStatus = (uid: number, is_verified: boolean) => {
|
||||
useFetchWrapped<
|
||||
{
|
||||
to_user_id: number
|
||||
is_verify: boolean
|
||||
} & AuthedRequest,
|
||||
BaseResponse<{
|
||||
status: number // 1: success, 0: failed
|
||||
}>
|
||||
>('App.User_User.SetUserVerify', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id!,
|
||||
to_user_id: uid,
|
||||
is_verify: is_verified,
|
||||
}).then((res) => {
|
||||
if (res.ret === 200 && res.data.status === 1) {
|
||||
toast.add({
|
||||
title: '操作成功',
|
||||
description: `已${is_verified ? '启用' : '停用'}账号`,
|
||||
color: 'green',
|
||||
icon: is_verified ? 'tabler:shield-check' : 'tabler:cancel',
|
||||
})
|
||||
refreshUsersData()
|
||||
} else {
|
||||
toast.add({
|
||||
title: '操作失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'tabler:alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const userBalanceEditing = ref(false)
|
||||
const userBalanceState = reactive({
|
||||
expire_time: dayjs().add(1, 'month').unix() * 1000,
|
||||
remain_count: 1800,
|
||||
request_type: '',
|
||||
})
|
||||
|
||||
const isActivateBalance = ref(false)
|
||||
|
||||
const isBalanceEditModalOpen = computed({
|
||||
get: () => !!viewingUser && userBalanceEditing.value,
|
||||
set: (val) => {
|
||||
userBalanceEditing.value = val
|
||||
if (!val) {
|
||||
userBalanceState.expire_time = dayjs().add(1, 'month').unix() * 1000
|
||||
userBalanceState.remain_count = 1800
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const udpateBalance = (tag: ServiceTag, isActivate: boolean = false) => {
|
||||
useFetchWrapped<
|
||||
{
|
||||
to_user_id: number
|
||||
request_type: ServiceTag
|
||||
expire_time: number
|
||||
remain_count: number
|
||||
} & AuthedRequest,
|
||||
BaseResponse<{
|
||||
code: number // 1: success, 0: failed
|
||||
data_id?: number
|
||||
}>
|
||||
>(
|
||||
isActivate ? 'App.User_UserBalance.Insert' : 'App.User_UserBalance.Update',
|
||||
{
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id!,
|
||||
to_user_id: viewingUser.value?.id || 0,
|
||||
request_type: tag,
|
||||
expire_time: userBalanceState.expire_time / 1000,
|
||||
remain_count: userBalanceState.remain_count,
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
if (res.ret === 200 && (res.data.code === 1 || !!res.data.data_id)) {
|
||||
toast.add({
|
||||
title: '操作成功',
|
||||
description: `已${isActivate ? '开通' : '更新'}服务`,
|
||||
color: 'green',
|
||||
icon: 'tabler:check',
|
||||
})
|
||||
} else {
|
||||
toast.add({
|
||||
title: '操作失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'tabler:alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.add({
|
||||
title: '操作失败',
|
||||
description: err.message || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'tabler:alert-triangle',
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
refreshUserBalances()
|
||||
isBalanceEditModalOpen.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<LoginNeededContent need-admin>
|
||||
<div class="p-4">
|
||||
<BubbleTitle
|
||||
bubble-color="amber-500"
|
||||
subtitle="User Management"
|
||||
title="用户管理"
|
||||
>
|
||||
<template #action>
|
||||
<UButton
|
||||
color="amber"
|
||||
icon="tabler:reload"
|
||||
variant="soft"
|
||||
@click="refreshUsersData"
|
||||
>
|
||||
刷新
|
||||
</UButton>
|
||||
</template>
|
||||
</BubbleTitle>
|
||||
<GradientDivider
|
||||
line-gradient-from="amber"
|
||||
line-gradient-to="amber"
|
||||
/>
|
||||
<div>
|
||||
<div class="flex justify-between items-center w-full py-3">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="text-sm leading-0">每页显示:</span>
|
||||
<USelect
|
||||
v-model="pageCount"
|
||||
:options="[5, 10, 15, 20]"
|
||||
class="me-2 w-20"
|
||||
size="xs"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-1.5 items-center">
|
||||
<USelectMenu
|
||||
v-model="state_filter"
|
||||
:options="[
|
||||
{
|
||||
label: '正常账号',
|
||||
value: 'verified',
|
||||
icon: 'tabler:user-check',
|
||||
},
|
||||
{
|
||||
label: '停用账号',
|
||||
value: 'unverified',
|
||||
icon: 'tabler:user-cancel',
|
||||
},
|
||||
]"
|
||||
:ui-menu="{
|
||||
width: 'w-fit',
|
||||
option: { size: 'text-xs', icon: { base: 'w-4 h-4' } },
|
||||
}"
|
||||
size="xs"
|
||||
value-attribute="value"
|
||||
/>
|
||||
<USelectMenu
|
||||
v-model="selectedColumns"
|
||||
:options="columns.filter((row) => !['actions'].includes(row.key))"
|
||||
:ui-menu="{
|
||||
width: 'w-fit',
|
||||
option: { size: 'text-xs', icon: { base: 'w-4 h-4' } },
|
||||
}"
|
||||
multiple
|
||||
>
|
||||
<UButton
|
||||
color="gray"
|
||||
icon="tabler:layout-columns"
|
||||
size="xs"
|
||||
>
|
||||
显示列
|
||||
</UButton>
|
||||
</USelectMenu>
|
||||
</div>
|
||||
</div>
|
||||
<UTable
|
||||
:columns="selectedColumns"
|
||||
:loading="usersDataStatus === 'pending'"
|
||||
:progress="{ color: 'amber', animation: 'carousel' }"
|
||||
:rows="usersData?.data.items"
|
||||
class="border dark:border-neutral-800 rounded-md"
|
||||
>
|
||||
<template #username-data="{ row }">
|
||||
<span
|
||||
:class="{
|
||||
'font-semibold text-amber-500': row.id === loginState.user.id,
|
||||
}"
|
||||
>
|
||||
{{ row.username }}
|
||||
<span class="text-xs">
|
||||
{{ row.id === loginState.user.id ? ' (本账号)' : '' }}
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
<template #avatar-data="{ row }">
|
||||
<UAvatar
|
||||
:alt="row.username.toUpperCase()"
|
||||
:src="row.avatar"
|
||||
size="sm"
|
||||
/>
|
||||
</template>
|
||||
<template #sex-data="{ row }">
|
||||
{{ row.sex === 0 ? '' : row.sex === 1 ? '男' : '女' }}
|
||||
</template>
|
||||
<template #actions-data="{ row }">
|
||||
<UDropdown :items="items(row)">
|
||||
<UButton
|
||||
color="gray"
|
||||
icon="tabler:dots"
|
||||
variant="ghost"
|
||||
/>
|
||||
</UDropdown>
|
||||
</template>
|
||||
</UTable>
|
||||
<div class="flex justify-end py-3.5">
|
||||
<UPagination
|
||||
v-if="(usersData?.data.total || -1) > 0"
|
||||
v-model="page"
|
||||
:page-count="pageCount"
|
||||
:total="usersData?.data.total || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<USlideover
|
||||
v-model="isSlideOpen"
|
||||
:ui="{ width: 'w-screen max-w-3xl' }"
|
||||
>
|
||||
<UCard
|
||||
:ui="{
|
||||
body: { base: 'flex-1 overflow-y-auto' },
|
||||
ring: '',
|
||||
divide: 'divide-y divide-gray-100 dark:divide-gray-800',
|
||||
}"
|
||||
class="flex flex-col overflow-hidden"
|
||||
>
|
||||
<template #header>
|
||||
<UButton
|
||||
class="flex absolute end-5 top-5 z-10"
|
||||
color="gray"
|
||||
icon="tabler:x"
|
||||
padded
|
||||
size="sm"
|
||||
square
|
||||
variant="ghost"
|
||||
@click="closeSlide"
|
||||
/>
|
||||
服务和用量管理
|
||||
<p class="text-sm font-medium text-primary">
|
||||
{{ viewingUser?.username }} (UID:{{ viewingUser?.id }})
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<div class="">
|
||||
<UDivider
|
||||
label="服务用量管理"
|
||||
class="mb-4"
|
||||
:ui="{ label: 'text-primary-500 dark:text-primary-400' }"
|
||||
/>
|
||||
|
||||
<div class="border dark:border-neutral-700 rounded-md">
|
||||
<UTable
|
||||
:columns="[
|
||||
{ key: 'service', label: '服务' },
|
||||
{ key: 'status', label: '状态' },
|
||||
{ key: 'create_time', label: '开通时间' },
|
||||
{ key: 'expire_time', label: '过期时间' },
|
||||
{ key: 'remain_count', label: '余量(秒)' },
|
||||
{ key: 'actions' },
|
||||
]"
|
||||
:loading="userBalancesStatus === 'pending'"
|
||||
:rows="[
|
||||
...systemServices,
|
||||
// 如果 userBalances?.data.items 具有 systemServices 中没有的服务,则添加到列表中
|
||||
...(userBalances?.data.items
|
||||
.filter(
|
||||
(row) =>
|
||||
!systemServices.find((s) => s.tag === row.request_type)
|
||||
)
|
||||
.map((row) => ({
|
||||
tag: row.request_type,
|
||||
name: row.request_type,
|
||||
})) || []),
|
||||
]"
|
||||
>
|
||||
<template #service-data="{ row }: { row: ServiceType }">
|
||||
{{
|
||||
systemServices.find((s) => s.tag === row.tag)?.name || row.tag
|
||||
}}
|
||||
</template>
|
||||
|
||||
<template #status-data="{ row }">
|
||||
<UBadge
|
||||
v-if="!getBalanceByTag(row.tag)"
|
||||
color="gray"
|
||||
variant="solid"
|
||||
size="xs"
|
||||
>
|
||||
未开通
|
||||
</UBadge>
|
||||
<UBadge
|
||||
v-else-if="
|
||||
getBalanceByTag(row.tag)!.expire_time < dayjs().unix()
|
||||
"
|
||||
color="red"
|
||||
variant="subtle"
|
||||
size="xs"
|
||||
>
|
||||
已过期
|
||||
</UBadge>
|
||||
<UBadge
|
||||
v-else
|
||||
color="green"
|
||||
variant="subtle"
|
||||
size="xs"
|
||||
>
|
||||
生效中
|
||||
</UBadge>
|
||||
</template>
|
||||
|
||||
<template #create_time-data="{ row }">
|
||||
<span class="text-xs">
|
||||
{{
|
||||
!!getBalanceByTag(row.tag)
|
||||
? dayjs(
|
||||
getBalanceByTag(row.tag)!.create_time * 1000
|
||||
).format('YYYY-MM-DD HH:mm:ss')
|
||||
: '未开通'
|
||||
}}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #expire_time-data="{ row }">
|
||||
<span class="text-xs">
|
||||
{{
|
||||
!!getBalanceByTag(row.tag)
|
||||
? dayjs(
|
||||
getBalanceByTag(row.tag)!.expire_time * 1000
|
||||
).format('YYYY-MM-DD HH:mm:ss')
|
||||
: '未开通'
|
||||
}}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #remain_count-data="{ row }">
|
||||
<span class="text-sm">
|
||||
{{ getBalanceByTag(row.tag)?.remain_count || 0 }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<template #actions-data="{ row }">
|
||||
<UButton
|
||||
v-if="!getBalanceByTag(row.tag)"
|
||||
color="green"
|
||||
icon="tabler:clock-check"
|
||||
size="xs"
|
||||
variant="soft"
|
||||
@click="
|
||||
() => {
|
||||
isActivateBalance = true
|
||||
userBalanceEditing = true
|
||||
userBalanceState.request_type = row.tag
|
||||
}
|
||||
"
|
||||
>
|
||||
开通
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="
|
||||
getBalanceByTag(row.tag)!.expire_time < dayjs().unix()
|
||||
"
|
||||
color="teal"
|
||||
icon="tabler:clock-plus"
|
||||
size="xs"
|
||||
variant="soft"
|
||||
@click="
|
||||
() => {
|
||||
isActivateBalance = false
|
||||
userBalanceEditing = true
|
||||
userBalanceState.request_type = row.tag
|
||||
}
|
||||
"
|
||||
>
|
||||
延续
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else
|
||||
color="sky"
|
||||
icon="tabler:rotate-clockwise"
|
||||
size="xs"
|
||||
variant="soft"
|
||||
@click="
|
||||
() => {
|
||||
isActivateBalance = false
|
||||
userBalanceEditing = true
|
||||
userBalanceState.request_type = row.tag
|
||||
userBalanceState.expire_time =
|
||||
getBalanceByTag(row.tag)!.expire_time * 1000
|
||||
userBalanceState.remain_count = getBalanceByTag(
|
||||
row.tag
|
||||
)!.remain_count
|
||||
}
|
||||
"
|
||||
>
|
||||
更新
|
||||
</UButton>
|
||||
</template>
|
||||
</UTable>
|
||||
|
||||
<UModal
|
||||
v-model="isBalanceEditModalOpen"
|
||||
:ui="{ width: 'w-xl' }"
|
||||
>
|
||||
<UCard
|
||||
:ui="{
|
||||
ring: '',
|
||||
divide: 'divide-y divide-gray-100 dark:divide-gray-800',
|
||||
}"
|
||||
>
|
||||
<template #header>
|
||||
<!-- 为 {{ viewingUser!.username }}
|
||||
<span class="text-primary">{{ isActivateBalance ? '开通' : '续期' }}</span>
|
||||
服务:
|
||||
{{
|
||||
systemServices.find(
|
||||
(s) => s.tag === userBalanceState.request_type
|
||||
)?.name || userBalanceState.request_type
|
||||
}} -->
|
||||
<div class="flex justify-between items-center gap-1">
|
||||
<h1 class="text-sm font-medium">
|
||||
{{ isActivateBalance ? '开通' : '续期' }}
|
||||
{{
|
||||
systemServices.find(
|
||||
(s) => s.tag === userBalanceState.request_type
|
||||
)?.name || userBalanceState.request_type
|
||||
}}
|
||||
服务
|
||||
</h1>
|
||||
<p
|
||||
class="text-xs text-indigo-500 inline-flex items-center gap-1"
|
||||
>
|
||||
<UIcon
|
||||
name="tabler:user-circle"
|
||||
class="text-base"
|
||||
/>
|
||||
{{ viewingUser!.username }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="flex justify-between gap-4">
|
||||
<UFormGroup
|
||||
label="到期时间"
|
||||
class="flex-1"
|
||||
>
|
||||
<UPopover :popper="{ placement: 'bottom-start' }">
|
||||
<UButton
|
||||
block
|
||||
variant="soft"
|
||||
icon="i-heroicons-calendar-days-20-solid"
|
||||
:label="
|
||||
dayjs(userBalanceState.expire_time).format(
|
||||
'YYYY-MM-DD HH:mm'
|
||||
)
|
||||
"
|
||||
/>
|
||||
|
||||
<template #panel="{ close }">
|
||||
<DatePicker
|
||||
v-model="userBalanceState.expire_time"
|
||||
locale="cn"
|
||||
mode="dateTime"
|
||||
title-position="left"
|
||||
is-required
|
||||
is24hr
|
||||
@close="close"
|
||||
/>
|
||||
</template>
|
||||
</UPopover>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="服务时长(秒)"
|
||||
class="flex-1"
|
||||
>
|
||||
<UInput v-model="userBalanceState.remain_count" />
|
||||
</UFormGroup>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<UButton
|
||||
color="gray"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
@click="isBalanceEditModalOpen = false"
|
||||
>
|
||||
取消
|
||||
</UButton>
|
||||
<UButton
|
||||
color="primary"
|
||||
icon="tabler:check"
|
||||
size="sm"
|
||||
@click="
|
||||
udpateBalance(
|
||||
userBalanceState.request_type as ServiceTag,
|
||||
isActivateBalance
|
||||
)
|
||||
"
|
||||
>
|
||||
{{ isActivateBalance ? '开通' : '续期' }}
|
||||
</UButton>
|
||||
</div>
|
||||
</template>
|
||||
</UCard>
|
||||
</UModal>
|
||||
</div>
|
||||
|
||||
<UDivider
|
||||
label="数字人权限管理"
|
||||
class="my-4"
|
||||
:ui="{ label: 'text-primary-500 dark:text-primary-400' }"
|
||||
/>
|
||||
|
||||
<div class="border dark:border-neutral-700 rounded-md">
|
||||
<UTable
|
||||
:columns="[
|
||||
{ key: 'name', label: '名称' },
|
||||
{ key: 'digital_human_id', label: '本地ID' },
|
||||
{ key: 'model_id', label: '上游ID' },
|
||||
{ key: 'actions' },
|
||||
]"
|
||||
:loading="digitalHumansDataStatus === 'pending'"
|
||||
:rows="digitalHumansData?.data.items"
|
||||
>
|
||||
<template #actions-data="{ row }">
|
||||
<UButton
|
||||
color="gray"
|
||||
icon="tabler:cancel"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
@click="
|
||||
revokeDigitalHuman(
|
||||
viewingUser?.id || 0,
|
||||
row.digital_human_id
|
||||
)
|
||||
"
|
||||
>
|
||||
撤销授权
|
||||
</UButton>
|
||||
</template>
|
||||
</UTable>
|
||||
</div>
|
||||
<div class="flex justify-between py-3.5">
|
||||
<UButton
|
||||
icon="tabler:plus"
|
||||
size="xs"
|
||||
@click="isDigitalSelectorOpen = true"
|
||||
>
|
||||
新增授权
|
||||
</UButton>
|
||||
<UPagination
|
||||
v-if="(digitalHumansData?.data.total || -1) > 0"
|
||||
v-model="dhPage"
|
||||
:page-count="dhPageCount"
|
||||
:total="digitalHumansData?.data.total || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
<ModalDigitalHumanSelect
|
||||
:disabled-digital-human-ids="
|
||||
digitalHumansData?.data.items.map((d) => d.model_id)
|
||||
"
|
||||
:is-open="isDigitalSelectorOpen"
|
||||
default-tab="system"
|
||||
multiple
|
||||
@close="isDigitalSelectorOpen = false"
|
||||
@select="
|
||||
(digitalHumans) =>
|
||||
onDigitalHumansSelected(digitalHumans as DigitalHumanItem[])
|
||||
"
|
||||
/>
|
||||
</USlideover>
|
||||
</LoginNeededContent>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
518
app/pages/generation/avatar-models.vue
Normal file
518
app/pages/generation/avatar-models.vue
Normal file
@@ -0,0 +1,518 @@
|
||||
<script lang="ts" setup>
|
||||
import { number, object, string, type InferType } from 'yup'
|
||||
import type { FormSubmitEvent } from '#ui/types'
|
||||
|
||||
const toast = useToast()
|
||||
const loginState = useLoginState()
|
||||
|
||||
const data_layout = ref<'grid' | 'list'>('grid')
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 14,
|
||||
})
|
||||
const showSystemAvatar = ref(false)
|
||||
watchEffect(() => {
|
||||
if (showSystemAvatar.value) {
|
||||
data_layout.value = 'list'
|
||||
}
|
||||
})
|
||||
|
||||
const {
|
||||
data: userAvatarList,
|
||||
status: userAvatarStatus,
|
||||
refresh: refreshUserAvatarList,
|
||||
} = useAsyncData(
|
||||
'user-digital-human',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
req.gen.DigitalHumanList & AuthedRequest,
|
||||
BaseResponse<PagedData<DigitalHumanItem>>
|
||||
>('App.User_UserDigital.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
page: pagination.page,
|
||||
perpage: pagination.pageSize,
|
||||
}),
|
||||
{
|
||||
watch: [pagination, showSystemAvatar],
|
||||
}
|
||||
)
|
||||
|
||||
const {
|
||||
data: systemAvatarList,
|
||||
status: systemAvatarStatus,
|
||||
refresh: refreshSystemAvatarList,
|
||||
} = useAsyncData(
|
||||
'sys-digital-human',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
req.gen.DigitalHumanList & AuthedRequest,
|
||||
BaseResponse<PagedData<DigitalHumanItem>>
|
||||
>('App.Digital_Human.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
page: pagination.page,
|
||||
perpage: pagination.pageSize,
|
||||
}),
|
||||
{
|
||||
watch: [pagination, showSystemAvatar],
|
||||
}
|
||||
)
|
||||
|
||||
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) => {
|
||||
useFetchWrapped<
|
||||
{ digital_human_id: number } & AuthedRequest,
|
||||
BaseResponse<{ code: 0 | 1 }>
|
||||
>('App.Digital_Human.Delete', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
digital_human_id: row.id!,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ret === 200 && res.data.code === 1) {
|
||||
toast.add({
|
||||
title: '删除成功',
|
||||
description: '数字人已删除',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
refreshSystemAvatarList()
|
||||
} else {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key: 'avatar',
|
||||
label: '图片',
|
||||
},
|
||||
{
|
||||
key: 'name',
|
||||
label: '名称',
|
||||
},
|
||||
{
|
||||
key: 'model_id',
|
||||
label: 'ID',
|
||||
},
|
||||
{
|
||||
key: 'type',
|
||||
label: '来源',
|
||||
},
|
||||
{
|
||||
key: 'description',
|
||||
label: '备注',
|
||||
},
|
||||
{
|
||||
key: 'actions',
|
||||
},
|
||||
]
|
||||
|
||||
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 isCreateSlideOpen = ref(false)
|
||||
const isTrainCreatorOpen = ref(false)
|
||||
|
||||
const createAvatarState = reactive({
|
||||
name: '',
|
||||
description: '',
|
||||
model_id: undefined,
|
||||
avatar: '',
|
||||
type: 2,
|
||||
})
|
||||
|
||||
const createAvatarSchema = object({
|
||||
name: string().required('请输入名称'),
|
||||
description: string().required('请输入备注'),
|
||||
model_id: number().required('请输入ID'),
|
||||
avatar: string().required('请上传图片'),
|
||||
type: number().required('请选择类型'),
|
||||
})
|
||||
|
||||
type CreateAvatarSchema = InferType<typeof createAvatarSchema>
|
||||
|
||||
const onCreateAvatarSubmit = (event: FormSubmitEvent<CreateAvatarSchema>) => {
|
||||
useFetchWrapped<
|
||||
CreateAvatarSchema & AuthedRequest,
|
||||
BaseResponse<{ digital_human_id: number }>
|
||||
>('App.Digital_Human.Create', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
name: event.data.name,
|
||||
description: event.data.description,
|
||||
model_id: event.data.model_id,
|
||||
avatar: createAvatarState.avatar,
|
||||
type: event.data.type,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ret === 200 && res.data.digital_human_id) {
|
||||
toast.add({
|
||||
title: '创建成功',
|
||||
description: '数字人已创建',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
refreshSystemAvatarList()
|
||||
showSystemAvatar.value = true
|
||||
isCreateSlideOpen.value = false
|
||||
} else {
|
||||
toast.add({
|
||||
title: '创建失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
toast.add({
|
||||
title: '创建失败',
|
||||
description: '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const onAvatarUpload = async (files: FileList) => {
|
||||
const file = files[0]
|
||||
try {
|
||||
const url = await useFileGo(file, 'material')
|
||||
createAvatarState.avatar = url
|
||||
toast.add({
|
||||
title: '上传文件成功',
|
||||
description: '文件已上传',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
} catch {
|
||||
toast.add({
|
||||
title: '上传文件失败',
|
||||
description: '请重试',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<div class="p-4 pb-0">
|
||||
<BubbleTitle
|
||||
title="数字讲师管理"
|
||||
subtitle="Avatars"
|
||||
>
|
||||
<template #action>
|
||||
<UButton
|
||||
color="gray"
|
||||
variant="soft"
|
||||
:label="showSystemAvatar ? '显示用户数字人' : '显示系统数字人'"
|
||||
@click="showSystemAvatar = !showSystemAvatar"
|
||||
/>
|
||||
<UButton
|
||||
:icon="
|
||||
data_layout === 'grid'
|
||||
? 'tabler:layout-list'
|
||||
: 'tabler:layout-grid'
|
||||
"
|
||||
variant="soft"
|
||||
color="gray"
|
||||
@click="data_layout = data_layout === 'grid' ? 'list' : '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>
|
||||
</BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<UAlert
|
||||
v-if="showSystemAvatar && loginState.user.auth_code === 2"
|
||||
icon="tabler:user-shield"
|
||||
title="正在显示系统数字人"
|
||||
description="当前正在显示和管理系统数字人,仅管理员可见"
|
||||
class="mb-4"
|
||||
/>
|
||||
<div
|
||||
v-if="data_layout === 'grid'"
|
||||
class="grid grid-cols-7 gap-4"
|
||||
>
|
||||
<div
|
||||
v-for="(avatar, k) in showSystemAvatar
|
||||
? systemAvatarList?.data.items
|
||||
: userAvatarList?.data.items"
|
||||
:key="avatar.model_id || k"
|
||||
class="relative rounded-lg shadow overflow-hidden w-full aspect-[9/16] group"
|
||||
>
|
||||
<NuxtImg
|
||||
:src="avatar.avatar"
|
||||
class="w-full h-full object-cover"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-x-0 bottom-0 p-2 bg-gradient-to-t from-black/50 to-transparent flex gap-2"
|
||||
>
|
||||
<UBadge
|
||||
color="white"
|
||||
variant="solid"
|
||||
icon="tabler:user-screen"
|
||||
>
|
||||
{{ avatar.name }}
|
||||
</UBadge>
|
||||
<template
|
||||
v-for="(t, i) in sourceTypeList"
|
||||
:key="i"
|
||||
>
|
||||
<UBadge
|
||||
v-if="t.value === avatar.type"
|
||||
variant="subtle"
|
||||
:color="t.color"
|
||||
:label="t.label"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
<div
|
||||
class="absolute inset-0 flex flex-col justify-center items-center bg-white/50 dark:bg-neutral-800/50 backdrop-blur opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
>
|
||||
<UButtonGroup>
|
||||
<UButton
|
||||
color="black"
|
||||
icon="tabler:download"
|
||||
label="下载图片"
|
||||
@click="
|
||||
() => {
|
||||
const { download } = useDownload(
|
||||
avatar.avatar,
|
||||
`数字人_${avatar.name}.png`
|
||||
)
|
||||
download()
|
||||
}
|
||||
"
|
||||
/>
|
||||
</UButtonGroup>
|
||||
<span
|
||||
class="text-xs font-medium text-neutral-400 dark:text-neutral-300 pt-4"
|
||||
>
|
||||
ID: {{ avatar.model_id }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<div class="flex flex-col gap-4">
|
||||
<UTable
|
||||
:rows="
|
||||
showSystemAvatar
|
||||
? systemAvatarList?.data.items
|
||||
: userAvatarList?.data.items
|
||||
"
|
||||
:columns="columns"
|
||||
:loading="userAvatarStatus === 'pending'"
|
||||
:progress="{ color: 'amber', animation: 'carousel' }"
|
||||
class="border dark:border-neutral-800 rounded-md"
|
||||
>
|
||||
<template #avatar-data="{ row }">
|
||||
<NuxtImg
|
||||
:src="row.avatar"
|
||||
class="h-16 aspect-[9/16] rounded-lg"
|
||||
/>
|
||||
</template>
|
||||
<template #type-data="{ row }">
|
||||
<template
|
||||
v-for="(t, i) in sourceTypeList"
|
||||
:key="i"
|
||||
>
|
||||
<UBadge
|
||||
v-if="t.value === row.type"
|
||||
variant="subtle"
|
||||
:color="t.color"
|
||||
:label="t.label"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
<template #actions-data="{ row }">
|
||||
<div class="flex gap-2">
|
||||
<UButton
|
||||
color="gray"
|
||||
icon="tabler:download"
|
||||
label="下载图片"
|
||||
variant="soft"
|
||||
size="xs"
|
||||
@click="
|
||||
() => {
|
||||
const { download } = useDownload(
|
||||
row.avatar,
|
||||
`数字人_${row.name}.png`
|
||||
)
|
||||
download()
|
||||
}
|
||||
"
|
||||
/>
|
||||
<UButton
|
||||
color="red"
|
||||
icon="tabler:trash"
|
||||
label="删除"
|
||||
variant="soft"
|
||||
size="xs"
|
||||
@click="onSystemAvatarDelete(row)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</UTable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4">
|
||||
<UPagination
|
||||
v-model="pagination.page"
|
||||
:max="9"
|
||||
:page-count="pagination.pageSize"
|
||||
:total="userAvatarList?.data.total || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<USlideover v-model="isCreateSlideOpen">
|
||||
<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="tabler:x"
|
||||
padded
|
||||
size="sm"
|
||||
square
|
||||
variant="ghost"
|
||||
@click="isCreateSlideOpen = false"
|
||||
/>
|
||||
创建系统数字人
|
||||
</template>
|
||||
|
||||
<UForm
|
||||
class="space-y-3"
|
||||
:schema="createAvatarSchema"
|
||||
:state="createAvatarState"
|
||||
@submit="onCreateAvatarSubmit"
|
||||
>
|
||||
<UFormGroup
|
||||
label="名称"
|
||||
name="name"
|
||||
>
|
||||
<UInput v-model="createAvatarState.name" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="备注"
|
||||
name="description"
|
||||
>
|
||||
<UInput v-model="createAvatarState.description" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="ID"
|
||||
name="model_id"
|
||||
>
|
||||
<UInput v-model="createAvatarState.model_id" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="图片"
|
||||
name="avatar"
|
||||
>
|
||||
<UniFileDnD
|
||||
accept="image/png,image/jpeg"
|
||||
@change="onAvatarUpload"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="类型"
|
||||
name="type"
|
||||
>
|
||||
<USelectMenu
|
||||
v-model="createAvatarState.type"
|
||||
value-attribute="value"
|
||||
:options="sourceTypeList"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup class="flex justify-end pt-4">
|
||||
<UButton
|
||||
type="submit"
|
||||
color="primary"
|
||||
label="创建"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</UForm>
|
||||
</UCard>
|
||||
</USlideover>
|
||||
|
||||
<!-- 数字人定制对话框 -->
|
||||
<DigitalHumanTrainCreator v-model="isTrainCreatorOpen" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
165
app/pages/generation/course.vue
Normal file
165
app/pages/generation/course.vue
Normal file
@@ -0,0 +1,165 @@
|
||||
<script lang="ts" setup>
|
||||
import ModalAuthentication from '~/components/ModalAuthentication.vue'
|
||||
import SlideCreateCourse from '~/components/SlideCreateCourse.vue'
|
||||
import { useFetchWrapped } from '~/composables/useFetchWrapped'
|
||||
|
||||
const toast = useToast()
|
||||
const modal = useModal()
|
||||
const slide = useSlideover()
|
||||
const loginState = useLoginState()
|
||||
|
||||
const deletePending = ref(false)
|
||||
const page = ref(1)
|
||||
|
||||
const { data: courseList, refresh: refreshCourseList } = useAsyncData(
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
req.gen.CourseGenList & AuthedRequest,
|
||||
BaseResponse<PagedData<resp.gen.CourseGenItem>>
|
||||
>('App.Digital_Convert.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
page: page.value,
|
||||
perpage: 15,
|
||||
}),
|
||||
{
|
||||
watch: [page],
|
||||
}
|
||||
)
|
||||
|
||||
const onCreateCourseClick = () => {
|
||||
slide.open(SlideCreateCourse, {
|
||||
onSuccess: () => {
|
||||
refreshCourseList()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const onCourseDelete = (task_id: string) => {
|
||||
if (!task_id) return
|
||||
deletePending.value = true
|
||||
useFetchWrapped<
|
||||
req.gen.CourseGenDelete & AuthedRequest,
|
||||
BaseResponse<resp.gen.CourseGenDelete>
|
||||
>('App.Digital_Convert.Delete', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
task_id,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ret === 200) {
|
||||
toast.add({
|
||||
title: '删除成功',
|
||||
description: '已删除任务记录',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
} else {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
deletePending.value = false
|
||||
refreshCourseList()
|
||||
})
|
||||
}
|
||||
|
||||
const beforeLeave = (el: any) => {
|
||||
el.style.width = `${el.offsetWidth}px`
|
||||
el.style.height = `${el.offsetHeight}px`
|
||||
}
|
||||
|
||||
const leave = (el: any, done: Function) => {
|
||||
el.style.position = 'absolute'
|
||||
el.style.transition = 'none' // 取消过渡动画
|
||||
el.style.opacity = 0 // 立即隐藏元素
|
||||
done()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const i = setInterval(refreshCourseList, 1000 * 5)
|
||||
onBeforeUnmount(() => clearInterval(i))
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="p-4 pb-0">
|
||||
<BubbleTitle
|
||||
subtitle="VIDEOS"
|
||||
title="我的微课视频"
|
||||
>
|
||||
<template #action>
|
||||
<UButton
|
||||
:trailing="false"
|
||||
color="primary"
|
||||
icon="i-tabler-plus"
|
||||
label="新建微课"
|
||||
size="md"
|
||||
variant="solid"
|
||||
@click="
|
||||
() => {
|
||||
if (!loginState.is_logged_in) {
|
||||
modal.open(ModalAuthentication)
|
||||
return
|
||||
}
|
||||
onCreateCourseClick()
|
||||
}
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
</BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
<Transition name="loading-screen">
|
||||
<div
|
||||
v-if="courseList?.data.items.length === 0"
|
||||
class="w-full py-20 flex flex-col justify-center items-center gap-2"
|
||||
>
|
||||
<Icon
|
||||
class="text-7xl text-neutral-300 dark:text-neutral-700"
|
||||
name="i-tabler-photo-hexagon"
|
||||
/>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">没有记录</p>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="p-4"
|
||||
>
|
||||
<div
|
||||
class="relative grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4 fhd:grid-cols-5 gap-4"
|
||||
>
|
||||
<TransitionGroup
|
||||
name="card"
|
||||
@beforeLeave="beforeLeave"
|
||||
@leave="leave"
|
||||
>
|
||||
<AigcGenerationCGTaskCard
|
||||
v-for="(course, index) in courseList?.data.items"
|
||||
:key="course.task_id || 'unknown' + index"
|
||||
:course="course"
|
||||
@delete="(task_id: string) => onCourseDelete(task_id)"
|
||||
/>
|
||||
</TransitionGroup>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4">
|
||||
<UPagination
|
||||
v-model="page"
|
||||
:max="9"
|
||||
:page-count="16"
|
||||
:total="courseList?.data.total || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
215
app/pages/generation/green-screen.vue
Normal file
215
app/pages/generation/green-screen.vue
Normal file
@@ -0,0 +1,215 @@
|
||||
<script lang="ts" setup>
|
||||
import { useFetchWrapped } from '~/composables/useFetchWrapped'
|
||||
import GBTaskCard from '~/components/aigc/generation/GBTaskCard.vue'
|
||||
import { useTourState } from '~/composables/useTourState'
|
||||
import SlideCreateCourseGreen from '~/components/SlideCreateCourseGreen.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const slide = useSlideover()
|
||||
const toast = useToast()
|
||||
const loginState = useLoginState()
|
||||
const tourState = useTourState()
|
||||
|
||||
const page = ref(1)
|
||||
const pageCount = ref(15)
|
||||
const searchInput = ref('')
|
||||
const debounceSearch = refDebounced(searchInput, 1000)
|
||||
|
||||
watch(debounceSearch, () => (page.value = 1))
|
||||
|
||||
const { data: videoList, refresh: refreshVideoList } = useAsyncData(
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
req.gen.GBVideoList & AuthedRequest,
|
||||
BaseResponse<PagedData<GBVideoItem>>
|
||||
>('App.Digital_VideoTask.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
page: page.value,
|
||||
perpage: pageCount.value,
|
||||
title: debounceSearch.value,
|
||||
}),
|
||||
{
|
||||
watch: [page, pageCount, debounceSearch],
|
||||
}
|
||||
)
|
||||
|
||||
const onCreateCourseGreenClick = () => {
|
||||
slide.open(SlideCreateCourseGreen, {
|
||||
onSuccess: () => {
|
||||
refreshVideoList()
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const onCourseGreenDelete = (task: GBVideoItem) => {
|
||||
if (!task.task_id) return
|
||||
useFetchWrapped<
|
||||
req.gen.GBVideoDelete & AuthedRequest,
|
||||
BaseResponse<resp.gen.GBVideoDelete>
|
||||
>('App.Digital_VideoTask.Delete', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
task_id: task.task_id,
|
||||
}).then((res) => {
|
||||
if (res.data.code === 1) {
|
||||
refreshVideoList()
|
||||
toast.add({
|
||||
title: '删除成功',
|
||||
description: '已删除任务记录',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
} else {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const beforeLeave = (el: any) => {
|
||||
el.style.width = `${el.offsetWidth}px`
|
||||
el.style.height = `${el.offsetHeight}px`
|
||||
}
|
||||
|
||||
const leave = (el: any, done: Function) => {
|
||||
el.style.position = 'absolute'
|
||||
el.style.transition = 'none' // 取消过渡动画
|
||||
el.style.opacity = 0 // 立即隐藏元素
|
||||
done()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const i = setInterval(refreshVideoList, 1000 * 5)
|
||||
onBeforeUnmount(() => clearInterval(i))
|
||||
|
||||
const driver = useDriver({
|
||||
showProgress: true,
|
||||
animate: true,
|
||||
smoothScroll: true,
|
||||
disableActiveInteraction: true,
|
||||
popoverOffset: 12,
|
||||
progressText: '{{current}} / {{total}}',
|
||||
prevBtnText: '上一步',
|
||||
nextBtnText: '下一步',
|
||||
doneBtnText: '完成',
|
||||
steps: [
|
||||
{
|
||||
element: '#button-create',
|
||||
popover: {
|
||||
title: '新建视频',
|
||||
description: '点击这里开始新建绿幕视频',
|
||||
},
|
||||
},
|
||||
{
|
||||
element: '#input-search',
|
||||
popover: {
|
||||
title: '搜索生成记录',
|
||||
description: '在这里输入视频标题,可以搜索符合条件的生成记录',
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
tourState.autoDriveTour(route.fullPath, driver)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<div class="p-4 pb-0">
|
||||
<BubbleTitle
|
||||
:subtitle="!debounceSearch ? 'GB VIDEOS' : 'SEARCH...'"
|
||||
:title="
|
||||
!debounceSearch
|
||||
? '我的绿幕视频'
|
||||
: `标题搜索:${debounceSearch.toLocaleUpperCase()}`
|
||||
"
|
||||
>
|
||||
<template #action>
|
||||
<UButtonGroup size="md">
|
||||
<UInput
|
||||
id="input-search"
|
||||
v-model="searchInput"
|
||||
:autofocus="false"
|
||||
:ui="{ icon: { trailing: { pointer: '' } } }"
|
||||
autocomplete="off"
|
||||
placeholder="标题搜索"
|
||||
variant="outline"
|
||||
>
|
||||
<template #trailing>
|
||||
<UButton
|
||||
v-show="searchInput !== ''"
|
||||
:padded="false"
|
||||
color="gray"
|
||||
icon="i-tabler-x"
|
||||
variant="link"
|
||||
@click="searchInput = ''"
|
||||
/>
|
||||
</template>
|
||||
</UInput>
|
||||
</UButtonGroup>
|
||||
<UButton
|
||||
id="button-create"
|
||||
:trailing="false"
|
||||
color="primary"
|
||||
icon="i-tabler-plus"
|
||||
label="新建"
|
||||
size="md"
|
||||
variant="solid"
|
||||
@click="onCreateCourseGreenClick"
|
||||
/>
|
||||
</template>
|
||||
</BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
|
||||
<Transition name="loading-screen">
|
||||
<div
|
||||
v-if="videoList?.data.items.length === 0"
|
||||
class="w-full py-20 flex flex-col justify-center items-center gap-2"
|
||||
>
|
||||
<Icon
|
||||
class="text-7xl text-neutral-300 dark:text-neutral-700"
|
||||
name="i-tabler-photo-hexagon"
|
||||
/>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">没有记录</p>
|
||||
</div>
|
||||
<div v-else>
|
||||
<div class="p-4">
|
||||
<div
|
||||
class="relative grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-3 fhd:grid-cols-5 gap-4"
|
||||
>
|
||||
<TransitionGroup
|
||||
name="card"
|
||||
@beforeLeave="beforeLeave"
|
||||
@leave="leave"
|
||||
>
|
||||
<GBTaskCard
|
||||
v-for="(v, i) in videoList?.data.items"
|
||||
:key="v.task_id"
|
||||
:video="v"
|
||||
@delete="(v) => onCourseGreenDelete(v)"
|
||||
/>
|
||||
</TransitionGroup>
|
||||
</div>
|
||||
<div class="flex justify-end mt-4">
|
||||
<UPagination
|
||||
v-model="page"
|
||||
:max="9"
|
||||
:page-count="pageCount"
|
||||
:total="videoList?.data.total || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
424
app/pages/generation/materials.vue
Normal file
424
app/pages/generation/materials.vue
Normal file
@@ -0,0 +1,424 @@
|
||||
<script lang="ts" setup>
|
||||
import type { FormSubmitEvent } from '#ui/types'
|
||||
import { number, object, string, type InferType } from 'yup'
|
||||
|
||||
const loginState = useLoginState()
|
||||
const toast = useToast()
|
||||
|
||||
const isCreateSystemTitlesSlideActive = ref(false)
|
||||
const isUserTitlesRequestModalActive = ref(false)
|
||||
|
||||
const systemPagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 15,
|
||||
})
|
||||
|
||||
const userPagination = reactive({
|
||||
page: 1,
|
||||
pageSize: 15,
|
||||
})
|
||||
|
||||
const {
|
||||
data: systemTitlesTemplate,
|
||||
status: systemTitlesTemplateStatus,
|
||||
refresh: refreshSystemTitlesTemplate,
|
||||
} = useAsyncData(
|
||||
'systemTitlesTemplate',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
PagedDataRequest & AuthedRequest,
|
||||
BaseResponse<PagedData<TitlesTemplate>>
|
||||
>('App.Digital_Titles.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
page: systemPagination.page,
|
||||
perpage: systemPagination.pageSize,
|
||||
}),
|
||||
{
|
||||
watch: [systemPagination],
|
||||
}
|
||||
)
|
||||
|
||||
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: userPagination.page,
|
||||
perpage: userPagination.pageSize,
|
||||
process_status: 1,
|
||||
}),
|
||||
{
|
||||
watch: [userPagination],
|
||||
}
|
||||
)
|
||||
|
||||
const { data: userTitlesRequests, refresh: refreshUserTitlesRequests } =
|
||||
useAsyncData('userTitlesTemplateRequests', () =>
|
||||
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,
|
||||
process_status: 0,
|
||||
})
|
||||
)
|
||||
|
||||
const userTitlesSchema = object({
|
||||
title_id: number().required().moreThan(0, '模板 ID 无效'),
|
||||
title: string().required('请填写课程名称'),
|
||||
description: string().required('请填写主讲人名字'),
|
||||
remark: string().optional(),
|
||||
})
|
||||
|
||||
type UserTitlesSchema = InferType<typeof userTitlesSchema>
|
||||
|
||||
const userTitlesState = reactive({
|
||||
title_id: 0,
|
||||
title: '',
|
||||
description: '',
|
||||
remark: '',
|
||||
})
|
||||
|
||||
const onUserTitlesRequest = (titles: TitlesTemplate) => {
|
||||
userTitlesState.title_id = titles.id
|
||||
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) => {
|
||||
useFetchWrapped<
|
||||
Pick<req.gen.TitlesTemplateRequest, 'to_user_id'> & {
|
||||
user_title_id: number
|
||||
} & AuthedRequest,
|
||||
BaseResponse<any>
|
||||
>('App.User_UserTitles.DeleteConn', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
user_title_id: titles.id,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ret === 200) {
|
||||
toast.add({
|
||||
title: '删除成功',
|
||||
description: '已删除片头素材',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
} else {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
userPagination.page = 1
|
||||
refreshUserTitlesTemplate()
|
||||
})
|
||||
}
|
||||
|
||||
const onUserTitlesSubmit = (event: FormSubmitEvent<UserTitlesSchema>) => {
|
||||
useFetchWrapped<
|
||||
req.gen.TitlesTemplateRequest & AuthedRequest,
|
||||
BaseResponse<any>
|
||||
>('App.User_UserTitles.CreateConn', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
to_user_id: loginState.user.id,
|
||||
...event.data,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ret === 200) {
|
||||
userTitlesState.title = ''
|
||||
userTitlesState.description = ''
|
||||
toast.add({
|
||||
title: '提交成功',
|
||||
description: '已提交片头制作请求',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
} else {
|
||||
toast.add({
|
||||
title: '提交失败',
|
||||
description: res.msg || '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
isUserTitlesRequestModalActive.value = false
|
||||
userPagination.page = 1
|
||||
refreshUserTitlesRequests()
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<div class="p-4 pb-0">
|
||||
<BubbleTitle
|
||||
title="片头片尾模版"
|
||||
subtitle="Materials"
|
||||
>
|
||||
<template #action>
|
||||
<UButton
|
||||
color="amber"
|
||||
icon="tabler:plus"
|
||||
variant="soft"
|
||||
v-if="loginState.user.auth_code === 2"
|
||||
@click="isCreateSystemTitlesSlideActive = true"
|
||||
>
|
||||
创建模板
|
||||
</UButton>
|
||||
</template>
|
||||
</BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
<div class="p-4">
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-5 gap-4"
|
||||
v-if="systemTitlesTemplateStatus === 'pending'"
|
||||
>
|
||||
<USkeleton
|
||||
class="w-full aspect-video"
|
||||
v-for="i in systemPagination.pageSize"
|
||||
:key="i"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="systemTitlesTemplate?.data.items.length === 0"
|
||||
class="w-full py-20 flex flex-col justify-center items-center gap-2"
|
||||
>
|
||||
<Icon
|
||||
class="text-7xl text-neutral-300 dark:text-neutral-700"
|
||||
name="i-tabler-photo-hexagon"
|
||||
/>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
暂时没有可用模板
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-5 gap-4"
|
||||
v-else
|
||||
>
|
||||
<AigcGenerationTitlesTemplate
|
||||
v-for="titles in systemTitlesTemplate?.data.items"
|
||||
:data="titles"
|
||||
type="system"
|
||||
:key="titles.id"
|
||||
@user-titles-request="onUserTitlesRequest"
|
||||
@system-titles-delete="onSystemTitlesDelete"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4 pb-0 pt-12">
|
||||
<BubbleTitle
|
||||
title="我的片头片尾"
|
||||
:bubble="false"
|
||||
></BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
<div class="p-4 pt-2">
|
||||
<UAlert
|
||||
v-if="userTitlesRequests?.data.total"
|
||||
color="primary"
|
||||
icon="tabler:info-circle"
|
||||
variant="subtle"
|
||||
class="mb-4"
|
||||
>
|
||||
<template #title>
|
||||
有 {{ userTitlesRequests?.data.total }} 个片头正在制作中
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="flex gap-2">
|
||||
<div
|
||||
v-for="titles in userTitlesRequests?.data.items"
|
||||
:key="titles.id"
|
||||
>
|
||||
<p>
|
||||
{{ titles.title }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</UAlert>
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-5 gap-4"
|
||||
v-if="userTitlesTemplateStatus === 'pending'"
|
||||
>
|
||||
<USkeleton
|
||||
class="w-full aspect-video"
|
||||
v-for="i in userPagination.pageSize"
|
||||
:key="i"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else-if="userTitlesTemplate?.data.items.length === 0"
|
||||
class="w-full py-20 flex flex-col justify-center items-center gap-2"
|
||||
>
|
||||
<Icon
|
||||
class="text-7xl text-neutral-300 dark:text-neutral-700"
|
||||
name="i-tabler-photo-hexagon"
|
||||
/>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
还没有使用过模板
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-5 gap-4"
|
||||
v-else
|
||||
>
|
||||
<AigcGenerationTitlesTemplate
|
||||
v-for="titles in userTitlesTemplate?.data.items"
|
||||
type="user"
|
||||
:data="titles"
|
||||
:key="titles.id"
|
||||
@user-titles-delete="onUserTitlesDelete"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UModal v-model="isUserTitlesRequestModalActive">
|
||||
<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>
|
||||
</div>
|
||||
<UButton
|
||||
class="-my-1"
|
||||
color="gray"
|
||||
icon="i-tabler-x"
|
||||
variant="ghost"
|
||||
@click="isUserTitlesRequestModalActive = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div>
|
||||
<UForm
|
||||
class="space-y-4"
|
||||
:schema="userTitlesSchema"
|
||||
:state="userTitlesState"
|
||||
@submit="onUserTitlesSubmit"
|
||||
>
|
||||
<UFormGroup
|
||||
label="课程名称"
|
||||
name="title"
|
||||
required
|
||||
>
|
||||
<UInput v-model="userTitlesState.title" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="主讲人"
|
||||
name="description"
|
||||
required
|
||||
>
|
||||
<UInput v-model="userTitlesState.description" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="备注"
|
||||
name="remark"
|
||||
help="可选,可以在此处填写学校、单位等额外信息"
|
||||
>
|
||||
<UTextarea v-model="userTitlesState.remark" />
|
||||
</UFormGroup>
|
||||
<UFormGroup name="title_id">
|
||||
<UInput
|
||||
type="hidden"
|
||||
v-model="userTitlesState.title_id"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<UAlert
|
||||
icon="tabler:info-circle"
|
||||
color="primary"
|
||||
variant="subtle"
|
||||
title="片头片尾模板"
|
||||
description="提交模板相应字段后,待工作人员制作好后即可使用"
|
||||
/>
|
||||
|
||||
<div class="flex justify-end gap-2">
|
||||
<UButton
|
||||
color="primary"
|
||||
variant="soft"
|
||||
label="取消"
|
||||
@click="isUserTitlesRequestModalActive = false"
|
||||
/>
|
||||
<UButton
|
||||
color="primary"
|
||||
type="submit"
|
||||
>
|
||||
提交
|
||||
</UButton>
|
||||
</div>
|
||||
</UForm>
|
||||
</div>
|
||||
</UCard>
|
||||
</UModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
531
app/pages/generation/ppt-templates.vue
Normal file
531
app/pages/generation/ppt-templates.vue
Normal file
@@ -0,0 +1,531 @@
|
||||
<script lang="ts" setup>
|
||||
import { number, object, string, type InferType } from 'yup'
|
||||
import type { FormSubmitEvent } from '#ui/types'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
const toast = useToast()
|
||||
const loginState = useLoginState()
|
||||
|
||||
const isCreateSlideOpen = ref(false)
|
||||
const isCatSlideOpen = ref(false)
|
||||
|
||||
const { data: pptCategories, refresh: refreshPPTCategories } = useAsyncData(
|
||||
'pptCategories',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
PagedDataRequest & AuthedRequest,
|
||||
BaseResponse<PagedData<PPTCategory>>
|
||||
>('App.PowerPoint_Category.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
page: 1,
|
||||
perpage: 20,
|
||||
})
|
||||
)
|
||||
|
||||
const selectedCat = ref<number>(0)
|
||||
const pagination = reactive({
|
||||
page: 1,
|
||||
perpage: 18,
|
||||
})
|
||||
|
||||
const { data: pptTemplates, refresh: refreshPptTemplates } = useAsyncData(
|
||||
'pptTemplates',
|
||||
() =>
|
||||
useFetchWrapped<
|
||||
PagedDataRequest & { type: string | number } & AuthedRequest,
|
||||
BaseResponse<PagedData<PPTTemplate>>
|
||||
>('App.PowerPoint_SysPowerPoint.GetList', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
page: pagination.page,
|
||||
perpage: pagination.perpage,
|
||||
type: selectedCat.value === 0 ? '' : selectedCat.value,
|
||||
}),
|
||||
{
|
||||
watch: [selectedCat, pagination],
|
||||
}
|
||||
)
|
||||
|
||||
const onDownloadClick = (ppt: PPTTemplate) => {
|
||||
const { download } = useDownload(ppt.file_url, `${ppt.title}.pptx`)
|
||||
download()
|
||||
}
|
||||
|
||||
const pptCreateState = reactive({
|
||||
title: '',
|
||||
description: '',
|
||||
type: 0,
|
||||
preview_url: '',
|
||||
file_url: '',
|
||||
})
|
||||
|
||||
const pptCreateSchema = object({
|
||||
title: string().required('模板标题不能为空'),
|
||||
description: string().required('模板描述不能为空'),
|
||||
type: number().notOneOf([0], '无效分类').required('请选择模板分类'),
|
||||
preview_url: string().required('请上传预览图'),
|
||||
file_url: string().required('请上传 PPT 文件'),
|
||||
})
|
||||
|
||||
type PPTCreateSchema = InferType<typeof pptCreateSchema>
|
||||
|
||||
const selectMenuOptions = computed(() => {
|
||||
return pptCategories.value?.data.items.map((cat) => ({
|
||||
label: cat.type,
|
||||
value: cat.id,
|
||||
}))
|
||||
})
|
||||
|
||||
const onCreateSubmit = (event: FormSubmitEvent<PPTCreateSchema>) => {
|
||||
useFetchWrapped<
|
||||
{
|
||||
title: string
|
||||
description: string
|
||||
type: number
|
||||
preview_url: string
|
||||
file_url: string
|
||||
} & AuthedRequest,
|
||||
BaseResponse<{ powerpoint_id: number }>
|
||||
>('App.PowerPoint_SysPowerPoint.Create', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
title: event.data.title,
|
||||
description: event.data.description,
|
||||
type: event.data.type,
|
||||
preview_url: event.data.preview_url,
|
||||
file_url: event.data.file_url,
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.data.powerpoint_id) {
|
||||
await refreshPPTCategories()
|
||||
toast.add({
|
||||
title: '创建成功',
|
||||
description: '已加入模板库',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
isCreateSlideOpen.value = false
|
||||
refreshPptTemplates()
|
||||
Object.assign(pptCreateState, {
|
||||
title: '',
|
||||
description: '',
|
||||
type: 0,
|
||||
preview_url: '',
|
||||
file_url: '',
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
toast.add({
|
||||
title: '创建失败',
|
||||
description: '请检查输入是否正确',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const onFileSelect = async (files: FileList, type: 'preview' | 'ppt') => {
|
||||
const url = await useFileGo(files[0], 'material')
|
||||
if (type === 'preview') {
|
||||
pptCreateState.preview_url = url
|
||||
} else {
|
||||
pptCreateState.file_url = url
|
||||
}
|
||||
toast.add({
|
||||
title: '上传成功',
|
||||
description: `已上传 ${type === 'preview' ? '预览图' : 'PPT 文件'}`,
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
}
|
||||
|
||||
const onDeletePPT = (ppt: PPTTemplate) => {
|
||||
useFetchWrapped<
|
||||
{ powerpoint_id: number } & AuthedRequest,
|
||||
BaseResponse<{ code: number }>
|
||||
>('App.PowerPoint_SysPowerPoint.Delete', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
powerpoint_id: ppt.id,
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.ret === 200 && res.data.code === 1) {
|
||||
await refreshPptTemplates()
|
||||
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(() => {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: '未知错误',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const createCatInput = ref('')
|
||||
|
||||
const onCreateCat = () => {
|
||||
if (createCatInput.value) {
|
||||
useFetchWrapped<
|
||||
{ type: string } & AuthedRequest,
|
||||
BaseResponse<{ ppt_cat_id: number }>
|
||||
>('App.PowerPoint_SysPowerPoint.Create', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
type: createCatInput.value,
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.data.ppt_cat_id) {
|
||||
await refreshPPTCategories()
|
||||
toast.add({
|
||||
title: '创建成功',
|
||||
description: '已加入分类列表',
|
||||
color: 'green',
|
||||
icon: 'i-tabler-check',
|
||||
})
|
||||
createCatInput.value = ''
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
toast.add({
|
||||
title: '创建失败',
|
||||
description: '请检查输入是否正确',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const onDeleteCat = (cat: PPTCategory) => {
|
||||
useFetchWrapped<
|
||||
{ ppt_cat_id: number } & AuthedRequest,
|
||||
BaseResponse<{ code: number }>
|
||||
>('App.PowerPoint_SysPowerPoint.Delete', {
|
||||
token: loginState.token!,
|
||||
user_id: loginState.user.id,
|
||||
ppt_cat_id: cat.id,
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res.ret === 200 && res.data.code === 1) {
|
||||
await refreshPPTCategories()
|
||||
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(() => {
|
||||
toast.add({
|
||||
title: '删除失败',
|
||||
description: '请检查输入是否正确',
|
||||
color: 'red',
|
||||
icon: 'i-tabler-alert-triangle',
|
||||
})
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="p-4 pb-0">
|
||||
<BubbleTitle
|
||||
title="PPT 模板库"
|
||||
subtitle="Slide Templates"
|
||||
>
|
||||
<template #action>
|
||||
<UButton
|
||||
v-if="loginState.user.auth_code === 2"
|
||||
label="分类管理"
|
||||
color="amber"
|
||||
variant="soft"
|
||||
icon="tabler:grid"
|
||||
@click="isCatSlideOpen = true"
|
||||
/>
|
||||
<UButton
|
||||
v-if="loginState.user.auth_code === 2"
|
||||
label="创建模板"
|
||||
color="amber"
|
||||
variant="soft"
|
||||
icon="tabler:plus"
|
||||
@click="isCreateSlideOpen = true"
|
||||
/>
|
||||
</template>
|
||||
</BubbleTitle>
|
||||
<GradientDivider />
|
||||
</div>
|
||||
<div class="p-4 pt-0">
|
||||
<!-- cat selector -->
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<div
|
||||
v-for="cat in [
|
||||
{ id: 0, type: '全部' },
|
||||
...(pptCategories?.data.items || []),
|
||||
]"
|
||||
@click="selectedCat = cat.id"
|
||||
:key="cat.id"
|
||||
:class="{
|
||||
'bg-primary text-white': selectedCat === cat.id,
|
||||
'bg-gray-100 text-gray-500': selectedCat !== cat.id,
|
||||
}"
|
||||
class="rounded-lg px-4 py-2 text-sm cursor-pointer"
|
||||
>
|
||||
{{ cat.type }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div
|
||||
v-if="pptTemplates?.data.items.length === 0"
|
||||
class="w-full py-20 flex flex-col justify-center items-center gap-2"
|
||||
>
|
||||
<Icon
|
||||
class="text-7xl text-neutral-300 dark:text-neutral-700"
|
||||
name="i-tabler-photo-hexagon"
|
||||
/>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
暂时没有可用模板
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4 gap-4 mt-4"
|
||||
>
|
||||
<div
|
||||
v-for="ppt in pptTemplates?.data.items"
|
||||
:key="ppt.id"
|
||||
class="relative bg-white rounded-lg shadow-md overflow-hidden"
|
||||
>
|
||||
<NuxtImg
|
||||
:src="ppt.preview_url"
|
||||
:alt="ppt.title"
|
||||
class="w-full aspect-video object-cover"
|
||||
/>
|
||||
<div
|
||||
class="absolute inset-x-0 bottom-0 p-3 pt-6 flex justify-between items-end bg-gradient-to-t from-black/50 to-transparent"
|
||||
>
|
||||
<div class="space-y-0.5">
|
||||
<h3 class="text-base font-bold text-white">{{ ppt.title }}</h3>
|
||||
<p class="text-xs font-medium text-neutral-200">
|
||||
{{ ppt.description }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- delete -->
|
||||
<UButton
|
||||
v-if="loginState.user.auth_code === 2"
|
||||
size="sm"
|
||||
color="red"
|
||||
icon="tabler:trash"
|
||||
variant="soft"
|
||||
@click="onDeletePPT(ppt)"
|
||||
/>
|
||||
<UButton
|
||||
label="下载"
|
||||
size="sm"
|
||||
color="primary"
|
||||
icon="tabler:download"
|
||||
@click="onDownloadClick(ppt)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex justify-end">
|
||||
<UPagination
|
||||
v-if="(pptTemplates?.data.total || 0) > pagination.perpage"
|
||||
:total="pptTemplates?.data.total"
|
||||
:page-count="pagination.perpage"
|
||||
:max="9"
|
||||
v-model="pagination.page"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<USlideover v-model="isCreateSlideOpen">
|
||||
<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="tabler:x"
|
||||
padded
|
||||
size="sm"
|
||||
square
|
||||
variant="ghost"
|
||||
@click="isCreateSlideOpen = false"
|
||||
/>
|
||||
创建 PPT 模板
|
||||
</template>
|
||||
|
||||
<UForm
|
||||
class="space-y-4"
|
||||
:schema="pptCreateSchema"
|
||||
:state="pptCreateState"
|
||||
@submit="onCreateSubmit"
|
||||
>
|
||||
<UFormGroup
|
||||
label="模板标题"
|
||||
name="title"
|
||||
>
|
||||
<UInput v-model="pptCreateState.title" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="模板描述"
|
||||
name="description"
|
||||
>
|
||||
<UTextarea v-model="pptCreateState.description" />
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="模板分类"
|
||||
name="type"
|
||||
>
|
||||
<USelectMenu
|
||||
v-model="pptCreateState.type"
|
||||
value-attribute="value"
|
||||
option-attribute="label"
|
||||
searchable
|
||||
searchable-placeholder="搜索现有分类..."
|
||||
:options="selectMenuOptions"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="预览图"
|
||||
name="preview_url"
|
||||
>
|
||||
<UniFileDnD
|
||||
@change="onFileSelect($event, 'preview')"
|
||||
accept="image/png,image/jpeg"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="PPT 文件"
|
||||
name="file_url"
|
||||
>
|
||||
<UniFileDnD
|
||||
@change="onFileSelect($event, 'ppt')"
|
||||
accept="application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||
/>
|
||||
</UFormGroup>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<UButton
|
||||
label="创建"
|
||||
color="primary"
|
||||
type="submit"
|
||||
/>
|
||||
</div>
|
||||
</UForm>
|
||||
</UCard>
|
||||
</USlideover>
|
||||
<USlideover v-model="isCatSlideOpen">
|
||||
<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="tabler:x"
|
||||
padded
|
||||
size="sm"
|
||||
square
|
||||
variant="ghost"
|
||||
@click="isCatSlideOpen = false"
|
||||
/>
|
||||
PPT 模板分类管理
|
||||
</template>
|
||||
|
||||
<div class="space-y-4">
|
||||
<UFormGroup label="创建分类">
|
||||
<UButtonGroup
|
||||
orientation="horizontal"
|
||||
class="w-full"
|
||||
size="lg"
|
||||
>
|
||||
<UInput
|
||||
class="flex-1"
|
||||
placeholder="分类名称"
|
||||
v-model="createCatInput"
|
||||
/>
|
||||
<UButton
|
||||
icon="tabler:plus"
|
||||
color="gray"
|
||||
label="创建"
|
||||
:disabled="!createCatInput"
|
||||
@click="onCreateCat"
|
||||
/>
|
||||
</UButtonGroup>
|
||||
</UFormGroup>
|
||||
<div class="border dark:border-neutral-700 rounded-md">
|
||||
<UTable
|
||||
:columns="[
|
||||
{ key: 'id', label: 'ID' },
|
||||
{ key: 'type', label: '分类' },
|
||||
{ key: 'create_time', label: '创建时间' },
|
||||
{ key: 'actions' },
|
||||
]"
|
||||
:rows="pptCategories?.data.items"
|
||||
>
|
||||
<template #create_time-data="{ row }">
|
||||
{{
|
||||
dayjs(row.create_time * 1000).format('YYYY-MM-DD HH:mm:ss')
|
||||
}}
|
||||
</template>
|
||||
<template #actions-data="{ row }">
|
||||
<UButton
|
||||
color="red"
|
||||
icon="tabler:trash"
|
||||
size="xs"
|
||||
variant="soft"
|
||||
@click="onDeleteCat(row)"
|
||||
/>
|
||||
</template>
|
||||
</UTable>
|
||||
</div>
|
||||
</div>
|
||||
</UCard>
|
||||
</USlideover>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user