import React, { useState, useMemo, useEffect } from "react"; import { connect } from "dva"; import { withRouter } from "dva/router"; import { Dropdown, Icon, Menu, message, Button, Modal, Input } from "antd"; import { HeaderSearch as OPTSearch, PictureThumb } from "@woowalker/feui"; import ModifyPassword from "../components/MainPage/ModifyPassword"; import FoUserInfoShow from "../components/MainPage/FoUserInfoShow"; import FeedbackQuestion from "../components/MainPage/FeedbackQuestion"; import GuideCanvas from "../components/MainPage/GuideCanvas"; import IconFont from "../utils/iconFont"; import { initFilter, requestFullScreenMethod } from "../utils/common"; import config from "../config"; import "./header.less"; import Option from "./Option"; import RiskFourPage from "./RiskFour"; import FullScreenPage from "./FullScreen"; // 投屏 const DataV = (props) => { const navTo = () => { const { OrgId, Tenant, baseConfig } = props.login; const preUrl = baseConfig.SCREEN_URL || config.dataVUrl; const queryStr = `OrgId=${OrgId}&Tenant=${Tenant}`; const url = `${ preUrl.indexOf("?") !== -1 ? preUrl : preUrl + "?" }${queryStr}`; window.open(url, "_blank"); }; return ( {/* */} ); }; const HeaderDataV = connect(({ login }) => ({ login }))(DataV); // 搜索 const SearchBox = (props) => { const [autoCompleteData, setAutoCompleteData] = useState([]); const [inputVal, setInputVal] = useState(""); const leafMenus = useMemo(() => { const menuForms = []; const menuDatas = []; function traverseChild(item) { if (!item.Menu.Nav_MenuForm || item.ChildMenus?.length) { item.ChildMenus.forEach((x) => { traverseChild(x); }); } else if (item.Menu.Nav_MenuForm) { menuForms.push({ MenuName: item.Menu.NAME, ...item.Menu.Nav_MenuForm, }); menuDatas.push(item); } } const menus = props.login.loginInfo.Menus || []; menus.forEach((item) => { traverseChild(item); }); return { menuForms, menuDatas }; }, [props.login.loginInfo?.Menus]); /** * 搜索菜单 * @param {*} e */ const handleSearchMenu = (e) => { setInputVal(e.target.value); if (!e.target.value || e.target.value === "") { setAutoCompleteData([]); return; } const validResult = []; leafMenus.menuForms.forEach((item) => { if ( item.CODE.toLowerCase().indexOf(e.target.value.toLowerCase()) >= 0 || item.NAME.toLowerCase().indexOf(e.target.value.toLowerCase()) >= 0 || item.MenuName.toLowerCase().indexOf(e.target.value.toLowerCase()) >= 0 ) { validResult.push(item); } }); setAutoCompleteData(validResult); }; /** * 选中菜单 * @param {*} e */ const overMenu = () => { if (autoCompleteData.length == 0) { return ( 暂无匹配项 ); } else { return ( {autoCompleteData.map((item, index) => { return ( { handleSelectMenu(item.ID); }} > {item.NAME}({item.CODE}) ); })} ); } }; const handleSelectMenu = (e) => { const menu = leafMenus.menuDatas.find( (item) => item.Menu.Nav_MenuForm.ID === e ); props.dispatch({ type: "app/updateActivatedMenu", payload: { currActivatedTab: menu.Node.ID, currActivatedMenu: menu.Node, }, }); props.history.push({ pathname: `/main/${menu.Node.ID}` }); setInputVal(""); setAutoCompleteData([]); }; if (window.navigator.userAgent.indexOf("Windows") < 1) { return ; } else { return ( // //
{/* */} } onChange={(e) => { handleSearchMenu(e); }} onPressEnter={(e) => { handleSearchMenu(e); }} value={inputVal} />
); } //return ( // // //) }; const HeaderSearch = withRouter(connect(({ login }) => ({ login }))(SearchBox)); // 个人中心 const User = (props) => { const [visible, setVisible] = useState(false); /** * 注销登录 */ const handleLogout = () => { const { OrgId, userId } = props.login; const logJson = initFilter(OrgId, userId, "", 0, 1, 0); props.dispatch({ type: "app/addLoginOut", payload: logJson, }); localStorage.removeItem("accessToken"); props.history.push({ pathname: "/login" }); }; /** * 锁屏 */ const handleLockScreen = () => { localStorage.removeItem("accessToken"); props.dispatch({ type: "login/save", payload: { screenLocked: true, }, }); }; /** * 菜单选中 * @param {*} evt */ const handleUserMenuClick = (evt) => { switch (evt.key) { case "user-menu-logout": handleLogout(); break; case "user-menu-lockscreen": handleLockScreen(); break; case "user-menu-cacheclean": window.localStorage.clear(); message.success("清除成功,即将重新加载页面", 2, () => { setTimeout(() => window.location.reload(true), 500); }); break; default: break; } setVisible(false); }; const { loginInfo = {} } = props.login; return ( 当前登录:{loginInfo.User?.NAME} 我的资料 修改密码 {/* 问题反馈 */} {/* 屏幕锁定 */} 清除缓存 版本号:{config.version} 退出登录 } > ); }; const HeaderUser = withRouter(connect(({ login }) => ({ login }))(User)); const GuideCodePage = (props) => { const [showCanvas, setshowCanvas] = useState(false); const currVans = (val) => { setshowCanvas(true); }; /** * 生产单元切换 * @param {*} evt */ if (window.navigator.userAgent.indexOf("Windows") < 1) { return
; } else { return (
{ currVans(); }} style={{ margin: "0px 36px", display: "flex", alignItems: "center" }} >
{ setshowCanvas(false); }} onCancel={() => { setshowCanvas(false); }} footer={null} >
); } }; const GuideCode = withRouter( connect(({ login }) => ({ login }))(GuideCodePage) ); const RiskFourColorOpton = (props) => { const [showModal, setshowModal] = useState(false); const escFunction = () => { let isFull = !!( document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen ); if (isFull) { // / } else { // requestFullScreenMethod(document.body); setshowModal(false); } }; useEffect(() => { // 监听退出全屏事件 --- chrome 用 esc 退出全屏并不会触发 keyup 事件 document.addEventListener( "webkitfullscreenchange", escFunction ); /* Chrome, Safari and Opera */ document.addEventListener("mozfullscreenchange", escFunction); /* Firefox */ document.addEventListener( "fullscreenchange", escFunction ); /* Standard syntax */ document.addEventListener( "msfullscreenchange", escFunction ); /* IE / Edge */ return () => { //销毁时清除监听 document.removeEventListener("webkitfullscreenchange", escFunction); document.removeEventListener("mozfullscreenchange", escFunction); document.removeEventListener("fullscreenchange", escFunction); document.removeEventListener("MSFullscreenChange", escFunction); }; }, []); if (window.navigator.userAgent.indexOf("Windows") < 1) { return
; } else { return (
{ setshowModal(true); requestFullScreenMethod(document.body); // 进入全屏 }} style={{ margin: "0px 36px", display: "flex", alignItems: "center" }} > {/* */}
{ setshowModal(false); }} onCancel={() => { setshowModal(false); }} className="fullScreen" >
); } }; const RiskFourColor = withRouter( connect(({ login }) => ({ login }))(RiskFourColorOpton) ); const FullScreenOpton = (props) => { const [showModal, setshowModal] = useState(false); const getChildCount = (val) => { setshowModal(val); }; const [fullScreen, setFullScreen] = useState(false); const [originResizeFunc, setOriginResizeFunc] = useState(); const escFunction = () => { let isFull = !!( document.fullscreen || document.mozFullScreen || document.webkitIsFullScreen || document.webkitFullScreen || document.msFullScreen ); if (isFull) { // / } else { // requestFullScreenMethod(document.body); setshowModal(false); } }; useEffect(() => { // 监听退出全屏事件 --- chrome 用 esc 退出全屏并不会触发 keyup 事件 document.addEventListener( "webkitfullscreenchange", escFunction ); /* Chrome, Safari and Opera */ document.addEventListener("mozfullscreenchange", escFunction); /* Firefox */ document.addEventListener( "fullscreenchange", escFunction ); /* Standard syntax */ document.addEventListener( "msfullscreenchange", escFunction ); /* IE / Edge */ return () => { //销毁时清除监听 document.removeEventListener("webkitfullscreenchange", escFunction); document.removeEventListener("mozfullscreenchange", escFunction); document.removeEventListener("fullscreenchange", escFunction); document.removeEventListener("MSFullscreenChange", escFunction); }; }, []); if (window.navigator.userAgent.indexOf("Windows") < 1) { return
; } else { return (
{ setshowModal(true); requestFullScreenMethod(document.body); // 进入全屏 }} > {/* */}
{ setshowModal(false); }} onCancel={() => { setshowModal(false); }} className="fullScreen" >
); } }; const FullScreen = withRouter( connect(({ login }) => ({ login }))(FullScreenOpton) ); const NavOpton = (props) => { const [showModal, setshowModal] = useState(false); const getChildCount = (val) => { setshowModal(val); }; if (window.navigator.userAgent.indexOf("Windows") < 1) { return
; } else { return (
{ setshowModal(true); }} > {/* */}
{ setshowModal(false); }} onCancel={() => { setshowModal(false); }} className="headerModal" >
); } }; const HeaderNav = withRouter(connect(({ login }) => ({ login }))(NavOpton)); function Header(props) { const { baseConfig = {} } = props.login; const thumbCode = baseConfig.Nav_PictureLogo ? baseConfig.Nav_PictureLogo.CODE : ""; let isMobile = false; if (window.navigator.userAgent.indexOf("Windows") < 1) { isMobile = true; } return (
{isMobile ? ( ) : ( 双重预防机制管控系统 {/* 安全管理系统 (SMS) */} {baseConfig.SYS_NAME}{" "} )}
{!props.matchLogin ? (
{window.location.host == "47.122.43.22:7001" ? : ""} {/* style={{"color":"#f3eded"}} */} {props.login.user.NAME}({props.login.user.CODE})
) : null}
); } export default connect(({ login }) => ({ login }))(Header);