/* eslint-disable no-undef,function-paren-newline */ import React, { Component } from 'react'; import { BarsOutlined, StarFilled } from '@ant-design/icons'; import { Button } from 'antd-v4'; import navdefault from '@/assets/navdefault.svg'; import config from '@/utils/config'; import * as commonFunc from '@/components/Common/commonFunc'; import styles from './index.less'; import commonConfig from '../../utils/config'; class MenuPanelComponent extends Component { constructor(props) { super(props); this.state = { expend: false, expendSid: null, }; this.timer = null; } componentWillMount() { this.getMenuPanel(); } componentDidMount() { document.addEventListener('click', (e) => { let count = 0; if (e.path && e.path.length > 0) { /* chrome最新版本不支持e.path */ e.path.forEach((item) => { if (item.id === 'allNavMenus' || item.id === 'allBtnNav') { count += 1; } }); } if (e.target) { const condition1 = e.target.id === 'allNavMenus' || e.target.id === 'allBtnNav'; const condition2 = typeof e.target.className === 'string' && e.target.className.includes('submenu'); if (condition1 || condition2) { count += 1; } else if (e.target.parentNode) { if ( e.target.parentNode.id === 'allNavMenus' || e.target.parentNode.id === 'allBtnNav' || (typeof e.target.parentNode.className === 'string' && e.target.parentNode.className.includes('menuMain')) ) { count += 1; } else if (e.target.parentNode.parentNode) { if (e.target.parentNode.parentNode.id === 'allNavMenus' || e.target.parentNode.parentNode.id === 'allBtnNav') { count += 1; } } } } if (!count) { if (this.state.expend) { this.setState({ expend: false, }); } } }); document.addEventListener('mouseover', (e) => { if ( typeof e.target.className === 'string' && (e.target.className.indexOf('ant-tabs-nav') !== -1 || e.target.className.indexOf('ant-tabs-tab-btn') !== -1) ) { this.setState({ expendSid: null, }); } }); } componentWillReceiveProps(nextProps) { const { currentPane, logoImageInfo } = nextProps.app; const btnDisabled = !!(currentPane !== undefined && currentPane.newRecordFlag !== undefined);/* 全部导航按钮的状态 */ this.setState({ btnDisabled, logoImageInfo }); } setExpendSid(e, leave) { if (leave && this.timer) { clearTimeout(this.timer); return; } this.timer = setTimeout(() => { this.setState({ expendSid: e, }); }, 50); } getMenuPanel = () => { const url = `${config.server_host}business/getBuMenu?sModelsId=100`; this.props.onGetMenuPanel(url); } handleCommonMenu = async (e, child) => { e.stopPropagation(); const { sId, sName, sMenuName } = child; const value = { sFormId: sId, sFormUrl: sName, sFormName: sMenuName }; let currentElement = e.target.parentNode.parentNode; if (e.target.nodeName === 'svg') { currentElement = e.target.parentNode; } if (currentElement.className.indexOf('selected') === -1) { const addUrl = `${config.server_host}parameter/addParameter?sModelsId=${sId}`; this.props.onAddParameter(value, addUrl); } else { const delUrl = `${config.server_host}parameter/deleteParameter?sModelsId=${sId}`; this.props.onDelParameter(value, delUrl); } // todo更新数据,重新渲染 setTimeout(() => { this.getMenuPanel(); }, 200); }; handleTabClick = (e) => { if (!e.bHasRole) return; const { sLanguage } = this.props.app.userinfo; const paneKey = new Date().getTime().toString(); const formId = e.sId; const route = e.sName; const title = e[sLanguage] || e.sMenuName; const sModelsType = e.sModelType; const { sProcName } = e; for (const each of this.props.app.panes) { /* 解决导航栏打开页签,Modal不消失问题 */ each.notCurrentPane = true; } const pane = { title, route, formId, key: paneKey, sModelsType, sProcName, notCurrentPane: false, }; let routeNew = route; if (route && route.includes('http')) { console.log('route', route); console.log('sModelsType:::', sModelsType); const sModelsTypeNew = sModelsType !== undefined ? sModelsType : ''; const { userinfo } = this.props.app; routeNew = routeNew.replace('{sBrandsId}', userinfo.sBrandsId).replace('{sSubsidiaryId}', userinfo.sSubsidiaryId).replace('{sUserName}', userinfo.sUserName) .replace('{sUserNo}', userinfo.sUserNo); const parameter = sModelsTypeNew.replace('{sBrandsId}', userinfo.sBrandsId).replace('{sSubsidiaryId}', userinfo.sSubsidiaryId).replace('{sUserName}', userinfo.sUserName) .replace('{sUserNo}', userinfo.sUserNo); window.open(routeNew, parameter); return; } this.props.onAddPane(pane); this.setState({ expend: false, }); }; handleButtonClick = () => { this.setState({ expend: !this.state.expend, }); }; render() { const { btnDisabled, logoImageInfo = [] } = this.state; const { menuPanel, app } = this.props; const { userinfo = {} } = app; const { sLanguage } = userinfo; const genSubmenuList = (data) => { const domList = []; if (data !== undefined && data !== []) { data.forEach((item) => { const dom = (