2025-11-11 11:58:59 +08:00
|
|
|
import React, { useRef, useState } from 'react';
|
|
|
|
|
import { PageContainer, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
|
|
|
|
import { message } from 'antd';
|
2025-09-23 10:32:35 +08:00
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
|
|
|
|
import { ordersApi } from '@/services/orders';
|
2025-11-11 11:58:59 +08:00
|
|
|
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
|
|
|
|
import VideoTemplateTable, { VideoTemplateTableRef } from './components/VideoTemplateTable';
|
|
|
|
|
import VideoTemplateForm, { VideoTemplateFormValues, STATUS_OPTIONS } from './components/VideoTemplateForm';
|
2025-09-23 10:32:35 +08:00
|
|
|
|
|
|
|
|
const VideoTemplatePage: React.FC = () => {
|
2025-11-11 11:58:59 +08:00
|
|
|
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);
|
2025-09-23 10:32:35 +08:00
|
|
|
|
2025-11-11 11:58:59 +08:00
|
|
|
// 处理新增
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-09-23 10:32:35 +08:00
|
|
|
|
|
|
|
|
return (
|
2025-11-11 11:58:59 +08:00
|
|
|
<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
|
|
|
|
|
/>
|
2025-09-23 10:32:35 +08:00
|
|
|
</SearchBarPlus>
|
|
|
|
|
|
2025-11-11 11:58:59 +08:00
|
|
|
<ActionBar
|
|
|
|
|
left={
|
|
|
|
|
<GradientButton
|
|
|
|
|
size="middle"
|
|
|
|
|
type="primary"
|
|
|
|
|
icon={<PlusOutlined />}
|
|
|
|
|
onClick={() => setCreateOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
新增模板
|
|
|
|
|
</GradientButton>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2025-09-23 10:32:35 +08:00
|
|
|
|
2025-11-11 11:58:59 +08:00
|
|
|
<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 || {}}
|
2025-09-23 10:32:35 +08:00
|
|
|
/>
|
|
|
|
|
</PageContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default VideoTemplatePage;
|
|
|
|
|
|