feat: 天气系统规则引擎
This commit is contained in:
@@ -0,0 +1,666 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Switch,
|
||||
Space,
|
||||
Typography,
|
||||
Alert,
|
||||
Divider,
|
||||
Button,
|
||||
Card,
|
||||
Row,
|
||||
Col,
|
||||
Tag,
|
||||
message,
|
||||
Spin,
|
||||
Empty,
|
||||
InputNumber,
|
||||
Select,
|
||||
Input,
|
||||
} from 'antd';
|
||||
import {
|
||||
CloudOutlined,
|
||||
ThunderboltOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
PlusOutlined,
|
||||
DeleteOutlined,
|
||||
InfoCircleOutlined,
|
||||
CheckCircleOutlined,
|
||||
CloseCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { deviceApi } from '@/services/device';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 天气参数配置
|
||||
const WEATHER_PARAMETERS = [
|
||||
{ key: 'windSpeed', label: '风速', unit: 'm/s', icon: '💨', defaultValue: 10 },
|
||||
{ key: 'temperature', label: '温度', unit: '°C', icon: '🌡️', defaultValue: -4 },
|
||||
{ key: 'humidity', label: '湿度', unit: '%', icon: '💧', defaultValue: 80 },
|
||||
{ key: 'precipitation', label: '降雨量', unit: 'mm/h', icon: '🌧️', defaultValue: 0.5 },
|
||||
{ key: 'visibility', label: '能见度', unit: 'm', icon: '👁️', defaultValue: 1000 },
|
||||
];
|
||||
|
||||
// 运算符配置
|
||||
const OPERATORS = [
|
||||
{ value: '>', label: '> 大于' },
|
||||
{ value: '>=', label: '>= 大于等于' },
|
||||
{ value: '<', label: '< 小于' },
|
||||
{ value: '<=', label: '<= 小于等于' },
|
||||
{ value: 'between', label: '区间' },
|
||||
];
|
||||
|
||||
interface RuleCondition {
|
||||
parameter?: string;
|
||||
operator?: string;
|
||||
value?: number;
|
||||
minValue?: number;
|
||||
maxValue?: number;
|
||||
unit?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
interface ConditionGroup {
|
||||
groupName?: string;
|
||||
conditions: RuleCondition[];
|
||||
logicalOperator: string; // 组内逻辑,默认AND
|
||||
}
|
||||
|
||||
interface WeatherRuleItem {
|
||||
id?: number;
|
||||
ruleCode?: string;
|
||||
ruleName?: string;
|
||||
ruleLevel?: number;
|
||||
targetId?: string;
|
||||
priority?: number;
|
||||
ruleContent?: {
|
||||
conditions?: RuleCondition[];
|
||||
conditionGroups?: ConditionGroup[];
|
||||
groupOperator?: string;
|
||||
logicalOperator?: string;
|
||||
};
|
||||
status?: number;
|
||||
}
|
||||
|
||||
interface WeatherBlockSettingModalProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
type: 'tourism' | 'device';
|
||||
targetId: string | number;
|
||||
targetName?: string;
|
||||
weatherBlockEnabled?: number;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
// 预设模板(使用分组模式)
|
||||
const RULE_TEMPLATES = [
|
||||
{
|
||||
name: '结冰风险规则',
|
||||
description: '风速>10 或 (温度<-4 且 湿度>80)',
|
||||
conditionGroups: [
|
||||
{
|
||||
groupName: '大风阻飞',
|
||||
conditions: [{ parameter: 'windSpeed', operator: '>', value: 10, unit: 'm/s' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
groupName: '结冰风险',
|
||||
conditions: [
|
||||
{ parameter: 'temperature', operator: '<', value: -4, unit: '°C' },
|
||||
{ parameter: 'humidity', operator: '>', value: 80, unit: '%' },
|
||||
],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
],
|
||||
groupOperator: 'OR',
|
||||
},
|
||||
{
|
||||
name: '标准阻飞规则',
|
||||
description: '风速>10 或 降雨>0.5',
|
||||
conditionGroups: [
|
||||
{
|
||||
groupName: '大风阻飞',
|
||||
conditions: [{ parameter: 'windSpeed', operator: '>', value: 10, unit: 'm/s' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
groupName: '降雨阻飞',
|
||||
conditions: [{ parameter: 'precipitation', operator: '>', value: 0.5, unit: 'mm/h' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
],
|
||||
groupOperator: 'OR',
|
||||
},
|
||||
{
|
||||
name: '严格阻飞规则',
|
||||
description: '风速>8 或 降雨>0 或 能见度<1000',
|
||||
conditionGroups: [
|
||||
{
|
||||
groupName: '大风',
|
||||
conditions: [{ parameter: 'windSpeed', operator: '>', value: 8, unit: 'm/s' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
groupName: '降雨',
|
||||
conditions: [{ parameter: 'precipitation', operator: '>', value: 0, unit: 'mm/h' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
groupName: '低能见度',
|
||||
conditions: [{ parameter: 'visibility', operator: '<', value: 1000, unit: 'm' }],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
],
|
||||
groupOperator: 'OR',
|
||||
},
|
||||
];
|
||||
|
||||
const WeatherBlockSettingModal: React.FC<WeatherBlockSettingModalProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
type,
|
||||
targetId,
|
||||
targetName,
|
||||
weatherBlockEnabled = 0,
|
||||
onSuccess,
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [enabled, setEnabled] = useState(weatherBlockEnabled === 1);
|
||||
const [existingRule, setExistingRule] = useState<WeatherRuleItem | null>(null);
|
||||
const [showRuleForm, setShowRuleForm] = useState(false);
|
||||
const [conditionGroups, setConditionGroups] = useState<ConditionGroup[]>([]);
|
||||
const [groupOperator, setGroupOperator] = useState<string>('OR');
|
||||
const [ruleName, setRuleName] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && targetId) {
|
||||
loadExistingRule();
|
||||
setEnabled(weatherBlockEnabled === 1);
|
||||
}
|
||||
}, [visible, targetId, weatherBlockEnabled]);
|
||||
|
||||
const loadExistingRule = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let rule = null;
|
||||
if (type === 'tourism') {
|
||||
rule = await ordersApi.getTourismWeatherRule(Number(targetId));
|
||||
} else {
|
||||
rule = await ordersApi.getDeviceWeatherRule(String(targetId));
|
||||
}
|
||||
setExistingRule(rule);
|
||||
if (rule?.ruleContent) {
|
||||
// 优先使用分组模式
|
||||
if (rule.ruleContent.conditionGroups?.length) {
|
||||
setConditionGroups(rule.ruleContent.conditionGroups);
|
||||
setGroupOperator(rule.ruleContent.groupOperator || 'OR');
|
||||
} else if (rule.ruleContent.conditions?.length) {
|
||||
// 兼容旧的简单模式,转换为单组
|
||||
setConditionGroups([{
|
||||
groupName: '条件组1',
|
||||
conditions: rule.ruleContent.conditions,
|
||||
logicalOperator: rule.ruleContent.logicalOperator || 'AND',
|
||||
}]);
|
||||
setGroupOperator('OR');
|
||||
}
|
||||
setRuleName(rule.ruleName || '');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载规则失败', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggle = (checked: boolean) => {
|
||||
setEnabled(checked);
|
||||
if (checked && !existingRule) {
|
||||
setShowRuleForm(true);
|
||||
}
|
||||
};
|
||||
|
||||
const applyTemplate = (template: typeof RULE_TEMPLATES[0]) => {
|
||||
setConditionGroups(template.conditionGroups);
|
||||
setGroupOperator(template.groupOperator);
|
||||
setRuleName(template.name);
|
||||
message.success(`已应用「${template.name}」模板`);
|
||||
};
|
||||
|
||||
// 添加条件组
|
||||
const addConditionGroup = () => {
|
||||
setConditionGroups([
|
||||
...conditionGroups,
|
||||
{
|
||||
groupName: `条件组${conditionGroups.length + 1}`,
|
||||
conditions: [],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
// 删除条件组
|
||||
const removeConditionGroup = (groupIndex: number) => {
|
||||
setConditionGroups(conditionGroups.filter((_, i) => i !== groupIndex));
|
||||
};
|
||||
|
||||
// 更新条件组名称
|
||||
const updateGroupName = (groupIndex: number, name: string) => {
|
||||
const newGroups = [...conditionGroups];
|
||||
newGroups[groupIndex].groupName = name;
|
||||
setConditionGroups(newGroups);
|
||||
};
|
||||
|
||||
// 更新组内逻辑
|
||||
const updateGroupLogicalOperator = (groupIndex: number, operator: string) => {
|
||||
const newGroups = [...conditionGroups];
|
||||
newGroups[groupIndex].logicalOperator = operator;
|
||||
setConditionGroups(newGroups);
|
||||
};
|
||||
|
||||
// 添加条件到组
|
||||
const addConditionToGroup = (groupIndex: number, paramKey?: string) => {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === paramKey);
|
||||
const newCondition: RuleCondition = {
|
||||
parameter: paramKey || '',
|
||||
operator: '>',
|
||||
value: param?.defaultValue,
|
||||
unit: param?.unit || '',
|
||||
};
|
||||
const newGroups = [...conditionGroups];
|
||||
newGroups[groupIndex].conditions.push(newCondition);
|
||||
setConditionGroups(newGroups);
|
||||
};
|
||||
|
||||
// 更新条件
|
||||
const updateCondition = (groupIndex: number, condIndex: number, field: string, value: any) => {
|
||||
const newGroups = [...conditionGroups];
|
||||
newGroups[groupIndex].conditions[condIndex] = {
|
||||
...newGroups[groupIndex].conditions[condIndex],
|
||||
[field]: value,
|
||||
};
|
||||
if (field === 'parameter') {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === value);
|
||||
if (param) {
|
||||
newGroups[groupIndex].conditions[condIndex].unit = param.unit;
|
||||
newGroups[groupIndex].conditions[condIndex].value = param.defaultValue;
|
||||
}
|
||||
}
|
||||
setConditionGroups(newGroups);
|
||||
};
|
||||
|
||||
// 删除条件
|
||||
const removeCondition = (groupIndex: number, condIndex: number) => {
|
||||
const newGroups = [...conditionGroups];
|
||||
newGroups[groupIndex].conditions = newGroups[groupIndex].conditions.filter((_, i) => i !== condIndex);
|
||||
setConditionGroups(newGroups);
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setSaving(true);
|
||||
try {
|
||||
// 1. 更新开关状态
|
||||
if (type === 'tourism') {
|
||||
await ordersApi.updateTourismWeatherBlock(Number(targetId), enabled ? 1 : 0);
|
||||
} else {
|
||||
await deviceApi.updateDeviceWeatherBlock(String(targetId), enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
// 2. 检查是否有有效条件
|
||||
const hasValidConditions = conditionGroups.some(g => g.conditions.length > 0);
|
||||
|
||||
if (enabled && hasValidConditions) {
|
||||
const ruleCode = type === 'tourism'
|
||||
? `TOURISM_${targetId}_RULE`
|
||||
: `DEVICE_${targetId}_RULE`;
|
||||
|
||||
const rulePayload = {
|
||||
ruleCode: existingRule?.ruleCode || ruleCode,
|
||||
ruleName: ruleName || `${targetName || targetId}天气规则`,
|
||||
ruleLevel: type === 'tourism' ? 2 : 3,
|
||||
targetId: String(targetId),
|
||||
priority: 100,
|
||||
status: 1,
|
||||
ruleContent: {
|
||||
conditionGroups,
|
||||
groupOperator,
|
||||
},
|
||||
};
|
||||
|
||||
console.log('保存规则:', rulePayload);
|
||||
|
||||
let result;
|
||||
if (existingRule?.id) {
|
||||
result = await ordersApi.updateWeatherRule(existingRule.id, rulePayload);
|
||||
} else {
|
||||
result = await ordersApi.createWeatherRule(rulePayload);
|
||||
}
|
||||
|
||||
console.log('规则保存结果:', result);
|
||||
|
||||
// 检查返回结果
|
||||
if (result && (result as any).resp_code !== 0 && (result as any).code !== 0) {
|
||||
throw new Error((result as any).resp_msg || (result as any).msg || '规则保存失败');
|
||||
}
|
||||
} else if (enabled && !hasValidConditions) {
|
||||
message.warning('请至少配置一个条件');
|
||||
setSaving(false);
|
||||
return;
|
||||
}
|
||||
|
||||
message.success('保存成功');
|
||||
onSuccess?.();
|
||||
onVisibleChange(false);
|
||||
} catch (error: any) {
|
||||
console.error('保存失败:', error);
|
||||
message.error(error?.message || '保存失败');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染条件行
|
||||
const renderConditionRow = (condition: RuleCondition, groupIndex: number, condIndex: number) => (
|
||||
<Row key={condIndex} gutter={8} align="middle" style={{ marginBottom: 8 }}>
|
||||
<Col span={7}>
|
||||
<Select
|
||||
value={condition.parameter}
|
||||
onChange={(v) => updateCondition(groupIndex, condIndex, 'parameter', v)}
|
||||
placeholder="参数"
|
||||
size="small"
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
{WEATHER_PARAMETERS.map(p => (
|
||||
<Select.Option key={p.key} value={p.key}>
|
||||
{p.icon} {p.label}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<Select
|
||||
value={condition.operator}
|
||||
onChange={(v) => updateCondition(groupIndex, condIndex, 'operator', v)}
|
||||
size="small"
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
{OPERATORS.map(op => (
|
||||
<Select.Option key={op.value} value={op.value}>
|
||||
{op.label}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
<Col span={7}>
|
||||
{condition.operator === 'between' ? (
|
||||
<Space size={4}>
|
||||
<InputNumber
|
||||
value={condition.minValue}
|
||||
onChange={(v) => updateCondition(groupIndex, condIndex, 'minValue', v)}
|
||||
size="small"
|
||||
style={{ width: 60 }}
|
||||
/>
|
||||
<span>~</span>
|
||||
<InputNumber
|
||||
value={condition.maxValue}
|
||||
onChange={(v) => updateCondition(groupIndex, condIndex, 'maxValue', v)}
|
||||
size="small"
|
||||
style={{ width: 60 }}
|
||||
/>
|
||||
</Space>
|
||||
) : (
|
||||
<InputNumber
|
||||
value={condition.value}
|
||||
onChange={(v) => updateCondition(groupIndex, condIndex, 'value', v)}
|
||||
size="small"
|
||||
style={{ width: '100%' }}
|
||||
addonAfter={<span style={{ fontSize: 11 }}>{condition.unit}</span>}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
size="small"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => removeCondition(groupIndex, condIndex)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
|
||||
// 渲染条件组
|
||||
const renderConditionGroup = (group: ConditionGroup, groupIndex: number) => {
|
||||
// 获取当前组已使用的参数
|
||||
const usedParams = group.conditions.map(c => c.parameter).filter(Boolean);
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={groupIndex}
|
||||
size="small"
|
||||
style={{ marginBottom: 12, borderColor: '#1890ff', borderStyle: 'dashed' }}
|
||||
title={
|
||||
<Row align="middle" justify="space-between">
|
||||
<Col>
|
||||
<Space>
|
||||
<Input
|
||||
value={group.groupName}
|
||||
onChange={(e) => updateGroupName(groupIndex, e.target.value)}
|
||||
size="small"
|
||||
style={{ width: 120 }}
|
||||
placeholder="组名称"
|
||||
/>
|
||||
{group.conditions.length > 1 && (
|
||||
<Select
|
||||
value={group.logicalOperator}
|
||||
onChange={(v) => updateGroupLogicalOperator(groupIndex, v)}
|
||||
size="small"
|
||||
style={{ width: 90 }}
|
||||
>
|
||||
<Select.Option value="AND">
|
||||
<Tag color="blue">AND</Tag>
|
||||
</Select.Option>
|
||||
<Select.Option value="OR">
|
||||
<Tag color="orange">OR</Tag>
|
||||
</Select.Option>
|
||||
</Select>
|
||||
)}
|
||||
</Space>
|
||||
</Col>
|
||||
<Col>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
size="small"
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => removeConditionGroup(groupIndex)}
|
||||
>
|
||||
删除组
|
||||
</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
}
|
||||
>
|
||||
{group.conditions.length === 0 ? (
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="请添加条件" style={{ margin: '8px 0' }} />
|
||||
) : (
|
||||
group.conditions.map((cond, condIndex) => renderConditionRow(cond, groupIndex, condIndex))
|
||||
)}
|
||||
<Space wrap style={{ marginTop: 8 }}>
|
||||
{WEATHER_PARAMETERS.map(param => (
|
||||
<Button
|
||||
key={param.key}
|
||||
size="small"
|
||||
type="dashed"
|
||||
disabled={usedParams.includes(param.key)}
|
||||
onClick={() => addConditionToGroup(groupIndex, param.key)}
|
||||
>
|
||||
+ {param.icon} {param.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
// 生成规则描述
|
||||
const generateRuleDescription = () => {
|
||||
if (conditionGroups.length === 0) return '';
|
||||
const groupDescs = conditionGroups.map(g => {
|
||||
if (g.conditions.length === 0) return '';
|
||||
const condDescs = g.conditions.map(c => {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === c.parameter);
|
||||
return `${param?.label || c.parameter} ${c.operator} ${c.value}${c.unit}`;
|
||||
});
|
||||
return g.conditions.length > 1 ? `(${condDescs.join(` ${g.logicalOperator} `)})` : condDescs[0];
|
||||
}).filter(Boolean);
|
||||
return groupDescs.join(` ${groupOperator} `);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<CloudOutlined style={{ color: '#1890ff' }} />
|
||||
<span>天气阻飞设置</span>
|
||||
<Tag color={type === 'tourism' ? 'green' : 'red'}>
|
||||
{type === 'tourism' ? '景区' : '设备'}
|
||||
</Tag>
|
||||
</Space>
|
||||
}
|
||||
open={visible}
|
||||
onCancel={() => onVisibleChange(false)}
|
||||
width={750}
|
||||
footer={[
|
||||
<Button key="cancel" onClick={() => onVisibleChange(false)}>取消</Button>,
|
||||
<Button key="save" type="primary" loading={saving} onClick={handleSave}>保存设置</Button>,
|
||||
]}
|
||||
destroyOnClose
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<Alert
|
||||
message={<Space><Text strong>{targetName || targetId}</Text><Text type="secondary">({type === 'tourism' ? `景区ID: ${targetId}` : `设备SN: ${targetId}`})</Text></Space>}
|
||||
type="info"
|
||||
showIcon
|
||||
icon={type === 'tourism' ? <CloudOutlined /> : <ThunderboltOutlined />}
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Row align="middle" justify="space-between">
|
||||
<Col>
|
||||
<Space>
|
||||
<SafetyCertificateOutlined style={{ fontSize: 20, color: enabled ? '#52c41a' : '#999' }} />
|
||||
<div>
|
||||
<div><Text strong>启用天气阻飞</Text></div>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>开启后,满足阻飞条件时将禁止创建任务</Text>
|
||||
</div>
|
||||
</Space>
|
||||
</Col>
|
||||
<Col>
|
||||
<Switch
|
||||
checked={enabled}
|
||||
onChange={handleToggle}
|
||||
checkedChildren={<CheckCircleOutlined />}
|
||||
unCheckedChildren={<CloseCircleOutlined />}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{enabled && (
|
||||
<>
|
||||
<Divider orientation="left" plain><Text type="secondary">阻飞规则配置</Text></Divider>
|
||||
|
||||
{existingRule && !showRuleForm ? (
|
||||
<Card size="small" style={{ marginBottom: 16 }}>
|
||||
<Row align="middle" justify="space-between">
|
||||
<Col><Text strong>{existingRule.ruleName}</Text></Col>
|
||||
<Col><Button size="small" onClick={() => setShowRuleForm(true)}>编辑规则</Button></Col>
|
||||
</Row>
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<Text type="secondary">{generateRuleDescription()}</Text>
|
||||
</div>
|
||||
</Card>
|
||||
) : (
|
||||
<>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text style={{ marginRight: 8 }}>规则名称:</Text>
|
||||
<Input
|
||||
value={ruleName}
|
||||
onChange={(e) => setRuleName(e.target.value)}
|
||||
placeholder="请输入规则名称"
|
||||
style={{ width: 300 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text type="secondary" style={{ marginRight: 8 }}>快速应用模板:</Text>
|
||||
<Space wrap>
|
||||
{RULE_TEMPLATES.map(t => (
|
||||
<Button key={t.name} size="small" onClick={() => applyTemplate(t)} title={t.description}>
|
||||
{t.name}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{conditionGroups.length > 1 && (
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text style={{ marginRight: 8 }}>条件组之间关系:</Text>
|
||||
<Select value={groupOperator} onChange={setGroupOperator} style={{ width: 200 }}>
|
||||
<Select.Option value="OR"><Tag color="orange">OR</Tag> 任一组满足则阻飞</Select.Option>
|
||||
<Select.Option value="AND"><Tag color="blue">AND</Tag> 所有组满足才阻飞</Select.Option>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{conditionGroups.length === 0 ? (
|
||||
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="请添加条件组" style={{ margin: '16px 0' }} />
|
||||
) : (
|
||||
<>
|
||||
{conditionGroups.map((group, index) => (
|
||||
<React.Fragment key={index}>
|
||||
{renderConditionGroup(group, index)}
|
||||
{index < conditionGroups.length - 1 && (
|
||||
<div style={{ textAlign: 'center', margin: '8px 0' }}>
|
||||
<Tag color={groupOperator === 'OR' ? 'orange' : 'blue'}>{groupOperator}</Tag>
|
||||
</div>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
<Button type="dashed" block icon={<PlusOutlined />} onClick={addConditionGroup} style={{ marginTop: 8 }}>
|
||||
添加条件组
|
||||
</Button>
|
||||
|
||||
{conditionGroups.length > 0 && (
|
||||
<Alert
|
||||
message={<Text strong>规则预览:</Text>}
|
||||
description={generateRuleDescription() || '请配置条件'}
|
||||
type="info"
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<Alert
|
||||
message={type === 'tourism' ? '景区级别规则对该景区下所有设备生效' : '设备级别规则优先级最高,仅对该设备生效'}
|
||||
type="warning"
|
||||
showIcon
|
||||
icon={<InfoCircleOutlined />}
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Spin>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeatherBlockSettingModal;
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -44,7 +44,7 @@ const FilesPage: React.FC = () => {
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '文件管理', subTitle: '平台文件' }}>
|
||||
<SearchBarPlus defaultCollapsed split span={6} onTenantChanged={() => actionRef.current?.reload()} onFinish={async (values) => setParams(values)}>
|
||||
<SearchBarPlus defaultCollapsed split span={6} hideReset={true} onTenantChanged={() => actionRef.current?.reload()} onFinish={async (values) => setParams(values)}>
|
||||
<ProFormText name="name" label="名称" placeholder="请输入关键字" />
|
||||
</SearchBarPlus>
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
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 { Popconfirm, Space, message, Modal, Button } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { SearchBarPlus, GlassCard } from '@/components/ui';
|
||||
|
||||
const EditTaskPage: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
const [editVisible, setEditVisible] = useState(false);
|
||||
const [createVisible, setCreateVisible] = useState(false);
|
||||
const [currentTask, setCurrentTask] = useState<any>(null);
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [createFormRef] = ProForm.useForm();
|
||||
|
||||
// 当查询参数变化时,自动重置到第一页
|
||||
useEffect(() => {
|
||||
@@ -49,6 +52,29 @@ const EditTaskPage: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 处理新增剪辑任务
|
||||
const handleCreateTask = async (values: any) => {
|
||||
const hide = message.loading('正在创建编辑任务...');
|
||||
try {
|
||||
const result = await ordersApi.generateEditTask(values.orderSn as any);
|
||||
|
||||
if (result && result.resp_code === 0) {
|
||||
message.success('编辑任务创建成功');
|
||||
actionRef.current?.reload();
|
||||
createFormRef.resetFields();
|
||||
return true;
|
||||
} else {
|
||||
message.error(result?.resp_msg || '创建编辑任务失败');
|
||||
return false;
|
||||
}
|
||||
} catch (error: any) {
|
||||
message.error(error?.message || '创建编辑任务失败');
|
||||
return false;
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
const handleEdit = async (values: any) => {
|
||||
const hide = message.loading('正在保存...');
|
||||
@@ -186,9 +212,49 @@ const EditTaskPage: React.FC = () => {
|
||||
showQuickJumper: true
|
||||
}}
|
||||
headerTitle="剪辑任务列表"
|
||||
toolBarRender={() => [
|
||||
<Button
|
||||
key="create"
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => setCreateVisible(true)}
|
||||
>
|
||||
新增剪辑任务
|
||||
</Button>
|
||||
]}
|
||||
/>
|
||||
</GlassCard>
|
||||
|
||||
{/* 新增剪辑任务表单 */}
|
||||
<ModalForm
|
||||
title="新增剪辑任务"
|
||||
visible={createVisible}
|
||||
form={createFormRef}
|
||||
onVisibleChange={(v) => {
|
||||
setCreateVisible(v);
|
||||
if (!v) createFormRef.resetFields();
|
||||
}}
|
||||
onFinish={handleCreateTask}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
}}
|
||||
width={500}
|
||||
>
|
||||
<ProFormText
|
||||
name="orderSn"
|
||||
label="订单编码"
|
||||
placeholder="请输入订单编码"
|
||||
rules={[
|
||||
{ required: true, message: '请输入订单编码' },
|
||||
{ whitespace: true, message: '订单编码不能为空格' },
|
||||
]}
|
||||
fieldProps={{
|
||||
autoComplete: 'off',
|
||||
}}
|
||||
/>
|
||||
</ModalForm>
|
||||
|
||||
{/* 编辑表单 */}
|
||||
<ModalForm
|
||||
title="编辑剪辑任务"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { Modal, Popconfirm, Space, Tag, message, Button } from 'antd';
|
||||
import { ProTable, type ActionType } from '@ant-design/pro-components';
|
||||
import { GradientButton } from '@/components/ui';
|
||||
@@ -7,6 +7,27 @@ import { ordersApi } from '@/services/orders';
|
||||
import { QrcodeItem } from './QrcodeItem';
|
||||
import QrcodeTourismForm from './QrcodeTourismForm';
|
||||
|
||||
const copyToClipboard = (text: string): Promise<void> => {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
return navigator.clipboard.writeText(text);
|
||||
}
|
||||
// Fallback for non-secure contexts
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.opacity = '0';
|
||||
document.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(textarea);
|
||||
return Promise.resolve();
|
||||
} catch {
|
||||
document.body.removeChild(textarea);
|
||||
return Promise.reject();
|
||||
}
|
||||
};
|
||||
|
||||
export interface QrcodeListModalProps {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
@@ -70,8 +91,7 @@ const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${touri
|
||||
icon={<CopyOutlined />}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
navigator.clipboard
|
||||
.writeText(codeId)
|
||||
copyToClipboard(codeId)
|
||||
.then(() => message.success('Code已复制'))
|
||||
.catch(() => message.error('复制失败'));
|
||||
}}
|
||||
@@ -96,8 +116,7 @@ const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${touri
|
||||
icon={<CopyOutlined />}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
navigator.clipboard
|
||||
.writeText(waylineId)
|
||||
copyToClipboard(waylineId)
|
||||
.then(() => message.success('航线ID已复制'))
|
||||
.catch(() => message.error('复制失败'));
|
||||
}}
|
||||
|
||||
@@ -13,6 +13,7 @@ export interface TourismItem {
|
||||
latitude?: string;
|
||||
showInHomepage?: number; // 1 是,0 否
|
||||
tourismDesc?: string;
|
||||
weatherBlockEnabled?: number; // 是否开启天气阻飞(0:关闭,1:开启)
|
||||
}
|
||||
|
||||
export interface TourismFormProps {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { PageContainer, ProFormText, ProTable, type ActionType } from '@ant-design/pro-components';
|
||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
||||
import { Popconfirm, Space, Tag, message, Tooltip } from 'antd';
|
||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { PlusOutlined, CloudOutlined, QrcodeOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import TourismForm, { TourismItem } from './components/TourismForm';
|
||||
import QrcodeListModal from './components/QrcodeListModal';
|
||||
import WeatherBlockSettingModal from '@/components/WeatherBlockSettingModal';
|
||||
import { tenantApi } from '@/services/tenant';
|
||||
|
||||
const TourismPage: React.FC = () => {
|
||||
@@ -15,6 +16,8 @@ const TourismPage: React.FC = () => {
|
||||
const [params, setParams] = useState<Record<string, any>>({});
|
||||
const [qrcodeOpen, setQrcodeOpen] = useState(false);
|
||||
const [qrcodeTourism, setQrcodeTourism] = useState<TourismItem | undefined>(undefined);
|
||||
const [weatherBlockOpen, setWeatherBlockOpen] = useState(false);
|
||||
const [weatherBlockTourism, setWeatherBlockTourism] = useState<TourismItem | undefined>(undefined);
|
||||
const actionRef = useRef<ActionType>();
|
||||
|
||||
// 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据
|
||||
@@ -53,13 +56,43 @@ const TourismPage: React.FC = () => {
|
||||
dataIndex: 'status',
|
||||
render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag>,
|
||||
},
|
||||
/* 暂时隐藏景区天气阻飞列,以设备为准
|
||||
{
|
||||
title: '天气阻飞',
|
||||
dataIndex: 'weatherBlockEnabled',
|
||||
width: 90,
|
||||
render: (v: number) => (
|
||||
<Tag color={v === 1 ? 'blue' : 'default'}>
|
||||
{v === 1 ? '已开启' : '未开启'}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
*/
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 120,
|
||||
render: (_: any, record: TourismItem) => (
|
||||
<Space>
|
||||
<a onClick={() => { setQrcodeTourism(record); setQrcodeOpen(true); }}>二维码</a>
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||
<Tooltip title="二维码">
|
||||
<a onClick={() => { setQrcodeTourism(record); setQrcodeOpen(true); }}>
|
||||
<QrcodeOutlined />
|
||||
</a>
|
||||
</Tooltip>
|
||||
{/* 暂时隐藏景区气象阻飞按钮,以设备为准 */}
|
||||
{/* <Tooltip title="天气阻飞">
|
||||
<a
|
||||
style={{ color: record.weatherBlockEnabled === 1 ? '#1890ff' : undefined }}
|
||||
onClick={() => { setWeatherBlockTourism(record); setWeatherBlockOpen(true); }}
|
||||
>
|
||||
<CloudOutlined />
|
||||
</a>
|
||||
</Tooltip> */}
|
||||
<Tooltip title="编辑">
|
||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>
|
||||
<EditOutlined />
|
||||
</a>
|
||||
</Tooltip>
|
||||
<Popconfirm
|
||||
title={`确认删除项目[${record.tourismName}]?`}
|
||||
onConfirm={async () => {
|
||||
@@ -73,7 +106,11 @@ const TourismPage: React.FC = () => {
|
||||
} finally { hide(); }
|
||||
}}
|
||||
>
|
||||
<a style={{ color: '#1677ff' }}>删除</a>
|
||||
<Tooltip title="删除">
|
||||
<a style={{ color: '#ff4d4f' }}>
|
||||
<DeleteOutlined />
|
||||
</a>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
@@ -170,6 +207,18 @@ const TourismPage: React.FC = () => {
|
||||
tourismName={qrcodeTourism.tourismName}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{weatherBlockOpen && weatherBlockTourism?.id ? (
|
||||
<WeatherBlockSettingModal
|
||||
visible={weatherBlockOpen}
|
||||
onVisibleChange={setWeatherBlockOpen}
|
||||
type="tourism"
|
||||
targetId={weatherBlockTourism.id}
|
||||
targetName={weatherBlockTourism.tourismName}
|
||||
weatherBlockEnabled={weatherBlockTourism.weatherBlockEnabled}
|
||||
onSuccess={() => actionRef.current?.reload()}
|
||||
/>
|
||||
) : null}
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
+371
@@ -0,0 +1,371 @@
|
||||
import React from 'react';
|
||||
import { Modal, Descriptions, Tag, Card, Space, Empty, Typography, Row, Col, Divider } from 'antd';
|
||||
import {
|
||||
CloudOutlined,
|
||||
ThunderboltOutlined,
|
||||
CheckCircleOutlined,
|
||||
CloseCircleOutlined,
|
||||
ClockCircleOutlined,
|
||||
InfoCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { WeatherRuleItem, RuleCondition, ConditionGroup } from './WeatherRuleForm';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
interface WeatherRuleDetailModalProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
data?: WeatherRuleItem;
|
||||
}
|
||||
|
||||
// 天气参数配置(与 WeatherBlockSettingModal 保持一致)
|
||||
const WEATHER_PARAM_CONFIG: Record<string, { label: string; icon: string; color: string }> = {
|
||||
windSpeed: { label: '风速', icon: '💨', color: '#1890ff' },
|
||||
temperature: { label: '温度', icon: '🌡️', color: '#fa8c16' },
|
||||
humidity: { label: '湿度', icon: '💧', color: '#2f54eb' },
|
||||
precipitation: { label: '降雨量', icon: '🌧️', color: '#13c2c2' },
|
||||
visibility: { label: '能见度', icon: '👁️', color: '#722ed1' },
|
||||
};
|
||||
|
||||
// 运算符显示
|
||||
const OPERATOR_DISPLAY: Record<string, string> = {
|
||||
'<=': '≤',
|
||||
'>=': '≥',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'==': '=',
|
||||
'between': '区间',
|
||||
};
|
||||
|
||||
/**
|
||||
* 天气规则详情查看组件
|
||||
*/
|
||||
const WeatherRuleDetailModal: React.FC<WeatherRuleDetailModalProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
data,
|
||||
}) => {
|
||||
if (!data) return null;
|
||||
|
||||
const ruleLevelConfig = {
|
||||
2: { text: '景区级别', color: '#52c41a', icon: <CloudOutlined />, bgColor: '#f6ffed' },
|
||||
3: { text: '设备级别', color: '#f5222d', icon: <ThunderboltOutlined />, bgColor: '#fff1f0' },
|
||||
};
|
||||
|
||||
const levelConfig = ruleLevelConfig[data.ruleLevel as keyof typeof ruleLevelConfig];
|
||||
|
||||
// 渲染条件值
|
||||
const renderConditionValue = (condition: RuleCondition) => {
|
||||
const op = OPERATOR_DISPLAY[condition.operator || ''] || condition.operator;
|
||||
if (condition.operator === 'between') {
|
||||
return `${condition.minValue} ~ ${condition.maxValue} ${condition.unit || ''}`;
|
||||
}
|
||||
return `${op} ${condition.value} ${condition.unit || ''}`;
|
||||
};
|
||||
|
||||
// 计算条件总数
|
||||
const getConditionCount = () => {
|
||||
const ruleContent = data.ruleContent;
|
||||
if (!ruleContent) return 0;
|
||||
|
||||
// 分组模式
|
||||
if (ruleContent.conditionGroups?.length) {
|
||||
return ruleContent.conditionGroups.reduce((sum: number, g: ConditionGroup) => {
|
||||
return sum + (g.conditions?.length || 0);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
// 简单模式
|
||||
return ruleContent.conditions?.length || 0;
|
||||
};
|
||||
|
||||
// 渲染条件卡片
|
||||
const renderConditionCard = (condition: RuleCondition, index: number) => {
|
||||
const paramConfig = WEATHER_PARAM_CONFIG[condition.parameter || ''];
|
||||
return (
|
||||
<Col span={12} key={index}>
|
||||
<Card
|
||||
size="small"
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
border: `1px solid ${paramConfig?.color || '#d9d9d9'}20`,
|
||||
background: `${paramConfig?.color || '#1890ff'}08`,
|
||||
}}
|
||||
bodyStyle={{ padding: 12 }}
|
||||
>
|
||||
<Row align="middle" gutter={12}>
|
||||
<Col>
|
||||
<div
|
||||
style={{
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 8,
|
||||
background: '#fff',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
fontSize: 20,
|
||||
boxShadow: '0 1px 4px rgba(0,0,0,0.1)',
|
||||
}}
|
||||
>
|
||||
{paramConfig?.icon || '📋'}
|
||||
</div>
|
||||
</Col>
|
||||
<Col flex="auto">
|
||||
<div>
|
||||
<Text strong style={{ color: paramConfig?.color }}>
|
||||
{paramConfig?.label || condition.parameter}
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
<Text style={{ fontSize: 16 }}>
|
||||
{renderConditionValue(condition)}
|
||||
</Text>
|
||||
</div>
|
||||
{condition.description && (
|
||||
<div>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
{condition.description}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
</Col>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染规则条件(支持分组模式)
|
||||
const renderRuleConditions = () => {
|
||||
const ruleContent = data.ruleContent;
|
||||
if (!ruleContent) {
|
||||
return <Empty description="暂无规则条件" image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
||||
}
|
||||
|
||||
// 分组模式
|
||||
if (ruleContent.conditionGroups?.length) {
|
||||
const groupOperator = ruleContent.groupOperator || 'OR';
|
||||
return (
|
||||
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||||
{ruleContent.conditionGroups.map((group: ConditionGroup, gIndex: number) => (
|
||||
<div key={gIndex}>
|
||||
{gIndex > 0 && (
|
||||
<div style={{ textAlign: 'center', margin: '8px 0' }}>
|
||||
<Tag color={groupOperator === 'OR' ? 'orange' : 'blue'} style={{ fontSize: 14 }}>
|
||||
{groupOperator === 'OR' ? 'OR(或)' : 'AND(且)'}
|
||||
</Tag>
|
||||
</div>
|
||||
)}
|
||||
<Card
|
||||
size="small"
|
||||
title={
|
||||
<Space>
|
||||
<Text strong>{group.groupName || `条件组 ${gIndex + 1}`}</Text>
|
||||
{group.conditions?.length > 1 && (
|
||||
<Tag color={group.logicalOperator === 'AND' ? 'blue' : 'orange'}>
|
||||
组内: {group.logicalOperator}
|
||||
</Tag>
|
||||
)}
|
||||
</Space>
|
||||
}
|
||||
style={{ borderRadius: 8, borderColor: '#1890ff', borderStyle: 'dashed' }}
|
||||
>
|
||||
{group.conditions?.length > 0 ? (
|
||||
<Row gutter={[12, 12]}>
|
||||
{group.conditions.map((cond, cIndex) => renderConditionCard(cond, cIndex))}
|
||||
</Row>
|
||||
) : (
|
||||
<Empty description="该组暂无条件" image={Empty.PRESENTED_IMAGE_SIMPLE} />
|
||||
)}
|
||||
</Card>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* 分组模式说明 */}
|
||||
<div
|
||||
style={{
|
||||
padding: 12,
|
||||
background: '#f5f5f5',
|
||||
borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<Space>
|
||||
<InfoCircleOutlined style={{ color: '#1890ff' }} />
|
||||
<Text type="secondary">
|
||||
以上 {ruleContent.conditionGroups.length} 个条件组之间为
|
||||
<Text strong style={{ color: groupOperator === 'OR' ? '#fa8c16' : '#1890ff', margin: '0 4px' }}>
|
||||
{groupOperator === 'OR' ? '或(OR)' : '与(AND)'}
|
||||
</Text>
|
||||
关系,
|
||||
{groupOperator === 'OR'
|
||||
? '任一组条件满足即触发阻飞'
|
||||
: '所有组条件都满足才触发阻飞'}
|
||||
</Text>
|
||||
</Space>
|
||||
</div>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
|
||||
// 简单模式(向后兼容)
|
||||
const conditions = ruleContent.conditions || [];
|
||||
if (conditions.length === 0) {
|
||||
return <Empty description="暂无规则条件" image={Empty.PRESENTED_IMAGE_SIMPLE} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Row gutter={[12, 12]}>
|
||||
{conditions.map((condition: RuleCondition, index: number) => renderConditionCard(condition, index))}
|
||||
</Row>
|
||||
|
||||
{/* 条件关系说明 */}
|
||||
{conditions.length > 1 && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: 16,
|
||||
padding: 12,
|
||||
background: '#f5f5f5',
|
||||
borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<Space>
|
||||
<InfoCircleOutlined style={{ color: '#1890ff' }} />
|
||||
<Text type="secondary">
|
||||
以上 {conditions.length} 个条件之间为
|
||||
<Text strong style={{ color: ruleContent.logicalOperator === 'AND' ? '#1890ff' : '#fa8c16', margin: '0 4px' }}>
|
||||
{ruleContent.logicalOperator === 'AND' ? '与(AND)' : '或(OR)'}
|
||||
</Text>
|
||||
关系,
|
||||
{ruleContent.logicalOperator === 'AND'
|
||||
? '需要所有条件都满足才触发阻飞'
|
||||
: '只需满足任一条件即触发阻飞'}
|
||||
</Text>
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<Space>
|
||||
<CloudOutlined style={{ color: '#1890ff' }} />
|
||||
<span>天气规则详情</span>
|
||||
</Space>
|
||||
}
|
||||
open={visible}
|
||||
onCancel={() => onVisibleChange(false)}
|
||||
footer={null}
|
||||
width={800}
|
||||
destroyOnClose
|
||||
bodyStyle={{ padding: '16px 24px' }}
|
||||
>
|
||||
{/* 规则头部信息 */}
|
||||
<Card
|
||||
style={{
|
||||
marginBottom: 16,
|
||||
borderRadius: 8,
|
||||
background: levelConfig?.bgColor || '#fafafa',
|
||||
border: `1px solid ${levelConfig?.color || '#d9d9d9'}`,
|
||||
}}
|
||||
bodyStyle={{ padding: 16 }}
|
||||
>
|
||||
<Row align="middle" gutter={24}>
|
||||
<Col>
|
||||
<div
|
||||
style={{
|
||||
width: 60,
|
||||
height: 60,
|
||||
borderRadius: 12,
|
||||
background: '#fff',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
fontSize: 28,
|
||||
color: levelConfig?.color,
|
||||
boxShadow: '0 2px 8px rgba(0,0,0,0.1)',
|
||||
}}
|
||||
>
|
||||
{levelConfig?.icon}
|
||||
</div>
|
||||
</Col>
|
||||
<Col flex="auto">
|
||||
<Space direction="vertical" size={4}>
|
||||
<Space>
|
||||
<Title level={4} style={{ margin: 0 }}>{data.ruleName}</Title>
|
||||
{data.status === 1 ? (
|
||||
<Tag icon={<CheckCircleOutlined />} color="success">启用中</Tag>
|
||||
) : (
|
||||
<Tag icon={<CloseCircleOutlined />} color="default">已禁用</Tag>
|
||||
)}
|
||||
</Space>
|
||||
<Space split={<Divider type="vertical" />}>
|
||||
<Text type="secondary">编码: <Text code>{data.ruleCode}</Text></Text>
|
||||
<Text type="secondary">级别: <Text strong style={{ color: levelConfig?.color }}>{levelConfig?.text}</Text></Text>
|
||||
<Text type="secondary">优先级: <Tag color="orange">{data.priority}</Tag></Text>
|
||||
</Space>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
|
||||
{/* 基本信息 */}
|
||||
<Card
|
||||
title={<Text strong>基本信息</Text>}
|
||||
size="small"
|
||||
style={{ marginBottom: 16, borderRadius: 8 }}
|
||||
headStyle={{ borderBottom: '1px solid #f0f0f0' }}
|
||||
>
|
||||
<Descriptions column={2} size="small">
|
||||
<Descriptions.Item label="目标ID">
|
||||
<Tag color="blue">{data.targetId}</Tag>
|
||||
<Text type="secondary" style={{ marginLeft: 8, fontSize: 12 }}>
|
||||
({data.ruleLevel === 2 ? '景区' : '设备'})
|
||||
</Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="规则模式">
|
||||
<Tag color={data.ruleContent?.conditionGroups?.length ? 'purple' : 'cyan'}>
|
||||
{data.ruleContent?.conditionGroups?.length ? '分组模式' : '简单模式'}
|
||||
</Tag>
|
||||
</Descriptions.Item>
|
||||
{data.ruleContent?.effectiveTime && (
|
||||
<Descriptions.Item label="生效时间段">
|
||||
<Space>
|
||||
<ClockCircleOutlined style={{ color: '#1890ff' }} />
|
||||
<Text>{data.ruleContent.effectiveTime}</Text>
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
<Descriptions.Item label="创建时间">{data.createTime}</Descriptions.Item>
|
||||
<Descriptions.Item label="更新时间">{data.updateTime}</Descriptions.Item>
|
||||
{data.remark && (
|
||||
<Descriptions.Item label="备注" span={2}>
|
||||
<Text type="secondary">{data.remark}</Text>
|
||||
</Descriptions.Item>
|
||||
)}
|
||||
</Descriptions>
|
||||
</Card>
|
||||
|
||||
{/* 规则条件 */}
|
||||
<Card
|
||||
title={
|
||||
<Space>
|
||||
<Text strong>规则条件</Text>
|
||||
<Tag>{getConditionCount()} 个条件</Tag>
|
||||
</Space>
|
||||
}
|
||||
size="small"
|
||||
style={{ borderRadius: 8 }}
|
||||
headStyle={{ borderBottom: '1px solid #f0f0f0' }}
|
||||
>
|
||||
{renderRuleConditions()}
|
||||
</Card>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeatherRuleDetailModal;
|
||||
@@ -0,0 +1,652 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
ModalForm,
|
||||
ProFormText,
|
||||
ProFormSelect,
|
||||
ProFormDigit,
|
||||
ProFormTextArea,
|
||||
StepsForm,
|
||||
ProFormRadio,
|
||||
ProCard,
|
||||
} from '@ant-design/pro-components';
|
||||
import {
|
||||
Form,
|
||||
message,
|
||||
Space,
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Row,
|
||||
Col,
|
||||
Tag,
|
||||
Typography,
|
||||
Alert,
|
||||
InputNumber,
|
||||
Select,
|
||||
Input,
|
||||
Tooltip,
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined,
|
||||
MinusCircleOutlined,
|
||||
ThunderboltOutlined,
|
||||
CloudOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
InfoCircleOutlined,
|
||||
DeleteOutlined,
|
||||
QuestionCircleOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
export interface WeatherRuleItem {
|
||||
id?: number;
|
||||
ruleCode?: string;
|
||||
ruleName?: string;
|
||||
ruleLevel?: number;
|
||||
targetId?: string;
|
||||
priority?: number;
|
||||
ruleContent?: RuleContent;
|
||||
status?: number;
|
||||
remark?: string;
|
||||
tenantId?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
}
|
||||
|
||||
export interface RuleContent {
|
||||
ruleCode?: string;
|
||||
ruleName?: string;
|
||||
conditions?: RuleCondition[];
|
||||
conditionGroups?: ConditionGroup[];
|
||||
groupOperator?: string;
|
||||
logicalOperator?: string;
|
||||
warningThresholds?: Record<string, any>;
|
||||
effectiveTime?: string;
|
||||
}
|
||||
|
||||
export interface ConditionGroup {
|
||||
groupName?: string;
|
||||
conditions: RuleCondition[];
|
||||
logicalOperator: string;
|
||||
}
|
||||
|
||||
export interface RuleCondition {
|
||||
parameter?: string;
|
||||
operator?: string;
|
||||
value?: number;
|
||||
minValue?: number;
|
||||
maxValue?: number;
|
||||
unit?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
interface WeatherRuleFormProps {
|
||||
visible: boolean;
|
||||
onVisibleChange: (visible: boolean) => void;
|
||||
initialValues?: WeatherRuleItem;
|
||||
onSuccess?: () => void;
|
||||
}
|
||||
|
||||
// 天气参数配置
|
||||
const WEATHER_PARAMETERS = [
|
||||
{ key: 'windSpeed', label: '风速', unit: 'm/s', icon: '💨', defaultMax: 12, description: '风速限制,超过此值禁止飞行' },
|
||||
{ key: 'temperature', label: '温度', unit: '°C', icon: '🌡️', defaultMin: -10, defaultMax: 45, description: '温度范围限制' },
|
||||
{ key: 'precipitation', label: '降雨量', unit: 'mm/h', icon: '🌧️', defaultMax: 0, description: '降雨量限制,有雨时禁止飞行' },
|
||||
{ key: 'visibility', label: '能见度', unit: 'm', icon: '👁️', defaultMin: 1000, description: '最低能见度要求' },
|
||||
{ key: 'humidity', label: '湿度', unit: '%', icon: '💧', defaultMax: 90, description: '湿度上限' },
|
||||
{ key: 'pressure', label: '气压', unit: 'hPa', icon: '📊', description: '气压范围限制' },
|
||||
{ key: 'cloudCover', label: '云量', unit: '%', icon: '☁️', defaultMax: 80, description: '云量上限' },
|
||||
{ key: 'cloudHeight', label: '云高', unit: 'm', icon: '⛅', defaultMin: 150, description: '最低云高要求' },
|
||||
];
|
||||
|
||||
// 运算符配置
|
||||
const OPERATORS = [
|
||||
{ value: '<=', label: '≤ 小于等于', description: '当前值不超过设定值' },
|
||||
{ value: '>=', label: '≥ 大于等于', description: '当前值不低于设定值' },
|
||||
{ value: '==', label: '= 等于', description: '当前值等于设定值' },
|
||||
{ value: 'between', label: '区间', description: '当前值在设定范围内' },
|
||||
];
|
||||
|
||||
// 预设模板
|
||||
const RULE_TEMPLATES = [
|
||||
{
|
||||
name: '标准飞行规则',
|
||||
description: '适用于大多数无人机飞行场景',
|
||||
conditions: [
|
||||
{ parameter: 'windSpeed', operator: '<=', value: 10, unit: 'm/s', description: '风速不超过10m/s' },
|
||||
{ parameter: 'precipitation', operator: '<=', value: 0, unit: 'mm/h', description: '无降雨' },
|
||||
{ parameter: 'visibility', operator: '>=', value: 1000, unit: 'm', description: '能见度大于1000m' },
|
||||
],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
name: '严格飞行规则',
|
||||
description: '适用于高精度作业或恶劣天气地区',
|
||||
conditions: [
|
||||
{ parameter: 'windSpeed', operator: '<=', value: 6, unit: 'm/s', description: '风速不超过6m/s' },
|
||||
{ parameter: 'precipitation', operator: '<=', value: 0, unit: 'mm/h', description: '无降雨' },
|
||||
{ parameter: 'visibility', operator: '>=', value: 3000, unit: 'm', description: '能见度大于3000m' },
|
||||
{ parameter: 'humidity', operator: '<=', value: 80, unit: '%', description: '湿度不超过80%' },
|
||||
{ parameter: 'cloudHeight', operator: '>=', value: 200, unit: 'm', description: '云高大于200m' },
|
||||
],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
{
|
||||
name: '宽松飞行规则',
|
||||
description: '适用于经验丰富的飞手或紧急任务',
|
||||
conditions: [
|
||||
{ parameter: 'windSpeed', operator: '<=', value: 15, unit: 'm/s', description: '风速不超过15m/s' },
|
||||
{ parameter: 'visibility', operator: '>=', value: 500, unit: 'm', description: '能见度大于500m' },
|
||||
],
|
||||
logicalOperator: 'AND',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* 天气规则表单组件
|
||||
* 支持创建和编辑天气规则
|
||||
*/
|
||||
const WeatherRuleForm: React.FC<WeatherRuleFormProps> = ({
|
||||
visible,
|
||||
onVisibleChange,
|
||||
initialValues,
|
||||
onSuccess,
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const [ruleLevel, setRuleLevel] = useState<number>(2);
|
||||
const [conditions, setConditions] = useState<RuleCondition[]>([]);
|
||||
const [logicalOperator, setLogicalOperator] = useState<string>('AND');
|
||||
|
||||
// 初始化表单数据
|
||||
useEffect(() => {
|
||||
if (visible && initialValues) {
|
||||
const initConditions = initialValues.ruleContent?.conditions || [];
|
||||
form.setFieldsValue({
|
||||
...initialValues,
|
||||
logicalOperator: initialValues.ruleContent?.logicalOperator || 'AND',
|
||||
effectiveTime: initialValues.ruleContent?.effectiveTime,
|
||||
});
|
||||
setRuleLevel(initialValues.ruleLevel || 2);
|
||||
setConditions(initConditions);
|
||||
setLogicalOperator(initialValues.ruleContent?.logicalOperator || 'AND');
|
||||
} else if (visible) {
|
||||
form.resetFields();
|
||||
setRuleLevel(2);
|
||||
setConditions([]);
|
||||
setLogicalOperator('AND');
|
||||
}
|
||||
}, [visible, initialValues, form]);
|
||||
|
||||
// 应用模板
|
||||
const applyTemplate = (template: typeof RULE_TEMPLATES[0]) => {
|
||||
setConditions(template.conditions);
|
||||
setLogicalOperator(template.logicalOperator);
|
||||
message.success(`已应用「${template.name}」模板`);
|
||||
};
|
||||
|
||||
// 添加条件
|
||||
const addCondition = (paramKey?: string) => {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === paramKey);
|
||||
const newCondition: RuleCondition = {
|
||||
parameter: paramKey || '',
|
||||
operator: '<=',
|
||||
value: param?.defaultMax,
|
||||
unit: param?.unit || '',
|
||||
description: '',
|
||||
};
|
||||
setConditions([...conditions, newCondition]);
|
||||
};
|
||||
|
||||
// 更新条件
|
||||
const updateCondition = (index: number, field: string, value: any) => {
|
||||
const newConditions = [...conditions];
|
||||
newConditions[index] = { ...newConditions[index], [field]: value };
|
||||
|
||||
// 如果更改了参数,自动更新单位
|
||||
if (field === 'parameter') {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === value);
|
||||
if (param) {
|
||||
newConditions[index].unit = param.unit;
|
||||
// 设置默认值
|
||||
if (newConditions[index].operator === '<=') {
|
||||
newConditions[index].value = param.defaultMax;
|
||||
} else if (newConditions[index].operator === '>=') {
|
||||
newConditions[index].value = param.defaultMin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setConditions(newConditions);
|
||||
};
|
||||
|
||||
// 删除条件
|
||||
const removeCondition = (index: number) => {
|
||||
setConditions(conditions.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const values = await form.validateFields();
|
||||
|
||||
if (conditions.length === 0) {
|
||||
message.error('请至少添加一个天气条件');
|
||||
return false;
|
||||
}
|
||||
|
||||
const ruleContent: RuleContent = {
|
||||
ruleCode: values.ruleCode,
|
||||
ruleName: values.ruleName,
|
||||
conditions: conditions,
|
||||
logicalOperator: logicalOperator,
|
||||
effectiveTime: values.effectiveTime,
|
||||
};
|
||||
|
||||
const payload: WeatherRuleItem = {
|
||||
...values,
|
||||
ruleContent,
|
||||
};
|
||||
|
||||
if (initialValues?.id) {
|
||||
await ordersApi.updateWeatherRule(initialValues.id, payload);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await ordersApi.createWeatherRule(payload);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
onSuccess?.();
|
||||
return true;
|
||||
} catch (error) {
|
||||
message.error(initialValues?.id ? '更新失败' : '创建失败');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染规则级别选择
|
||||
const renderLevelSelect = () => (
|
||||
<Row gutter={16}>
|
||||
{[
|
||||
{ value: 2, label: '景区级别', icon: <CloudOutlined />, color: '#52c41a', desc: '对指定景区下所有设备生效' },
|
||||
{ value: 3, label: '设备级别', icon: <ThunderboltOutlined />, color: '#f5222d', desc: '仅对指定设备生效(最高优先级)' },
|
||||
].map(item => (
|
||||
<Col span={12} key={item.value}>
|
||||
<Card
|
||||
hoverable
|
||||
style={{
|
||||
borderColor: ruleLevel === item.value ? item.color : '#d9d9d9',
|
||||
borderWidth: ruleLevel === item.value ? 2 : 1,
|
||||
cursor: 'pointer',
|
||||
}}
|
||||
bodyStyle={{ padding: 16, textAlign: 'center' }}
|
||||
onClick={() => {
|
||||
setRuleLevel(item.value);
|
||||
form.setFieldValue('ruleLevel', item.value);
|
||||
}}
|
||||
>
|
||||
<Space direction="vertical" size={4}>
|
||||
<span style={{ fontSize: 24, color: item.color }}>{item.icon}</span>
|
||||
<Text strong>{item.label}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{item.desc}</Text>
|
||||
</Space>
|
||||
</Card>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
);
|
||||
|
||||
// 渲染条件卡片
|
||||
const renderConditionCard = (condition: RuleCondition, index: number) => {
|
||||
const param = WEATHER_PARAMETERS.find(p => p.key === condition.parameter);
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={index}
|
||||
size="small"
|
||||
style={{ marginBottom: 12, borderRadius: 8 }}
|
||||
bodyStyle={{ padding: 16 }}
|
||||
>
|
||||
<Row gutter={16} align="middle">
|
||||
<Col flex="auto">
|
||||
<Row gutter={12} align="middle">
|
||||
{/* 参数选择 */}
|
||||
<Col span={6}>
|
||||
<Select
|
||||
value={condition.parameter}
|
||||
onChange={(value) => updateCondition(index, 'parameter', value)}
|
||||
placeholder="选择参数"
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
{WEATHER_PARAMETERS.map(p => (
|
||||
<Select.Option key={p.key} value={p.key}>
|
||||
<Space>
|
||||
<span>{p.icon}</span>
|
||||
<span>{p.label}</span>
|
||||
</Space>
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
|
||||
{/* 运算符选择 */}
|
||||
<Col span={5}>
|
||||
<Select
|
||||
value={condition.operator}
|
||||
onChange={(value) => updateCondition(index, 'operator', value)}
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
{OPERATORS.map(op => (
|
||||
<Select.Option key={op.value} value={op.value}>
|
||||
{op.label}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Col>
|
||||
|
||||
{/* 值输入 */}
|
||||
<Col span={6}>
|
||||
{condition.operator === 'between' ? (
|
||||
<Space>
|
||||
<InputNumber
|
||||
value={condition.minValue}
|
||||
onChange={(value) => updateCondition(index, 'minValue', value)}
|
||||
placeholder="最小值"
|
||||
style={{ width: 80 }}
|
||||
/>
|
||||
<span>~</span>
|
||||
<InputNumber
|
||||
value={condition.maxValue}
|
||||
onChange={(value) => updateCondition(index, 'maxValue', value)}
|
||||
placeholder="最大值"
|
||||
style={{ width: 80 }}
|
||||
/>
|
||||
</Space>
|
||||
) : (
|
||||
<InputNumber
|
||||
value={condition.value}
|
||||
onChange={(value) => updateCondition(index, 'value', value)}
|
||||
placeholder="请输入值"
|
||||
style={{ width: '100%' }}
|
||||
addonAfter={condition.unit}
|
||||
/>
|
||||
)}
|
||||
</Col>
|
||||
|
||||
{/* 描述输入 */}
|
||||
<Col span={7}>
|
||||
<Input
|
||||
value={condition.description}
|
||||
onChange={(e) => updateCondition(index, 'description', e.target.value)}
|
||||
placeholder="条件描述(可选)"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
|
||||
{/* 删除按钮 */}
|
||||
<Col flex="40px">
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
onClick={() => removeCondition(index)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 参数说明 */}
|
||||
{param && (
|
||||
<div style={{ marginTop: 8 }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>
|
||||
<InfoCircleOutlined style={{ marginRight: 4 }} />
|
||||
{param.description}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<ModalForm
|
||||
title={
|
||||
<Space>
|
||||
<CloudOutlined style={{ color: '#1890ff' }} />
|
||||
<span>{initialValues?.id ? '编辑天气规则' : '新建天气规则'}</span>
|
||||
</Space>
|
||||
}
|
||||
visible={visible}
|
||||
form={form}
|
||||
onVisibleChange={onVisibleChange}
|
||||
onFinish={handleSubmit}
|
||||
width={900}
|
||||
modalProps={{
|
||||
destroyOnClose: true,
|
||||
maskClosable: false,
|
||||
bodyStyle: { maxHeight: '70vh', overflowY: 'auto' },
|
||||
}}
|
||||
submitter={{
|
||||
searchConfig: {
|
||||
submitText: initialValues?.id ? '保存修改' : '创建规则',
|
||||
},
|
||||
}}
|
||||
>
|
||||
{/* 基本信息 */}
|
||||
<ProCard
|
||||
title={<Text strong>基本信息</Text>}
|
||||
headerBordered
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<Row gutter={24}>
|
||||
<Col span={12}>
|
||||
<ProFormText
|
||||
name="ruleCode"
|
||||
label="规则编码"
|
||||
placeholder="请输入规则编码(唯一标识)"
|
||||
rules={[
|
||||
{ required: true, message: '请输入规则编码' },
|
||||
{ pattern: /^[A-Za-z0-9_-]+$/, message: '只能包含字母、数字、下划线和横线' },
|
||||
]}
|
||||
disabled={!!initialValues?.id}
|
||||
tooltip="规则的唯一标识,创建后不可修改"
|
||||
fieldProps={{
|
||||
maxLength: 50,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<ProFormText
|
||||
name="ruleName"
|
||||
label="规则名称"
|
||||
placeholder="请输入规则名称"
|
||||
rules={[{ required: true, message: '请输入规则名称' }]}
|
||||
fieldProps={{
|
||||
maxLength: 100,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={24}>
|
||||
<Col span={12}>
|
||||
<ProFormDigit
|
||||
name="priority"
|
||||
label="优先级"
|
||||
placeholder="请输入优先级"
|
||||
min={0}
|
||||
max={9999}
|
||||
initialValue={100}
|
||||
rules={[{ required: true, message: '请输入优先级' }]}
|
||||
tooltip="数值越大优先级越高,同级别规则按优先级排序"
|
||||
fieldProps={{
|
||||
precision: 0,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<ProFormSelect
|
||||
name="status"
|
||||
label="状态"
|
||||
placeholder="请选择状态"
|
||||
initialValue={1}
|
||||
options={[
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
]}
|
||||
rules={[{ required: true, message: '请选择状态' }]}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</ProCard>
|
||||
|
||||
{/* 规则级别 */}
|
||||
<ProCard
|
||||
title={
|
||||
<Space>
|
||||
<Text strong>规则级别</Text>
|
||||
<Tooltip title="优先级:设备级别 > 景区级别 > 租户级别">
|
||||
<QuestionCircleOutlined style={{ color: '#999' }} />
|
||||
</Tooltip>
|
||||
</Space>
|
||||
}
|
||||
headerBordered
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
<Form.Item name="ruleLevel" initialValue={2} noStyle>
|
||||
<input type="hidden" />
|
||||
</Form.Item>
|
||||
{renderLevelSelect()}
|
||||
|
||||
<div style={{ marginTop: 16 }}>
|
||||
<ProFormText
|
||||
name="targetId"
|
||||
label={ruleLevel === 2 ? '景区ID' : '设备SN'}
|
||||
placeholder={
|
||||
ruleLevel === 2
|
||||
? '请输入景区ID'
|
||||
: '请输入设备序列号(SN)'
|
||||
}
|
||||
rules={[{ required: true, message: '请输入目标ID' }]}
|
||||
/>
|
||||
</div>
|
||||
</ProCard>
|
||||
|
||||
{/* 天气条件配置 */}
|
||||
<ProCard
|
||||
title={<Text strong>天气条件配置</Text>}
|
||||
headerBordered
|
||||
extra={
|
||||
<Space>
|
||||
<Select
|
||||
placeholder="选择预设模板"
|
||||
style={{ width: 160 }}
|
||||
onChange={(value) => {
|
||||
const template = RULE_TEMPLATES.find(t => t.name === value);
|
||||
if (template) applyTemplate(template);
|
||||
}}
|
||||
allowClear
|
||||
>
|
||||
{RULE_TEMPLATES.map(t => (
|
||||
<Select.Option key={t.name} value={t.name}>
|
||||
{t.name}
|
||||
</Select.Option>
|
||||
))}
|
||||
</Select>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
{/* 逻辑运算符 */}
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Space>
|
||||
<Text>条件关系:</Text>
|
||||
<Select
|
||||
value={logicalOperator}
|
||||
onChange={setLogicalOperator}
|
||||
style={{ width: 200 }}
|
||||
>
|
||||
<Select.Option value="AND">
|
||||
<Tag color="blue">AND</Tag> 所有条件都满足
|
||||
</Select.Option>
|
||||
<Select.Option value="OR">
|
||||
<Tag color="orange">OR</Tag> 任一条件满足
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
{/* 条件列表 */}
|
||||
{conditions.length === 0 ? (
|
||||
<Alert
|
||||
message="暂无天气条件"
|
||||
description="请点击下方按钮添加天气条件,或选择预设模板快速配置"
|
||||
type="info"
|
||||
showIcon
|
||||
style={{ marginBottom: 16 }}
|
||||
/>
|
||||
) : (
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
{conditions.map((condition, index) => renderConditionCard(condition, index))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 快速添加按钮 */}
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text type="secondary" style={{ marginBottom: 8, display: 'block' }}>快速添加:</Text>
|
||||
<Space wrap>
|
||||
{WEATHER_PARAMETERS.map(param => (
|
||||
<Button
|
||||
key={param.key}
|
||||
size="small"
|
||||
onClick={() => addCondition(param.key)}
|
||||
disabled={conditions.some(c => c.parameter === param.key)}
|
||||
>
|
||||
{param.icon} {param.label}
|
||||
</Button>
|
||||
))}
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="dashed"
|
||||
block
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => addCondition()}
|
||||
>
|
||||
添加自定义条件
|
||||
</Button>
|
||||
</ProCard>
|
||||
|
||||
{/* 其他设置 */}
|
||||
<ProCard
|
||||
title={<Text strong>其他设置</Text>}
|
||||
headerBordered
|
||||
collapsible
|
||||
defaultCollapsed
|
||||
>
|
||||
<ProFormText
|
||||
name="effectiveTime"
|
||||
label="生效时间段"
|
||||
placeholder="例如:06:00-18:00(留空表示全天生效)"
|
||||
tooltip="24小时制,设置规则生效的时间段"
|
||||
/>
|
||||
|
||||
<ProFormTextArea
|
||||
name="remark"
|
||||
label="备注"
|
||||
placeholder="请输入备注信息"
|
||||
fieldProps={{
|
||||
rows: 3,
|
||||
maxLength: 500,
|
||||
showCount: true,
|
||||
}}
|
||||
/>
|
||||
</ProCard>
|
||||
</ModalForm>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeatherRuleForm;
|
||||
@@ -0,0 +1,557 @@
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import { PageContainer, ProTable, type ActionType, ProCard } from '@ant-design/pro-components';
|
||||
import {
|
||||
Button,
|
||||
Space,
|
||||
Tag,
|
||||
message,
|
||||
Badge,
|
||||
Tooltip,
|
||||
Row,
|
||||
Col,
|
||||
Statistic,
|
||||
Switch,
|
||||
Typography,
|
||||
Dropdown,
|
||||
Modal,
|
||||
} from 'antd';
|
||||
import {
|
||||
ThunderboltOutlined,
|
||||
CloudOutlined,
|
||||
SafetyCertificateOutlined,
|
||||
SettingOutlined,
|
||||
CopyOutlined,
|
||||
EyeOutlined,
|
||||
DeleteOutlined,
|
||||
MoreOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import WeatherRuleForm, { WeatherRuleItem } from './components/WeatherRuleForm';
|
||||
import WeatherRuleDetailModal from './components/WeatherRuleDetailModal';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 天气参数配置(与 WeatherBlockSettingModal 保持一致)
|
||||
const WEATHER_PARAMETERS: Record<string, { label: string; unit: string; icon: string }> = {
|
||||
windSpeed: { label: '风速', unit: 'm/s', icon: '💨' },
|
||||
temperature: { label: '温度', unit: '°C', icon: '🌡️' },
|
||||
humidity: { label: '湿度', unit: '%', icon: '💧' },
|
||||
precipitation: { label: '降雨量', unit: 'mm/h', icon: '🌧️' },
|
||||
visibility: { label: '能见度', unit: 'm', icon: '👁️' },
|
||||
};
|
||||
|
||||
interface RuleCondition {
|
||||
parameter?: string;
|
||||
operator?: string;
|
||||
value?: number;
|
||||
minValue?: number;
|
||||
maxValue?: number;
|
||||
unit?: string;
|
||||
}
|
||||
|
||||
interface ConditionGroup {
|
||||
groupName?: string;
|
||||
conditions: RuleCondition[];
|
||||
logicalOperator: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 天气规则管理页面
|
||||
* 支持景区级别、设备级别的天气规则配置
|
||||
* 优先级:设备级别 > 景区级别
|
||||
*/
|
||||
const WeatherRulePage: React.FC = () => {
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
const [current, setCurrent] = useState<WeatherRuleItem | undefined>(undefined);
|
||||
const [statistics, setStatistics] = useState({
|
||||
total: 0,
|
||||
enabled: 0,
|
||||
scenicLevel: 0,
|
||||
deviceLevel: 0,
|
||||
});
|
||||
const actionRef = useRef<ActionType>();
|
||||
|
||||
// 规则级别配置
|
||||
const ruleLevelConfig = {
|
||||
2: { text: '景区级别', color: '#52c41a', icon: <CloudOutlined /> },
|
||||
3: { text: '设备级别', color: '#f5222d', icon: <ThunderboltOutlined /> },
|
||||
};
|
||||
|
||||
// 加载统计数据
|
||||
const loadStatistics = async () => {
|
||||
try {
|
||||
const response = await ordersApi.getWeatherRuleList({ current: 1, size: 1000 });
|
||||
const list = response.data || [];
|
||||
setStatistics({
|
||||
total: list.length,
|
||||
enabled: list.filter((item: WeatherRuleItem) => item.status === 1).length,
|
||||
scenicLevel: list.filter((item: WeatherRuleItem) => item.ruleLevel === 2).length,
|
||||
deviceLevel: list.filter((item: WeatherRuleItem) => item.ruleLevel === 3).length,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败', error);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadStatistics();
|
||||
}, []);
|
||||
|
||||
// 快速切换状态
|
||||
const handleStatusChange = async (record: WeatherRuleItem, checked: boolean) => {
|
||||
const hide = message.loading('正在更新...');
|
||||
try {
|
||||
await ordersApi.updateWeatherRuleStatus(record.id!, checked ? 1 : 0);
|
||||
message.success('状态更新成功');
|
||||
actionRef.current?.reload();
|
||||
loadStatistics();
|
||||
} catch {
|
||||
message.error('状态更新失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
// 删除规则
|
||||
const handleDelete = async (record: WeatherRuleItem) => {
|
||||
Modal.confirm({
|
||||
title: '确认删除',
|
||||
content: `确定要删除规则「${record.ruleName}」吗?`,
|
||||
okText: '确定',
|
||||
cancelText: '取消',
|
||||
okButtonProps: { danger: true },
|
||||
onOk: async () => {
|
||||
const hide = message.loading('正在删除...');
|
||||
try {
|
||||
await ordersApi.deleteWeatherRule(record.id!);
|
||||
message.success('删除成功');
|
||||
actionRef.current?.reload();
|
||||
loadStatistics();
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// 复制规则
|
||||
const handleCopyRule = (record: WeatherRuleItem) => {
|
||||
const newRule = {
|
||||
...record,
|
||||
id: undefined,
|
||||
ruleCode: `${record.ruleCode}_copy`,
|
||||
ruleName: `${record.ruleName}(副本)`,
|
||||
};
|
||||
setCurrent(newRule);
|
||||
setCreateOpen(true);
|
||||
};
|
||||
|
||||
// 生成规则描述(支持分组模式)
|
||||
const generateRuleDescription = (ruleContent: any): string => {
|
||||
if (!ruleContent) return '';
|
||||
|
||||
// 分组模式
|
||||
if (ruleContent.conditionGroups?.length) {
|
||||
const groupDescs = ruleContent.conditionGroups.map((g: ConditionGroup) => {
|
||||
if (!g.conditions?.length) return '';
|
||||
const condDescs = g.conditions.map((c: RuleCondition) => {
|
||||
const param = WEATHER_PARAMETERS[c.parameter || ''];
|
||||
const label = param?.label || c.parameter;
|
||||
if (c.operator === 'between') {
|
||||
return `${label} ${c.minValue}-${c.maxValue}${c.unit || ''}`;
|
||||
}
|
||||
return `${label}${c.operator}${c.value}${c.unit || ''}`;
|
||||
});
|
||||
return g.conditions.length > 1 ? `(${condDescs.join(` ${g.logicalOperator} `)})` : condDescs[0];
|
||||
}).filter(Boolean);
|
||||
return groupDescs.join(` ${ruleContent.groupOperator || 'OR'} `);
|
||||
}
|
||||
|
||||
// 简单模式(向后兼容)
|
||||
if (ruleContent.conditions?.length) {
|
||||
const condDescs = ruleContent.conditions.map((c: RuleCondition) => {
|
||||
const param = WEATHER_PARAMETERS[c.parameter || ''];
|
||||
const label = param?.label || c.parameter;
|
||||
if (c.operator === 'between') {
|
||||
return `${label} ${c.minValue}-${c.maxValue}${c.unit || ''}`;
|
||||
}
|
||||
return `${label}${c.operator}${c.value}${c.unit || ''}`;
|
||||
});
|
||||
return condDescs.join(` ${ruleContent.logicalOperator || 'AND'} `);
|
||||
}
|
||||
|
||||
return '';
|
||||
};
|
||||
|
||||
// 渲染条件预览(支持分组模式)
|
||||
const renderConditionsPreview = (record: WeatherRuleItem) => {
|
||||
const ruleContent = record.ruleContent;
|
||||
if (!ruleContent) return <Text type="secondary">暂无条件</Text>;
|
||||
|
||||
// 分组模式
|
||||
if (ruleContent.conditionGroups?.length) {
|
||||
const groupOperator = ruleContent.groupOperator || 'OR';
|
||||
return (
|
||||
<Space direction="vertical" size={4} style={{ width: '100%' }}>
|
||||
{ruleContent.conditionGroups.map((group: ConditionGroup, gIndex: number) => (
|
||||
<div key={gIndex}>
|
||||
{gIndex > 0 && (
|
||||
<Tag color={groupOperator === 'OR' ? 'orange' : 'blue'} style={{ marginBottom: 4 }}>
|
||||
{groupOperator}
|
||||
</Tag>
|
||||
)}
|
||||
<Space size={4} wrap>
|
||||
{group.groupName && (
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>[{group.groupName}]</Text>
|
||||
)}
|
||||
{group.conditions?.map((cond: RuleCondition, cIndex: number) => {
|
||||
const param = WEATHER_PARAMETERS[cond.parameter || ''];
|
||||
return (
|
||||
<React.Fragment key={cIndex}>
|
||||
{cIndex > 0 && (
|
||||
<Text type="secondary" style={{ fontSize: 11 }}>{group.logicalOperator}</Text>
|
||||
)}
|
||||
<Tag color="blue" style={{ margin: 0 }}>
|
||||
{param?.icon} {param?.label || cond.parameter} {cond.operator}{' '}
|
||||
{cond.operator === 'between'
|
||||
? `${cond.minValue}-${cond.maxValue}`
|
||||
: cond.value}
|
||||
{cond.unit}
|
||||
</Tag>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
</div>
|
||||
))}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
|
||||
// 简单模式(向后兼容)
|
||||
const conditions = ruleContent.conditions || [];
|
||||
if (conditions.length === 0) return <Text type="secondary">暂无条件</Text>;
|
||||
|
||||
const operator = ruleContent.logicalOperator || 'AND';
|
||||
return (
|
||||
<Space size={4} wrap>
|
||||
{conditions.map((cond: RuleCondition, index: number) => {
|
||||
const param = WEATHER_PARAMETERS[cond.parameter || ''];
|
||||
return (
|
||||
<React.Fragment key={index}>
|
||||
{index > 0 && <Text type="secondary" style={{ fontSize: 11 }}>{operator}</Text>}
|
||||
<Tag color="blue" style={{ margin: 0 }}>
|
||||
{param?.icon} {param?.label || cond.parameter} {cond.operator}{' '}
|
||||
{cond.operator === 'between'
|
||||
? `${cond.minValue}-${cond.maxValue}`
|
||||
: cond.value}
|
||||
{cond.unit}
|
||||
</Tag>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
|
||||
const columns: any[] = [
|
||||
{
|
||||
title: '规则信息',
|
||||
dataIndex: 'ruleName',
|
||||
width: 280,
|
||||
render: (_: any, record: WeatherRuleItem) => (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Space>
|
||||
<Text strong style={{ fontSize: 14 }}>{record.ruleName}</Text>
|
||||
{record.status === 1 && <Badge status="success" />}
|
||||
</Space>
|
||||
<Text type="secondary" copyable={{ text: record.ruleCode }} style={{ fontSize: 12 }}>
|
||||
{record.ruleCode}
|
||||
</Text>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '规则级别',
|
||||
dataIndex: 'ruleLevel',
|
||||
width: 130,
|
||||
render: (_: any, record: WeatherRuleItem) => {
|
||||
const level = record.ruleLevel;
|
||||
const config = ruleLevelConfig[level as keyof typeof ruleLevelConfig];
|
||||
return config ? (
|
||||
<Tag
|
||||
icon={config.icon}
|
||||
color={config.color}
|
||||
style={{ borderRadius: 12, padding: '2px 10px' }}
|
||||
>
|
||||
{config.text}
|
||||
</Tag>
|
||||
) : (
|
||||
<Tag>{level || '未知'}</Tag>
|
||||
);
|
||||
},
|
||||
filters: [
|
||||
{ text: '景区级别', value: 2 },
|
||||
{ text: '设备级别', value: 3 },
|
||||
],
|
||||
valueEnum: {
|
||||
2: { text: '景区级别' },
|
||||
3: { text: '设备级别' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '目标ID',
|
||||
dataIndex: 'targetId',
|
||||
width: 160,
|
||||
ellipsis: true,
|
||||
copyable: true,
|
||||
render: (text: string, record: WeatherRuleItem) => (
|
||||
<Tooltip title={`${record.ruleLevel === 2 ? '景区' : '设备'}: ${text}`}>
|
||||
<Text code style={{ fontSize: 12 }}>{text}</Text>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '规则条件',
|
||||
dataIndex: 'ruleContent',
|
||||
width: 350,
|
||||
search: false,
|
||||
render: (_: any, record: WeatherRuleItem) => renderConditionsPreview(record),
|
||||
},
|
||||
{
|
||||
title: '优先级',
|
||||
dataIndex: 'priority',
|
||||
width: 90,
|
||||
sorter: true,
|
||||
search: false,
|
||||
render: (priority: number) => (
|
||||
<Tag color={priority >= 100 ? 'orange' : 'default'} style={{ minWidth: 50, textAlign: 'center' }}>
|
||||
{priority}
|
||||
</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (_: any, record: WeatherRuleItem) => {
|
||||
const isEnabled = record.status === 1;
|
||||
return (
|
||||
<Switch
|
||||
checked={isEnabled}
|
||||
checkedChildren="启用"
|
||||
unCheckedChildren="禁用"
|
||||
onChange={(checked) => handleStatusChange(record, checked)}
|
||||
/>
|
||||
);
|
||||
},
|
||||
filters: [
|
||||
{ text: '启用', value: 1 },
|
||||
{ text: '禁用', value: 0 },
|
||||
],
|
||||
valueEnum: {
|
||||
0: { text: '禁用', status: 'Default' },
|
||||
1: { text: '启用', status: 'Success' },
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '更新时间',
|
||||
dataIndex: 'updateTime',
|
||||
valueType: 'dateTime',
|
||||
width: 160,
|
||||
sorter: true,
|
||||
search: false,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 120,
|
||||
fixed: 'right',
|
||||
search: false,
|
||||
render: (_: any, record: WeatherRuleItem) => (
|
||||
<Space size={0} split={<span style={{ color: '#d9d9d9', margin: '0 4px' }}>|</span>}>
|
||||
<Tooltip title="查看详情">
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<EyeOutlined />}
|
||||
onClick={() => {
|
||||
setCurrent(record);
|
||||
setDetailOpen(true);
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Dropdown
|
||||
menu={{
|
||||
items: [
|
||||
{
|
||||
key: 'copy',
|
||||
icon: <CopyOutlined />,
|
||||
label: '复制规则',
|
||||
onClick: () => handleCopyRule(record),
|
||||
},
|
||||
{
|
||||
type: 'divider',
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
icon: <DeleteOutlined />,
|
||||
label: '删除',
|
||||
danger: true,
|
||||
onClick: () => handleDelete(record),
|
||||
},
|
||||
],
|
||||
}}
|
||||
>
|
||||
<Button type="link" size="small" icon={<MoreOutlined />} />
|
||||
</Dropdown>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<PageContainer
|
||||
header={{
|
||||
title: (
|
||||
<Space>
|
||||
<CloudOutlined style={{ fontSize: 24, color: '#1890ff' }} />
|
||||
<span>天气规则管理</span>
|
||||
</Space>
|
||||
),
|
||||
subTitle: '配置无人机飞行天气限制规则,保障飞行安全',
|
||||
}}
|
||||
>
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={16} style={{ marginBottom: 16 }}>
|
||||
<Col span={6}>
|
||||
<ProCard hoverable style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<Text type="secondary">规则总数</Text>}
|
||||
value={statistics.total}
|
||||
prefix={<SettingOutlined style={{ color: '#1890ff' }} />}
|
||||
valueStyle={{ color: '#1890ff' }}
|
||||
/>
|
||||
</ProCard>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<ProCard hoverable style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<Text type="secondary">已启用</Text>}
|
||||
value={statistics.enabled}
|
||||
prefix={<SafetyCertificateOutlined style={{ color: '#52c41a' }} />}
|
||||
valueStyle={{ color: '#52c41a' }}
|
||||
suffix={<Text type="secondary" style={{ fontSize: 14 }}>/ {statistics.total}</Text>}
|
||||
/>
|
||||
</ProCard>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<ProCard hoverable style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<Text type="secondary">景区级别</Text>}
|
||||
value={statistics.scenicLevel}
|
||||
prefix={<CloudOutlined style={{ color: '#52c41a' }} />}
|
||||
valueStyle={{ color: '#52c41a', fontSize: 20 }}
|
||||
/>
|
||||
</ProCard>
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<ProCard hoverable style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<Text type="secondary">设备级别</Text>}
|
||||
value={statistics.deviceLevel}
|
||||
prefix={<ThunderboltOutlined style={{ color: '#f5222d' }} />}
|
||||
valueStyle={{ color: '#f5222d', fontSize: 20 }}
|
||||
/>
|
||||
</ProCard>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 规则列表 */}
|
||||
<ProCard style={{ borderRadius: 8 }}>
|
||||
<ProTable
|
||||
actionRef={actionRef}
|
||||
rowKey="id"
|
||||
columns={columns}
|
||||
request={async (params, sort) => {
|
||||
try {
|
||||
const response = await ordersApi.getWeatherRuleList({
|
||||
...params,
|
||||
current: params.current,
|
||||
size: params.pageSize,
|
||||
...sort,
|
||||
});
|
||||
// 刷新统计
|
||||
loadStatistics();
|
||||
return {
|
||||
data: response.data || [],
|
||||
success: true,
|
||||
total: response.total || 0,
|
||||
};
|
||||
} catch (error) {
|
||||
message.error('查询失败');
|
||||
return { data: [], success: false, total: 0 };
|
||||
}
|
||||
}}
|
||||
search={{
|
||||
labelWidth: 'auto',
|
||||
defaultCollapsed: false,
|
||||
span: 6,
|
||||
}}
|
||||
pagination={{
|
||||
defaultPageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total) => `共 ${total} 条规则`,
|
||||
}}
|
||||
scroll={{ x: 1400 }}
|
||||
options={{
|
||||
density: true,
|
||||
fullScreen: true,
|
||||
reload: true,
|
||||
setting: true,
|
||||
}}
|
||||
toolBarRender={false}
|
||||
tableAlertRender={false}
|
||||
rowClassName={(record) => record.status === 0 ? 'disabled-row' : ''}
|
||||
/>
|
||||
</ProCard>
|
||||
|
||||
{/* 创建规则弹窗 */}
|
||||
<WeatherRuleForm
|
||||
visible={createOpen}
|
||||
onVisibleChange={setCreateOpen}
|
||||
initialValues={current}
|
||||
onSuccess={() => {
|
||||
setCreateOpen(false);
|
||||
setCurrent(undefined);
|
||||
actionRef.current?.reload();
|
||||
loadStatistics();
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 规则详情弹窗 */}
|
||||
<WeatherRuleDetailModal
|
||||
visible={detailOpen}
|
||||
onVisibleChange={setDetailOpen}
|
||||
data={current}
|
||||
/>
|
||||
|
||||
<style>{`
|
||||
.disabled-row {
|
||||
opacity: 0.6;
|
||||
background-color: #fafafa;
|
||||
}
|
||||
.ant-pro-card:hover {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.09);
|
||||
transition: box-shadow 0.3s;
|
||||
}
|
||||
`}</style>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeatherRulePage;
|
||||
@@ -370,5 +370,29 @@ export const deviceApi = {
|
||||
return { success: false, message: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
// ========== 天气阻飞设置 ==========
|
||||
|
||||
/**
|
||||
* 更新设备天气阻飞开关
|
||||
* @param deviceSn 设备SN
|
||||
* @param weatherBlockEnabled 是否开启天气阻飞(0:关闭,1:开启)
|
||||
*/
|
||||
updateDeviceWeatherBlock: async (deviceSn: string, weatherBlockEnabled: number): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/weather-block', {
|
||||
method: 'PUT',
|
||||
data: { deviceSn, weatherBlockEnabled },
|
||||
});
|
||||
return normalizeResponse(res);
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取设备详情(包含天气阻飞状态)
|
||||
* @param deviceSn 设备SN
|
||||
*/
|
||||
getDeviceDetail: async (deviceSn: string) => {
|
||||
const res = await request(`/api-device/device/location/${deviceSn}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -469,4 +469,113 @@ export const ordersApi = {
|
||||
const res = await request(`/api-order/qrcode/${codeId}/orders`, { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: OrderItem[]; total: number };
|
||||
},
|
||||
|
||||
// ==================== 天气规则管理 ====================
|
||||
|
||||
// 获取天气规则列表
|
||||
getWeatherRuleList: async (params: { current?: number; size?: number; [k: string]: any }) => {
|
||||
const res = await request('/api-order/weather/rules/list', { method: 'GET', params });
|
||||
const list = (res as any)?.data ?? [];
|
||||
const total = (res as any)?.count ?? 0;
|
||||
return { data: list, total };
|
||||
},
|
||||
|
||||
// 创建天气规则
|
||||
createWeatherRule: async (data: any) => {
|
||||
const res = await request('/api-order/weather/rules/create', { method: 'POST', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 更新天气规则
|
||||
updateWeatherRule: async (id: number, data: any) => {
|
||||
const res = await request(`/api-order/weather/rules/${id}`, { method: 'PUT', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 更新规则状态
|
||||
updateWeatherRuleStatus: async (id: number, status: number) => {
|
||||
const res = await request(`/api-order/weather/rules/${id}/status`, { method: 'PUT', data: { status } });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 删除天气规则
|
||||
deleteWeatherRule: async (id: number) => {
|
||||
const res = await request(`/api-order/weather/rules/${id}`, { method: 'DELETE' });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 获取规则详情
|
||||
getWeatherRuleDetail: async (id: number) => {
|
||||
const res = await request(`/api-order/weather/rules/${id}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// 根据规则编码查询
|
||||
getWeatherRuleByCode: async (ruleCode: string) => {
|
||||
const res = await request(`/api-order/weather/rules/code/${ruleCode}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// 查找适用的规则
|
||||
findApplicableWeatherRule: async (params: { deviceSn?: string; tourismId?: number; tenantId?: string }) => {
|
||||
const res = await request('/api-order/weather/rules/applicable', { method: 'GET', params });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// ==================== 天气检查 ====================
|
||||
|
||||
// 订单创建天气检查
|
||||
checkWeatherForOrder: async (data: { tourismId: number; orderNo?: string }) => {
|
||||
const res = await request('/api-order/weather/check/order', { method: 'POST', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 任务创建天气检查
|
||||
checkWeatherForMission: async (data: { deviceSn: string; tourismId: number; missionId?: string }) => {
|
||||
const res = await request('/api-order/weather/check/mission', { method: 'POST', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 航线作业天气检查
|
||||
checkWeatherForLineJob: async (data: { deviceSn: string; tourismId: number; lineJobId?: string }) => {
|
||||
const res = await request('/api-order/weather/check/linejob', { method: 'POST', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// 通用天气检查
|
||||
validateWeather: async (data: { deviceSn?: string; tourismId: number; tenantId?: string }) => {
|
||||
const res = await request('/api-order/weather/check/validate', { method: 'POST', data });
|
||||
return res;
|
||||
},
|
||||
|
||||
// ==================== 天气阻飞设置 ====================
|
||||
|
||||
// 更新景区天气阻飞开关
|
||||
updateTourismWeatherBlock: async (id: number, weatherBlockEnabled: number) => {
|
||||
const res = await request(`/api-order/tourism/${id}/weather-block`, {
|
||||
method: 'PUT',
|
||||
data: { weatherBlockEnabled }
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
// 获取景区的天气规则
|
||||
getTourismWeatherRule: async (tourismId: number) => {
|
||||
const res = await request('/api-order/weather/rules/list', {
|
||||
method: 'GET',
|
||||
params: { ruleLevel: 2, targetId: String(tourismId), status: 1 }
|
||||
});
|
||||
const list = (res as any)?.data ?? [];
|
||||
return list.length > 0 ? list[0] : null;
|
||||
},
|
||||
|
||||
// 获取设备的天气规则
|
||||
getDeviceWeatherRule: async (deviceSn: string) => {
|
||||
const res = await request('/api-order/weather/rules/list', {
|
||||
method: 'GET',
|
||||
params: { ruleLevel: 3, targetId: deviceSn, status: 1 }
|
||||
});
|
||||
const list = (res as any)?.data ?? [];
|
||||
return list.length > 0 ? list[0] : null;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user