Yansen 2 yıl önce
ebeveyn
işleme
71c70008b4

+ 31
- 23
src/pages/Machinery/Sensing/components/FeiFangForm.jsx Dosyayı Görüntüle

@@ -1,33 +1,41 @@
1 1
 import React from 'react';
2
-import { Modal, Form, Input, Button } from 'antd';
2
+import { Modal, Form, Input, Select, Button } from 'antd';
3 3
 
4 4
 const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
5 5
 const FormItem = Form.Item;
6 6
 
7 7
 export default (props) => {
8
-  const { openfeiyang, onCancel, onFinish } = props;
8
+  const { onCancel, onFinish } = props;
9 9
 
10 10
   const [form] = Form.useForm();
11
-  const [loading, setLoading] = React.useState(false);
11
+
12 12
   return (
13
-    <Modal title="飞防" visible={openfeiyang} maskClosable={false} footer={null} onCancel={onCancel}>
14
-      <Form {...formItemLayout} onFinish={onFinish} form={form}>
15
-        <FormItem
16
-          label="设备编号"
17
-          name="deviceNo"
18
-          rules={[{ required: true, message: '请输入设备编号' }]}
19
-        >
20
-          <Input placeholder="请输入" />
21
-        </FormItem>
22
-        <FormItem label=" " colon={false}>
23
-          <Button type="default" onClick={onCancel}>
24
-            取消
25
-          </Button>
26
-          <Button type="primary" loading={loading} htmlType="Submit" style={{ marginLeft: '2em' }}>
27
-            确认
28
-          </Button>
29
-        </FormItem>
30
-      </Form>
31
-    </Modal>
13
+    <Form {...formItemLayout} onFinish={onFinish} form={form}>
14
+      <FormItem
15
+        label="设备大类"
16
+        name="deviceKind"
17
+        initialValue="feifang"
18
+        rules={[{ required: true, message: '请选择设备大类' }]}
19
+      >
20
+        <Select placeholder="请选择">
21
+          <Select.Option value="feifang">飞防</Select.Option>
22
+        </Select>
23
+      </FormItem>
24
+      <FormItem
25
+        label="设备编号"
26
+        name="deviceNo"
27
+        rules={[{ required: true, message: '请输入设备编号' }]}
28
+      >
29
+        <Input placeholder="请输入" />
30
+      </FormItem>
31
+      <FormItem label=" " colon={false}>
32
+        <Button type="default" onClick={onCancel}>
33
+          取消
34
+        </Button>
35
+        <Button type="primary" htmlType="Submit" style={{ marginLeft: '2em' }}>
36
+          确认
37
+        </Button>
38
+      </FormItem>
39
+    </Form>
32 40
   );
33
-}
41
+};

+ 19
- 36
src/pages/Machinery/Sensing/components/List.jsx Dosyayı Görüntüle

@@ -3,22 +3,15 @@ import { Link } from 'umi';
3 3
 import moment from 'moment';
4 4
 import { Button, Popconfirm, Dropdown, Menu, message } from 'antd';
5 5
 import PageTable from '@/components/PageTable';
6
-import { } from '@/services/device';
7
-import { getDeviceList, syncShenSong } from '@/services/device';
6
+import { getDeviceList } from '@/services/device';
8 7
 
9 8
 const formatterTime = (val) => {
10 9
   return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
11 10
 };
12 11
 
13
-const menus = (
14
-  <Menu>
15
-    <Menu.Item key="shensong">深松</Menu.Item>
16
-    <Menu.Item key="feifang">飞防</Menu.Item>
17
-  </Menu>
18
-);
19
-
20 12
 const List = (props, ref) => {
21
-  const { onBindOpt, onFeiFang } = props;
13
+  const { onOperate, toolBar } = props;
14
+
22 15
   const columns = [
23 16
     {
24 17
       title: '设备类型',
@@ -69,43 +62,40 @@ const List = (props, ref) => {
69 62
     {
70 63
       title: '操作',
71 64
       valueType: 'option',
72
-      width: 160,
65
+      width: 240,
73 66
       render: (_, record) => [
74 67
         <Link
75 68
           to={`/Machinery/OperationStatistics?deviceType=${record.deviceType}&deviceNo=${record.deviceNo}`}
76 69
           key={1}
77 70
         >
78
-          查看作业
71
+          作业
79 72
         </Link>,
80 73
         record.machineryId === null ? (
81
-          <Button key={2} type="link" onClick={() => onBindOpt(record)}>
74
+          <Button key={2} type="link" onClick={() => onOperate(record, 'bind')}>
82 75
             绑定
83 76
           </Button>
84 77
         ) : (
85
-          <Popconfirm key={3} title={`是否进行'解绑'操作?`} onConfirm={() => onBindOpt(record)}>
78
+          <Popconfirm
79
+            key={3}
80
+            title={`是否进行解绑操作?`}
81
+            onConfirm={() => onOperate(record, 'unbind')}
82
+          >
86 83
             <Button type="link">解绑</Button>
87 84
           </Popconfirm>
88 85
         ),
86
+        <Popconfirm
87
+          key={4}
88
+          title={`确认进行删除操作?`}
89
+          onConfirm={() => onOperate(record, 'delete')}
90
+        >
91
+          <a href="#">删除</a>
92
+        </Popconfirm>,
89 93
       ],
90 94
     },
91 95
   ];
92 96
 
93
-  const [syncing, setSyncing] = React.useState(false);
94 97
   const actionRef = React.useRef();
95 98
 
96
-  const onSyncShenSong = () => {
97
-    setSyncing(true);
98
-    syncShenSong()
99
-      .then((res) => {
100
-        setSyncing(false);
101
-        actionRef.current.reload();
102
-        message.success('同步完成');
103
-      })
104
-      .catch(() => {
105
-        setSyncing(false);
106
-      });
107
-  };
108
-
109 99
   React.useImperativeHandle(ref, () => {
110 100
     return {
111 101
       reload: () => actionRef.current.reload(),
@@ -118,14 +108,7 @@ const List = (props, ref) => {
118 108
       columns={columns}
119 109
       rowKey={(row) => `${row.deviceType}-${row.deviceNo}`}
120 110
       options={false}
121
-      toolBarRender={() => [
122
-        <Button key={1} type="primary" loading={syncing} onClick={onSyncShenSong}>
123
-          同步深松
124
-        </Button>,
125
-        <Button key={3} type="primary" onClick={() => { onFeiFang() }}>
126
-          同步飞防
127
-        </Button>,
128
-      ]}
111
+      toolBarRender={() => toolBar}
129 112
       scroll={{ x: 1000 }}
130 113
     />
131 114
   );

+ 37
- 45
src/pages/Machinery/Sensing/components/MaBind.jsx Dosyayı Görüntüle

@@ -8,14 +8,13 @@ const FormItem = Form.Item;
8 8
 const Option = Select.Option;
9 9
 
10 10
 export default (props) => {
11
-  const { open, onCancel, onFinish } = props;
11
+  const { onCancel, onFinish } = props;
12 12
 
13 13
   const [form] = Form.useForm();
14 14
   const [machineryTypeList, setMachineryTypeList] = React.useState([]);
15 15
   const [typeId, setTypeId] = React.useState();
16 16
   const [machineryList, setMachineryList] = React.useState([]);
17 17
   const [machineryId, setMachineryId] = React.useState();
18
-  const [loading, setLoading] = React.useState(false);
19 18
 
20 19
   // 查询分类列表, 构造下拉框
21 20
   React.useEffect(() => {
@@ -42,48 +41,41 @@ export default (props) => {
42 41
   }, [typeId]);
43 42
 
44 43
   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>
44
+    <Form {...formItemLayout} onFinish={onFinish} form={form}>
45
+      <FormItem
46
+        label="农机分类"
47
+        name="typeId"
48
+        rules={[{ required: true, message: '请选择农机分类' }]}
49
+      >
50
+        <Select value={typeId} onChange={setTypeId} allowClear style={{ width: '320px' }}>
51
+          {machineryTypeList.map((item) => (
52
+            <Option value={item.typeId} key={item.typeId}>
53
+              {item.name}
54
+            </Option>
55
+          ))}
56
+        </Select>
57
+      </FormItem>
58
+      <FormItem
59
+        label="选择农机"
60
+        name="machineryId"
61
+        rules={[{ required: true, message: '请选择农机名' }]}
62
+      >
63
+        <Select value={machineryId} onChange={setMachineryId} allowClear style={{ width: '320px' }}>
64
+          {machineryList.map((item) => (
65
+            <Option value={item.machineryId} key={item.machineryId}>
66
+              {item.name}
67
+            </Option>
68
+          ))}
69
+        </Select>
70
+      </FormItem>
71
+      <FormItem label=" " colon={false}>
72
+        <Button type="default" onClick={onCancel}>
73
+          取消
74
+        </Button>
75
+        <Button type="primary" htmlType="Submit" style={{ marginLeft: '2em' }}>
76
+          确认
77
+        </Button>
78
+      </FormItem>
79
+    </Form>
88 80
   );
89 81
 };

+ 115
- 26
src/pages/Machinery/Sensing/index.jsx Dosyayı Görüntüle

@@ -1,65 +1,154 @@
1 1
 import React, { useState, useEffect, useRef } from 'react';
2 2
 import { Button, Modal, Select, Form, message } from 'antd';
3 3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
-import { addDevice, deleteDevice } from '@/services/device';
4
+import {
5
+  addDevice,
6
+  deleteDevice,
7
+  syncShenSong,
8
+  addRawDevice,
9
+  deleteRawDevice,
10
+} from '@/services/device';
5 11
 import List from './components/List';
6 12
 import MaBind from './components/MaBind';
7 13
 import FeiFangForm from './components/FeiFangForm';
8 14
 
9 15
 export default (props) => {
10
-  // 绑定表单
11
-
12 16
   const [open, setOpen] = useState(false);
13
-  const [openfeiyang, setOpenFeiYang] = useState(false);
17
+  const [syncing, setSyncing] = React.useState(false);
18
+  const [syncing2, setSyncing2] = React.useState(false);
14 19
   const [device, setDevice] = useState();
15 20
   const listRef = useRef();
21
+  const actRef = useRef();
22
+
23
+  const modalTitle = actRef.current === 'add' ? '新增设备' : '绑定农机';
16 24
 
17 25
   // 绑定农机
18 26
   const onBind = ({ machineryId }) => {
27
+    const hide = message.loading('请稍候...', 0);
19 28
     const data = { ...device, machineryId };
20
-    addDevice(data).then((res) => {
21
-      setOpen(false);
22
-      message.success(`绑定成功`);
23
-      listRef.current.reload();
24
-    });
29
+    addDevice(data)
30
+      .then((res) => {
31
+        hide();
32
+        setOpen(false);
33
+        message.success(`绑定成功`);
34
+        listRef.current.reload();
35
+      })
36
+      .catch((err) => {
37
+        hide();
38
+        message.error(err.message || err);
39
+      });
25 40
   };
26 41
 
27 42
   // 解绑
28 43
   const unBind = (deviceId) => {
44
+    const hide = message.loading('请稍候...', 0);
29 45
     deleteDevice(deviceId)
30 46
       .then(() => {
31
-        // setLoading(false);
47
+        hide();
32 48
         message.success(`解绑成功`);
33 49
         listRef.current.reload();
34 50
       })
35 51
       .catch((err) => {
36
-        // setLoading(false);
52
+        hide();
37 53
         message.error(err.message || err);
38 54
       });
39 55
   };
40 56
 
41
-  // 设备农机绑定或者解绑操作
42
-  const onBindOpt = (row) => {
57
+  // 删除设备
58
+  const onDelete = (row) => {
59
+    const hide = message.loading('请稍候...', 0);
60
+    deleteRawDevice(row.deviceId)
61
+      .then(() => {
62
+        hide();
63
+        message.success('删除成功');
64
+        listRef.current.reload();
65
+      })
66
+      .catch((err) => {
67
+        hide();
68
+        message.error(err.message || err);
69
+      });
70
+  };
71
+
72
+  // 新增飞防设备
73
+  const onAddDevice = ({ deviceNo, deviceKind = 'feifang' }) => {
74
+    setSyncing2(true);
75
+    addRawDevice({ deviceKind, deviceNo })
76
+      .then((res) => {
77
+        message.success('添加设备成功');
78
+        setSyncing2(false);
79
+        setOpen(false);
80
+        listRef.current.reload();
81
+      })
82
+      .catch((err) => {});
83
+  };
84
+
85
+  // 同步深松
86
+  const onSyncShenSong = () => {
87
+    setSyncing(true);
88
+    syncShenSong()
89
+      .then((res) => {
90
+        setSyncing(false);
91
+        listRef.current.reload();
92
+        message.success('同步完成');
93
+      })
94
+      .catch(() => {
95
+        setSyncing(false);
96
+      });
97
+  };
98
+
99
+  // 同步飞防
100
+  const onSyncFeiFang = () => {
101
+    actRef.current = 'add';
102
+    setOpen(true);
103
+  };
104
+
105
+  // 设备操作
106
+  const onOperate = (row, act) => {
107
+    actRef.current = act;
43 108
     setDevice({ ...row });
44 109
 
45
-    if (!row.machineryId) {
46
-      // 农机ID 不存在, 说明是绑定业务
47
-      setOpen(true);
48
-    } else {
49
-      unBind(row.deviceId);
110
+    switch (act) {
111
+      case 'bind':
112
+        setOpen(true);
113
+        break;
114
+      case 'unbind':
115
+        unBind(row.deviceId);
116
+        break;
117
+      case 'delete':
118
+        onDelete(row);
119
+        break;
120
+      default:
121
+        break;
50 122
     }
51 123
   };
52 124
 
53
-  //同步飞防弹窗
54
-  const onFeiFang = () => {
55
-    setOpenFeiYang(true);
56
-  }
57
-
58 125
   return (
59 126
     <PageHeaderWrapper>
60
-      <List ref={listRef} onBindOpt={onBindOpt} onFeiFang={onFeiFang} onSyncDevice={console.log} />
61
-      <MaBind open={open} device={device} onCancel={() => setOpen(false)} onFinish={onBind} />
62
-      <FeiFangForm openfeiyang={openfeiyang} onCancel={() => setOpenFeiYang(false)} />
127
+      <List
128
+        ref={listRef}
129
+        onOperate={onOperate}
130
+        toolBar={[
131
+          <Button ghost key={1} type="primary" loading={syncing} onClick={onSyncShenSong}>
132
+            同步深松
133
+          </Button>,
134
+          <Button ghost key={3} type="primary" loading={syncing2} onClick={onSyncFeiFang}>
135
+            同步飞防
136
+          </Button>,
137
+        ]}
138
+      />
139
+      <Modal
140
+        title={modalTitle}
141
+        visible={open}
142
+        maskClosable={false}
143
+        footer={null}
144
+        onCancel={() => setOpen(false)}
145
+      >
146
+        {actRef.current === 'add' ? (
147
+          <FeiFangForm onCancel={() => setOpen(false)} onFinish={onAddDevice} />
148
+        ) : (
149
+          <MaBind onCancel={() => setOpen(false)} onFinish={onBind} />
150
+        )}
151
+      </Modal>
63 152
     </PageHeaderWrapper>
64 153
   );
65 154
 };

+ 12
- 0
src/services/device.js Dosyayı Görüntüle

@@ -64,3 +64,15 @@ export const getMachineryListByUser = (userId) => request(`/device-job/user/${us
64 64
  * @returns
65 65
  */
66 66
 export const syncShenSong = () => request('/raw-device/sync', { method: 'put' });
67
+
68
+/**
69
+ * 增加设备
70
+ * @returns
71
+ */
72
+export const addRawDevice = (data) => request('/raw-device', { method: 'POST', data });
73
+
74
+/**
75
+ * 删除设备
76
+ * @returns
77
+ */
78
+export const deleteRawDevice = (id) => request(`/raw-device/${id}`, { method: 'DELETE' });