'use strict' import React, { useState, useEffect, useMemo } from 'react' import { Menu } from 'antd' import { Link } from 'react-router-dom' import { connect } from 'react-redux' import styles from './style.css' import { setCurrentTab } from '$utils/someStores' import { WEATHERMARGIN, ICONSMAP } from '../../constants/weather' import { RouteRequest } from '@peace/utils' import moment from 'moment' import ShowTime from './showTime' import { MenuFoldOutlined, MenuUnfoldOutlined, UserOutlined, LogoutOutlined } from '@ant-design/icons' const Header = props => { const { dispatch, history, user, pathname, actions, clientWidth=100, toggleCollapsed, globalTab, tabChange } = props const [tabs, setTabs] = useState({ patrolManage: [ { name: '巡检管理', value: 'manage' }, { name: '巡检项', value: 'item' }, { name: '巡检日历', value: 'calendar' }, { name: '巡检报告', value: 'report' }, ], deviceManageTabs: [ { name: '设备统计', value: 'statistics' }, { name: '设备台账', value: 'list' }, ], }) const [patrolManageVisible, setPatrolManageVisible] = useState(false) const [deviceManageTabsVisible, setDeviceManageTabsVisible] = useState(false) const [currentSubMenuTab, setCurrentSubMenuTab] = useState('') const [tab, setTab] = useState('leader') const [projectName, setProjectName ]= useState('') const [weather, setWeather] = useState([]) let headerTitleStyle = { position: 'absolute', left: '3.125rem', top: '.125rem', fontSize: '1.875rem', color: ' #FFFFFF', fontWeight: 600, fontFamily: 'PangMenZhengDao', letterSpacing: '.5231rem', width:'39rem' } let headerTabStyle = { width: '4.375rem', height: '1.125rem', fontFamily: 'PangMenZhengDao', fontSize: '1.125rem', color: '#CCE6FF', letterSpacing: '.0231rem' } useEffect(() => { queryWeather() const projectName = JSON.parse(sessionStorage.getItem('user')).projectName setProjectName(projectName) const timeUpdate = setInterval(() => { queryWeather() }, WEATHERMARGIN) return () => { clearInterval(timeUpdate) } }, []) const queryWeather = () => { RouteRequest.get(`/query/weather/3d?location=101240101`).then(res => { if (res?.daily?.length === 3) { setWeather(res.daily) } }) } const iconSrc = useMemo(() => { if (weather.length === 3) { const icon = [ICONSMAP[weather[0].textDay], ICONSMAP[weather[1].textDay], ICONSMAP[weather[2].textDay]] return icon } return [] }, [weather]) const handelClick = item => { if (item.key == 'logout') { dispatch(actions.auth.logout(user)) dispatch({ type: 'CLEAR_GLOBAL_SITE_LIST' }) //清空用户关注工地列表 history.push(`/signin?pcode=${user.pcode}`) } } const onClick1 = tab => { setTab(tab) if (tab == 'inspection') { setPatrolManageVisible(true) setDeviceManageTabsVisible(false) } else if (tab == 'device') { setDeviceManageTabsVisible(true) setPatrolManageVisible(false) } else { setPatrolManageVisible(false) setDeviceManageTabsVisible(false) setCurrentSubMenuTab('') // dispatch({ type: 'TAB-CHANGE', data: tab }) } tabChange(tab) } return (