feat: 天气系统规则引擎

This commit is contained in:
2026-01-28 17:30:34 +08:00
parent d1e340af83
commit ad41a38620
69 changed files with 10282 additions and 33 deletions
@@ -97,7 +97,10 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
placeholder="如:116.397428"
tooltip="设备所在位置的经度,范围 -180 ~ 180"
fieldProps={{ precision: 6, step: 0.000001 }}
rules={[{ type: 'number', min: -180, max: 180, message: '经度范围应为 -180 ~ 180' }]}
rules={[
{ required: true, message: '请输入经度' },
{ type: 'number', min: -180, max: 180, message: '经度范围应为 -180 ~ 180' }
]}
/>
<ProFormDigit
name="latitude"
@@ -106,7 +109,10 @@ const DeviceForm: React.FC<DeviceFormProps> = ({ title, visible, onVisibleChange
placeholder="如:39.90923"
tooltip="设备所在位置的纬度,范围 -90 ~ 90"
fieldProps={{ precision: 6, step: 0.000001 }}
rules={[{ type: 'number', min: -90, max: 90, message: '纬度范围应为 -90 ~ 90' }]}
rules={[
{ required: true, message: '请输入纬度' },
{ type: 'number', min: -90, max: 90, message: '纬度范围应为 -90 ~ 90' }
]}
/>
<ProFormDigit
name="altitude"
@@ -1,7 +1,8 @@
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 } from 'antd';
import { Space, Tag, Tooltip } from 'antd';
import { CloudOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
import { deviceApi } from '@/services/device';
export interface DeviceTableRef { reload: () => void }
@@ -10,9 +11,10 @@ interface DeviceTableProps {
params?: Record<string, any>;
onEdit?: (record: any) => void;
onDelete?: (record: any) => void;
onWeatherBlock?: (record: any) => void;
}
const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEdit, onDelete }, ref) => {
const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEdit, onDelete, onWeatherBlock }, ref) => {
const actionRef = useRef<ActionType>();
useImperativeHandle(ref, () => ({ reload: () => actionRef.current?.reload() }));
@@ -54,11 +56,37 @@ const DeviceTable = forwardRef<DeviceTableRef, DeviceTableProps>(({ params, onEd
// { 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',
title: '天气阻飞',
dataIndex: 'weatherBlockEnabled',
width: 90,
render: (v: number) => (
<Tag color={v === 1 ? 'blue' : 'default'}>
{v === 1 ? '已开启' : '未开启'}
</Tag>
),
},
{
title: '操作', key: 'action', valueType: 'option', width: 120, fixed: 'right',
render: (_, record) => (
<Space>
<a onClick={() => onEdit?.(record)}>编辑</a>
<a style={{ color: '#1677ff' }} onClick={() => onDelete?.(record)}>删除</a>
<Tooltip title="天气阻飞">
<a
style={{ color: record.weatherBlockEnabled === 1 ? '#1890ff' : undefined }}
onClick={() => onWeatherBlock?.(record)}
>
<CloudOutlined />
</a>
</Tooltip>
<Tooltip title="编辑">
<a onClick={() => onEdit?.(record)}>
<EditOutlined />
</a>
</Tooltip>
<Tooltip title="删除">
<a style={{ color: '#ff4d4f' }} onClick={() => onDelete?.(record)}>
<DeleteOutlined />
</a>
</Tooltip>
</Space>
)
},
@@ -6,6 +6,7 @@ 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';
import WeatherBlockSettingModal from '@/components/WeatherBlockSettingModal';
const DevicePage: React.FC = () => {
const tableRef = useRef<DeviceTableRef>(null);
@@ -13,6 +14,8 @@ const DevicePage: React.FC = () => {
const [createOpen, setCreateOpen] = useState(false);
const [editOpen, setEditOpen] = useState(false);
const [current, setCurrent] = useState<any | null>(null);
const [weatherBlockOpen, setWeatherBlockOpen] = useState(false);
const [weatherBlockDevice, setWeatherBlockDevice] = useState<any | null>(null);
const add = async (values: DeviceFormValues) => {
const hide = message.loading('保存中...');
@@ -82,6 +85,7 @@ const DevicePage: React.FC = () => {
params={query}
onEdit={(r) => { setCurrent(r); setEditOpen(true); }}
onDelete={(r) => del(r)}
onWeatherBlock={(r) => { setWeatherBlockDevice(r); setWeatherBlockOpen(true); }}
/>
</GlassCard>
@@ -96,6 +100,18 @@ const DevicePage: React.FC = () => {
onFinish={edit}
initialValues={current || {}}
/>
{weatherBlockOpen && weatherBlockDevice?.deviceSn ? (
<WeatherBlockSettingModal
visible={weatherBlockOpen}
onVisibleChange={setWeatherBlockOpen}
type="device"
targetId={weatherBlockDevice.deviceSn}
targetName={weatherBlockDevice.deviceName || weatherBlockDevice.deviceSn}
weatherBlockEnabled={weatherBlockDevice.weatherBlockEnabled}
onSuccess={() => tableRef.current?.reload()}
/>
) : null}
</PageContainer>
);
};