feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件

This commit is contained in:
2025-09-23 10:32:35 +08:00
parent 10ddfd6f75
commit 408b500b6a
199 changed files with 16850 additions and 34874 deletions
@@ -0,0 +1,56 @@
import React, { useEffect, useRef } from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-components';
export type DeviceFormValues = {
id?: number;
deviceSn?: string;
deviceName?: string;
nickname?: string;
deviceType?: number;
firmwareVersion?: string;
remark?: string;
};
interface DeviceFormProps {
title: string;
visible: boolean;
onVisibleChange: (v: boolean) => void;
onFinish: (values: DeviceFormValues) => Promise<boolean>;
initialValues?: Partial<DeviceFormValues>;
}
const DEVICE_TYPE_OPTIONS = [
{ label: '机场', value: 1 },
{ label: '无人机', value: 2 },
{ label: '遥控器', value: 3 },
];
const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange, onFinish, initialValues }) => {
const formRef = useRef<any>();
useEffect(() => {
if (initialValues) formRef.current?.setFieldsValue(initialValues);
}, [initialValues]);
return (
<ModalForm<DeviceFormValues>
title={title}
visible={visible}
formRef={formRef}
onVisibleChange={onVisibleChange}
onFinish={onFinish}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText name="deviceSn" label="设备序列号" rules={[{ required: true, message: '请输入设备序列号' }]} width="md" />
<ProFormText name="deviceName" label="设备名称" rules={[{ required: true, message: '请输入设备名称' }]} width="md" />
<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" />
</ProForm.Group>
</ModalForm>
);
};
export default DeviceForm;
@@ -0,0 +1,53 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import { ProTable } from '@ant-design/pro-components';
import type { ProColumns, ActionType } from '@ant-design/pro-components';
import { Space, Switch } from 'antd';
import { deviceApi } from '@/services/device';
export interface DeviceTableRef { reload: () => void }
interface DeviceTableProps {
params?: Record<string, any>;
onEdit?: (record: any) => void;
onDelete?: (record: any) => void;
}
const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEdit, onDelete }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
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: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '操作', key: 'action', valueType: 'option', width: 140, fixed: 'right',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
</Space>
)
},
];
return (
<ProTable<any>
rowKey="id"
headerTitle="设备列表"
actionRef={actionRef}
request={(p) => deviceApi.deviceList({ page: p.current, limit: p.pageSize, ...params })}
columns={columns}
search={false}
scroll={{ x: 1000 }}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
);
});
export default DeviceTable;
@@ -0,0 +1,95 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Modal, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
import DeviceTable, { DeviceTableRef } from './components/DeviceTable';
import DeviceForm, { DeviceFormValues } from './components/DeviceForm';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
const DevicePage: React.FC = () => {
const tableRef = useRef<DeviceTableRef>(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 add = async (values: DeviceFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateDevice(values as any);
message.success('新增成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('新增失败');
return false;
} finally {
hide();
}
};
const edit = async (values: DeviceFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateDevice({ ...(current || {}), ...values } as any);
message.success('修改成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally {
hide();
}
};
const del = async (record: any) => {
Modal.confirm({
title: `确认删除设备[${record.deviceName || record.deviceSn}]?`,
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await deviceApi.deleteDevice(record.deviceSn);
message.success('删除成功');
tableRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally {
hide();
}
},
});
};
return (
<PageContainer header={{ title: '设备管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} 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: 3 },
]} />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<DeviceTable
ref={tableRef}
params={query}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={(r) => del(r)}
/>
</GlassCard>
<DeviceForm title="新增设备" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
<DeviceForm title="编辑设备" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
</PageContainer>
);
};
export default DevicePage;
@@ -0,0 +1,113 @@
import React, { useEffect, useRef, useState } from 'react';
import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
import { Button, Upload, message } from 'antd';
import { UploadOutlined } from '@ant-design/icons';
export type WaylineFormValues = {
id?: number;
name?: string;
workspaceId?: string;
waylineId?: string;
sign?: string;
};
interface WaylineFormProps {
title: string;
visible: boolean;
onVisibleChange: (v: boolean) => void;
onFinish: (values: WaylineFormValues) => Promise<boolean>;
initialValues?: Partial<WaylineFormValues>;
workspaceOptions?: Array<{ label: string; value: string }>;
}
// 简单上传到文件服务,返回 id/url/path
async function uploadWaylineFile(file: File) {
const formData = new FormData();
formData.append('file', file);
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData });
const data = await resp.json();
if (!data || !data.id) throw new Error('上传失败');
return data as { id: string; url: string; path: string };
}
const WaylineForm: React.FC<WaylineFormProps> = ({ title, visible, onVisibleChange, onFinish, initialValues, workspaceOptions }) => {
const formRef = useRef<any>();
const [fileInfo, setFileInfo] = useState<{ id: string; url: string } | undefined>();
useEffect(() => {
if (initialValues) {
formRef.current?.setFieldsValue(initialValues);
}
}, [initialValues]);
return (
<ModalForm<WaylineFormValues>
title={title}
visible={visible}
formRef={formRef}
onVisibleChange={(v) => {
onVisibleChange?.(v);
if (!v) setFileInfo(undefined);
}}
onFinish={async (values) => {
if (!values.waylineId && !fileInfo) {
message.warning('请上传航线文件');
return false;
}
const payload: WaylineFormValues = {
...initialValues,
...values,
waylineId: values.waylineId || fileInfo?.id,
};
return onFinish(payload);
}}
modalProps={{ destroyOnClose: true }}
>
<ProForm.Group>
<ProFormText
name="name"
label="航线名称"
rules={[{ required: true, message: '请输入航线名称' }]}
width="md"
/>
<ProFormSelect
name="workspaceId"
label="工作区"
rules={[{ required: true, message: '请选择工作区' }]}
options={workspaceOptions}
width="md"
/>
<ProFormText name="waylineId" hidden />
<ProFormText name="sign" hidden />
</ProForm.Group>
<div style={{ marginBottom: 12 }}>航线文件</div>
<Upload
maxCount={1}
accept=".kmz,.kml"
showUploadList={false}
customRequest={async ({ file, onSuccess, onError }) => {
try {
if (file instanceof File) {
const r = await uploadWaylineFile(file);
setFileInfo({ id: r.id, url: r.url });
formRef.current?.setFieldsValue({ waylineId: r.id });
message.success('上传成功');
onSuccess?.('ok');
}
} catch (err) {
message.error('上传失败');
onError?.(err as any);
}
}}
>
<Button icon={<UploadOutlined />}>{fileInfo ? '重新上传' : '上传文件'}</Button>
</Upload>
{fileInfo && (
<div style={{ marginTop: 8, color: '#666' }}>已上传:{fileInfo.id}</div>
)}
</ModalForm>
);
};
export default WaylineForm;
@@ -0,0 +1,64 @@
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import type { ProColumns } from '@ant-design/pro-components';
import { Space } from 'antd';
import { deviceApi } from '@/services/device';
import { downloadByUrl } from '@/utils/download';
export interface WaylineTableRef {
reload: () => void;
}
interface WaylineTableProps {
params?: Record<string, any>;
onEdit?: (record: any) => void;
onDelete?: (record: any) => void;
}
const WaylineTable = forwardRef<WaylineTableRef, WaylineTableProps>(({ params, onEdit, onDelete }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
const columns: ProColumns<any>[] = [
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
{ title: '航线名称', dataIndex: 'name' },
{ title: '航线ID', dataIndex: 'waylineId' },
{ title: '空间ID', dataIndex: 'workspaceId' },
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
{
title: '航线文件', dataIndex: 'fileUrl', search: false,
render: (_, record) => record.fileUrl ? (
<a
href={record.fileUrl}
onClick={(e) => { e.preventDefault(); downloadByUrl(record.fileUrl, record.name || 'wayline.kmz'); }}
>下载文件</a>
) : '-'
},
{ title: '文件签名', dataIndex: 'sign', ellipsis: true, copyable: true },
{
title: '操作', key: 'action', valueType: 'option',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
</Space>
)
},
];
return (
<ProTable<any>
rowKey="id"
headerTitle="航线列表"
actionRef={actionRef}
request={(p) => deviceApi.wayline({ ...p, ...params })}
columns={columns}
search={false}
pagination={{ showSizeChanger: true, showQuickJumper: true }}
/>
);
});
export default WaylineTable;
@@ -0,0 +1,88 @@
import React, { useRef, useState } from 'react';
import { PageContainer, ProFormText } from '@ant-design/pro-components';
import { Modal, message } from 'antd';
import { PlusOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
import WaylineTable, { WaylineTableRef } from './components/WaylineTable';
import WaylineForm, { WaylineFormValues } from './components/WaylineForm';
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
const WaylinePage: React.FC = () => {
const tableRef = useRef<WaylineTableRef>(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 add = async (values: WaylineFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateWayline(values as any);
message.success('新增成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('新增失败');
return false;
} finally {
hide();
}
};
const edit = async (values: WaylineFormValues) => {
const hide = message.loading('保存中...');
try {
await deviceApi.saveOrUpdateWayline({ ...(current || {}), ...values } as any);
message.success('修改成功');
tableRef.current?.reload();
return true;
} catch (e) {
message.error('修改失败');
return false;
} finally {
hide();
}
};
const del = async (record: any) => {
Modal.confirm({
title: `确认删除航线[${record.name}]?`,
onOk: async () => {
const hide = message.loading('正在删除...');
try {
await deviceApi.deleteWayline(record.id);
message.success('删除成功');
tableRef.current?.reload();
} catch (e) {
message.error('删除失败');
} finally { hide(); }
},
});
};
return (
<PageContainer header={{ title: '航线管理' }}>
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => tableRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
<ProFormText name="name" label="名称" placeholder="请输入关键字" />
</SearchBarPlus>
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
<GlassCard>
<WaylineTable
ref={tableRef}
params={query}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={(r) => del(r)}
/>
</GlassCard>
<WaylineForm title="新增航线" visible={createOpen} onVisibleChange={setCreateOpen} onFinish={add} />
<WaylineForm title="编辑航线" visible={editOpen} onVisibleChange={setEditOpen} onFinish={edit} initialValues={current || {}} />
</PageContainer>
);
};
export default WaylinePage;