'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 (
{/* */}
{projectName}
{ onClick1('leader') }} style={{ ...headerTabStyle, // color: tab == 'leader' ? '#E9CF14' : '#FFFFFF', // fontWeight: tab == 'leader' ? 500 : 400, position: 'relative', marginRight: '1.375rem', }}> {/* */} 领导驾驶舱 {/* */} { onClick1('run') }} style={{ ...headerTabStyle, // color: tab == 'run' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight: '1.375rem' }}> {/* */} 运行监控 {/* */} { onClick1('error') }} style={{ ...headerTabStyle, // color: tab == 'error' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight: '1.375rem' }}> {/* */} 故障管理 {/* */} { onClick1('inspection') }} style={{ ...headerTabStyle, // color: tab == 'inspection' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight: '1.375rem' }}> {/* */} 巡检管理 {/* */} { onClick1('aiot') }} style={{ ...headerTabStyle, // color: tab == 'aiot' ? '#E9CF14' : '#FFFFFF', position: 'relative',marginRight: '1.375rem' }}> {/* */} AIOT运维 {/* */} { onClick1('device') }} style={{ ...headerTabStyle, // color: tab == 'device' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight: '1.375rem' }}> {/* */} 设备管理 {/* */} { onClick1('expert') }} style={{ // color: tab == 'expert' ? '#E9CF14' : '#FFFFFF', ...headerTabStyle, position: 'relative', marginRight: '1.375rem' }}> {/* */} 运维专家 {/* */} { onClick1('info') }} style={{ ...headerTabStyle, // color: tab == 'info' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight: '1.375rem' }}> {/* */} 知识库 {/* */} { onClick1('task') }} style={{ ...headerTabStyle, // color: tab == 'task' ? '#E9CF14' : '#FFFFFF', position: 'relative', marginRight:'2.1875rem' }}> {/* */} 任务统计 {/* */}
{weather[0]?.textDay}
{/*
{weather[0]?.tempMin}-{weather[0]?.tempMax}℃
*/}
icon
{patrolManageVisible || deviceManageTabsVisible ? (
{(patrolManageVisible ? tabs.patrolManage : tabs.deviceManageTabs).map((tab, index) => (
this.clickSubMenuTab(tab.value)} style={{ color: currentSubMenuTab == tab.value ? '#E9CF14' : 'white', fontSize: '1rem', margin: '0 .625rem', }}> {tab.name} {/* */}
))}
) : ( '' )}
) } function mapStateToProps(state) { const { global, auth, globalTab } = state return { actions: global.actions, user: auth.user, clientWidth: global.clientWidth, clientHeight:global.clientHeight, globalTab: globalTab.tab, } } export default connect(mapStateToProps)(Header)