import { Space, Checkbox } from 'antd'; import type { CheckboxValueType } from 'antd/es/checkbox/Group'; import React, { useState, useEffect } from 'react'; import { connect } from 'umi'; import type { StateType } from '../../model'; import styles from '../style.less'; type Props = { legendOptions: LegendOptionsItem[]; value?: string[]; domainManger: StateType; onChange?: (ids: CheckboxValueType[]) => void; defaultCheckAll?: boolean; [key: string]: any; }; type LegendOptionsItem = { id: string; label: string; }; const GraphLegend: React.FC = ({ legendOptions, value, defaultCheckAll = false, onChange, }) => { const [groupValue, setGroupValue] = useState(value || []); useEffect(() => { if (!defaultCheckAll) { return; } if (!Array.isArray(legendOptions)) { setGroupValue([]); return; } setGroupValue( legendOptions.map((item) => { return item.id; }), ); }, [legendOptions]); useEffect(() => { if (!Array.isArray(value)) { setGroupValue([]); return; } setGroupValue(value); }, [value]); const handleChange = (checkedValues: CheckboxValueType[]) => { setGroupValue(checkedValues); onChange?.(checkedValues); }; return (
可见数据源
{legendOptions.map((item) => { return ( {item.label} ); })}
); }; export default connect(({ domainManger }: { domainManger: StateType }) => ({ domainManger, }))(GraphLegend);