Basic.tsx 1.72 KB
Newer Older
1
// @ts-ignore
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
import React, { useEffect, useState } from 'react';
import Empty from '@wisdom-components/empty';
import BasicTable from '../index';
import request from 'umi-request';

const Demo = () => {
  const [columns, setColumns] = useState([]);
  const [dataSource, setDataSource] = useState([]);

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

  const fetchData = (params = {}) => {
    request(`${baseUrl}/AcrossTable/GetEquipmentDataReport`, {
      method: 'get',
      params: {},
    }).then(function (response) {
      const data = response.data;
      let column = data.map((item, index) => {
        return {
          title: `${item.DName + item.DType}(${item.Unit})`,
          dataIndex: `name${index}`,
          key: `name${index}`,
        };
      });
      column.unshift({
        title: '时间',
        dataIndex: 'time',
        key: 'time',
      });
      let dataSource = data[0].NameDate.map((item, index) => ({ key: index, time: item.Time }));
      data.forEach((item, index) => {
        item.NameDate.forEach((child) => {
          dataSource.forEach((v) => {
            if (child.Time === v.time) v[`name${index}`] = child.Value;
          });
        });
      });
      setColumns(column);
      setDataSource(dataSource);
    });
  };

46
  // @ts-ignore
47
  return (
涂茜's avatar
涂茜 committed
48
    <div style={{ height: '800px' }}>
李纪文's avatar
李纪文 committed
49 50 51 52
      {!!dataSource.length && (
        <BasicTable
          dataSource={dataSource}
          columns={columns}
李纪文's avatar
李纪文 committed
53 54
          bordered={false}
          pagination={{ pageSize: 20, size: 'default' }}
李纪文's avatar
李纪文 committed
55 56
        />
      )}
57 58 59 60 61 62 63 64
      {!dataSource.length && <Empty description={'暂无数据'} />}
    </div>
  );
};

export default Demo;

const baseUrl = 'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api';