device-management.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. "use client"
  2. import {useState} from "react"
  3. import {Button, Card, Col, Form, Input, Modal, Popconfirm, Row, Select, Space, Table, Tag} from "antd"
  4. import {DeleteOutlined, EditOutlined, PlusOutlined, ToolOutlined} from "@ant-design/icons"
  5. import globalMessage from "@/app/_modules/globalMessage";
  6. const { Option } = Select
  7. // 模拟监测设备数据
  8. const mockDeviceData = [
  9. {
  10. id: "D001",
  11. name: "压力监测器001",
  12. type: "压力监测",
  13. model: "PT-100",
  14. location: "解放路调压站",
  15. installDate: "2023-03-15",
  16. status: "在线",
  17. lastMaintenance: "2024-01-10",
  18. nextMaintenance: "2024-04-10",
  19. manufacturer: "华为技术",
  20. serialNumber: "HW20230315001",
  21. },
  22. {
  23. id: "D002",
  24. name: "流量监测器002",
  25. type: "流量监测",
  26. model: "FM-200",
  27. location: "人民路段",
  28. installDate: "2023-05-20",
  29. status: "离线",
  30. lastMaintenance: "2023-12-15",
  31. nextMaintenance: "2024-03-15",
  32. manufacturer: "中兴通讯",
  33. serialNumber: "ZX20230520002",
  34. },
  35. {
  36. id: "D003",
  37. name: "温度监测器003",
  38. type: "温度监测",
  39. model: "TM-300",
  40. location: "建设路段",
  41. installDate: "2023-07-10",
  42. status: "在线",
  43. lastMaintenance: "2024-01-05",
  44. nextMaintenance: "2024-04-05",
  45. manufacturer: "海康威视",
  46. serialNumber: "HK20230710003",
  47. },
  48. {
  49. id: "D004",
  50. name: "泄漏检测器004",
  51. type: "泄漏检测",
  52. model: "LD-400",
  53. location: "解放路北段",
  54. installDate: "2023-09-25",
  55. status: "维护中",
  56. lastMaintenance: "2024-01-20",
  57. nextMaintenance: "2024-04-20",
  58. manufacturer: "大华技术",
  59. serialNumber: "DH20230925004",
  60. },
  61. ]
  62. export default function DeviceManagement() {
  63. const [isModalVisible, setIsModalVisible] = useState(false)
  64. const [editingRecord, setEditingRecord] = useState(null)
  65. const [form] = Form.useForm()
  66. const handleAdd = () => {
  67. setEditingRecord(null)
  68. form.resetFields()
  69. setIsModalVisible(true)
  70. }
  71. const handleEdit = (record: any) => {
  72. setEditingRecord(record)
  73. form.setFieldsValue(record)
  74. setIsModalVisible(true)
  75. }
  76. const handleDelete = (id: string) => {
  77. globalMessage.success("删除成功")
  78. }
  79. const handleMaintenance = (record: any) => {
  80. globalMessage.success(`设备 ${record.name} 维护记录已更新`)
  81. }
  82. const handleModalOk = () => {
  83. form.validateFields().then((values) => {
  84. if (editingRecord) {
  85. globalMessage.success("更新成功")
  86. } else {
  87. globalMessage.success("添加成功")
  88. }
  89. setIsModalVisible(false)
  90. form.resetFields()
  91. })
  92. }
  93. const columns = [
  94. { title: "设备编号", dataIndex: "id", key: "id" },
  95. { title: "设备名称", dataIndex: "name", key: "name" },
  96. { title: "设备类型", dataIndex: "type", key: "type" },
  97. { title: "设备型号", dataIndex: "model", key: "model" },
  98. { title: "安装位置", dataIndex: "location", key: "location" },
  99. { title: "制造商", dataIndex: "manufacturer", key: "manufacturer" },
  100. { title: "序列号", dataIndex: "serialNumber", key: "serialNumber" },
  101. { title: "安装日期", dataIndex: "installDate", key: "installDate" },
  102. { title: "上次维护", dataIndex: "lastMaintenance", key: "lastMaintenance" },
  103. { title: "下次维护", dataIndex: "nextMaintenance", key: "nextMaintenance" },
  104. {
  105. title: "状态",
  106. dataIndex: "status",
  107. key: "status",
  108. render: (status: string) => {
  109. const colorMap = {
  110. 在线: "green",
  111. 离线: "red",
  112. 维护中: "orange",
  113. 故障: "red",
  114. }
  115. return <Tag color={colorMap[status as keyof typeof colorMap]}>{status}</Tag>
  116. },
  117. },
  118. {
  119. title: "操作",
  120. key: "action",
  121. render: (_, record) => (
  122. <Space>
  123. <Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>
  124. 编辑
  125. </Button>
  126. <Button type="link" icon={<ToolOutlined />} onClick={() => handleMaintenance(record)}>
  127. 维护
  128. </Button>
  129. <Popconfirm title="确定删除吗?" onConfirm={() => handleDelete(record.id)}>
  130. <Button type="link" danger icon={<DeleteOutlined />}>
  131. 删除
  132. </Button>
  133. </Popconfirm>
  134. </Space>
  135. ),
  136. },
  137. ]
  138. return (
  139. <div className="p-6">
  140. <Card title="监测设备管理">
  141. <Row gutter={16} className="mb-4">
  142. <Col span={6}>
  143. <Card size="small">
  144. <div className="text-center">
  145. <div className="text-2xl font-bold text-blue-600">342</div>
  146. <div className="text-gray-600">设备总数</div>
  147. </div>
  148. </Card>
  149. </Col>
  150. <Col span={6}>
  151. <Card size="small">
  152. <div className="text-center">
  153. <div className="text-2xl font-bold text-green-600">298</div>
  154. <div className="text-gray-600">在线设备</div>
  155. </div>
  156. </Card>
  157. </Col>
  158. <Col span={6}>
  159. <Card size="small">
  160. <div className="text-center">
  161. <div className="text-2xl font-bold text-red-600">12</div>
  162. <div className="text-gray-600">离线设备</div>
  163. </div>
  164. </Card>
  165. </Col>
  166. <Col span={6}>
  167. <Card size="small">
  168. <div className="text-center">
  169. <div className="text-2xl font-bold text-orange-600">32</div>
  170. <div className="text-gray-600">维护中</div>
  171. </div>
  172. </Card>
  173. </Col>
  174. </Row>
  175. <div className="mb-4">
  176. <Space>
  177. <Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
  178. 新增设备
  179. </Button>
  180. <Input.Search placeholder="搜索设备..." style={{ width: 300 }} onSearch={(value) => console.log(value)} />
  181. <Select placeholder="设备类型" style={{ width: 120 }}>
  182. <Option value="pressure">压力监测</Option>
  183. <Option value="flow">流量监测</Option>
  184. <Option value="temperature">温度监测</Option>
  185. <Option value="leak">泄漏检测</Option>
  186. </Select>
  187. <Select placeholder="设备状态" style={{ width: 120 }}>
  188. <Option value="online">在线</Option>
  189. <Option value="offline">离线</Option>
  190. <Option value="maintenance">维护中</Option>
  191. </Select>
  192. </Space>
  193. </div>
  194. <Table
  195. columns={columns}
  196. dataSource={mockDeviceData}
  197. rowKey="id"
  198. pagination={{ pageSize: 10 }}
  199. scroll={{ x: 1200 }}
  200. />
  201. <Modal
  202. title={editingRecord ? "编辑设备" : "新增设备"}
  203. open={isModalVisible}
  204. onOk={handleModalOk}
  205. onCancel={() => setIsModalVisible(false)}
  206. width={800}
  207. >
  208. <Form form={form} layout="vertical">
  209. <Row gutter={16}>
  210. <Col span={12}>
  211. <Form.Item name="name" label="设备名称" rules={[{ required: true }]}>
  212. <Input />
  213. </Form.Item>
  214. </Col>
  215. <Col span={12}>
  216. <Form.Item name="type" label="设备类型" rules={[{ required: true }]}>
  217. <Select>
  218. <Option value="压力监测">压力监测</Option>
  219. <Option value="流量监测">流量监测</Option>
  220. <Option value="温度监测">温度监测</Option>
  221. <Option value="泄漏检测">泄漏检测</Option>
  222. </Select>
  223. </Form.Item>
  224. </Col>
  225. </Row>
  226. <Row gutter={16}>
  227. <Col span={12}>
  228. <Form.Item name="model" label="设备型号" rules={[{ required: true }]}>
  229. <Input />
  230. </Form.Item>
  231. </Col>
  232. <Col span={12}>
  233. <Form.Item name="manufacturer" label="制造商" rules={[{ required: true }]}>
  234. <Input />
  235. </Form.Item>
  236. </Col>
  237. </Row>
  238. <Row gutter={16}>
  239. <Col span={12}>
  240. <Form.Item name="serialNumber" label="序列号" rules={[{ required: true }]}>
  241. <Input />
  242. </Form.Item>
  243. </Col>
  244. <Col span={12}>
  245. <Form.Item name="location" label="安装位置" rules={[{ required: true }]}>
  246. <Input />
  247. </Form.Item>
  248. </Col>
  249. </Row>
  250. <Row gutter={16}>
  251. <Col span={12}>
  252. <Form.Item name="installDate" label="安装日期" rules={[{ required: true }]}>
  253. <Input type="date" />
  254. </Form.Item>
  255. </Col>
  256. <Col span={12}>
  257. <Form.Item name="status" label="设备状态" rules={[{ required: true }]}>
  258. <Select>
  259. <Option value="在线">在线</Option>
  260. <Option value="离线">离线</Option>
  261. <Option value="维护中">维护中</Option>
  262. </Select>
  263. </Form.Item>
  264. </Col>
  265. </Row>
  266. </Form>
  267. </Modal>
  268. </Card>
  269. </div>
  270. )
  271. }