"use client" import type React from "react" import {useMemo, useState} from "react" import dayjs from "dayjs" import {Button, Card, Col, Flex, Form, Input, Popconfirm, Row, Select, Space, Table, Tag} from "antd" import {BadgeAlertIcon as Alert, FileText} from "lucide-react" import globalMessage from "@/app/_modules/globalMessage"; type Level = "红色" | "橙色" | "黄色" | "蓝色" type WarnType = "燃气" | "供水" | "电力" | "交通" | "综合" type MatterItemStatus = "启用" | "禁用" | "作废" export type MatterItem = { id: string code: string name: string type: WarnType level: Level status: MatterItemStatus createdAt: string updatedAt: string } export type ReasonEntry = { id: string type: WarnType level: Level reason: string createdAt: string } export type MatterManagementProps = { matters: MatterItem[] setMatters: React.Dispatch> reasons: ReasonEntry[] setReasons: React.Dispatch> } const LEVELS: Level[] = ["红色", "橙色", "黄色", "蓝色"] const TYPES: WarnType[] = ["燃气", "供水", "电力", "交通", "综合"] function levelColor(lvl: Level) { switch (lvl) { case "红色": return "red" case "橙色": return "orange" case "黄色": return "gold" case "蓝色": return "blue" default: return "default" } } function genId(prefix = "id") { return `${prefix}_${Math.random().toString(36).slice(2, 10)}` } function autoCode(type: WarnType, level: Level, seq: number) { const date = dayjs().format("YYYYMMDD") const t = { 燃气: "GAS", 供水: "WTR", 电力: "ELE", 交通: "TRF", 综合: "COM" }[type] const l = { 红色: "R", 橙色: "O", 黄色: "Y", 蓝色: "B" }[level] return `YW-${t}-${l}-${date}-${seq.toString().padStart(3, "0")}` } export default function MatterManagement({ matters, setMatters, reasons, setReasons }: MatterManagementProps) { const [form] = Form.useForm<{ name: string; type: WarnType; level: Level }>() const [seq, setSeq] = useState(matters.length + 1) const type = Form.useWatch("type", form) const level = Form.useWatch("level", form) const computedCode = useMemo(() => { if (!type || !level) return "" return autoCode(type, level, seq) }, [type, level, seq]) return ( 预警清单管理 } >
{ const item: MatterItem = { id: genId("matter"), code: computedCode || autoCode(vals.type, vals.level, seq), name: vals.name, type: vals.type, level: vals.level, status: "启用", createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), } setMatters((prev) => [item, ...prev]) setSeq((s) => s + 1) form.resetFields() globalMessage.success("已新增事项") }} > ({ label: l, value: l }))} />
size="small" rowKey="id" dataSource={matters} pagination={{ pageSize: 6 }} columns={[ { title: "名称", dataIndex: "name" }, { title: "编码", dataIndex: "code" }, { title: "类型", dataIndex: "type" }, { title: "等级", dataIndex: "level" }, { title: "状态", dataIndex: "status", render: (s: MatterItemStatus) => ( {s} ), }, { title: "操作", render: (_, r) => ( setMatters((prev) => prev.map((m) => m.id === r.id ? { ...m, status: "作废", updatedAt: new Date().toISOString() } : m, ), ) } > ), }, ]} />
预警原因库管理 } >
{ const item: ReasonEntry = { id: genId("reason"), type: vals.type, level: vals.level, reason: vals.reason, createdAt: new Date().toISOString(), } setReasons((prev) => [item, ...prev]) globalMessage.success("已添加原因") }} initialValues={{ type: "综合", level: "黄色" }} > ({ label: l, value: l }))} />
size="small" rowKey="id" dataSource={reasons} pagination={{ pageSize: 6 }} columns={[ { title: "类型", dataIndex: "type" }, { title: "等级", dataIndex: "level" }, { title: "原因", dataIndex: "reason" }, { title: "创建时间", dataIndex: "createdAt", render: (t) => dayjs(t).format("YYYY-MM-DD") }, ]} />
) }