Your Name 2 gadus atpakaļ
vecāks
revīzija
d9bdcf0ae6
2 mainītis faili ar 123 papildinājumiem un 84 dzēšanām
  1. 102
    84
      src/pages/SystemManagement/Sensing/index.jsx
  2. 21
    0
      src/services/device.js

+ 102
- 84
src/pages/SystemManagement/Sensing/index.jsx Parādīt failu

1
 import React, { useState, useEffect, useRef } from 'react';
1
 import React, { useState, useEffect, useRef } from 'react';
2
-import { Button, Popconfirm, Modal, Form, Input, message } from 'antd';
2
+import { Button, Select, Modal, Form, Input, message } from 'antd';
3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
 import moment from 'moment';
4
 import moment from 'moment';
5
 import PageTable from '@/components/PageTable';
5
 import PageTable from '@/components/PageTable';
6
+import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
7
+import { queryTable } from '@/utils/request';
6
 
8
 
9
+const { Option } = Select;
7
 const formatterTime = (val) => {
10
 const formatterTime = (val) => {
8
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
11
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
9
 };
12
 };
10
 const FormItem = Form.Item;
13
 const FormItem = Form.Item;
11
 
14
 
12
 export default (props) => {
15
 export default (props) => {
16
+  // 绑定表单
13
   const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
17
   const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
14
   const [form] = Form.useForm();
18
   const [form] = Form.useForm();
15
   const [editModal, setEditModal] = useState(false);
19
   const [editModal, setEditModal] = useState(false);
16
   const [loading, setLoading] = useState(false);
20
   const [loading, setLoading] = useState(false);
17
-  const [regionId, setRegionId] = useState();
21
+  const [deviceId, setdeviceId] = useState();
22
+  const [machineryId, setmachineryId] = useState();
18
   const actionRef = useRef();
23
   const actionRef = useRef();
19
-
20
-  // const Submit = (values) => {
21
-  //   setLoading(true);
22
-  //   if (regionId) {
23
-  //     updateRegion(regionId, values).then(() => {
24
-  //       setLoading(false);
25
-  //       message.success(`修改成功`);
26
-  //       onCancel();
27
-  //       actionRef.current.reload();
28
-  //     }).catch((err) => {
29
-  //       setLoading(false);
30
-  //       console.log(err.message)
31
-  //     });
32
-  //   } else {
33
-  //     addRegion(values)
34
-  //       .then(() => {
35
-  //         setLoading(false);
36
-  //         message.success(`保存成功`);
37
-  //         onCancel();
38
-  //         actionRef.current.reload();
39
-  //       })
40
-  //       .catch((err) => {
41
-  //         setLoading(false);
42
-  //         message.error(err.message || err);
43
-  //       });
44
-  //   }
45
-  // };
46
-  // const handelEdit = (val) => {
47
-  //   setRegionId(val.regionId);
48
-  //   form.setFieldsValue(val);
49
-  //   setEditModal(true);
50
-  // };
51
-  // const onCancel = () => {
52
-  //   setRegionId();
53
-  //   form.resetFields();
54
-  //   setEditModal(false);
55
-  // };
56
-  // const handleDelete = (id) => {
57
-  //   deleteRegion(id)
58
-  //     .then(() => {
59
-  //       message.success('删除成功');
60
-  //       actionRef.current.reload();
61
-  //     })
62
-  //     .catch((err) => {
63
-  //       console.log(err.message)
64
-  //     });
65
-  // };
24
+  const [newsTypeList, setNewsTypeList] = useState([]);
66
   // useEffect(() => {
25
   // useEffect(() => {
67
   //   if (regionId) {
26
   //   if (regionId) {
68
   //   } else {
27
   //   } else {
69
   //     form.resetFields();
28
   //     form.resetFields();
70
   //   }
29
   //   }
71
   // }, [regionId]);
30
   // }, [regionId]);
72
-  // const actions = () => [
73
-  //   <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
74
-  //     新增
75
-  //   </Button>,
76
-  // ];
31
+
32
+  //列表编辑
33
+  const handelEdit = (val) => {
34
+    setmachineryId(val.machineryId);
35
+    form.setFieldsValue(val);
36
+    setEditModal(true);
37
+  };
38
+
39
+  //绑定弹窗关闭
40
+  const onCancel = () => {
41
+    setmachineryId();
42
+    form.resetFields();
43
+    setEditModal(false);
44
+  };
45
+
46
+  // 绑定提交
47
+  const Submit = (values) => {
48
+    setLoading(true);
49
+    addDevice(...values, machineryId).then(() => {
50
+      setLoading(false);
51
+      message.success(`绑定成功`);
52
+      onCancel();
53
+      actionRef.current.reload();
54
+    });
55
+    // if (machineryId) {
56
+    //   deleteDevice(machineryId)
57
+    //     .then(() => {
58
+    //       setLoading(false);
59
+    //       message.success(`解绑成功`);
60
+    //       onCancel();
61
+    //       actionRef.current.reload();
62
+    //     })
63
+    //     .catch((err) => {
64
+    //       setLoading(false);
65
+    //       message.error(err.message || err);
66
+    //     });
67
+    // }
68
+  };
69
+
70
+  useEffect(() => {
71
+    getDeviceList().then((res) => {
72
+      setNewsTypeList(res.records);
73
+    }).catch((err) => {
74
+      console.log(err.message)
75
+    });
76
+  }, []);
77
+
77
   const columns = [
78
   const columns = [
78
     {
79
     {
79
       title: '行号',
80
       title: '行号',
80
-      dataIndex: 'name',
81
-      key: 'name',
81
+      dataIndex: 'deviceId',
82
+      key: 'deviceId',
82
     },
83
     },
83
     {
84
     {
84
       title: '设备编号',
85
       title: '设备编号',
85
-      dataIndex: 'name',
86
-      key: 'name',
86
+      dataIndex: 'deviceNo',
87
+      key: 'deviceNo',
87
       search: false,
88
       search: false,
88
     },
89
     },
89
     {
90
     {
90
       title: '设备类型',
91
       title: '设备类型',
91
-      dataIndex: 'name',
92
-      key: 'name',
92
+      dataIndex: 'deviceType',
93
+      key: 'deviceType',
94
+      valueType: 'select',
95
+      // request: () => queryTable(getDeviceList)(),
93
     },
96
     },
94
     {
97
     {
95
       title: '在线状态',
98
       title: '在线状态',
96
-      dataIndex: 'name',
97
-      key: 'name',
99
+      dataIndex: 'onlineStatus',
100
+      key: 'onlineStatus',
101
+      render: (_, record) => {
102
+        return record.onlineStatus === 1 ? '在线' : '离线';
103
+      },
98
     },
104
     },
99
     {
105
     {
100
       title: '注册时间',
106
       title: '注册时间',
106
     },
112
     },
107
     {
113
     {
108
       title: '绑定农机',
114
       title: '绑定农机',
109
-      dataIndex: 'name',
110
-      key: 'name',
115
+      dataIndex: 'machineryId',
116
+      key: 'machineryId',
111
       search: false,
117
       search: false,
112
     },
118
     },
113
     {
119
     {
116
       width: 160,
122
       width: 160,
117
       render: (_, record) => [
123
       render: (_, record) => [
118
         <Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
124
         <Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
119
-          编辑
125
+          查看作业
126
+        </Button>,
127
+        <Button type="link" style={{ padding: 0 }} key={2} onClick={() => handelEdit(record)}>
128
+          修改
129
+        </Button>,
130
+        <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
131
+          {record.machineryId === null ? '绑定' : '解绑'}
120
         </Button>,
132
         </Button>,
121
-        <Popconfirm
122
-          key={2}
123
-          title="您是否确认删除 ?"
124
-          onConfirm={() => handleDelete(record.regionId)}
125
-          okText="确定"
126
-          cancelText="取消"
127
-        >
128
-          <Button style={{ padding: 0 }} type="link">
129
-            删除
130
-          </Button>
131
-        </Popconfirm>,
132
       ],
133
       ],
133
     },
134
     },
134
   ];
135
   ];
136
   return (
137
   return (
137
     <PageHeaderWrapper>
138
     <PageHeaderWrapper>
138
       <PageTable
139
       <PageTable
140
+        request={getDeviceList}
139
         columns={columns}
141
         columns={columns}
140
         actionRef={actionRef}
142
         actionRef={actionRef}
141
-        rowKey="regionId"
143
+        // rowKey="deviceId"
142
         options={false}
144
         options={false}
143
         // toolBarRender={actions}
145
         // toolBarRender={actions}
144
         scroll={{ x: 1000 }}
146
         scroll={{ x: 1000 }}
145
       />
147
       />
146
-      {/* <Modal
148
+      <Modal
147
         forceRender
149
         forceRender
148
-        title={regionId ? '区域编辑' : '区域新增'}
150
+        title="绑定农机"
149
         visible={editModal}
151
         visible={editModal}
150
         onCancel={onCancel}
152
         onCancel={onCancel}
151
         keyboard={false}
153
         keyboard={false}
154
         footer={null}
156
         footer={null}
155
       >
157
       >
156
         <Form {...formItemLayout} onFinish={Submit} form={form}>
158
         <Form {...formItemLayout} onFinish={Submit} form={form}>
157
-          <FormItem label="区域名" name="name" rules={[{ required: true, message: '请输入' }]}>
158
-            <Input placeholder="请输入" />
159
+          <FormItem label="农机分类" name="deviceType" rules={[{ required: true, message: '请选择农机分类' }]}
160
+          >
161
+            <Select allowClear style={{ width: '320px' }}>
162
+              {newsTypeList.map((item) => (
163
+                <Option value={item.deviceType} key={item.deviceType}>
164
+                  {item.deviceType}
165
+                </Option>
166
+              ))}
167
+            </Select>
168
+          </FormItem>
169
+          <FormItem label="选择农机" name="deviceNo" rules={[{ required: true, message: '请选择农机名' }]}>
170
+            <Select allowClear style={{ width: '320px' }}>
171
+              {newsTypeList.map((item) => (
172
+                <Option value={item.deviceNo} key={item.deviceNo}>
173
+                  {item.deviceNo}
174
+                </Option>
175
+              ))}
176
+            </Select>
159
           </FormItem>
177
           </FormItem>
160
           <FormItem label=" " colon={false}>
178
           <FormItem label=" " colon={false}>
161
-            <Button type="default" onClick={onCancel}>
179
+            <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
162
               取消
180
               取消
163
             </Button>
181
             </Button>
164
             <Button
182
             <Button
165
               type="primary"
183
               type="primary"
166
               loading={loading}
184
               loading={loading}
167
               htmlType="Submit"
185
               htmlType="Submit"
168
-              style={{ marginLeft: '4em' }}
186
+              style={{ marginTop: '2em', marginLeft: '2em' }}
169
             >
187
             >
170
               确认
188
               确认
171
             </Button>
189
             </Button>
172
           </FormItem>
190
           </FormItem>
173
         </Form>
191
         </Form>
174
-      </Modal> */}
192
+      </Modal>
175
     </PageHeaderWrapper>
193
     </PageHeaderWrapper>
176
   );
194
   );
177
 };
195
 };

+ 21
- 0
src/services/device.js Parādīt failu

7
  */
7
  */
8
 export const getHatcDeviceList = (params) => request('/hatc-device', { params });
8
 export const getHatcDeviceList = (params) => request('/hatc-device', { params });
9
 
9
 
10
+/**
11
+ * 传感设备列表
12
+ * @param {*} params
13
+ * @returns
14
+ */
15
+export const getDeviceList = (params) => request('/device', { params });
16
+
10
 /**
17
 /**
11
  * 通过设备号查询相关设备列表  选好了点击绑定时根据当前选择的设备id查询
18
  * 通过设备号查询相关设备列表  选好了点击绑定时根据当前选择的设备id查询
12
  * 同终端列表
19
  * 同终端列表
30
  * @returns
37
  * @returns
31
  */
38
  */
32
 export const addDevice = (data) => request('/device', { method: 'post', data });
39
 export const addDevice = (data) => request('/device', { method: 'post', data });
40
+
41
+/**
42
+ * 保存农机
43
+ * @param {*} data
44
+ * @returns
45
+ */
46
+export const addMachinery = (data) => request('/device', { method: 'post', data });
47
+
48
+/**
49
+ * 取消绑定
50
+ * @param {*} data
51
+ * @returns
52
+ */
53
+export const deleteDevice = (id) => request(`/device/${id}`, { method: 'delete' });