import React, { useState, useEffect } from 'react'; import { ICardMultiText } from './interface'; import './style/index.less'; import { checkLabelContainTag } from '../../index'; import { isSymbolFormatTime } from './utils'; const prefixCls = 'iot-card-multi-text-out'; const getItem = (len: number) => { const itemLen = len; const itemWidth = Math.floor((1 / itemLen) * 100) + '%'; const style = { gridTemplateColumns: `repeat(${itemLen}, ${itemWidth})`, }; // console.log(style); return style; }; const IOTCardMultiText: React.FC = ({ list, streamId, specs, ...rest }) => { const [moreShow, setMoreShow] = useState(false); const [allList, setAllList] = useState>>([]); const [curList, setCurList] = useState>>([]); useEffect(() => { const arr = []; if (list.length > 0 && list.length <= 3) { arr.push(list); setCurList(arr); } else { let len = Math.floor(list.length / 3); let sur = list.length % 3; if (sur > 0) { len = len + 1; } // console.log(len); for (let i = 0; i < len; i++) { arr.push(list.slice(i * 3, i * 3 + 3)); } setAllList(arr); // setCurList(arr.slice(0, 2)); if (moreShow) { setCurList(arr); } else { setCurList(arr.slice(0, 2)); } } }, [list]); useEffect(() => { if (allList.length < 2) return; if (moreShow) { setCurList(allList); } else { setCurList(allList.slice(0, 2)); } }, [moreShow]); const timeConverHandler = ( text: string,items:any) => { if (checkLabelContainTag('7', items.label ?? '')) { return isSymbolFormatTime(Number.parseInt(text), items.unit || 'min', items.unitConvertFlag); } else { return text } } return (
2 ? 'show-bord':''}`}> {curList.map((lists, key) => { return (
{lists.map((items, index) => { return (
{items.title}
{items.text ? timeConverHandler( items.text,items) : '- -'}
); })}
); })}
{allList.length > 2 && (
{ setMoreShow(!moreShow); }} >
{moreShow ? '收起信息' : '显示更多信息'}
)}
); }; export default IOTCardMultiText;