feat: 1:视频剪辑模板管理
2:视频剪辑任务管理
3:设备管理
This commit is contained in:
+182
@@ -0,0 +1,182 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProForm,
|
||||
ProFormText,
|
||||
ProFormTextArea,
|
||||
ProFormSelect,
|
||||
} from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
|
||||
export const STATUS_OPTIONS = [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
];
|
||||
|
||||
export type VideoTemplateFormValues = {
|
||||
id?: number;
|
||||
templateId?: string;
|
||||
templateName?: string;
|
||||
name?: string; // 兼容旧字段
|
||||
description?: string;
|
||||
config?: string;
|
||||
status?: number;
|
||||
};
|
||||
|
||||
interface VideoTemplateFormProps {
|
||||
title: string;
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
onFinish: (values: VideoTemplateFormValues) => Promise<boolean>;
|
||||
initialValues?: Partial<VideoTemplateFormValues>;
|
||||
}
|
||||
|
||||
const VideoTemplateForm: React.FC<VideoTemplateFormProps> = ({
|
||||
title,
|
||||
visible,
|
||||
onVisibleChange,
|
||||
onFinish,
|
||||
initialValues,
|
||||
}) => {
|
||||
const formRef = useRef<any>();
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && initialValues) {
|
||||
// 延迟设置,确保表单已经渲染
|
||||
setTimeout(() => {
|
||||
// 处理字段兼容性
|
||||
const values = {
|
||||
...initialValues,
|
||||
templateName: initialValues.templateName || initialValues.name,
|
||||
config: initialValues.config || '{}', // 确保config有默认值
|
||||
};
|
||||
formRef.current?.setFieldsValue(values);
|
||||
}, 0);
|
||||
}
|
||||
}, [visible, initialValues]);
|
||||
|
||||
const handleFinish = async (values: VideoTemplateFormValues) => {
|
||||
try {
|
||||
// 确保兼容性
|
||||
const submitValues = {
|
||||
...values,
|
||||
name: values.templateName, // 同时设置name字段
|
||||
};
|
||||
const result = await onFinish(submitValues);
|
||||
return result;
|
||||
} catch (error) {
|
||||
message.error('操作失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm<VideoTemplateFormValues>
|
||||
title={title}
|
||||
width={800}
|
||||
visible={visible}
|
||||
formRef={formRef}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={handleFinish}
|
||||
initialValues={{
|
||||
status: 1, // 默认启用
|
||||
config: '{}', // 默认空JSON对象
|
||||
...initialValues,
|
||||
}}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
}}
|
||||
>
|
||||
<ProForm.Group title="基本信息">
|
||||
<ProFormText
|
||||
name="templateId"
|
||||
label="模板ID"
|
||||
width="md"
|
||||
placeholder="请输入模板ID"
|
||||
rules={[
|
||||
{ required: true, message: '请输入模板ID' },
|
||||
{
|
||||
pattern: /^[a-zA-Z0-9_-]+$/,
|
||||
message: '模板ID只能包含字母、数字、下划线和横线'
|
||||
}
|
||||
]}
|
||||
/>
|
||||
<ProFormText
|
||||
name="templateName"
|
||||
label="模板名称"
|
||||
width="md"
|
||||
placeholder="请输入模板名称"
|
||||
rules={[
|
||||
{ required: true, message: '请输入模板名称' },
|
||||
{ max: 50, message: '模板名称不能超过50个字符' }
|
||||
]}
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
width="md"
|
||||
options={STATUS_OPTIONS}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group title="详细配置">
|
||||
<ProFormTextArea
|
||||
name="description"
|
||||
label="模板描述"
|
||||
width="xl"
|
||||
placeholder="请输入模板描述"
|
||||
fieldProps={{
|
||||
rows: 4,
|
||||
maxLength: 200,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
<ProFormTextArea
|
||||
name="config"
|
||||
label="模板配置"
|
||||
width="xl"
|
||||
placeholder='请输入JSON格式的模板配置,例如: {"key": "value"}'
|
||||
tooltip="请输入有效的JSON格式配置,默认为空对象 {}"
|
||||
fieldProps={{
|
||||
rows: 8,
|
||||
maxLength: 2000,
|
||||
showCount: true,
|
||||
style: { fontFamily: 'monospace' },
|
||||
onBlur: (e) => {
|
||||
// 格式化JSON
|
||||
const value = e.target.value;
|
||||
if (value) {
|
||||
try {
|
||||
const json = JSON.parse(value);
|
||||
const formatted = JSON.stringify(json, null, 2);
|
||||
formRef.current?.setFieldValue('config', formatted);
|
||||
} catch (error) {
|
||||
// 格式化失败,保持原样
|
||||
}
|
||||
}
|
||||
},
|
||||
}}
|
||||
rules={[
|
||||
{ required: true, message: '请输入模板配置' },
|
||||
{
|
||||
validator: async (_, value) => {
|
||||
if (value) {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
} catch (error) {
|
||||
throw new Error('请输入有效的JSON格式');
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</ProForm.Group>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default VideoTemplateForm;
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
import React, { forwardRef, useImperativeHandle, useRef, useEffect } from 'react';
|
||||
import { ProTable } from '@ant-design/pro-components';
|
||||
import type { ProColumns, ActionType } from '@ant-design/pro-components';
|
||||
import { Space, Tag, Typography, Modal, message } from 'antd';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
|
||||
const { Link } = Typography;
|
||||
|
||||
export interface VideoTemplateTableRef {
|
||||
reload: () => void;
|
||||
reloadAndReset: () => void; // 重新加载并重置页码
|
||||
}
|
||||
|
||||
interface VideoTemplateTableProps {
|
||||
params?: Record<string, any>;
|
||||
onEdit?: (record: any) => void;
|
||||
onStatusChange?: (record: any, status: number) => void;
|
||||
}
|
||||
|
||||
const VideoTemplateTable = forwardRef<VideoTemplateTableRef, VideoTemplateTableProps>(
|
||||
({ params, onEdit, onStatusChange }, ref) => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
reload: () => actionRef.current?.reload(),
|
||||
reloadAndReset: () => {
|
||||
// 重置到第一页并重新加载
|
||||
if (actionRef.current) {
|
||||
actionRef.current.setPageInfo?.({ current: 1 });
|
||||
actionRef.current.reload();
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
// 当查询参数变化时,自动重置到第一页
|
||||
useEffect(() => {
|
||||
if (actionRef.current) {
|
||||
// 重置页码到第一页
|
||||
actionRef.current.setPageInfo?.({ current: 1 });
|
||||
// 重新加载数据
|
||||
actionRef.current.reload();
|
||||
}
|
||||
}, [JSON.stringify(params)]); // 使用JSON.stringify确保对象内容变化时触发
|
||||
|
||||
// 处理删除
|
||||
const handleDelete = async (record: any) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除模板[${record.templateName || record.name}]吗?`,
|
||||
onOk: async () => {
|
||||
const hide = message.loading('正在删除...');
|
||||
try {
|
||||
await ordersApi.deleteVideoTemplate(record.id);
|
||||
message.success('删除成功');
|
||||
actionRef.current?.reload();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 处理状态更新
|
||||
const handleStatusChange = async (record: any) => {
|
||||
const newStatus = record.status === 1 ? 0 : 1;
|
||||
const statusText = newStatus === 1 ? '启用' : '禁用';
|
||||
|
||||
Modal.confirm({
|
||||
title: '确认操作',
|
||||
content: `确定要${statusText}该模板吗?`,
|
||||
onOk: async () => {
|
||||
const hide = message.loading('正在更新...');
|
||||
try {
|
||||
await ordersApi.updateVideoTemplateStatus(record.id, newStatus);
|
||||
message.success('状态更新成功');
|
||||
onStatusChange?.(record, newStatus);
|
||||
actionRef.current?.reload();
|
||||
} catch (error) {
|
||||
message.error('状态更新失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const columns: ProColumns<any>[] = [
|
||||
{
|
||||
dataIndex: 'index',
|
||||
valueType: 'indexBorder',
|
||||
width: 48,
|
||||
fixed: 'left',
|
||||
},
|
||||
{
|
||||
title: '模板ID',
|
||||
dataIndex: 'templateId',
|
||||
width: 180,
|
||||
ellipsis: true,
|
||||
copyable: true,
|
||||
},
|
||||
{
|
||||
title: '模板名称',
|
||||
dataIndex: 'templateName',
|
||||
width: 180,
|
||||
render: (text, record) => text || record.name,
|
||||
},
|
||||
{
|
||||
title: '模板配置',
|
||||
dataIndex: 'config',
|
||||
width: 200,
|
||||
ellipsis: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (_, record) => (
|
||||
<Tag color={record.status === 1 ? 'success' : 'default'}>
|
||||
{record.status === 1 ? '启用' : '禁用'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
width: 180,
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
width: 180,
|
||||
valueType: 'dateTime',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
valueType: 'option',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Link onClick={() => onEdit?.(record)}>编辑</Link>
|
||||
<Link onClick={() => handleStatusChange(record)}>
|
||||
{record.status === 1 ? '禁用' : '启用'}
|
||||
</Link>
|
||||
<Link style={{ color: '#ff4d4f' }} onClick={() => handleDelete(record)}>
|
||||
删除
|
||||
</Link>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<ProTable<any>
|
||||
rowKey="id"
|
||||
headerTitle="视频模板列表"
|
||||
actionRef={actionRef}
|
||||
request={async (p) => {
|
||||
const { current, pageSize, ...rest } = p;
|
||||
const result = await ordersApi.getVideoTemplateList({
|
||||
page: current,
|
||||
limit: pageSize,
|
||||
...params,
|
||||
...rest,
|
||||
} as any);
|
||||
return {
|
||||
data: result.data || [],
|
||||
success: true,
|
||||
total: result.total || 0,
|
||||
};
|
||||
}}
|
||||
columns={columns}
|
||||
search={false}
|
||||
scroll={{ x: 1200 }}
|
||||
pagination={{
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default VideoTemplateTable;
|
||||
@@ -1,48 +1,128 @@
|
||||
import React, { useState } from 'react';
|
||||
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
|
||||
import { Space, Switch, message } from 'antd';
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { PageContainer, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||
import { message } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import VideoTemplateTable, { VideoTemplateTableRef } from './components/VideoTemplateTable';
|
||||
import VideoTemplateForm, { VideoTemplateFormValues, STATUS_OPTIONS } from './components/VideoTemplateForm';
|
||||
|
||||
const VideoTemplatePage: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
const tableRef = useRef<VideoTemplateTableRef>(null);
|
||||
const [query, setQuery] = useState<Record<string, any>>({});
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<any | null>(null);
|
||||
|
||||
const columns: any[] = [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||
{ title: '模板名称', dataIndex: 'name' },
|
||||
{ title: '描述', dataIndex: 'description' },
|
||||
{ title: '状态', dataIndex: 'status', render: (v: number, r: any) => <Switch checked={v === 1} onChange={(c) => ordersApi.updateVideoTemplateStatus(r.id, c ? 1 : 0)} /> },
|
||||
{
|
||||
title: '操作', key: 'action',
|
||||
render: (_: any, record: any) => (
|
||||
<Space>
|
||||
<a onClick={async () => { message.info('演示环境暂不提供修改参数'); }}>编辑</a>
|
||||
<a style={{ color: '#1677ff' }} onClick={async () => { try { await ordersApi.deleteVideoTemplate(record.id); message.success('删除成功'); } catch { message.error('删除失败'); } }}>删除</a>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
];
|
||||
// 处理新增
|
||||
const handleAdd = async (values: VideoTemplateFormValues) => {
|
||||
const hide = message.loading('正在保存...');
|
||||
try {
|
||||
await ordersApi.saveVideoTemplate(values as any);
|
||||
message.success('新增成功');
|
||||
tableRef.current?.reload();
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('新增失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
const handleEdit = async (values: VideoTemplateFormValues) => {
|
||||
const hide = message.loading('正在保存...');
|
||||
try {
|
||||
await ordersApi.updateVideoTemplate({
|
||||
...current,
|
||||
...values,
|
||||
} as any);
|
||||
message.success('修改成功');
|
||||
tableRef.current?.reload();
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error('修改失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '视频模板' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => { /* 租户切换 */ }} onFinish={async (values) => setParams(values)}>
|
||||
<ProFormText name="name" label="模板名称" />
|
||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} allowClear />
|
||||
<PageContainer header={{ title: '视频模板管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed
|
||||
split
|
||||
span={8}
|
||||
showTenant={false}
|
||||
onTenantChanged={() => tableRef.current?.reload()}
|
||||
onFinish={async (values) => {
|
||||
setQuery(values);
|
||||
// params变化会触发表格组件内部的useEffect,自动重置页码并刷新
|
||||
}}
|
||||
>
|
||||
<ProFormText
|
||||
name="templateName"
|
||||
label="模板名称"
|
||||
placeholder="请输入模板名称"
|
||||
/>
|
||||
<ProFormText
|
||||
name="templateId"
|
||||
label="模板ID"
|
||||
placeholder="请输入模板ID"
|
||||
/>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
options={STATUS_OPTIONS}
|
||||
placeholder="请选择状态"
|
||||
allowClear
|
||||
/>
|
||||
</SearchBarPlus>
|
||||
|
||||
<ActionBar left={<GradientButton size="middle" type="primary" onClick={async () => {
|
||||
const hide = message.loading('保存中...');
|
||||
try { await ordersApi.saveVideoTemplate({ name: '新模板', status: 1 }); message.success('新增成功'); }
|
||||
catch { message.error('新增失败'); } finally { hide(); }
|
||||
}}><PlusOutlined /> 新增</GradientButton>} />
|
||||
<ActionBar
|
||||
left={
|
||||
<GradientButton
|
||||
size="middle"
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => setCreateOpen(true)}
|
||||
>
|
||||
新增模板
|
||||
</GradientButton>
|
||||
}
|
||||
/>
|
||||
|
||||
<ProTable<any>
|
||||
rowKey="id"
|
||||
request={(p) => ordersApi.getVideoTemplateList({ ...p, ...params } as any)}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||
<GlassCard>
|
||||
<VideoTemplateTable
|
||||
ref={tableRef}
|
||||
params={query}
|
||||
onEdit={(record) => {
|
||||
setCurrent(record);
|
||||
setEditOpen(true);
|
||||
}}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
{/* 新增表单 */}
|
||||
<VideoTemplateForm
|
||||
title="新增视频模板"
|
||||
visible={createOpen}
|
||||
onVisibleChange={setCreateOpen}
|
||||
onFinish={handleAdd}
|
||||
/>
|
||||
|
||||
{/* 编辑表单 */}
|
||||
<VideoTemplateForm
|
||||
title="编辑视频模板"
|
||||
visible={editOpen}
|
||||
onVisibleChange={(v) => {
|
||||
setEditOpen(v);
|
||||
if (!v) setCurrent(null); // 关闭时清空当前编辑数据
|
||||
}}
|
||||
onFinish={handleEdit}
|
||||
initialValues={current || {}}
|
||||
/>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user