import React, { useEffect, useState, useCallback } from 'react'; import Slider from './poleSlider'; import { IOTPoleSliderProps,Iitem,specialObjProps } from "./interface"; import './style/index.less'; const prefixCls = 'iot-pole-slider-out'; const returnText = (items: Iitem[], curValue: string) => { let values: string = ''; items.map((item: Iitem) => { if (item.value === curValue) { values = item.text } }) return values; } const IOTPoleSlider: React.FC = ({ streamId, title, streamName, subTitle, type, icon, showIconFont, disabled = false, curValue, specialObj, items, styleType, startHandler = (val: any) => { }, endHandler = (val: any) => { }, handler = (val: any) => { }, ...rest }) => { const [dataSource, setDataSource] = useState(items); const [currentValue, setcurrentValue] = useState(curValue); const [currentText, setcurrentText] = useState(curValue ? returnText(items, curValue):items[0].text); const defaultDataSource:Iitem[] = JSON.parse(JSON.stringify(items)); useEffect(() => { const dataList: any = []; if (specialObj?.checked && specialObj?.item !== undefined) { items.map((item: any) => { if (item.value !== specialObj?.item?.value) { dataList.push(item) } }) setDataSource(dataList); } else { setDataSource(items); } }, [ items, specialObj]); useEffect(() => { setcurrentValue(curValue); setcurrentText(curValue ? returnText(items, curValue):items[0].text); }, [curValue]); const filterHandler = (specialObj?: specialObjProps) => { if(!specialObj) return; const specialData = JSON.parse(JSON.stringify(specialObj)); if (!specialData?.checked && specialData?.item !== undefined) { specialData.item = undefined; return specialData; } return specialData; } return (
{icon?.show && (
)}
{title}
{specialObj?.item && specialObj?.checked && curValue === specialObj?.item?.value ? specialObj?.item?.text : currentText}
{ const item = { streamId, value: val, }; handler(item); }} move={(val: any) => { setcurrentValue(val.currentValue); setcurrentText(val.currentText); }} start={() => { startHandler('start'); }} >
); }; export default IOTPoleSlider;