feat: 1:视频剪辑模板管理
2:视频剪辑任务管理
3:设备管理
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user