index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import { PageContainer } from '@ant-design/pro-components';
  2. import { Button, Card, Form, Input, Select, Space } from 'antd';
  3. import React, { useEffect, useState } from 'react';
  4. import { ReloadOutlined, SearchOutlined } from '@ant-design/icons';
  5. // import { history } from 'umi';
  6. // import {ColumnsType} from "antd/es/table";
  7. import { queryHomeList } from '@/services/home';
  8. // interface DataType {
  9. // key: string;
  10. // name: string;
  11. // photo: string;
  12. // number: number;
  13. // status: number;
  14. // record_id: string;
  15. // }
  16. /**
  17. * 家列表
  18. * @constructor
  19. */
  20. const Home: React.FC = () => {
  21. const [form] = Form.useForm();
  22. const [loading, setLoading] = useState(false);
  23. const [searchData, setSearchData] = useState<object | null>({});
  24. const [dataList, setDataList] = useState([
  25. {
  26. photo:
  27. '/s/yongxu/1t7svi0uq7jcofyssvo2czj200w7iwdr/%E6%B0%B8%E7%BB%AD%E7%BB%BF%E5%BB%BAlogo.png',
  28. name: '家',
  29. number: 12,
  30. status: 1,
  31. record_id: 1,
  32. },
  33. ]);
  34. const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
  35. const getData = () => {
  36. const params = {
  37. q: 'page',
  38. current: pagination.current,
  39. pageSize: pagination.pageSize,
  40. ...searchData,
  41. };
  42. queryHomeList(params).then((res) => {
  43. if (res.code === 0) {
  44. setDataList(res.data.list);
  45. setPagination(res.data.pagination);
  46. setLoading(false);
  47. console.log(loading, dataList);
  48. }
  49. });
  50. };
  51. // useEffect(()=>{
  52. // setLoading(true);
  53. // getData();
  54. // },[]);
  55. useEffect(() => {
  56. getData();
  57. }, [searchData]);
  58. // 查询
  59. const onFinish = () => {
  60. form.validateFields().then((data) => {
  61. setLoading(true);
  62. setSearchData(data);
  63. });
  64. };
  65. // 重置
  66. const onReset = () => {
  67. form.resetFields();
  68. setLoading(true);
  69. setSearchData(null);
  70. };
  71. // table切换
  72. // const tableChange = (page: any) => {
  73. // setLoading(true);
  74. // const param = {
  75. // q: 'page',
  76. // current: page.current,
  77. // pageSize: page.pageSize,
  78. // ...searchData,
  79. // };
  80. // queryHomeList(param).then(res =>{
  81. // if (res.code === 0) {
  82. // setDataList(res.data.list);
  83. // setPagination(res.data.pagination);
  84. // setLoading(false);
  85. // }
  86. // })
  87. // }
  88. // 跳转到房间
  89. // const toRoom = (record: DataType) => {
  90. // history.push({ pathname : '/room' , state :record.record_id})
  91. // }
  92. // const columns: ColumnsType<DataType> = [
  93. // {
  94. // title: '序号',
  95. // align: 'center',
  96. // key: 'index',
  97. // render: (_: any, row: any, index: number) => index + 1,
  98. // },
  99. // {
  100. // title: '头像',
  101. // dataIndex: 'photo',
  102. // key: 'photo',
  103. // render: (v) => v && <Image width={50} src={v} alt="头像" />,
  104. // },
  105. // {
  106. // title: '姓名',
  107. // dataIndex: 'name',
  108. // key: 'name',
  109. // },
  110. // {
  111. // title: '成员人数',
  112. // dataIndex: 'number',
  113. // key: 'number',
  114. // },
  115. // {
  116. // title: '状态',
  117. // dataIndex: 'status',
  118. // key: 'status',
  119. // render: (v) =>
  120. // v && (
  121. // <span style={{ color: `${{ 1: '#00a650', 2: 'red' }[v]}` }}>
  122. // {{ 1: '在线', 2: '离线' }[v]}
  123. // </span>
  124. // ),
  125. // },
  126. // {
  127. // title: '操作',
  128. // key: 'action',
  129. // render: (_, record) => (
  130. // <Space size="middle">
  131. // <a
  132. // onClick={() => {
  133. // toRoom(record);
  134. // }}
  135. // >
  136. // 查看房间
  137. // </a>
  138. // </Space>
  139. // ),
  140. // },
  141. // ]
  142. // const paginationProps = {
  143. // showSizeChanger: true,
  144. // showQuickJumper: true,
  145. // showTotal: (total: number) => {
  146. // return <span> 共 {total}条 </span>;
  147. // },
  148. // ...pagination,
  149. // };
  150. return (
  151. <PageContainer>
  152. <Card>
  153. <Form form={form} layout="inline" onFinish={onFinish}>
  154. <Form.Item name="name" label="名称">
  155. <Input placeholder="请输入姓名" />
  156. </Form.Item>
  157. <Form.Item name="status" label="状态">
  158. <Select style={{ width: '175px' }} placeholder="请选择状态">
  159. <Select.Option key={1} value={1}>
  160. 在线
  161. </Select.Option>
  162. <Select.Option key={2} value={2}>
  163. 离线
  164. </Select.Option>
  165. </Select>
  166. </Form.Item>
  167. <Form.Item style={{ marginBottom: '10px' }}>
  168. <Space>
  169. <Button type="primary" htmlType="submit">
  170. <SearchOutlined />
  171. 查询
  172. </Button>
  173. <Button htmlType="button" onClick={onReset}>
  174. <ReloadOutlined />
  175. 重置
  176. </Button>
  177. </Space>
  178. </Form.Item>
  179. </Form>
  180. {/*<Table*/}
  181. {/* columns={columns}*/}
  182. {/* dataSource={dataList}*/}
  183. {/* rowKey={(record: any) => record.record_id}*/}
  184. {/* pagination={paginationProps}*/}
  185. {/* loading={loading}*/}
  186. {/* onChange={tableChange}*/}
  187. {/* style={{ marginTop:'20px'}}*/}
  188. {/*/>*/}
  189. </Card>
  190. </PageContainer>
  191. );
  192. };
  193. export default Home;