import React, { useEffect, useRef, useState } from 'react'; import { connect } from 'react-redux'; import { Skeleton, Button, Pagination, Form, Popconfirm, Table, Toast } from '@douyinfe/semi-ui'; import moment from "moment"; const Header = (props) => { const { dispatch, actions, user,match, weatherRealtime, history } = props const [date, setDate] = useState(moment()); const dayMap = { 0: '日', 1: '一', 2: '二', 3: '三', 4: '四', 5: '五', 6: '六' } const weatherMap = { CLEAR_DAY: '晴(白天)', CLEAR_NIGHT: '晴(夜间)', PARTLY_CLOUDY_DAY: '多云(白天)', PARTLY_CLOUDY_NIGHT: '多云(夜间)', CLOUDY: '阴', WIND: '大风', HAZE: '雾霾', RAIN: '雨', SNOW: '雪' } const [weatherTemperature, setWeatherTemperature] = useState(''); const getWeather = () => { dispatch(actions.auth.getWeatherRealtime()) } useEffect(() => { const setTime = () => { setDate(moment()); setTimeout(() => { setTime() }, 1000); } const refreshWeather = () => { getWeather(); setTimeout(() => { refreshWeather() }, 1000 * 60 * 15); } setTimeout(() => { setTime() refreshWeather() }, 0); }, []) useEffect(() => { setWeatherTemperature( weatherRealtime?.temperature ? (weatherRealtime?.temperature - Math.ceil(Math.random() * 5)) + '~' + (weatherRealtime?.temperature + Math.ceil(Math.random() * 3)) + '℃' : '' ) }, [weatherRealtime]) const lineBetweenStyle = { width: 1, height: 15, border: '1px solid #B3C9FF', margin: '0 4px' } return (
{match?.path == '/projectGroup/bigscreen' ? `${JSON.parse(localStorage.getItem('project_group'))?.find(v => v.userId == user?.id)?.name}数据统计大屏` : '运维中台大屏'}
{date.format('HH:mm:ss')}
星期{dayMap[date.day()]} {date.format('YYYY-MM-DD')}
{weatherTemperature} {weatherMap[weatherRealtime?.skycon]}
{match?.path == '/projectGroup/bigscreen' ? <>
{ history.push({ pathname: `/projectGroup/statistic`, }) }}> 返回后台
: <> }
) } function mapStateToProps (state) { const { auth, global, weatherRealtime } = state; return { user: auth.user, actions: global.actions, weatherRealtime: weatherRealtime.data || {} }; } export default connect(mapStateToProps)(Header);