import React, { useState, useEffect } from 'react'; import ChartColorPicker from '../RegularColorPicker/ColorPicker'; import { InputNumber, Popover, Tooltip } from 'antd'; export default function twoInput(props: IProps) { const { color, max, min, index, theme = 'white', fillType = '', isPure = false, change, status, length } = props; const dom = document; // document const [close, setClose] = useState(true); const [minValue, setMinValue] = useState(min); const [maxValue, setMaxValue] = useState(max); const [visible, setVisible] = useState(false); const [oldMax, setOldMax] = useState(0); const [oldMin, setOldMin] = useState(0); useEffect(() => { setMinValue(min); }, [min]); useEffect(() => { setMaxValue(max); }, [max]); useEffect(() => { setOldMax(max); }, []); useEffect(() => { setOldMin(min); }, []); useEffect(() => { dom.addEventListener('mousedown', isPopover); return () => { dom?.removeEventListener('mousedown', isPopover); }; }, []); const isPopover = (e) => { if ( !( elementContains( document.querySelector('.color-pick-select'), e.target ) || elementContains(document.querySelector('.colorPopover'), e.target) || elementContains( document.querySelector('.zl-large-screen-setting'), e.target ) ) ) { setClose(true); } }; // 判断父元素是否包含某个元素 const elementContains = (parent, child) => parent !== child && parent?.contains(child); //确认事件 const handleChange = (params, type) => { change(params, type, index - 1); setClose(true); }; const content1 = (value) => { return (
{ handleChange(params, 'twoInputColor'); }} handleCancel={(_) => {}} handleParams={() => { setClose(true); }} />
); }; return (
{ setClose(!close); }} /> { setMinValue(value); }} onBlur={() => { if (minValue === null) { setMinValue(oldMin); } change( minValue === null ? oldMin : minValue, 'twoInputMin', index - 1 ); }} onPressEnter={() => { change( minValue === null ? oldMin : minValue, 'twoInputMin', index - 1 ); }} /> ~
{ setVisible(true); }} onMouseOut={() => { setVisible(false); }} > { change?.(value, 'twoInputMaxChange', index - 1); setMaxValue(value); }} onBlur={() => { if ( status !== '' || (maxValue <= minValue && maxValue === 0) || maxValue === null ) { setMaxValue(oldMax); } change( maxValue <= minValue || maxValue === null ? oldMax : maxValue, 'twoInputMax', index - 1 ); }} onPressEnter={() => { if (status !== '') { setMaxValue(oldMax); } change( maxValue <= minValue ? oldMax : maxValue, 'twoInputMax', index - 1 ); }} />
); } export interface IProps { color: string; max: number; mix?: number; min?: number; index?: number; theme?: string; fillType?: string; isPure?: boolean; change?: Function; status?: string; length?: number; }