feat: 1:视频剪辑模板管理

2:视频剪辑任务管理
      3:设备管理
This commit is contained in:
2025-11-11 11:58:59 +08:00
parent 3b4e8eb02c
commit 5e7f983624
16 changed files with 814 additions and 109 deletions
@@ -29,8 +29,13 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
const formRef = useRef<any>();
useEffect(() => {
if (initialValues) formRef.current?.setFieldsValue(initialValues);
}, [initialValues]);
if (visible && initialValues) {
// 延迟设置,确保表单已经渲染
setTimeout(() => {
formRef.current?.setFieldsValue(initialValues);
}, 0);
}
}, [visible, initialValues]);
return (
<ModalForm<DeviceFormValues>
@@ -40,6 +45,7 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
onVisibleChange={onVisibleChange}
onFinish={onFinish}
modalProps={{ destroyOnClose: true }}
initialValues={initialValues} // 同时设置 initialValues 属性
>
<ProForm.Group>
<ProFormText name="deviceSn" label="设备序列号" rules={[{ required: true, message: '请输入设备序列号' }]} width="md" />
@@ -47,7 +53,7 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
<ProFormText name="nickname" label="昵称" width="md" />
<ProFormSelect name="deviceType" label="设备类型" options={DEVICE_TYPE_OPTIONS} width="md" />
<ProFormText name="firmwareVersion" label="固件版本" width="md" />
<ProFormTextArea name="remark" label="备注" width="lg" />
<ProFormTextArea name="deviceDesc" label="备注" width="lg" />
</ProForm.Group>
</ModalForm>
);
@@ -1,7 +1,7 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
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, Switch } from 'antd';
import { Space } from 'antd';
import { deviceApi } from '@/services/device';
export interface DeviceTableRef { reload: () => void }
@@ -16,14 +16,36 @@ const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEd
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
// 当查询参数变化时,自动重置到第一页
useEffect(() => {
if (actionRef.current) {
// 重置页码到第一页
actionRef.current.setPageInfo?.({ current: 1 });
// 重新加载数据
actionRef.current.reload();
}
}, [JSON.stringify(params)]); // 使用JSON.stringify确保对象内容变化时触发
// 设备类型映射
const deviceTypeMap: Record<number, string> = {
1: '机场',
2: '无人机',
3: '遥控器',
};
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48, fixed: 'left' },
{ title: '设备序列号', dataIndex: 'deviceSn', copyable: true, fixed: 'left', width: 160 },
{ title: '设备名称', dataIndex: 'deviceName' },
{ title: '昵称', dataIndex: 'nickname' },
{ title: '设备类型', dataIndex: 'deviceType' },
{ title: '固件版本', dataIndex: 'firmwareVersion' },
{ title: '绑定状态', dataIndex: 'boundStatus', render: (_, r) => <Switch checked={r.boundStatus === 1} disabled /> },
{
title: '设备类型',
dataIndex: 'deviceType',
render: (_, record) => deviceTypeMap[record.deviceType] || record.deviceType
},
{ title: '备注', dataIndex: 'deviceDesc' },
// { title: '固件版本', dataIndex: 'firmwareVersion' }, // 隐藏固件版本
// { title: '绑定状态', dataIndex: 'boundStatus', render: (_, r) => <Switch checked={r.boundStatus === 1} disabled /> }, // 隐藏绑定状态
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作', key: 'action', valueType: 'option', width: 140, fixed: 'right',
@@ -50,7 +50,7 @@ const DevicePage: React.FC = () => {
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await deviceApi.deleteDevice(record.deviceSn);
await deviceApi.deleteDevice(record.id);
message.success('删除成功');
tableRef.current?.reload();
} catch (e) {
@@ -64,12 +64,12 @@ const DevicePage: React.FC = () => {
return (
<PageContainer header={{ title: '设备管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} showTenant={false} onFinish={async (values) => setQuery(values)}>
<ProFormText name="deviceSn" label="设备序列号" />
<ProFormText name="deviceName" label="设备名称" />
<ProFormSelect name="deviceType" label="设备类型" options={[
{ label: '无人机', value: 1 },
{ label: '地面站', value: 2 },
{ label: '机场', value: 1 },
{ label: '无人机', value: 2 },
{ label: '遥控器', value: 3 },
]} />
</SearchBarPlus>
@@ -86,7 +86,16 @@ const DevicePage: React.FC = () => {
</GlassCard>
<DeviceForm title="新增设备" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
<DeviceForm title="编辑设备" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
<DeviceForm
title="编辑设备"
visible={editOpen}
onVisibleChange={(v) => {
setEditOpen(v);
if (!v) setCurrent(null); // 关闭时清空当前编辑数据
}}
onFinish={edit}
initialValues={current || {}}
/>
</PageContainer>
);
};
@@ -22,6 +22,18 @@ interface WaylineFormProps {
initialValues?: Partial<WaylineFormValues>;
}
/**
* 校验文件名是否合法
* 只允许字母、数字和下划线
*/
function validateFileName(fileName: string): boolean {
// 获取不带扩展名的文件名
const nameWithoutExtension = fileName.substring(0, fileName.lastIndexOf('.')) || fileName;
// 正则表达式:只允许字母、数字和下划线
const regex = /^[a-zA-Z0-9_]+$/;
return regex.test(nameWithoutExtension);
}
/**
* 计算文件的 MD5 值
*/
@@ -127,6 +139,13 @@ const WaylineForm: React.FC<WaylineFormProps> = ({ title, visible, onVisibleChan
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
// 校验文件名
if (!validateFileName(file.name)) {
message.error('文件名不合法!只允许使用字母、数字和下划线');
onError?.(new Error('文件名不合法'));
return;
}
// 计算文件 MD5
const md5 = await calculateFileMD5(file);
@@ -1,25 +1,129 @@
import React, { useState } from 'react';
import { PageContainer, ProFormText, ProTable, ProFormSelect } from '@ant-design/pro-components';
import { Popconfirm, Space, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer, ProFormText, ProTable, ProFormSelect, ProFormTextArea, ActionType, ModalForm, ProForm } from '@ant-design/pro-components';
import { Popconfirm, Space, message, Modal } from 'antd';
import { ordersApi } from '@/services/orders';
import { ActionBar, GradientButton, SearchBarPlus } from '@/components/ui';
import { SearchBarPlus, GlassCard } from '@/components/ui';
const EditTaskPage: React.FC = () => {
const [params, setParams] = useState<Record<string, any>>({});
const [editVisible, setEditVisible] = useState(false);
const [currentTask, setCurrentTask] = useState<any>(null);
const actionRef = useRef<ActionType>();
// 当查询参数变化时,自动重置到第一页
useEffect(() => {
if (actionRef.current) {
// 重置页码到第一页
actionRef.current.setPageInfo?.({ current: 1 });
// 重新加载数据
actionRef.current.reload();
}
}, [JSON.stringify(params)]); // 使用JSON.stringify确保对象内容变化时触发
// 处理创建编辑任务
const handleGenerateEditTask = async (orderSn: string) => {
Modal.confirm({
title: '确认创建编辑任务',
content: `确定为订单 ${orderSn} 创建编辑任务吗?`,
onOk: async () => {
const hide = message.loading('正在创建编辑任务...');
try {
// 直接传递 orderSn 字符串,或根据实际 API 需要调整参数格式
const result = await ordersApi.generateEditTask(orderSn as any);
// 检查响应结果
if (result && result.resp_code === 0) {
message.success('编辑任务创建成功');
actionRef.current?.reload();
} else {
// 显示后端返回的错误信息
message.error(result?.resp_msg || '创建编辑任务失败');
}
} catch (error: any) {
// 处理异常情况
message.error(error?.message || '创建编辑任务失败');
} finally {
hide();
}
},
});
};
// 处理编辑
const handleEdit = async (values: any) => {
const hide = message.loading('正在保存...');
try {
await ordersApi.saveOrUpdateEditTask({
...currentTask,
...values,
});
message.success('修改成功');
actionRef.current?.reload();
return true;
} catch (error) {
message.error('修改失败');
return false;
} finally {
hide();
}
};
const columns: any[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '任务ID', dataIndex: 'id' },
{ title: '订单号', dataIndex: 'orderNo' },
{ title: '状态', dataIndex: 'status' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime' },
{ title: '任务ID', dataIndex: 'id', width: 120 },
{ title: '用户ID', dataIndex: 'userId', width: 120 },
{ title: '订单号', dataIndex: 'orderSn', width: 180, copyable: true },
{ title: '任务id', dataIndex: 'jobId', width: 180, copyable: true },
{
title: '操作', key: 'action',
title: '状态',
dataIndex: 'status',
width: 120,
valueEnum: {
0: { text: '待处理', status: 'Default' },
1: { text: '处理中', status: 'Processing' },
2: { text: '完成', status: 'Success' },
3: { text: '失败', status: 'Error' },
}
},
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{ title: '更新时间', dataIndex: 'updateTime', valueType: 'dateTime', width: 180 },
{
title: '操作',
key: 'action',
width: 240,
render: (_: any, record: any) => (
<Space>
<Popconfirm title="确认删除?" onConfirm={async () => { try { await ordersApi.deleteEditTask(record.id); message.success('删除成功'); } catch { message.error('删除失败'); } }}>
<a style={{ color: '#1677ff' }}>删除</a>
<a onClick={() => {
setCurrentTask(record);
setEditVisible(true);
}}>
编辑
</a>
{/* 只有状态为3(失败)时显示创建编辑任务按钮 */}
{record.status === 3 && (
<a
style={{ color: '#52c41a' }}
onClick={() => handleGenerateEditTask(record.orderSn)}
>
创建编辑任务
</a>
)}
<Popconfirm
title="确认删除?"
onConfirm={async () => {
const hide = message.loading('正在删除...');
try {
await ordersApi.deleteEditTask(record.id);
message.success('删除成功');
actionRef.current?.reload();
} catch {
message.error('删除失败');
} finally {
hide();
}
}}
>
<a style={{ color: '#ff4d4f' }}>删除</a>
</Popconfirm>
</Space>
)
@@ -27,39 +131,114 @@ const EditTaskPage: React.FC = () => {
];
return (
<PageContainer header={{ title: '剪辑任务' }}>
<PageContainer header={{ title: '剪辑任务管理' }}>
<SearchBarPlus
defaultCollapsed={false}
split
span={8}
onTenantChanged={() => { /* 后端上下文 */ }}
onFinish={async (values) => setParams(values)}
showTenant={false}
onTenantChanged={() => actionRef.current?.reload()}
onFinish={async (values) => {
setParams(values);
// useEffect 会自动触发重置页码并刷新
}}
>
<ProFormText name="orderNo" label="订单号" />
<ProFormSelect name="status" label="状态" valueEnum={{ pending: '待处理', processing: '处理中', done: '完成' }} />
<ProFormText
name="orderSn"
label="订单号"
placeholder="请输入订单号"
/>
<ProFormSelect
name="status"
label="状态"
placeholder="请选择状态"
options={[
{ label: '待处理', value: 0 },
{ label: '处理中', value: 1 },
{ label: '完成', value: 2 },
{ label: '失败', value: 3 }
]}
/>
</SearchBarPlus>
<ActionBar
left={
<Space>
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={async () => {
const hide = message.loading('提交中...');
try { await ordersApi.saveOrUpdateEditTask({ orderNo: 'DEMO' }); message.success('新增成功'); } catch { message.error('新增失败'); } finally { hide(); }
}}>新增</GradientButton>
</Space>
}
/>
<GlassCard>
<ProTable<any>
rowKey="id"
actionRef={actionRef}
request={async (p) => {
const { current, pageSize, ...rest } = p;
const result = await ordersApi.getEditTaskList({
page: current,
limit: pageSize,
...params,
...rest
} as any);
return {
data: result.data || [],
success: true,
total: result.total || 0,
};
}}
columns={columns}
search={false}
pagination={{
showSizeChanger: true,
showQuickJumper: true
}}
headerTitle="剪辑任务列表"
/>
</GlassCard>
<ProTable<any>
rowKey="id"
request={(p) => ordersApi.getEditTaskList({ ...p, ...params } as any)}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
{/* 编辑表单 */}
<ModalForm
title="编辑剪辑任务"
visible={editVisible}
onVisibleChange={(v) => {
setEditVisible(v);
if (!v) setCurrentTask(null);
}}
onFinish={handleEdit}
initialValues={currentTask}
modalProps={{
destroyOnClose: true,
maskClosable: false,
}}
width={600}
>
<ProForm.Group>
<ProFormText
name="orderSn"
label="订单号"
width="md"
disabled
placeholder="订单号"
/>
<ProFormSelect
name="status"
label="状态"
width="md"
options={[
{ label: '待处理', value: 0 },
{ label: '处理中', value: 1 },
{ label: '完成', value: 2 },
{ label: '失败', value: 3 },
]}
rules={[{ required: true, message: '请选择状态' }]}
/>
</ProForm.Group>
<ProFormTextArea
name="remark"
label="备注"
placeholder="请输入备注信息"
fieldProps={{
rows: 4,
maxLength: 500,
showCount: true,
}}
/>
</ModalForm>
</PageContainer>
);
};
export default EditTaskPage;
@@ -63,11 +63,11 @@ const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, init
// 景区素材类型字典(按业务提供)
const TYPE_LABEL: Record<number, string> = {
5: '视频',
6: '首页 Banner',
4: '展示图片',
3: '景区详情',
2: '景区小图展示',
5: '景区视频',
6: '景区订单展示图',
4: '展示大图',
3: '拍照引导图',
2: '拍照角度展示图',
1: '活动',
};
const typeName = (t: any) => TYPE_LABEL[Number(t)] || '其他';
@@ -12,12 +12,13 @@ export interface TourismItem {
longitude?: string;
latitude?: string;
showInHomepage?: number; // 1 是,0 否
description?: string;
tourismDesc?: string;
}
export interface TourismFormProps {
open: boolean;
title: string;
initialValues?: Partial<TourismItem>;
onOpenChange: (v: boolean) => void;
onFinish: (values: TourismItem) => Promise<boolean>;
@@ -64,7 +65,7 @@ const TourismForm: React.FC<TourismFormProps> = ({ open, title, initialValues, o
]}
initialValue={1}
/>
<ProFormTextArea name="description" label="描述" />
<ProFormTextArea name="tourismDesc" label="描述" />
</ModalForm>
);
};
@@ -23,11 +23,11 @@ export interface TourismFileFormProps {
}
const TYPE_OPTIONS = [
{ label: '视频', value: 5 },
{ label: '首页 Banner', value: 6 },
{ label: '展示图片', value: 4 },
{ label: '景区详情', value: 3 },
{ label: '景区小图展示', value: 2 },
{ label: '景区视频', value: 5 },
{ label: '景区订单展示图', value: 6 },
{ label: '展示大图', value: 4 },
{ label: '拍照引导图', value: 3 },
{ label: '拍照角度展示图', value: 2 },
{ label: '活动', value: 1 },
] as const;
@@ -8,11 +8,11 @@ import TourismFileForm, { TourismFileItem } from './components/TourismFileForm';
// 资源类型枚举(用于卡片展示的颜色)
const TYPE_OPTIONS = [
{ label: '视频', value: 5, color: '#f5222d' },
{ label: '首页 Banner', value: 6, color: '#2f54eb' },
{ label: '展示图片', value: 4, color: '#52c41a' },
{ label: '景区详情', value: 3, color: '#722ed1' },
{ label: '景区小图展示', value: 2, color: '#13c2c2' },
{ label: '景区视频', value: 5, color: '#f5222d' },
{ label: '景区订单展示图', value: 6, color: '#2f54eb' },
{ label: '展示大图', value: 4, color: '#52c41a' },
{ label: '拍照引导图', value: 3, color: '#722ed1' },
{ label: '拍照角度展示图', value: 2, color: '#13c2c2' },
{ label: '活动', value: 1, color: '#1890ff' },
] as const;
@@ -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;
@@ -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>
);