|
@@ -13,12 +13,15 @@ interface FilterProps {
|
|
|
action?: number;
|
|
action?: number;
|
|
|
data: TermsType;
|
|
data: TermsType;
|
|
|
isLast: boolean;
|
|
isLast: boolean;
|
|
|
- onChange: (value: TermsType) => void;
|
|
|
|
|
|
|
+ onChange?: (value: TermsType | any) => void;
|
|
|
|
|
+ onValueChange: (value: TermsType) => void;
|
|
|
onLabelChange: (lb: any[]) => void;
|
|
onLabelChange: (lb: any[]) => void;
|
|
|
options: any[];
|
|
options: any[];
|
|
|
label?: any[];
|
|
label?: any[];
|
|
|
onAdd: () => void;
|
|
onAdd: () => void;
|
|
|
onDelete: () => void;
|
|
onDelete: () => void;
|
|
|
|
|
+ onColumns: (columns: string[]) => void;
|
|
|
|
|
+ columns?: string[];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const handleName = (_data: any) => (
|
|
const handleName = (_data: any) => (
|
|
@@ -46,6 +49,7 @@ export default observer((props: FilterProps) => {
|
|
|
const labelCache = useRef<any[]>([undefined, undefined, {}, 'and']);
|
|
const labelCache = useRef<any[]>([undefined, undefined, {}, 'and']);
|
|
|
|
|
|
|
|
const [deleteVisible, setDeleteVisible] = useState(false);
|
|
const [deleteVisible, setDeleteVisible] = useState(false);
|
|
|
|
|
+ const columnsRef = useRef<string[]>([]);
|
|
|
|
|
|
|
|
const ValueRef = useRef<Partial<TermsType>>({
|
|
const ValueRef = useRef<Partial<TermsType>>({
|
|
|
column: '',
|
|
column: '',
|
|
@@ -55,7 +59,7 @@ export default observer((props: FilterProps) => {
|
|
|
|
|
|
|
|
const valueChange = useCallback(
|
|
const valueChange = useCallback(
|
|
|
(_value: any) => {
|
|
(_value: any) => {
|
|
|
- props.onChange?.({ ..._value });
|
|
|
|
|
|
|
+ props.onValueChange?.({ ..._value });
|
|
|
},
|
|
},
|
|
|
[column, termType, value],
|
|
[column, termType, value],
|
|
|
);
|
|
);
|
|
@@ -71,17 +75,27 @@ export default observer((props: FilterProps) => {
|
|
|
[column, termType],
|
|
[column, termType],
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- const convertLabelValue = (columnValue?: string) => {
|
|
|
|
|
- if (columnValue) {
|
|
|
|
|
- const labelOptions = columnOptionsMap.get(columnValue);
|
|
|
|
|
- if (!labelOptions) return;
|
|
|
|
|
-
|
|
|
|
|
- const _termTypeOptions: any[] =
|
|
|
|
|
- labelOptions?.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) || [];
|
|
|
|
|
- setTtOptions(_termTypeOptions);
|
|
|
|
|
- setValueType(labelOptions?.type);
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ const convertLabelValue = useCallback(
|
|
|
|
|
+ (columnValue?: string) => {
|
|
|
|
|
+ if (columnValue) {
|
|
|
|
|
+ const labelOptions = columnOptionsMap.get(columnValue);
|
|
|
|
|
+ console.log('filter-convertLabelValue', labelOptions);
|
|
|
|
|
+ if (labelOptions) {
|
|
|
|
|
+ const _termTypeOptions: any[] =
|
|
|
|
|
+ labelOptions?.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) ||
|
|
|
|
|
+ [];
|
|
|
|
|
+ setTtOptions(_termTypeOptions);
|
|
|
|
|
+ setValueType(labelOptions?.type);
|
|
|
|
|
+ props.onChange?.(props.data);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ props.onChange?.({});
|
|
|
|
|
+ setTtOptions([]);
|
|
|
|
|
+ setValueType('');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ [props.data],
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
const handleTreeData = (data: any): any[] => {
|
|
const handleTreeData = (data: any): any[] => {
|
|
|
if (data.length > 0) {
|
|
if (data.length > 0) {
|
|
@@ -116,6 +130,7 @@ export default observer((props: FilterProps) => {
|
|
|
}, [props.data]);
|
|
}, [props.data]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
|
|
+ columnOptionsMap.clear();
|
|
|
const newOptions = handleTreeData(props.options || []);
|
|
const newOptions = handleTreeData(props.options || []);
|
|
|
convertLabelValue(props.data?.column);
|
|
convertLabelValue(props.data?.column);
|
|
|
setBuiltInOptions(newOptions);
|
|
setBuiltInOptions(newOptions);
|
|
@@ -126,6 +141,10 @@ export default observer((props: FilterProps) => {
|
|
|
labelCache.current = props.label || [undefined, undefined, {}, 'and'];
|
|
labelCache.current = props.label || [undefined, undefined, {}, 'and'];
|
|
|
}, [props.label]);
|
|
}, [props.label]);
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ columnsRef.current = props.columns || [];
|
|
|
|
|
+ }, [props.columns]);
|
|
|
|
|
+
|
|
|
return (
|
|
return (
|
|
|
<div className="filter-condition-warp">
|
|
<div className="filter-condition-warp">
|
|
|
<div
|
|
<div
|
|
@@ -160,6 +179,11 @@ export default observer((props: FilterProps) => {
|
|
|
const _termTypeOptions: any[] =
|
|
const _termTypeOptions: any[] =
|
|
|
node.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) || [];
|
|
node.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) || [];
|
|
|
setTtOptions(_termTypeOptions);
|
|
setTtOptions(_termTypeOptions);
|
|
|
|
|
+ if (!node.metadata) {
|
|
|
|
|
+ columnsRef.current = [node.column];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current = [];
|
|
|
|
|
+ }
|
|
|
// 默认选中第一个
|
|
// 默认选中第一个
|
|
|
let _termTypeValue = undefined;
|
|
let _termTypeValue = undefined;
|
|
|
if (_termTypeOptions.length) {
|
|
if (_termTypeOptions.length) {
|
|
@@ -201,6 +225,7 @@ export default observer((props: FilterProps) => {
|
|
|
|
|
|
|
|
labelCache.current[1] = v;
|
|
labelCache.current[1] = v;
|
|
|
ValueRef.current.termType = v;
|
|
ValueRef.current.termType = v;
|
|
|
|
|
+ columnsRef.current.length = 1;
|
|
|
valueChange({
|
|
valueChange({
|
|
|
column: props.data!.column,
|
|
column: props.data!.column,
|
|
|
value: _value as TermsVale,
|
|
value: _value as TermsVale,
|
|
@@ -219,7 +244,7 @@ export default observer((props: FilterProps) => {
|
|
|
BuiltInOptions={BuiltInOptions}
|
|
BuiltInOptions={BuiltInOptions}
|
|
|
showLabelKey="fullName"
|
|
showLabelKey="fullName"
|
|
|
name={0}
|
|
name={0}
|
|
|
- onChange={(v, lb) => {
|
|
|
|
|
|
|
+ onChange={(v, lb, node) => {
|
|
|
const _myValue = {
|
|
const _myValue = {
|
|
|
value: [v.value, ValueRef.current.value?.value?.[1]],
|
|
value: [v.value, ValueRef.current.value?.value?.[1]],
|
|
|
source: v.source,
|
|
source: v.source,
|
|
@@ -228,6 +253,17 @@ export default observer((props: FilterProps) => {
|
|
|
setValue(_myValue);
|
|
setValue(_myValue);
|
|
|
labelCache.current[2] = { ...labelCache.current[2], 0: lb };
|
|
labelCache.current[2] = { ...labelCache.current[2], 0: lb };
|
|
|
labelCache.current[3] = props.data.type;
|
|
labelCache.current[3] = props.data.type;
|
|
|
|
|
+
|
|
|
|
|
+ if (v.source === 'upper') {
|
|
|
|
|
+ if (!node.metadata) {
|
|
|
|
|
+ columnsRef.current[1] = node.column;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.splice(1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.length = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ props.onColumns(columnsRef.current);
|
|
|
props.onLabelChange?.(labelCache.current);
|
|
props.onLabelChange?.(labelCache.current);
|
|
|
valueEventChange(_myValue);
|
|
valueEventChange(_myValue);
|
|
|
}}
|
|
}}
|
|
@@ -241,7 +277,7 @@ export default observer((props: FilterProps) => {
|
|
|
BuiltInOptions={BuiltInOptions}
|
|
BuiltInOptions={BuiltInOptions}
|
|
|
showLabelKey="fullName"
|
|
showLabelKey="fullName"
|
|
|
name={1}
|
|
name={1}
|
|
|
- onChange={(v, lb) => {
|
|
|
|
|
|
|
+ onChange={(v, lb, node) => {
|
|
|
const _myValue = {
|
|
const _myValue = {
|
|
|
value: [ValueRef.current.value?.value?.[0], v.value],
|
|
value: [ValueRef.current.value?.value?.[0], v.value],
|
|
|
source: v.source,
|
|
source: v.source,
|
|
@@ -250,6 +286,17 @@ export default observer((props: FilterProps) => {
|
|
|
setValue(_myValue);
|
|
setValue(_myValue);
|
|
|
labelCache.current[2] = { ...labelCache.current[2], 1: lb };
|
|
labelCache.current[2] = { ...labelCache.current[2], 1: lb };
|
|
|
labelCache.current[3] = props.data.type;
|
|
labelCache.current[3] = props.data.type;
|
|
|
|
|
+
|
|
|
|
|
+ if (v.source === 'upper') {
|
|
|
|
|
+ if (!node.metadata) {
|
|
|
|
|
+ columnsRef.current[2] = node.column;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.splice(2, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.length = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ props.onColumns(columnsRef.current);
|
|
|
props.onLabelChange?.(labelCache.current);
|
|
props.onLabelChange?.(labelCache.current);
|
|
|
valueEventChange(_myValue);
|
|
valueEventChange(_myValue);
|
|
|
}}
|
|
}}
|
|
@@ -264,10 +311,21 @@ export default observer((props: FilterProps) => {
|
|
|
value={value}
|
|
value={value}
|
|
|
BuiltInOptions={BuiltInOptions}
|
|
BuiltInOptions={BuiltInOptions}
|
|
|
showLabelKey="fullName"
|
|
showLabelKey="fullName"
|
|
|
- onChange={(v, lb) => {
|
|
|
|
|
|
|
+ onChange={(v, lb, node) => {
|
|
|
setValue({
|
|
setValue({
|
|
|
...v,
|
|
...v,
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ if (v.source === 'upper') {
|
|
|
|
|
+ if (!node.metadata) {
|
|
|
|
|
+ columnsRef.current[1] = node.column;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.splice(1, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ columnsRef.current.length = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ props.onColumns(columnsRef.current);
|
|
|
labelCache.current[2] = { 0: lb };
|
|
labelCache.current[2] = { 0: lb };
|
|
|
labelCache.current[3] = props.data.type;
|
|
labelCache.current[3] = props.data.type;
|
|
|
props.onLabelChange?.(labelCache.current);
|
|
props.onLabelChange?.(labelCache.current);
|