import React, { useState, useEffect } from 'react'; import { Radio, Input, Popover, Space, Checkbox, Row, Col, Button } from 'knowdesign'; import { IconFont } from '@knowdesign/icons'; import { InodeScopeModule } from './index'; import './style/node-scope.less'; interface propsType { change: Function; nodeScopeModule: InodeScopeModule; } const OptionsDefault = [ { label: 'Top 5', value: 5, }, { label: 'Top 10', value: 10, }, { label: 'Top 15', value: 15, }, ]; const NodeScope = ({ nodeScopeModule, change }: propsType) => { const { customScopeList: customList, scopeName = '', scopeLabel = '自定义范围', searchPlaceholder = '输入内容进行搜索', } = nodeScopeModule; const [topNum, setTopNum] = useState(5); const [isTop, setIsTop] = useState(true); const [audioOptions, setAudioOptions] = useState(OptionsDefault); const [scopeSearchValue, setScopeSearchValue] = useState(''); const [inputValue, setInputValue] = useState(null); const [indeterminate, setIndeterminate] = useState(false); const [popVisible, setPopVisible] = useState(false); const [checkAll, setCheckAll] = useState(false); const [checkedListTemp, setCheckedListTemp] = useState([]); const [checkedList, setCheckedList] = useState([]); const [allCheckedList, setAllCheckedList] = useState([]); useEffect(() => { const all = customList?.map((item) => item.value) || []; setAllCheckedList(all); }, [customList]); useEffect(() => { if (topNum) { const timeOption = audioOptions.find((item) => item.value === topNum); setInputValue(timeOption?.label); setCheckedListTemp([]); setCheckedList([]); setPopVisible(false); } }, [topNum]); useEffect(() => { setIndeterminate(!!checkedListTemp.length && checkedListTemp.length < allCheckedList.length); setCheckAll(checkedListTemp?.length === allCheckedList.length); }, [checkedListTemp]); const customSure = () => { if (checkedListTemp?.length > 0) { setCheckedList(checkedListTemp); change(checkedListTemp, false); setIsTop(false); setTopNum(null); setInputValue(`${checkedListTemp?.length}项`); setPopVisible(false); } }; const customCancel = () => { setCheckedListTemp(checkedList); setPopVisible(false); }; const visibleChange = (visible: any) => { setCheckedListTemp(checkedList); setPopVisible(visible); }; const periodtimeChange = (e: any) => { const topNum = e.target.value; setTopNum(topNum); change(topNum, true); setIsTop(true); }; const onCheckAllChange = (e: any) => { setCheckedListTemp(e.target.checked ? allCheckedList : []); setIndeterminate(false); setCheckAll(e.target.checked); }; const checkChange = (val: any) => { setCheckedListTemp(val); // setIndeterminate(!!val.length && val.length < allCheckedList.length); // setCheckAll(val?.length === allCheckedList.length); }; const clickContent = (
{/* 时间: */}
选择 top 范围
{audioOptions.map((item, index) => ( {item.label} ))}
{scopeLabel}
全选 } size="small" placeholder={searchPlaceholder} onChange={(e) => setScopeSearchValue(e.target.value)} />
{customList .filter((item) => item.label.includes(scopeSearchValue)) .map((item) => ( {item.label} ))}
); return (
{scopeName}筛选:
} />
); }; export default NodeScope;