import { PageContainer } from '@ant-design/pro-components'; import React, { useEffect, useState } from 'react'; import { Button, Card, Form, Input, Select, Space, Table } from 'antd'; import { ReloadOutlined, SearchOutlined } from '@ant-design/icons'; import type { ColumnsType } from 'antd/es/table'; import { history } from 'umi'; import { queryRoomList } from '@/services/home'; interface DataType { control_number: number; home_name: string; name: string; type: string; temperature: number; humidity: number; is_master: number; power: number; status: number; record_id: string; } /** * 房间列表 * @constructor */ const Room: React.FC = () => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const [searchData, setSearchData] = useState({}); const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 }); const [dataList, setDataList] = useState([]); // 获取列表数据秀 const getRoomList = () => { const { state } = history.location; const params = { q: 'page', home_id: state, current: pagination.current, pageSize: pagination.pageSize, ...searchData, }; queryRoomList(params).then((res) => { if (res.code === 0) { setDataList(res.data.list); setPagination(res.data.pagination); setLoading(false); } }); }; useEffect(() => { getRoomList(); }, []); useEffect(() => { getRoomList(); }, [searchData]); const onFinish = () => { form.validateFields().then((data) => { setLoading(true); setSearchData(data); }); }; // 重置 const onReset = () => { form.resetFields(); setLoading(true); setSearchData(null); }; // table切换 const tableChange = (page: any) => { setLoading(true); const { state } = history.location; const param = { q: 'page', current: page.current, pageSize: page.pageSize, home_id: state, ...searchData, }; queryRoomList(param).then((res) => { if (res.code === 0) { setDataList(res.data.list); setPagination(res.data.pagination); setLoading(false); } }); }; const columns: ColumnsType = [ { title: '序号', align: 'center', key: 'index', render: (_: any, row: any, index: number) => index + 1, }, { title: '分控编号', dataIndex: 'control_number', key: 'control_number', }, { title: '家名称', dataIndex: 'home_name', key: 'home_name', }, { title: '房间名称', dataIndex: 'name', key: 'name', }, { title: '温度', dataIndex: 'temperature', key: 'temperature', }, { title: '设定温度', dataIndex: 'set_temp', key: 'set_temp', }, { title: '湿度', dataIndex: 'humidity', key: 'humidity', }, { title: '是否为主控', dataIndex: 'is_master', key: 'is_master', render: (v) => {v ? '是' : '否'}, }, { title: '模式', dataIndex: 'mode', key: 'mode', render: (v) => {{ 0: '制冷', 1: '制热', 2: '除湿', 3: '送风', 4: '加湿' }[v]}, }, { title: '风速', dataIndex: 'fan_speed', key: 'fan_speed', }, { title: '状态', dataIndex: 'power', key: 'power', render: (v) => {v ? '开' : '关'}, }, ]; const paginationProps = { showSizeChanger: true, showQuickJumper: true, showTotal: (total: number) => { return 共 {total}条 ; }, ...pagination, }; return (
record.record_id} pagination={paginationProps} loading={loading} onChange={tableChange} style={{ marginTop: '20px' }} /> ); }; export default Room;