|
|
@@ -1,9 +1,10 @@
|
|
|
-import React, { useEffect, useState } from 'react';
|
|
|
+import React, { useCallback, useEffect, useState } from 'react';
|
|
|
import { PageContainer } from '@ant-design/pro-components';
|
|
|
-import { Card, Space, Table } from 'antd';
|
|
|
+import { Button, Card, Form, Input, Space, Table, Select, Tag } from 'antd';
|
|
|
import type { ColumnsType } from 'antd/es/table';
|
|
|
import { queryScenes } from '@/services/scene';
|
|
|
import SceneHistory from '@/pages/SceneManagement/sceneHistory';
|
|
|
+import { ReloadOutlined, SearchOutlined } from '@ant-design/icons';
|
|
|
|
|
|
interface DataType {
|
|
|
name: string;
|
|
|
@@ -19,51 +20,60 @@ interface DataType {
|
|
|
* @constructor
|
|
|
*/
|
|
|
const SceneManagement: React.FC = () => {
|
|
|
+ const [form] = Form.useForm();
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
|
|
|
+ const { current, pageSize } = pagination;
|
|
|
const [dataList, setDataList] = useState([]);
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
const [recordId, setRecordId] = useState('');
|
|
|
const weekArray = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
|
|
+ const [searchData, setSearchData] = useState<object | null>({});
|
|
|
|
|
|
// 获取列表数据
|
|
|
- const getList = () => {
|
|
|
+ const getList = useCallback(() => {
|
|
|
+ setLoading(true);
|
|
|
const params = {
|
|
|
q: 'page',
|
|
|
- current: pagination.current,
|
|
|
- pageSize: pagination.pageSize,
|
|
|
+ current,
|
|
|
+ pageSize,
|
|
|
+ ...(searchData || {}),
|
|
|
};
|
|
|
queryScenes(params).then((res) => {
|
|
|
if (res && res.code === 0) {
|
|
|
setDataList(res.data.list);
|
|
|
setPagination(res.data.pagination);
|
|
|
- setLoading(false);
|
|
|
}
|
|
|
+ setLoading(false);
|
|
|
});
|
|
|
- };
|
|
|
+ }, [current, pageSize, searchData]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- setLoading(true);
|
|
|
getList();
|
|
|
- }, []);
|
|
|
+ }, [getList]);
|
|
|
|
|
|
// 分页切换
|
|
|
const tableChange = (page: any) => {
|
|
|
- setLoading(true);
|
|
|
- const params = {
|
|
|
- q: 'page',
|
|
|
+ setPagination((prev) => ({
|
|
|
+ ...prev,
|
|
|
current: page.current,
|
|
|
pageSize: page.pageSize,
|
|
|
- };
|
|
|
- queryScenes(params).then((res) => {
|
|
|
- if (res && res.code === 0) {
|
|
|
- setDataList(res.data.list);
|
|
|
- setPagination(res.data.pagination);
|
|
|
- setLoading(false);
|
|
|
- }
|
|
|
+ }));
|
|
|
+ };
|
|
|
+
|
|
|
+ // 搜索
|
|
|
+ const onFinish = () => {
|
|
|
+ form.validateFields().then((data) => {
|
|
|
+ setSearchData(data);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ // 搜索重置
|
|
|
+ const onReset = () => {
|
|
|
+ form.resetFields();
|
|
|
+ setSearchData(null);
|
|
|
+ };
|
|
|
+
|
|
|
// 跳转到历史记录弹框中
|
|
|
const toHistory = (record: any) => {
|
|
|
setVisible(true);
|
|
|
@@ -110,7 +120,7 @@ const SceneManagement: React.FC = () => {
|
|
|
render: (_: any, row: any, index: number) => index + 1,
|
|
|
},
|
|
|
{
|
|
|
- title: '房间名称',
|
|
|
+ title: '家庭名称',
|
|
|
dataIndex: 'home_name',
|
|
|
key: 'home_name',
|
|
|
width: 250,
|
|
|
@@ -206,6 +216,15 @@ const SceneManagement: React.FC = () => {
|
|
|
return <span>{{ or: '满足任一条件', and: '满足所有条件' }[v]}</span>;
|
|
|
},
|
|
|
},
|
|
|
+ {
|
|
|
+ title: '启用状态',
|
|
|
+ dataIndex: 'status',
|
|
|
+ key: 'status',
|
|
|
+ width: 250,
|
|
|
+ render: (v: string | number | boolean) => (
|
|
|
+ <Tag color={v ? 'green' : 'red'}>{v ? '启用' : '未启用'}</Tag>
|
|
|
+ ),
|
|
|
+ },
|
|
|
{
|
|
|
title: '创建者',
|
|
|
dataIndex: 'creator_name',
|
|
|
@@ -241,6 +260,52 @@ const SceneManagement: React.FC = () => {
|
|
|
<PageContainer>
|
|
|
<div>
|
|
|
<Card>
|
|
|
+ <Form form={form} layout="inline" onFinish={onFinish}>
|
|
|
+ <Form.Item name="home_name" label="家庭名称">
|
|
|
+ <Input placeholder="请输入家庭名称" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="name" label="场景名称">
|
|
|
+ <Input placeholder="请输入场景名称" />
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="type_code" label="场景类型">
|
|
|
+ <Select style={{ width: '175px' }} placeholder="请选择场景类型">
|
|
|
+ <Select.Option key={1} value={'oneKey'}>
|
|
|
+ 一键执行
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option key={2} value={'timer'}>
|
|
|
+ 定时
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option key={3} value={'weather'}>
|
|
|
+ 气象变化时
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option key={4} value={'device_status'}>
|
|
|
+ 设备变化时
|
|
|
+ </Select.Option>
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item name="status" label="启用状态">
|
|
|
+ <Select style={{ width: '175px' }} placeholder="请选择启用状态">
|
|
|
+ <Select.Option key={1} value={1}>
|
|
|
+ 启用
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option key={2} value={2}>
|
|
|
+ 未启用
|
|
|
+ </Select.Option>
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ <Form.Item style={{ marginBottom: '10px' }}>
|
|
|
+ <Space>
|
|
|
+ <Button type="primary" htmlType="submit">
|
|
|
+ <SearchOutlined />
|
|
|
+ 查询
|
|
|
+ </Button>
|
|
|
+ <Button htmlType="button" onClick={onReset}>
|
|
|
+ <ReloadOutlined />
|
|
|
+ 重置
|
|
|
+ </Button>
|
|
|
+ </Space>
|
|
|
+ </Form.Item>
|
|
|
+ </Form>
|
|
|
<Table
|
|
|
columns={columns}
|
|
|
dataSource={dataList}
|