import React, { useEffect, useMemo, useRef, useState } from 'react' import Helmet from 'react-helmet' import Container from 'components/Container' import { init, EChartOption, ECharts } from 'echarts' import styles from './index.less' import api from 'utils/api' import request from 'utils/request' const DEFAULT_COLORS = [ '#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc' ] // tslint:disable-next-line:interface-name interface DataOverviewState { originDept: number, // 来源部门数量 countCatalogue: number, // 近一个月目录增长数量 originSystem: number, // 来源系统数量 dataSource: number, // 数据资源数量 industryData: Array<{ name: string, value: number }>, // 行业分类饼图 originDeptData: Array<{ name: string, value: number }>, // 来源部门柱状图 } export default function DataOverview() { const pieElementRef = useRef(null) const barElementRef = useRef(null) const pieRef = useRef(null) const barRef = useRef(null) const [overview, setOverview] = useState( { originDept: 0, countCatalogue: 0, originSystem: 0, dataSource: 0, industryData: [], originDeptData: [] }) const getDataScreening = async() => { try { const data = await request(api.dataScreening, { method: 'get' }) setOverview((data as unknown as DataOverviewState)) } catch (e) { console.log(e) } } const pieOption = useMemo(() => ({ tooltip: { trigger: 'item' }, color: DEFAULT_COLORS, legend: { orient: 'vertical', right: 10, top: 'middle' }, series: [ { type: 'pie', radius: '50%', data: overview.industryData, emphasis: { itemStyle: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }), [overview.industryData]) const barOption = useMemo(() => ({ tooltip: {}, dataset: { dimensions: ['name', 'value'], source: overview.originDeptData }, xAxis: {}, yAxis: { type: 'category', data: overview.originDeptData.map((o) => o.name) }, series: [{ type: 'bar', data: overview.originDeptData.map((o, idx) => ({ value: o.value, itemStyle: { color: DEFAULT_COLORS[idx] } })) }] }), [overview.originDeptData]) useEffect(() => { getDataScreening() }, []) useEffect(() => { barRef.current = init(barElementRef.current) barRef.current.setOption(barOption) }, [barOption]) useEffect(() => { pieRef.current = init(pieElementRef.current) pieRef.current.setOption(pieOption) }, [pieOption]) return (
{[ { title: '数据资源数量', num: overview.dataSource }, { title: '来源部门数量', num: overview.originDept }, { title: '来源系统数量', num: overview.originSystem }, { title: '近一月目录新增数量', num: overview.countCatalogue } ].map((item) => (
{item.title}
{item.num}
))}
行业分类
资源目录各行业资源数量
数据资源来源部门
数据资源来源部门TOP10
) }