Yansen 2 years ago
parent
commit
ac1da469b7

+ 22
- 15
config/routes.js View File

@@ -159,6 +159,11 @@ export default [
159 159
         component: './Machinery/OperationStatistics/Detail',
160 160
         hideInMenu: true,
161 161
       },
162
+      {
163
+        path: '/Machinery/Sensing',
164
+        name: '传感设备列表',
165
+        component: './Machinery/Sensing',
166
+      },
162 167
     ],
163 168
   },
164 169
   {
@@ -305,22 +310,24 @@ export default [
305 310
         component: './SystemManagement/BasicParameters',
306 311
       },
307 312
       {
308
-        path: '/SystemManagement/Subsoiler',
309
-        name: '深松机',
313
+        path: '/SystemManagement/iot',
314
+        name: 'IOT平台',
310 315
         access: 'setting',
311
-        component: './SystemManagement/Subsoiler',
312
-      },
313
-      {
314
-        path: '/SystemManagement/Sensing',
315
-        name: '传感设备列表',
316
-        access: 'setting',
317
-        component: './SystemManagement/Sensing',
318
-      },
319
-      {
320
-        path: '/SystemManagement/Classification',
321
-        name: '分类管理',
322
-        access: 'setting',
323
-        component: './SystemManagement/Classification',
316
+        component: '../layouts/BasicLayout',
317
+        routes: [
318
+          {
319
+            path: '/SystemManagement/iot/Subsoiler',
320
+            name: '深松机',
321
+            access: 'setting',
322
+            component: './SystemManagement/Subsoiler',
323
+          },
324
+          {
325
+            path: '/SystemManagement/iot/Classification',
326
+            name: '外设分类',
327
+            access: 'setting',
328
+            component: './SystemManagement/Classification',
329
+          },
330
+        ],
324 331
       },
325 332
     ],
326 333
   },

+ 122
- 0
src/pages/Machinery/Sensing/components/List.jsx View File

@@ -0,0 +1,122 @@
1
+import React from 'react';
2
+import { Link } from 'umi';
3
+import moment from 'moment';
4
+import { Button, Popconfirm, Dropdown, Menu } from 'antd';
5
+import PageTable from '@/components/PageTable';
6
+import { getDeviceList } from '@/services/device';
7
+import {} from '@/services/device';
8
+
9
+const formatterTime = (val) => {
10
+  return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
11
+};
12
+
13
+const menus = (
14
+  <Menu>
15
+    <Menu.Item key="shensong">深松</Menu.Item>
16
+    <Menu.Item key="feifang">飞防</Menu.Item>
17
+  </Menu>
18
+);
19
+
20
+const List = (props, ref) => {
21
+  const { onBindOpt, onSyncDevice } = props;
22
+
23
+  const columns = [
24
+    {
25
+      title: '设备类型',
26
+      dataIndex: 'deviceType',
27
+      key: 'deviceType',
28
+      valueEnum: {
29
+        shensong: {
30
+          text: '深松',
31
+        },
32
+        feifang: {
33
+          text: '飞防',
34
+        },
35
+      },
36
+    },
37
+    {
38
+      title: '设备编号',
39
+      dataIndex: 'deviceNo',
40
+      key: 'deviceNo',
41
+      search: false,
42
+    },
43
+    {
44
+      title: '绑定农机',
45
+      dataIndex: 'machineryName',
46
+      key: 'machineryName',
47
+      search: false,
48
+    },
49
+    {
50
+      title: '注册时间',
51
+      dataIndex: 'createDate',
52
+      key: 'createDate',
53
+      render: formatterTime,
54
+      search: false,
55
+      width: 240,
56
+    },
57
+    {
58
+      title: '在线状态',
59
+      dataIndex: 'onlineStatus',
60
+      key: 'onlineStatus',
61
+      valueEnum: {
62
+        1: {
63
+          text: '在线',
64
+        },
65
+        0: {
66
+          text: '离线',
67
+        },
68
+      },
69
+    },
70
+    {
71
+      title: '操作',
72
+      valueType: 'option',
73
+      width: 160,
74
+      render: (_, record) => [
75
+        <Link
76
+          to={`/Machinery/OperationStatistics?deviceType=${record.deviceType}&deviceNo=${record.deviceNo}`}
77
+          key={1}
78
+        >
79
+          查看作业
80
+        </Link>,
81
+        record.machineryId === null ? (
82
+          <Button key={2} type="link" onClick={() => onBindOpt(record)}>
83
+            绑定
84
+          </Button>
85
+        ) : (
86
+          <Popconfirm key={3} title={`是否进行'解绑'操作?`} onConfirm={() => onBindOpt(record)}>
87
+            <Button type="link">解绑</Button>
88
+          </Popconfirm>
89
+        ),
90
+      ],
91
+    },
92
+  ];
93
+
94
+  const actionRef = React.useRef();
95
+
96
+  React.useImperativeHandle(ref, () => {
97
+    return {
98
+      reload: () => actionRef.current.reload(),
99
+    };
100
+  });
101
+
102
+  return (
103
+    <PageTable
104
+      request={getDeviceList}
105
+      actionRef={actionRef}
106
+      columns={columns}
107
+      rowKey={(row) => `${row.deviceType}-${row.deviceNo}`}
108
+      options={false}
109
+      toolBarRender={() => [
110
+        <Button key={1} type="primary">
111
+          同步深松
112
+        </Button>,
113
+        <Button key={3} type="primary">
114
+          同步飞防
115
+        </Button>,
116
+      ]}
117
+      scroll={{ x: 1000 }}
118
+    />
119
+  );
120
+};
121
+
122
+export default React.forwardRef(List);

+ 89
- 0
src/pages/Machinery/Sensing/components/MaBind.jsx View File

@@ -0,0 +1,89 @@
1
+import React from 'react';
2
+import { Modal, Form, Select, Button } from 'antd';
3
+import { getMachineryTypeList } from '@/services/machineryType';
4
+import { getMachineryList } from '@/services/machinery';
5
+
6
+const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
7
+const FormItem = Form.Item;
8
+const Option = Select.Option;
9
+
10
+export default (props) => {
11
+  const { open, onCancel, onFinish } = props;
12
+
13
+  const [form] = Form.useForm();
14
+  const [machineryTypeList, setMachineryTypeList] = React.useState([]);
15
+  const [typeId, setTypeId] = React.useState();
16
+  const [machineryList, setMachineryList] = React.useState([]);
17
+  const [machineryId, setMachineryId] = React.useState();
18
+  const [loading, setLoading] = React.useState(false);
19
+
20
+  // 查询分类列表, 构造下拉框
21
+  React.useEffect(() => {
22
+    getMachineryTypeList({ pageSize: 999 })
23
+      .then((res) => {
24
+        setMachineryTypeList(res.records);
25
+      })
26
+      .catch((err) => {
27
+        console.log(err.message);
28
+      });
29
+  }, []);
30
+
31
+  // 联动下拉列表
32
+  React.useEffect(() => {
33
+    if (typeId) {
34
+      getMachineryList({ typeId })
35
+        .then((e) => {
36
+          setMachineryList(e.records || []);
37
+        })
38
+        .catch((err) => {
39
+          console.log(err.message);
40
+        });
41
+    }
42
+  }, [typeId]);
43
+
44
+  return (
45
+    <Modal title="绑定农机" visible={open} maskClosable={false} footer={null} onCancel={onCancel}>
46
+      <Form {...formItemLayout} onFinish={onFinish} form={form}>
47
+        <FormItem
48
+          label="农机分类"
49
+          name="typeId"
50
+          rules={[{ required: true, message: '请选择农机分类' }]}
51
+        >
52
+          <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
53
+            {machineryTypeList.map((item) => (
54
+              <Option value={item.typeId} key={item.typeId}>
55
+                {item.name}
56
+              </Option>
57
+            ))}
58
+          </Select>
59
+        </FormItem>
60
+        <FormItem
61
+          label="选择农机"
62
+          name="machineryId"
63
+          rules={[{ required: true, message: '请选择农机名' }]}
64
+        >
65
+          <Select
66
+            value={machineryId}
67
+            onChange={setMachineryId}
68
+            allowClear
69
+            style={{ width: '320px' }}
70
+          >
71
+            {machineryList.map((item) => (
72
+              <Option value={item.machineryId} key={item.machineryId}>
73
+                {item.name}
74
+              </Option>
75
+            ))}
76
+          </Select>
77
+        </FormItem>
78
+        <FormItem label=" " colon={false}>
79
+          <Button type="default" onClick={onCancel}>
80
+            取消
81
+          </Button>
82
+          <Button type="primary" loading={loading} htmlType="Submit" style={{ marginLeft: '2em' }}>
83
+            确认
84
+          </Button>
85
+        </FormItem>
86
+      </Form>
87
+    </Modal>
88
+  );
89
+};

+ 57
- 0
src/pages/Machinery/Sensing/index.jsx View File

@@ -0,0 +1,57 @@
1
+import React, { useState, useEffect, useRef } from 'react';
2
+import { Button, Modal, Select, Form, message } from 'antd';
3
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
+import { addDevice, deleteDevice } from '@/services/device';
5
+import List from './components/List';
6
+import MaBind from './components/MaBind';
7
+
8
+export default (props) => {
9
+  // 绑定表单
10
+
11
+  const [open, setOpen] = useState(false);
12
+  const [device, setDevice] = useState();
13
+  const listRef = useRef();
14
+
15
+  // 绑定农机
16
+  const onBind = ({ machineryId }) => {
17
+    const data = { ...device, machineryId };
18
+    addDevice(data).then((res) => {
19
+      setOpen(false);
20
+      message.success(`绑定成功`);
21
+      listRef.current.reload();
22
+    });
23
+  };
24
+
25
+  // 解绑
26
+  const unBind = (deviceId) => {
27
+    deleteDevice(deviceId)
28
+      .then(() => {
29
+        // setLoading(false);
30
+        message.success(`解绑成功`);
31
+        listRef.current.reload();
32
+      })
33
+      .catch((err) => {
34
+        // setLoading(false);
35
+        message.error(err.message || err);
36
+      });
37
+  };
38
+
39
+  // 设备农机绑定或者解绑操作
40
+  const onBindOpt = (row) => {
41
+    setDevice({ ...row });
42
+
43
+    if (!row.machineryId) {
44
+      // 农机ID 不存在, 说明是绑定业务
45
+      setOpen(true);
46
+    } else {
47
+      unBind(row.deviceId);
48
+    }
49
+  };
50
+
51
+  return (
52
+    <PageHeaderWrapper>
53
+      <List ref={listRef} onBindOpt={onBindOpt} onSyncDevice={console.log} />
54
+      <MaBind open={open} device={device} onCancel={() => setOpen(false)} onFinish={onBind} />
55
+    </PageHeaderWrapper>
56
+  );
57
+};

+ 0
- 232
src/pages/SystemManagement/Sensing/index.jsx View File

@@ -1,232 +0,0 @@
1
-import React, { useState, useEffect, useRef } from 'react';
2
-import { Button, Modal, Select, Form, message } from 'antd';
3
-import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
-import moment from 'moment';
5
-import PageTable from '@/components/PageTable';
6
-import { getDeviceList, deleteDevice, addDevice } from '@/services/device';
7
-import { getMachineryList } from '@/services/machinery';
8
-import { getMachineryTypeList } from '@/services/machineryType';
9
-import { Link } from 'umi';
10
-
11
-const formatterTime = (val) => {
12
-  return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
13
-};
14
-
15
-export default (props) => {
16
-  // 绑定表单
17
-  const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
18
-  const [form] = Form.useForm();
19
-  const [editModal, setEditModal] = useState(false);
20
-  const [loading, setLoading] = useState(false);
21
-  const [machineryId, setMachineryId] = useState();
22
-  const [device, setDeviceList] = useState();
23
-  const actionRef = useRef();
24
-  const [machineryTypeList, setMachineryTypeList] = useState([]);
25
-  const [typeId, setTypeId] = useState();
26
-  const [machineryList, setMachineryList] = useState([]);
27
-  const { Option } = Select;
28
-  const FormItem = Form.Item;
29
-
30
-  //列表编辑
31
-  const handelEdit = (val) => {
32
-    if (val.machineryId != null) {
33
-      setEditModal(false);
34
-      const title = '确认当前设备要解绑"' + val.machineryName + '"农机设备吗?';
35
-      Modal.confirm({
36
-        title: title,
37
-        okText: '确认',
38
-        cancelText: '取消',
39
-        onOk () {
40
-          deleteDevice(val.deviceId)
41
-            .then(() => {
42
-              setLoading(false);
43
-              message.success(`解绑成功`);
44
-              onCancel();
45
-              actionRef.current.reload();
46
-
47
-            })
48
-            .catch((err) => {
49
-              setLoading(false);
50
-              message.error(err.message || err);
51
-            });
52
-        }
53
-      })
54
-    } else {
55
-      setEditModal(true);
56
-      setDeviceList(val);
57
-    }
58
-
59
-    form.setFieldsValue(val);
60
-  };
61
-
62
-  //绑定弹窗关闭
63
-  const onCancel = () => {
64
-    setEditModal(false);
65
-  };
66
-
67
-  // 绑定提交
68
-  const Submit = (values) => {
69
-    let params = { ...device, ...values };
70
-    setLoading(true);
71
-    addDevice(params).then((res) => {
72
-      setLoading(false);
73
-      message.success(`绑定成功`);
74
-      actionRef.current.reload();
75
-      onCancel();
76
-    });
77
-  };
78
-
79
-  useEffect(() => {
80
-    getMachineryTypeList({ pageSize: 999 }).then((res) => {
81
-      setMachineryTypeList(res.records);
82
-    }).catch((err) => {
83
-      console.log(err.message)
84
-    });
85
-  }, []);
86
-
87
-  useEffect(() => {
88
-    if (typeId) {
89
-      getMachineryList({ typeId }).then((e) => {
90
-        setMachineryList(e.records);
91
-      }).catch((err) => {
92
-        console.log(err.message)
93
-      });
94
-    }
95
-
96
-  }, [typeId])
97
-
98
-  const columns = [
99
-    {
100
-      title: '行号',
101
-      dataIndex: 'deviceId',
102
-      key: 'deviceId',
103
-    },
104
-    {
105
-      title: '设备编号',
106
-      dataIndex: 'deviceNo',
107
-      key: 'deviceNo',
108
-      search: false,
109
-    },
110
-    {
111
-      title: '设备类型',
112
-      dataIndex: 'deviceType',
113
-      key: 'deviceType',
114
-      valueEnum: {
115
-        shensong: {
116
-          text: '深松',
117
-        },
118
-        feifang: {
119
-          text: '飞防',
120
-        },
121
-      },
122
-      // request: () => queryTable(getDeviceList)(),
123
-    },
124
-    {
125
-      title: '在线状态',
126
-      dataIndex: 'onlineStatus',
127
-      key: 'onlineStatus',
128
-      valueEnum: {
129
-        1: {
130
-          text: '在线',
131
-        },
132
-        0: {
133
-          text: '离线',
134
-        },
135
-      },
136
-      // render: (_, record) => {
137
-      //   return record.onlineStatus === 1 ? '在线' : '离线';
138
-      // },
139
-    },
140
-    {
141
-      title: '注册时间',
142
-      dataIndex: 'createDate',
143
-      key: 'createDate',
144
-      render: formatterTime,
145
-      search: false,
146
-      width: 240,
147
-    },
148
-    {
149
-      title: '绑定农机',
150
-      dataIndex: 'machineryId',
151
-      key: 'machineryId',
152
-      search: false,
153
-    },
154
-    {
155
-      title: '操作',
156
-      valueType: 'option',
157
-      width: 160,
158
-      render: (_, record) => [
159
-        <Link to={`/Machinery/OperationStatistics`} key={2} >查看作业</Link>,
160
-        <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handelEdit(record)}>
161
-          {record.machineryId === null ? '绑定' : '解绑'}
162
-        </Button>,
163
-      ],
164
-    },
165
-  ];
166
-
167
-  return (
168
-    <PageHeaderWrapper>
169
-      <PageTable
170
-        request={getDeviceList}
171
-        columns={columns}
172
-        actionRef={actionRef}
173
-        rowKey="deviceId"
174
-        options={false}
175
-        toolBarRender={() => [
176
-          <Button
177
-            key="1"
178
-            type="primary"
179
-          >
180
-            +同步设备信息
181
-          </Button>,
182
-        ]}
183
-        scroll={{ x: 1000 }}
184
-      />
185
-      <Modal
186
-        forceRender
187
-        title="绑定农机"
188
-        visible={editModal}
189
-        onCancel={onCancel}
190
-        keyboard={false}
191
-        maskClosable={false}
192
-        destroyOnClose={true}
193
-        footer={null}
194
-        machineryId={machineryId}
195
-      >
196
-        <Form  {...formItemLayout} onFinish={Submit} form={form}>
197
-          <FormItem label="农机分类" name="typeId" rules={[{ required: true, message: '请选择农机分类' }]}>
198
-            <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
199
-              {machineryTypeList.map((item) => (
200
-                <Option value={item.typeId} key={item.typeId}>
201
-                  {item.name}
202
-                </Option>
203
-              ))}
204
-            </Select>
205
-          </FormItem>
206
-          <FormItem label="选择农机" name="machineryId" rules={[{ required: true, message: '请选择农机名' }]}>
207
-            <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
208
-              {machineryList.map((item) => (
209
-                <Option value={item.machineryId} key={item.machineryId}>
210
-                  {item.name}
211
-                </Option>
212
-              ))}
213
-            </Select>
214
-          </FormItem>
215
-          <FormItem label=" " colon={false}>
216
-            <Button type="default" onClick={onCancel} style={{ marginTop: '2em', marginLeft: '4em' }}>
217
-              取消
218
-            </Button>
219
-            <Button
220
-              type="primary"
221
-              loading={loading}
222
-              htmlType="Submit"
223
-              style={{ marginTop: '2em', marginLeft: '2em' }}
224
-            >
225
-              确认
226
-            </Button>
227
-          </FormItem>
228
-        </Form>
229
-      </Modal>
230
-    </PageHeaderWrapper>
231
-  );
232
-};