Basic.tsx 4.74 KB
Newer Older
涂茜's avatar
涂茜 committed
1 2 3 4 5 6
// @ts-ignore
import React, { useEffect, useState } from 'react';
import request from 'umi-request';
import { UnorderedListOutlined, SearchOutlined } from '@ant-design/icons';
import PandaQuotaSelect from '../index';
import { service } from '@wisdom-utils/utils';
7
import { getMonitorConf } from '../apis';
涂茜's avatar
涂茜 committed
8 9 10 11 12 13

const REQUEST_HTTP = 'http';
const REQUEST_METHOD_GET = 'get';
const REQUEST_METHOD_POST = 'post';

const GET_QUOTA_LIST =
涂茜's avatar
涂茜 committed
14
  'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/Publish/GCK/Device/GetQuotaList'; //获取指标列表
涂茜's avatar
涂茜 committed
15
// '/api/Publish/GCK/Device/GetQuotaList'; //获取指标列表
涂茜's avatar
涂茜 committed
16 17

const GET_DEVICE_CONF =
涂茜's avatar
涂茜 committed
18 19
  'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/Publish/GCK/MonitorConfig/GetMonitorConf'; //根据设备类型、方案名称、用户工号获取对应设备监控配置
// '/api/Publish/GCK/MonitorConfig/GetMonitorConf'; //根据设备类型、方案名称、用户工号获取对应设备监控配置
涂茜's avatar
涂茜 committed
20 21

const UPDATE_DEVICE_CONF =
涂茜's avatar
涂茜 committed
22 23
  'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/Publish/GCK/MonitorConfig/AddOrUpdateMonitorConf'; //添加或修改设备监控配置
// '/api/Publish/GCK/MonitorConfig/AddOrUpdateMonitorConf'; //添加或修改设备监控配置
涂茜's avatar
涂茜 committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

const quotaSelectService = {
  getQuotaList: {
    url: GET_QUOTA_LIST,
    method: REQUEST_METHOD_GET,
    type: REQUEST_HTTP,
  },
  getDeviceConf: {
    url: GET_DEVICE_CONF,
    method: REQUEST_METHOD_GET,
    type: REQUEST_HTTP,
  },
  updateDeviceConfService: {
    url: UPDATE_DEVICE_CONF,
    method: REQUEST_METHOD_POST,
    type: REQUEST_HTTP,
  },
};

const qsService = service(quotaSelectService);

const getQuotaList = qsService.getQuotaList;
46
const getDeviceConf = getMonitorConf;
涂茜's avatar
涂茜 committed
47 48 49 50 51 52 53 54 55 56
const updateDeviceConfService = qsService.updateDeviceConfService;

const pointType = 'cardPoints';

const Demo = () => {
  const [deviceList, setDeviceList] = useState([]); // 设备列表
  const [confList, setConfList] = useState([]); // 设备配置列表

  const fetchData = () => {
    getDeviceConf({
57
      user: 'admin',
涂茜's avatar
涂茜 committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
      showAll: true,
      deviceType: '二供泵房,二供机组',
    })
      .then(function (response) {
        if (response.code == '0') {
          let curData = response.data;
          DeviceList.forEach((item) => {
            curData.forEach((child) => {
              if (item.deviceType === child.deviceType) item.confList = child[pointType].split(',');
            });
          });
          setConfList(curData);
          setDeviceList(DeviceList);
        }
      })
      .catch(function (error) {
        console.log(error);
      });
  };

  useEffect(() => {
    fetchData();
  }, []);

  const onModalOk = () => {
    console.log('onModalOk');
  };

  const onModalClose = () => {
    console.log('onModalClose');
  };

  const onModalCancel = () => {
    console.log('onModalCancel');
  };

  const onSelect = ({ device, selectKey, selectList }) => {
    let list = [...deviceList];
    list.forEach((child) => {
      if (child.stationID === device.stationID) {
        child.confList = selectKey;
      }
    });
    setDeviceList(list);
  };

  return (
    <>
      <h3>无 user, 无“保存修改”按钮</h3>
      <PandaQuotaSelect
涂茜's avatar
涂茜 committed
108
        buttonProps={{}}
李纪文's avatar
李纪文 committed
109
        // defaultSelect={'all'}
涂茜's avatar
涂茜 committed
110 111 112 113 114 115 116 117 118 119 120
        deviceList={deviceList}
        pointType={pointType}
        onSelect={onSelect}
        // onModalCancel={onModalCancel}
        // onModalOk={onModalOk}
        // onModalClose={onModalClose}
        maximum={5}
      />
      <br />
      <h3>带 user, 有“保存修改”按钮</h3>
      <PandaQuotaSelect
涂茜's avatar
涂茜 committed
121
        buttonProps={{}}
涂茜's avatar
涂茜 committed
122 123 124 125 126 127 128 129
        deviceList={deviceList}
        confList={confList}
        pointType={pointType}
        onSelect={onSelect}
        onModalCancel={onModalCancel}
        onModalOk={onModalOk}
        onModalClose={onModalClose}
        maximum={5}
130
        user={'admin'}
涂茜's avatar
涂茜 committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
      />
    </>
  );
};

export default Demo;

const DeviceList = [
  {
    deviceName: '001东北明珠',
    shortName: '001东北明珠',
    code: 'EGBF00000001',
    fatherCode: null,
    deviceType: '二供泵房',
    entryTime: '2020-03-29 04:20:49',
    deviceGroup: '箱式变频',
    pointAddressID: 4,
    children: [],
    stationID: 27,
  },
  {
    deviceName: '低区',
    shortName: '低区',
    code: 'EGJZ00000162',
    fatherCode: 'EGBF00000001',
    deviceType: '二供机组',
    entryTime: '2020-03-29 04:20:49',
    deviceGroup: '箱式变频',
    pointAddressID: 30,
    children: [],
    stationID: 28,
  },
  {
    deviceName: '002世元国际',
    shortName: '002世元国际',
    code: 'EGBF00000002',
    fatherCode: null,
    deviceType: '二供机组',
    entryTime: '2020-03-29 04:24:19',
    deviceGroup: '智慧标准泵房',
    pointAddressID: 4,
    children: [],
    stationID: 29,
  },
];