"use client"
import {useState} from "react"
import {Button, Card, Col, Form, Input, Modal, Popconfirm, Row, Select, Space, Table, Tag} from "antd"
import {DeleteOutlined, EditOutlined, PlusOutlined, ToolOutlined} from "@ant-design/icons"
import globalMessage from "@/app/_modules/globalMessage";
const { Option } = Select
// 模拟监测设备数据
const mockDeviceData = [
{
id: "D001",
name: "压力监测器001",
type: "压力监测",
model: "PT-100",
location: "解放路调压站",
installDate: "2023-03-15",
status: "在线",
lastMaintenance: "2024-01-10",
nextMaintenance: "2024-04-10",
manufacturer: "华为技术",
serialNumber: "HW20230315001",
},
{
id: "D002",
name: "流量监测器002",
type: "流量监测",
model: "FM-200",
location: "人民路段",
installDate: "2023-05-20",
status: "离线",
lastMaintenance: "2023-12-15",
nextMaintenance: "2024-03-15",
manufacturer: "中兴通讯",
serialNumber: "ZX20230520002",
},
{
id: "D003",
name: "温度监测器003",
type: "温度监测",
model: "TM-300",
location: "建设路段",
installDate: "2023-07-10",
status: "在线",
lastMaintenance: "2024-01-05",
nextMaintenance: "2024-04-05",
manufacturer: "海康威视",
serialNumber: "HK20230710003",
},
{
id: "D004",
name: "泄漏检测器004",
type: "泄漏检测",
model: "LD-400",
location: "解放路北段",
installDate: "2023-09-25",
status: "维护中",
lastMaintenance: "2024-01-20",
nextMaintenance: "2024-04-20",
manufacturer: "大华技术",
serialNumber: "DH20230925004",
},
]
export default function DeviceManagement() {
const [isModalVisible, setIsModalVisible] = useState(false)
const [editingRecord, setEditingRecord] = useState(null)
const [form] = Form.useForm()
const handleAdd = () => {
setEditingRecord(null)
form.resetFields()
setIsModalVisible(true)
}
const handleEdit = (record: any) => {
setEditingRecord(record)
form.setFieldsValue(record)
setIsModalVisible(true)
}
const handleDelete = (id: string) => {
globalMessage.success("删除成功")
}
const handleMaintenance = (record: any) => {
globalMessage.success(`设备 ${record.name} 维护记录已更新`)
}
const handleModalOk = () => {
form.validateFields().then((values) => {
if (editingRecord) {
globalMessage.success("更新成功")
} else {
globalMessage.success("添加成功")
}
setIsModalVisible(false)
form.resetFields()
})
}
const columns = [
{ title: "设备编号", dataIndex: "id", key: "id" },
{ title: "设备名称", dataIndex: "name", key: "name" },
{ title: "设备类型", dataIndex: "type", key: "type" },
{ title: "设备型号", dataIndex: "model", key: "model" },
{ title: "安装位置", dataIndex: "location", key: "location" },
{ title: "制造商", dataIndex: "manufacturer", key: "manufacturer" },
{ title: "序列号", dataIndex: "serialNumber", key: "serialNumber" },
{ title: "安装日期", dataIndex: "installDate", key: "installDate" },
{ title: "上次维护", dataIndex: "lastMaintenance", key: "lastMaintenance" },
{ title: "下次维护", dataIndex: "nextMaintenance", key: "nextMaintenance" },
{
title: "状态",
dataIndex: "status",
key: "status",
render: (status: string) => {
const colorMap = {
在线: "green",
离线: "red",
维护中: "orange",
故障: "red",
}
return