import React, { useEffect, useState, useMemo } from 'react'; import dynamic from 'next/dynamic'; const Liquid = dynamic(() => import('@ant-design/plots').then(({ Liquid }) => Liquid), { ssr: false } ); const RingProgress = dynamic(() => import('@ant-design/plots').then(({ RingProgress }) => RingProgress), { ssr: false } ); const Progress = dynamic(() => import('@ant-design/plots').then(({ Progress }) => Progress), { ssr: false } ); const Line = dynamic(() => import('@ant-design/plots').then(({ Line }) => Line), { ssr: false } ); import { List, Carousel, Cascader, Skeleton, Spin } from 'antd'; import _ from 'lodash'; import { getTimeRate, getAbnlException, getSevenQualifiedRate, getOpByRouterLine, getOrganization, } from '../../../reportUtils/getHomePageData'; import homecss from '../../../styles/homecss.module.css'; function HomePage() { let [loading, setLoading] = useState(false); // 工厂选择 let [workShops, setWorkShops] = useState([]); // 级联选择框的数据存储 let [workShopValue, setWorkShopValue] = useState([]); // 级联选择工作中心 let [caWorkCenterCode, setCaWorkCenterCode] = useState(''); // 级联选择产线 let [caRouterLineCode, setCaRouterLineCode] = useState(''); // 水波图,柱形图,环形图 let [timeRate, setTimeRate] = useState({}); // 异常消息 let [abnlException, setAbnlException] = useState({ equip: [], quality: [], prodexec: [], }); let [exceptions, setExceptions] = useState([]); let [currentExceptions, setCurrentExceptions] = useState([]); //存储工序消息 let [opData, setOpdata] = useState([]); // 质量合格率 let [qualifiedRate, setQualifiedRate] = useState([]); // 页面初始化加载 useEffect(() => { getOrganization().then(data => { if (data.length > 0) { let defaultOrg = {}; for (let i = 0; i < data.length; i++) { if ( data[i]['children'] && data[i]['children'].length === 0 ) { data[i]['isLeaf'] = false; } if (data[i]['defaultWorkCenter']) { defaultOrg = data[i]; } } let defaultOrgValue = []; if (defaultOrg['defaultWorkCenter']) { defaultOrgValue.push(defaultOrg['value']); let child = defaultOrg['children']; let flag = true; for (let i = 0; i < child.length; i++) { if (child[i]['defaultRoute'] && flag) { flag = false; defaultOrgValue.push(child[i]['value']); } } } setWorkShops(data); setWorkShopValue(defaultOrgValue); } }); }, []); useEffect(() => { let workCenterCode = ''; let routerLineCode = ''; if (workShopValue.length > 0) { workCenterCode = workShopValue[0]; setOpdata([]); getTimeRate(workCenterCode).then(data => { if (data) { for (let key in data) { if (data[key] == 1 || data[key] == 0) { data[key] = parseInt(data[key]); } else { data[key] = parseFloat(data[key].toFixed(3)); } } setTimeRate(data); } }); getAbnlException(workCenterCode).then(data => { if (data) { let exceptions = { equip: [], quality: [], prodexec: [], }; for (let i = 0; i < data.length; i++) { if (data[i].typeException === 'equip') { exceptions['equip'].push(data[i]); } else if (data[i].typeException === 'quality') { exceptions['quality'].push(data[i]); } else { exceptions['prodexec'].push(data[i]); } } setExceptions(data); setCurrentExceptions(data); setAbnlException(exceptions); } }); getSevenQualifiedRate(workCenterCode).then(data => { if (data) { let rates = []; for (let key in data) { rates.push({ month: key, value: data[key], }); } setQualifiedRate(rates); } }); if (workShopValue.length === 2) { setLoading(true); routerLineCode = workShopValue[1]; getOpByRouterLine(routerLineCode).then(data => { setLoading(false); if (data && data.length > 0) { setOpdata(data); } else { setOpdata([]); } }); } } else { setQualifiedRate([]); setOpdata([]); setCurrentExceptions([]); setExceptions([]); setTimeRate({}); setAbnlException({ equip: [], quality: [], prodexec: [], }); } }, [workShopValue]); const clickException = type => { let exceptionData = []; if (type === 'all') { exceptionData = exceptions; } else if (type === 'equip') { exceptionData = abnlException['equip']; } else if (type === 'quality') { exceptionData = abnlException['quality']; } else { exceptionData = abnlException['prodexec']; } setCurrentExceptions(exceptionData); }; const factoryChange = (value, selectedOptions) => { let currentValue = []; if (value) { currentValue = value; } console.log(currentValue); setWorkShopValue(currentValue); }; // 用来进行异步加载 /* const loadData = selectedOptions => { const targetOption = selectedOptions[selectedOptions.length - 1]; const { value = '' } = targetOption; targetOption.loading = true; getRouterLineByFactory(value).then(data => { targetOption.loading = false; let children = []; if (data.length > 0) { for (let i = 0; i < data.length; i++) { children.push({ value: data[i].code, label: data[i].name, }); } } targetOption.children = children; setWorkShops([...workShops]); }); }; */ return (
} options={workShops} onChange={factoryChange} changeOnSelect placeholder={'请选择产线'} />
  • 生产
  • 待产
  • 停产
时间稼动率
本月
本周
今日
性能稼动率
本月
{timeRate['BY_PERFORMANCE'] ? parseFloat( ( timeRate['BY_PERFORMANCE'] * 100 ).toFixed(2) ) + '%' : '0%'}
本周
{timeRate['BZ_PERFORMANCE'] ? parseFloat( ( timeRate['BZ_PERFORMANCE'] * 100 ).toFixed(2) ) + '%' : '0%'}
今日
{timeRate['BZ_PERFORMANCE'] ? parseFloat( ( timeRate['JR_PERFORMANCE'] * 100 ).toFixed(2) ) + '%' : '0%'}
合格率
clickException('all')} > 今日预警通知
  • clickException('equip')}> 设备预警 {abnlException['equip'].length}
  • clickException('quality')}> 质量预警 {abnlException['quality'].length}
  • clickException('prodexec')} > 生产预警 {abnlException['prodexec'].length}
( {item.time}
} > {item.typeException === 'equip' ? '【设备】' : item.typeException === 'quality' ? '【质量】' : '【生产】'}
} description={
{item.phenomenonName}
} /> )} />
合格率走势图
); } const WaterWave = React.memo(props => { const { color, stroke, percent } = props; let config = { autoFit: true, liquidStyle: { fill: color }, percent: percent, outline: { border: 3, distance: 1, style: { stroke: stroke, }, }, wave: { length: 80, count: 3, }, statistic: { title: { style: { fontFamily: 'PingFangSC-Medium', fontSize: '28px', color: 'rgba(0,0,0,0.85)', textAlign: 'center', lineHeight: '26px', fontWeight: '500', }, formatter: data => { return `${parseFloat((data.percent * 100).toFixed(1))}%`; }, offsetX: 3, offsetY: -20, }, content: false, }, }; return ; }); const CircleProgress = React.memo(props => { const { percent } = props; let config = { autoFit: true, percent: percent, color: ['#28a3ff', '#f1f1f1'], statistic: { title: { style: { fontFamily: 'PingFangSC-Medium', fontSize: '14px', color: 'rgba(0,0,0,0.85)', textAlign: 'center', lineHeight: '20px', fontWeight: '400', }, content: '合格率', offsetX: 1, offsetY: 35, }, content: { style: { fontFamily: 'PingFangSC-Medium', fontSize: '24px', color: 'rgba(0,0,0,0.85)', textAlign: 'center', lineHeight: '18px', fontWeight: '500', }, formatter: data => { return `${data.percent * 100}%`; }, offsetX: 3, offsetY: -18, }, }, }; return ; }); const ProgressBar = React.memo(props => { const { percent, barWidthRatio, color } = props.config; let config = { autoFit: true, percent: percent, barWidthRatio: barWidthRatio, color: color, }; return ; }); const LineChart = React.memo(props => { let { data = [] } = props; const config = { autoFit: true, smooth: true, color: '#2D99FF', lineStyle: { fill: '#cae5ff', }, yAxis: { line: { style: { stroke: '#bfbfbf', lineWidth: 1, opacity: 0.75, }, }, label: { formatter: axisValue => { if (axisValue > 0) { return axisValue * 100 + '%'; } return axisValue; }, }, }, data, xField: 'month', yField: 'value', point: { size: 4, shape: 'circle', style: { fill: '#2D99FF', stroke: '#2D99FF', lineWidth: 1, }, }, tooltip: { formatter: datum => { return { name: '合格率', value: datum.value * 100 + '%' }; }, }, }; return ; }); const Triangle = React.memo(() => { return (
); }); const ProcessCard = React.memo(props => { const spacing = [24, 24]; const { Content, data, rowKey, workCenterCode } = props; const [ruleLength] = useState(5); const memoData = useMemo(() => { let res = []; data.forEach((item, index) => { let row = Math.ceil((index + 1) / ruleLength); let rowIndex = index % ruleLength; if (!res[row]) res[row] = []; res[row][rowIndex] = item; }); return res; }, [data, ruleLength]); return (
{memoData.map((row, rowIndex) => { let reverse = rowIndex % 2 > 0; return (
{row.map(item => { return (
); })}
); })}
); }); const OperationCard = React.memo(props => { let { equipList = [], title = '', workCenterCode = '' } = props; return (
{title}
{equipList.map(item => { return (
); })}
); }); const EquipCard = React.memo(props => { let { status, equipCode, equipName, workCenterCode } = props.config; let title = ''; let background = ''; let img = ''; if (status === 1) { title = '待产中'; background = 'linear-gradient(270deg, #FFDB93 0%, #FAAB0C 100%)'; img = '/img/dc.png'; } else if (status === 2) { title = '生产中'; background = 'linear-gradient(270deg, #7AC7FF 0%, #28A3FF 100%)'; img = '/img/sz.png'; } else if (status === 3) { title = '停产中'; background = 'linear-gradient(270deg, #FF735F 0%, #F5222D 100%)'; img = '/img/tc.png'; } return (
{ setTimeout(() => { window.parent.postMessage( { path: `/mdgeneric/neusoft_web/runtime/f4c2f3083ec84daca1b6bea7985194cb?workCenterCode=${workCenterCode[0]}`, }, '*' ); }, 0); localStorage.setItem('workCenterCode', workCenterCode[0]); console.log(workCenterCode[0], '+++++'); }} >
{title}
{equipName} {equipCode}
); }); export default HomePage;