Browse Source

fix: bug#9080、8721、9045

xieyonghong 3 năm trước cách đây
mục cha
commit
a397183592

+ 23 - 13
src/pages/rule-engine/Scene/Save/action/ListItem/FilterCondition.tsx

@@ -13,7 +13,8 @@ interface FilterProps {
   action?: number;
   data: TermsType;
   isLast: boolean;
-  onChange: (value: TermsType) => void;
+  onChange?: (value: TermsType | any) => void;
+  onValueChange: (value: TermsType) => void;
   onLabelChange: (lb: any[]) => void;
   options: any[];
   label?: any[];
@@ -55,7 +56,7 @@ export default observer((props: FilterProps) => {
 
   const valueChange = useCallback(
     (_value: any) => {
-      props.onChange?.({ ..._value });
+      props.onValueChange?.({ ..._value });
     },
     [column, termType, value],
   );
@@ -71,17 +72,26 @@ export default observer((props: FilterProps) => {
     [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);
+        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[] => {
     if (data.length > 0) {

+ 6 - 3
src/pages/rule-engine/Scene/Save/action/ListItem/FilterGroup.tsx

@@ -57,6 +57,9 @@ export default observer((props: TermsProps) => {
                     {
                       validator(_, v) {
                         if (v) {
+                          if (!Object.keys(v).length) {
+                            return Promise.reject(new Error('该数据已发生变更,请重新配置'));
+                          }
                           if (!v.column) {
                             return Promise.reject(new Error('请选择参数'));
                           }
@@ -116,12 +119,12 @@ export default observer((props: TermsProps) => {
                         terms: terms,
                       });
                     }}
-                    onChange={(data) => {
+                    onValueChange={(data) => {
                       terms[index] = {
-                        ...terms[index],
+                        ...item,
                         ...data,
                       };
-
+                      debugger;
                       props.onValueChange({
                         ...props.data,
                         terms: terms,

+ 9 - 8
src/pages/rule-engine/Scene/Save/action/ListItem/Item.tsx

@@ -333,6 +333,7 @@ export default (props: ItemProps) => {
   useEffect(() => {
     cacheValueRef.current = props.data;
     setThenTerms(props.data.terms);
+    console.log('optionsRef.current-change', props.data);
   }, [props.data]);
 
   useEffect(() => {
@@ -381,7 +382,7 @@ export default (props: ItemProps) => {
               actionColumns={props.options?.otherColumns}
               onColumnsChange={(columns) => {
                 optionsRef.current['columns'] = columns;
-                props.onUpdate(props.data, optionsRef.current);
+                props.onUpdate(cacheValueRef.current, optionsRef.current);
               }}
               onAddGroup={() => {
                 const newThenTerms = [...thenTerms];
@@ -398,15 +399,15 @@ export default (props: ItemProps) => {
                     },
                   ],
                 });
-                const _data = props.data;
+                const _data = cacheValueRef.current;
                 set(_data, 'terms', newThenTerms);
                 props.onUpdate(_data, optionsRef.current);
               }}
               onValueChange={(termsData) => {
-                const _data = props.data;
-                console.log('update-onValueChange', termsData, optionsRef.current);
+                const _data = cacheValueRef.current;
                 set(_data, ['terms', index], termsData);
                 // cacheValueRef.current = _data;
+                console.log('optionsRef.current', _data, cacheValueRef.current);
                 props.onUpdate(_data, {
                   ...optionsRef.current,
                 });
@@ -415,14 +416,14 @@ export default (props: ItemProps) => {
                 const newLabel: any[] = props.options?.terms || [];
                 newLabel.splice(index, 1, lb);
                 optionsRef.current['terms'] = newLabel;
-                props.onUpdate(props.data, optionsRef.current);
+                console.log('optionsRef.current2', props.data);
+                props.onUpdate(cacheValueRef.current, optionsRef.current);
               }}
               onDelete={() => {
                 const _data = thenTerms.filter((a) => a.key !== termsItem.key);
-                console.log(_data, thenTerms, termsItem);
                 props.onUpdate(
                   {
-                    ...props.data,
+                    ...cacheValueRef.current,
                     terms: _data,
                   },
                   optionsRef.current,
@@ -435,7 +436,7 @@ export default (props: ItemProps) => {
             className="filter-add-button"
             onClick={() => {
               getParams();
-              let _data = props.data;
+              let _data = cacheValueRef.current;
               optionsRef.current['terms'] = [];
               if (!_data.terms) {
                 _data = {

+ 1 - 2
src/pages/rule-engine/Scene/Save/action/ListItem/List.tsx

@@ -43,11 +43,9 @@ export default (props: ListProps) => {
               }}
               onUpdate={(data, options) => {
                 props.onAdd({
-                  ...item,
                   ...data,
                   options,
                 });
-                console.log('update-options', options);
                 setVisible(false);
               }}
             />
@@ -82,6 +80,7 @@ export default (props: ListProps) => {
               key: data.key,
               options,
             };
+            console.log('addModel', item);
             props.onAdd(item);
             setVisible(false);
           }}

+ 8 - 5
src/pages/rule-engine/Scene/Save/action/ListItem/index.less

@@ -13,7 +13,8 @@
 
   .filter-add-button {
     display: inline-block;
-    margin-bottom: 24px;
+    margin-bottom: 16px;
+    margin-left: 8px;
     color: #2f54eb;
     cursor: pointer;
   }
@@ -105,7 +106,7 @@
     position: relative;
     display: flex;
     padding: 4px;
-    border: 1px dashed rgba(0, 0, 0, 0.3);
+    border: 1px solid rgba(#000, 0.1);
     border-radius: 2px;
     transition: border 0.3s;
 
@@ -148,16 +149,18 @@
 
 .actions-item-filter-warp {
   display: flex;
+  margin-bottom: 24px;
   padding-top: 10px;
   overflow-x: auto;
   overflow-y: visible;
+  border: 1px dashed #999;
+  border-radius: 2px;
   row-gap: 16px;
 
   .terms-params {
     // display: inline-block;
     display: flex;
     flex-shrink: 0;
-    margin-bottom: 24px;
 
     // &:not(:first-child) {
     //   margin-bottom: 16px;
@@ -165,7 +168,7 @@
 
     .terms-params-warp {
       display: flex;
-      align-items: center;
+      align-items: baseline;
     }
 
     .terms-params-content {
@@ -174,7 +177,7 @@
       // flex-wrap: wrap;
       padding: 8px;
       padding-bottom: 0;
-      background-color: #fafafa;
+      background-color: #fff;
       row-gap: 16px;
 
       .terms-params-item {

+ 1 - 0
src/pages/rule-engine/Scene/Save/action/index.tsx

@@ -90,6 +90,7 @@ export default (props: ActionsProps) => {
                 parallel={false}
                 actions={serialArray.length ? serialArray[0].actions : []}
                 onAdd={(actionItem) => {
+                  console.log('addModel', serialArray);
                   if (serialArray.length) {
                     const indexOf = serialArray[0].actions?.findIndex(
                       (aItem) => aItem.key === actionItem.key,

+ 0 - 5
src/pages/rule-engine/Scene/Save/components/Buttons/Dropdown.tsx

@@ -22,7 +22,6 @@ interface DropdownButtonProps {
   type: 'param' | 'termType' | 'value' | 'type';
   fieldNames?: any;
   showLabelKey?: string;
-  onVailChange?: (vail: boolean) => void;
 }
 
 const TypeStyle = {
@@ -46,14 +45,11 @@ const DropdownButton = (props: DropdownButtonProps) => {
     (key?: string) => {
       if (key && paramOptions.length) {
         const labelOptions = valueOptions.get(key);
-        console.log('dropdown', key, labelOptions);
         if (labelOptions) {
           const nameKey = props.showLabelKey || 'title';
           setLabel(labelOptions[nameKey]);
-          props.onVailChange?.(true);
         } else {
           setLabel(key);
-          props.onVailChange?.(false);
         }
       } else {
         setLabel(key!);
@@ -145,7 +141,6 @@ const DropdownButton = (props: DropdownButtonProps) => {
       <div
         className={classNames(styles['dropdown-button'], props.className, typeClassName)}
         onClick={() => {
-          console.log(props.options);
           if (props.options.length === 0 && props.type !== 'termType') {
             onlyMessage('请先配置设备触发规则', 'warning');
           }

+ 1 - 6
src/pages/rule-engine/Scene/Save/terms/branchItem.tsx

@@ -9,7 +9,6 @@ import classNames from 'classnames';
 import { set } from 'lodash';
 import { Store } from 'jetlinks-store';
 import { Form, FormInstance, Popconfirm } from 'antd';
-import { BranchesThen } from '@/pages/rule-engine/Scene/typings';
 
 interface BranchesItemProps {
   name: number;
@@ -24,7 +23,6 @@ interface BranchesItemProps {
 
 export default observer((props: BranchesItemProps) => {
   const [when, setWhen] = useState<TermsType[]>([]);
-  const [actions, setActions] = useState<BranchesThen[]>([]);
   const [error, setError] = useState(false);
   const [deleteVisible, setDeleteVisible] = useState(false);
 
@@ -40,9 +38,6 @@ export default observer((props: BranchesItemProps) => {
     if (props.data.when) {
       setWhen(props.data.when);
     }
-    if (props.data.then) {
-      setActions(props.data.then);
-    }
   }, [props.data]);
 
   const addWhen = (index: number) => {
@@ -162,7 +157,7 @@ export default observer((props: BranchesItemProps) => {
                   <Actions
                     openShakeLimit={true}
                     name={props.name}
-                    thenOptions={actions}
+                    thenOptions={FormModel.current.branches?.[props.name].then || []}
                     onAdd={(data) => {
                       if (FormModel.current.branches && data) {
                         const newThen = [...FormModel.current.branches[props.name].then, data];

+ 1 - 1
src/pages/rule-engine/Scene/Save/terms/index.less

@@ -104,7 +104,7 @@
 
   .terms-params-warp {
     display: flex;
-    align-items: center;
+    align-items: baseline;
   }
 
   .terms-params-content {

+ 2 - 4
src/pages/rule-engine/Scene/Save/terms/paramsItem.tsx

@@ -20,7 +20,7 @@ interface ParamsItemProps {
   isDelete: boolean;
   options: any[];
   onValueChange?: (value: TermsType) => void;
-  onChange?: (value: TermsType) => void;
+  onChange?: (value: TermsType | any) => void;
   onLabelChange?: (label: string[]) => void;
   label?: any[];
   onAdd: () => void;
@@ -159,6 +159,7 @@ const ParamsItem = observer((props: ParamsItemProps) => {
             setMetricsOptions(_metrics);
           }
         } else {
+          props.onChange?.({});
           setTtOptions([]);
           setValueType('');
         }
@@ -210,9 +211,6 @@ const ParamsItem = observer((props: ParamsItemProps) => {
           }}
           showLabelKey="fullName"
           isTree={true}
-          onVailChange={(v) => {
-            console.log('onVailChange', v);
-          }}
           onChange={(_value, item) => {
             setValue({
               value: undefined,