import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Textarea } from "@/components/ui/textarea"; import { Droplets, Power, PowerOff, Settings, Thermometer, Zap } from "lucide-react"; import type { DecisionFormState, DecisionLevel, ExecutionMode } from "./types"; interface DecisionFormDialogProps { mode: 'create' | 'edit'; open: boolean; onOpenChange: (open: boolean) => void; formState: DecisionFormState; onFormChange: (key: K, value: DecisionFormState[K]) => void; onSubmit: () => void; } const triggerDeviceOptions = [ { value: '土壤传感器-01', label: '土壤传感器-01', icon: Droplets }, { value: '土壤传感器-02', label: '土壤传感器-02', icon: Droplets }, { value: '土壤传感器-03', label: '土壤传感器-03', icon: Droplets }, { value: '温度传感器-01', label: '温度传感器-01', icon: Thermometer }, { value: '温度传感器-02', label: '温度传感器-02', icon: Thermometer }, { value: '湿度传感器-01', label: '湿度传感器-01' }, { value: '光照传感器-01', label: '光照传感器-01' }, { value: 'CO2传感器-01', label: 'CO2传感器-01' }, ]; const triggerParameterOptions = [ { value: '土壤湿度', label: '土壤湿度 (%)' }, { value: '土壤温度', label: '土壤温度 (℃)' }, { value: '空气温度', label: '空气温度 (℃)' }, { value: '空气湿度', label: '空气湿度 (%)' }, { value: '光照强度', label: '光照强度 (lux)' }, { value: 'CO2浓度', label: 'CO₂ 浓度 (ppm)' }, { value: 'EC值', label: 'EC 值 (mS/cm)' }, { value: 'PH值', label: 'PH 值' }, ]; const compareOperatorOptions = [ { value: '>', label: '大于' }, { value: '<', label: '小于' }, { value: '>=', label: '大于等于' }, { value: '<=', label: '小于等于' }, { value: '==', label: '等于' }, ]; const targetDeviceOptions = [ '水肥机-01', '水肥机-02', '灌溉阀门-A1', '灌溉阀门-B2', '排风扇-01', '排风扇-02', '喷雾器-01', '喷雾器-02', '补光灯-01', '加热器-01', ]; export function DecisionFormDialog({ mode, open, onOpenChange, formState, onFormChange, onSubmit }: DecisionFormDialogProps) { const dialogTitle = mode === 'create' ? '新建决策' : '编辑决策'; const dialogDescription = mode === 'create' ? '创建基于设备参数的业务融合决策。' : '更新当前决策的触发条件、执行动作与详细内容。'; const submitLabel = mode === 'create' ? '保存决策' : '保存修改'; return ( {dialogTitle} {dialogDescription}

基础信息

onFormChange('name', event.target.value)} />
onFormChange('confidence', Number(event.target.value))} />

{formState.executionMode === 'auto' ? '当触发条件满足时,系统将自动执行设备控制操作。' : '需要人工点击执行按钮,验证触发条件后再执行。'}

触发条件设置

设置触发条件:当设备参数满足指定阈值时自动触发决策。

onFormChange('triggerValue', event.target.value)} />

执行设置

配置决策触发后要执行的设备和动作。

onFormChange('duration', Number(event.target.value))} />

决策内容