import { PageContainer } from '@ant-design/pro-components'; import { Button, Card, Form, Input, Space, Table } from 'antd'; import React, { useEffect, useState } from 'react'; import { ReloadOutlined, SearchOutlined } from '@ant-design/icons'; import { history } from 'umi'; import type { ColumnsType } from 'antd/es/table'; import { queryHomeList } from '@/services/home'; import Overwrite from '@/pages/home/overwrite'; interface DataType { name: string; member: any[]; power: number; record_id: string; } /** * 家列表 * @constructor */ const Home: React.FC = () => { const [form] = Form.useForm(); const [loading, setLoading] = useState(false); const [searchData, setSearchData] = useState({}); const [dataList, setDataList] = useState([]); const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 }); const [visible, setVisible] = useState(false); const [editData, setEditData] = useState(null); const getData = () => { const params = { q: 'page', current: pagination.current, pageSize: pagination.pageSize, ...searchData, }; queryHomeList(params).then((res) => { if (res.code === 0) { setDataList(res.data.list); setPagination(res.data.pagination); setLoading(false); } }); }; useEffect(() => { setLoading(true); getData(); }, []); useEffect(() => { getData(); }, [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 param = { q: 'page', current: page.current, pageSize: page.pageSize, ...searchData, }; queryHomeList(param).then((res) => { if (res.code === 0) { setDataList(res.data.list); setPagination(res.data.pagination); setLoading(false); } }); }; // 下发 const onOverwrite = (data: any) => { setVisible(true); setEditData(data); }; // 下发弹框回调 const overwriteCallback = () => { setVisible(false); getData(); }; // 跳转到房间 const toRoom = (record: DataType) => { history.push({ pathname: '/roomList', state: record.record_id }); }; const columns: ColumnsType = [ { title: '序号', align: 'center', key: 'index', render: (_: any, row: any, index: number) => index + 1, }, { title: '名称', width: 200, dataIndex: 'name', key: 'name', }, { title: '设备编号', width: 100, dataIndex: 'gateway', key: 'gateway', }, { title: '设备是否在线', dataIndex: 'is_online', key: 'is_online', render: (v) => {v ? '在线' : '离线'}, }, { title: '成员人数', dataIndex: 'member', key: 'member', render: (v) => v && {v.length}, }, { title: '地区', dataIndex: 'district', key: 'district', }, { title: '操作', key: 'action', render: (_, record) => ( { toRoom(record); }} > 查看房间 { onOverwrite(record); }} > 远程配置 ), }, ]; 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' }} /> {visible && ( )} ); }; export default Home;