import React, { useState, useEffect } from 'react';
import Wrap from '../wrap/Wrap';
import FooterBtn from '../FooterBtn/index';
import LabelColorPick from '../colorPick/index';
import LabelSelect from '../LabelSelect/index';
import ChartColorPicker from '../RegularColorPicker/ColorPicker';
import ToInput from './twoInput';
import { Popover, InputNumber } from 'antd';
import { CaretDownOutlined, CaretUpOutlined } from '@ant-design/icons';
import '../g.scss';
const LabelPopoverTab = (props: IProps) => {
const {
wrapStyle = { padding: '6px 20px 6px 20px' },
title,
tabTitle,
tableList,
attrKey,
change,
quantileValue,
showColor,
selectList,
selectValue,
linearValue,
theme = 'white',
fillType = '',
isPure = false,
tabActiveValue = 'linear',
isShowTab = false,
quantizeSelectList,
quantizeSelectValue,
quantizeValueList,
quantizeNum
} = props;
const dom = document; // document
const [isVisible, setIsVisible] = useState(false); //显隐
const [current, setCurrent] = useState(tabActiveValue || 'linear'); //当前选中
const [close, setClose] = useState(true);
const [close2, setClose2] = useState(true);
const [numValue, setNumValue] = useState(quantizeNum);
useEffect(() => {
dom.addEventListener('mousedown', isPopover);
return () => {
dom?.removeEventListener('mousedown', isPopover);
};
}, []);
useEffect(() => {
// 弹窗开启时更新当前选中
if (isShowTab) {
setCurrent(tabActiveValue || 'linear');
}
}, [isShowTab]);
useEffect(() => {
setNumValue(quantizeNum);
}, [quantizeNum]);
const colorType = () => {
if (showColor?.length > 1) {
return {
backgroundImage: `linear-gradient(to right, ${showColor[0]},${showColor[1]} )`
};
} else {
return {
background: showColor[0]
};
}
};
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
)
)
) {
setClose2(true);
setClose(true);
}
};
// 判断父元素是否包含某个元素
const elementContains = (parent, child) =>
parent !== child && parent?.contains(child);
//确认事件
const handleChange = (params, type) => {
change(params, type);
setClose(true);
setClose2(true);
};
const content1 = (value, type) => {
return (
handleChange(params, type)}
handleCancel={(_) => {}}
handleParams={() => {
setClose(true);
setClose2(true);
}}
/>
);
};
const content = (
{title}
{tableList?.length > 0 &&
tableList?.map((item, index) => {
return (
{
change(item?.key, 'tableClick');
setCurrent(item?.key);
}}
>
{item?.title}
);
})}
{current === 'quantile' ? (
{
change(params, 'quantileColor');
}}
wrapStyle={{}}
attrKey={attrKey}
paddingSize="normal"
/>
) : (
<>>
)}
{current === 'linear' ? (
<>
change(value, 'linearSelect')}
size="normal"
wrapStyle={{}}
paddingSize="normal"
suffixIcon="icon-arrow-down-filling"
customStyle={{ width: '176px' }}
/>
{
setClose(false);
}}
/>
{
setClose2(false);
}}
/>
>
) : (
<>>
)}
{current === 'threshold' ? (
<>
change(value, 'quantizeSelect')}
size="normal"
wrapStyle={{}}
paddingSize="normal"
suffixIcon="icon-arrow-down-filling"
customStyle={{ width: '176px' }}
/>
{quantizeValueList &&
quantizeValueList?.length > 0 &&
quantizeValueList?.map((item, index) => {
return (
);
})}
{quantizeValueList &&
quantizeValueList?.length > 0 &&
quantizeValueList?.map((item, index) => {
return (
);
})}
组数
,
downIcon:
}}
size="small"
onChange={(value) => {
if (value < 1 || isNaN(value)) {
setNumValue(quantizeNum);
} else {
setNumValue(value);
}
}}
onBlur={() => {
change(numValue, 'quantizeNum');
}}
onPressEnter={() => {
change(numValue, 'quantizeNum');
}}
/>
>
) : (
<>>
)}
item?.max <= item?.min)
}
change={(type) => {
change(type, 'popoverTabBtn');
setIsVisible(false);
// change(false, 'isShowTab')
// setCurrent('quantile');
}}
/>
);
return (
{title}
{
// setIsVisible(true);
change(true, 'isShowTab');
}}
>
{tabTitle}
{tabActiveValue === 'threshold' ? (
{
// setIsVisible(true);
change(true, 'isShowTab');
}}
>
{quantizeValueList &&
quantizeValueList?.length > 0 &&
quantizeValueList?.map((item, index) => {
return (
);
})}
) : (
{
change(true, 'isShowTab');
}}
/>
)}
);
};
export default LabelPopoverTab;
export interface IProps {
wrapStyle: React.CSSProperties;
title: string;
tabTitle: string;
tableList: ITableList[];
attrKey?: string;
change: Function;
quantileValue: string;
showColor: string;
selectList: ISelectList[];
selectValue: string;
linearValue: string[];
theme?: string;
fillType?: string;
isPure?: boolean;
tabActiveValue?: string;
isShowTab?: boolean;
quantizeSelectList: ISelectList[];
quantizeSelectValue: string;
quantizeValueList: IQuantizeValueList[];
quantizeNum?: number;
}
export interface ITableList {
key: string;
title: string;
}
export interface ISelectList {
key: string;
name: string;
type: string;
img: string;
value: string[];
}
export interface IQuantizeValueList {
color: string;
max: number;
min: number;
status?: string;
}