wzyyy 3 tahun lalu
induk
melakukan
ddc33080cc

+ 4 - 3
src/pages/rule-engine/Scene/Save/action/ListItem/FilterCondition.tsx

@@ -95,7 +95,7 @@ export default observer((props: FilterProps) => {
 
   const convertLabelValue = (columnValue?: string) => {
     if (columnValue) {
-      console.log(columnOptionsMap, columnValue);
+      console.log('filter-convertLabelValue', columnOptionsMap, columnValue);
       const labelOptions = columnOptionsMap.get(columnValue);
       const _termTypeOptions: any[] =
         labelOptions?.termTypes?.map((tItem: any) => ({ title: tItem.name, key: tItem.id })) || [];
@@ -159,6 +159,8 @@ export default observer((props: FilterProps) => {
       time_lt_now: '距离当前时间小于_value秒',
       in: '在_value,_value2之中',
       nin: '不在_value,_value2之中',
+      like: '包含_value',
+      nlike: '不包含_value',
     };
 
     if (DoubleFilter.includes(t)) {
@@ -266,7 +268,7 @@ export default observer((props: FilterProps) => {
               ValueRef.current.termType = v;
               valueChange({
                 column: props.data!.column,
-                value: value as TermsVale,
+                value: _value as TermsVale,
                 termType: v,
               });
             }}
@@ -326,7 +328,6 @@ export default observer((props: FilterProps) => {
               BuiltInOptions={BuiltInOptions}
               showLabelKey="fullName"
               onChange={(v, lb) => {
-                console.log('valueChange4', v);
                 setValue({
                   ...v,
                 });

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

@@ -304,6 +304,7 @@ export default (props: ItemProps) => {
                 terms: [{}],
               };
               cacheValueRef.current = _data;
+              console.log('FilterCondition-add', _data);
               props.onUpdate(_data, op);
             }
           }}

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

@@ -11,7 +11,7 @@ interface ListProps {
   actions: ActionsType[];
   parallel: boolean;
   onAdd: (data: any) => void;
-  onDelete: (index: number) => void;
+  onDelete: (key: string) => void;
 }
 
 export default (props: ListProps) => {
@@ -36,7 +36,7 @@ export default (props: ListProps) => {
           parallel={props.parallel}
           options={item.options}
           onDelete={() => {
-            props.onDelete(index);
+            props.onDelete(item.key!);
           }}
           onUpdate={(data, options) => {
             props.onAdd({

+ 83 - 71
src/pages/rule-engine/Scene/Save/action/index.tsx

@@ -4,8 +4,10 @@ import { FormModel } from '@/pages/rule-engine/Scene/Save';
 import ShakeLimit from '../components/ShakeLimit';
 import './index.less';
 import { Observer } from '@formily/react';
-import { get, set } from 'lodash';
+import { get } from 'lodash';
 import type { ShakeLimitType, BranchesThen } from '../../typings';
+import { randomString } from '@/utils/util';
+import { useEffect, useState } from 'react';
 
 const { Panel } = Collapse;
 
@@ -13,9 +15,20 @@ interface ActionsProps {
   name: number;
   openShakeLimit?: boolean;
   thenOptions: BranchesThen[];
+  onAdd: (data: BranchesThen) => void;
+  onUpdate: (data: BranchesThen, type: boolean) => void;
 }
 
 export default (props: ActionsProps) => {
+  const [parallelArray, setParallelArray] = useState<BranchesThen[]>([]); // 并行行
+  const [serialArray, setSerialArray] = useState<BranchesThen[]>([]); // 串行
+
+  useEffect(() => {
+    setParallelArray(props.thenOptions.filter((item) => item.parallel));
+    setSerialArray(props.thenOptions.filter((item) => !item.parallel));
+    console.log('action-effect', props.thenOptions);
+  }, [props.thenOptions]);
+
   return (
     <div className="actions">
       <div className="actions-title">
@@ -53,42 +66,42 @@ export default (props: ActionsProps) => {
             key="1"
           >
             <div className="actions-list">
-              <Observer>
-                {() => {
-                  const parallelThens = props.thenOptions.filter((item) => !item.parallel);
-                  return (
-                    <List
-                      thenName={props.name}
-                      type="serial"
-                      parallel={false}
-                      actions={parallelThens.length ? parallelThens[0].actions : []}
-                      onAdd={(actionItem) => {
-                        const thenIndex = props.thenOptions.findIndex((item) => !item.parallel);
-                        if (thenIndex !== -1) {
-                          const indexOf = props.thenOptions[thenIndex].actions?.findIndex(
-                            (aItem) => aItem.key === actionItem.key,
-                          );
-                          if (indexOf !== -1) {
-                            props.thenOptions[thenIndex].actions.splice(indexOf, 1, actionItem);
-                          } else {
-                            props.thenOptions[thenIndex].actions.push(actionItem);
-                          }
-                        } else {
-                          props.thenOptions.push({
-                            parallel: false,
-                            actions: [actionItem],
-                          });
-                        }
-                        set(FormModel.current, ['branches', props.name, 'then'], props.thenOptions);
-                      }}
-                      onDelete={(_index) => {
-                        parallelThens[0].actions.splice(_index, 1);
-                        set(FormModel.current, ['branches', props.name, 'then'], props.thenOptions);
-                      }}
-                    />
-                  );
+              <List
+                thenName={props.name}
+                type="serial"
+                parallel={false}
+                actions={serialArray.length ? serialArray[0].actions : []}
+                onAdd={(actionItem) => {
+                  console.log('action-onAdd');
+                  if (serialArray.length) {
+                    const indexOf = serialArray[0].actions?.findIndex(
+                      (aItem) => aItem.key === actionItem.key,
+                    );
+                    if (indexOf !== -1) {
+                      serialArray[0].actions.splice(indexOf, 1, actionItem);
+                    } else {
+                      serialArray[0].actions.push(actionItem);
+                    }
+                    setSerialArray([...serialArray]);
+                    props.onUpdate(serialArray[0], false);
+                  } else {
+                    actionItem.key = randomString();
+                    props.onAdd({
+                      parallel: false,
+                      key: randomString(),
+                      actions: [actionItem],
+                    });
+                  }
                 }}
-              </Observer>
+                onDelete={(key) => {
+                  const aIndex = serialArray[0].actions?.findIndex((aItem) => aItem.key === key);
+                  if (aIndex !== -1) {
+                    serialArray[0].actions?.splice(aIndex, 1);
+                    setSerialArray([...serialArray]);
+                    props.onUpdate(serialArray[0], false);
+                  }
+                }}
+              />
             </div>
           </Panel>
           <Panel
@@ -100,42 +113,41 @@ export default (props: ActionsProps) => {
             key="2"
           >
             <div className="actions-list">
-              <Observer>
-                {() => {
-                  const parallelThens = props.thenOptions.filter((item) => item.parallel);
-                  return (
-                    <List
-                      thenName={props.name}
-                      type="parallel"
-                      parallel={true}
-                      actions={parallelThens.length ? parallelThens[0].actions : []}
-                      onAdd={(actionItem) => {
-                        const thenIndex = props.thenOptions.findIndex((item) => item.parallel);
-                        if (thenIndex !== -1) {
-                          const indexOf = props.thenOptions[thenIndex].actions?.findIndex(
-                            (aItem) => aItem.key === actionItem.key,
-                          );
-                          if (indexOf !== -1) {
-                            props.thenOptions[thenIndex].actions.splice(indexOf, 1, actionItem);
-                          } else {
-                            props.thenOptions[thenIndex].actions.push(actionItem);
-                          }
-                        } else {
-                          props.thenOptions.push({
-                            parallel: true,
-                            actions: [actionItem],
-                          });
-                        }
-                        set(FormModel.current, ['branches', props.name, 'then'], props.thenOptions);
-                      }}
-                      onDelete={(_index) => {
-                        parallelThens[0].actions.splice(_index, 1);
-                        set(FormModel.current, ['branches', props.name, 'then'], props.thenOptions);
-                      }}
-                    />
-                  );
+              <List
+                thenName={props.name}
+                type="parallel"
+                parallel={true}
+                actions={parallelArray.length ? parallelArray[0].actions : []}
+                onAdd={(actionItem) => {
+                  if (parallelArray.length) {
+                    const indexOf = parallelArray[0].actions?.findIndex(
+                      (aItem) => aItem.key === actionItem.key,
+                    );
+                    if (indexOf !== -1) {
+                      parallelArray[0].actions.splice(indexOf, 1, actionItem);
+                    } else {
+                      parallelArray[0].actions.push(actionItem);
+                    }
+                    setParallelArray([...parallelArray]);
+                    props.onUpdate(parallelArray[0], true);
+                  } else {
+                    actionItem.key = randomString();
+                    props.onAdd({
+                      parallel: true,
+                      key: randomString(),
+                      actions: [actionItem],
+                    });
+                  }
+                }}
+                onDelete={(key) => {
+                  const aIndex = parallelArray[0].actions?.findIndex((aItem) => aItem.key === key);
+                  if (aIndex !== -1) {
+                    parallelArray[0].actions?.splice(aIndex, 1);
+                    setParallelArray([...parallelArray]);
+                    props.onUpdate(serialArray[0], true);
+                  }
                 }}
-              </Observer>
+              />
             </div>
           </Panel>
         </Collapse>

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

@@ -76,6 +76,7 @@ const DropdownButton = (props: DropdownButtonProps) => {
     if (props.showLabelKey) {
       titleKey = props.showLabelKey;
     }
+    console.log('drop-tree', e.node, titleKey);
     setLabel(e.node[titleKey]);
   };
 

+ 2 - 5
src/pages/rule-engine/Scene/Save/components/Buttons/ParamsDropdown.tsx

@@ -65,7 +65,6 @@ export default (props: ParamsDropdownProps) => {
 
   const onValueChange = useCallback(
     (value: any, _label: any) => {
-      console.log('valueChange-activeKey', activeKey);
       setMyValue(value);
       setLabel(_label);
       const changeValue = {
@@ -208,10 +207,9 @@ export default (props: ParamsDropdownProps) => {
 
   const initData = useCallback(() => {
     let _value = props.value?.value;
-    if ('name' in props) {
-      _value = props.value?.value[props.name!];
+    if ('name' in props && _value) {
+      _value = props.value?.value?.[props.name!];
     }
-    console.log('initData', _value);
     setMyValue(_value);
     if (_value === undefined || _value === '') {
       setLabel('');
@@ -226,7 +224,6 @@ export default (props: ParamsDropdownProps) => {
 
   useEffect(() => {
     initData();
-    console.log('valueChange-params-effect', props.value?.source, props.value?.value);
     if (props.value?.source) {
       setActiveKey(props.value?.source);
     } else {

+ 19 - 4
src/pages/rule-engine/Scene/Save/components/TimingTrigger/index.tsx

@@ -36,8 +36,6 @@ export default (props: TimmingTriggerProps) => {
   const trigger = Form.useWatch([...name, 'trigger'], form);
   const mod = Form.useWatch([...name, 'mod'], form);
 
-  console.log('trigger', trigger, mod);
-
   const TimeTypeAfter = (
     <Form.Item noStyle name={[...props.name, 'period', 'unit']} initialValue="seconds">
       <Select
@@ -53,7 +51,23 @@ export default (props: TimmingTriggerProps) => {
   return (
     <>
       <Form.Item name={[...name, 'trigger']} initialValue="week">
-        <Radio.Group options={triggerOptions} optionType="button" buttonStyle="solid" />
+        <Radio.Group
+          options={triggerOptions}
+          optionType="button"
+          buttonStyle="solid"
+          onChange={() => {
+            form.setFields([
+              {
+                name: [...name, 'when'],
+                value: [],
+              },
+              {
+                name: [...name, 'mod'],
+                value: 'period',
+              },
+            ]);
+          }}
+        />
       </Form.Item>
       {trigger === 'cron' ? (
         <Form.Item
@@ -91,6 +105,7 @@ export default (props: TimmingTriggerProps) => {
                 },
               },
             ]}
+            initialValue={[]}
           >
             <WhenOption type={trigger} />
           </Form.Item>
@@ -141,7 +156,7 @@ export default (props: TimmingTriggerProps) => {
                 addonAfter={TimeTypeAfter}
                 style={{ maxWidth: 170 }}
                 precision={0}
-                min={0}
+                min={1}
                 max={59}
               />
             </Form.Item>

+ 1 - 1
src/pages/rule-engine/Scene/Save/components/TimingTrigger/whenOption.tsx

@@ -74,7 +74,7 @@ export default (props: TimerWhenProps) => {
               }
 
               setValue(_value.length ? [..._value] : undefined);
-              props.onChange?.(_value.length ? _value : undefined);
+              props.onChange?.(_value.length ? _value.sort() : undefined);
             }}
           >
             {item.label}

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

@@ -25,7 +25,7 @@
     width: 237px;
     //width: 100%;
     padding: 12px 16px;
-    border: 1px solid rgba(#e0e4e8, 0.6);
+    border: 1px solid #e0e4e8;
     border-radius: 2px;
     cursor: pointer;
     transition: all 0.3s;

+ 13 - 0
src/pages/rule-engine/Scene/Save/manual/index.tsx

@@ -10,6 +10,19 @@ export default observer(() => {
           <Action
             thenOptions={FormModel.current.branches ? FormModel.current.branches[0].then : []}
             name={0}
+            onAdd={(data) => {
+              if (FormModel.current.branches) {
+                FormModel.current.branches[0].then.push(data);
+              }
+            }}
+            onUpdate={(data, type) => {
+              const indexOf = FormModel.current.branches![0].then.findIndex(
+                (item) => item.parallel === type,
+              );
+              if (indexOf !== -1) {
+                FormModel.current.branches![0].then[indexOf] = data;
+              }
+            }}
           />
         )}
       </Observer>

+ 36 - 7
src/pages/rule-engine/Scene/Save/terms/branchItem.tsx

@@ -11,7 +11,7 @@ import { Store } from 'jetlinks-store';
 interface BranchesItemProps {
   name: number;
   data: ActionBranchesProps;
-  isFrist: boolean;
+  isFirst: boolean;
   paramsOptions: any[];
   onDelete: () => void;
 }
@@ -71,11 +71,11 @@ export default observer((props: BranchesItemProps) => {
 
   return (
     <div className="actions-terms-warp">
-      <div className="actions-terms-title">{props.isFrist ? '当' : '否则'}</div>
+      <div className="actions-terms-title">{props.isFirst ? '当' : '否则'}</div>
       <div
-        className={classNames('actions-terms-options', { border: !props.isFrist, error: error })}
+        className={classNames('actions-terms-options', { border: !props.isFirst, error: error })}
       >
-        {!props.isFrist && props.data.when.length ? (
+        {!props.isFirst && props.data.when.length ? (
           <div className={classNames('terms-params-delete denger show')} onClick={props.onDelete}>
             <DeleteOutlined />
           </div>
@@ -115,7 +115,7 @@ export default observer((props: BranchesItemProps) => {
                     fontSize: 14,
                     color: '#2F54EB',
                     cursor: 'pointer',
-                    padding: props.isFrist ? '16px 0' : 0,
+                    padding: props.isFirst ? '16px 0' : 0,
                   }}
                   onClick={() => addWhen(props.name)}
                 >
@@ -126,8 +126,37 @@ export default observer((props: BranchesItemProps) => {
             }
           </Observer>
         </div>
-        <div className="actions-branchs">
-          <Actions openShakeLimit={true} name={props.name} thenOptions={props.data.then} />
+        <div className="actions-branches">
+          <Observer>
+            {() => {
+              console.log('action-onAdd', FormModel.current.branches?.[props.name].then);
+              return (
+                <Actions
+                  openShakeLimit={true}
+                  name={props.name}
+                  thenOptions={props.data.then}
+                  onAdd={(data) => {
+                    console.log('action-onAdd', data, FormModel.current.branches);
+                    if (FormModel.current.branches) {
+                      FormModel.current.branches[props.name].then = [
+                        ...FormModel.current.branches[props.name].then,
+                        data,
+                      ];
+                      console.log('action-onAdd2', FormModel.current.branches[props.name].then);
+                    }
+                  }}
+                  onUpdate={(data, type) => {
+                    const indexOf = FormModel.current.branches![props.name].then.findIndex(
+                      (item) => item.parallel === type,
+                    );
+                    if (indexOf !== -1) {
+                      FormModel.current.branches![props.name].then[indexOf] = data;
+                    }
+                  }}
+                />
+              );
+            }}
+          </Observer>
         </div>
       </div>
     </div>

+ 16 - 4
src/pages/rule-engine/Scene/Save/terms/index.tsx

@@ -22,7 +22,6 @@ export default observer(() => {
   const [open, setOpen] = useState(true);
 
   useEffect(() => {
-    console.log('terms-effect', FormModel.current.branches);
     if (FormModel.current.branches && FormModel.current.branches.length === 1) {
       setOpen(false);
     }
@@ -35,7 +34,6 @@ export default observer(() => {
   };
 
   const openChange = (checked: boolean) => {
-    console.log('terms-effect-change');
     setOpen(checked);
     if (checked) {
       FormModel.current.branches = cloneDeep([
@@ -105,12 +103,13 @@ export default observer(() => {
         <Observer>
           {() =>
             FormModel.current.branches?.map((item, index) => {
-              const isFrist = index === 0;
+              const isFirst = index === 0;
               return (
                 <BranchItem
                   data={item}
-                  isFrist={isFrist}
+                  isFirst={isFirst}
                   name={index}
+                  key={item.key}
                   paramsOptions={TermsModel.columnOptions}
                   onDelete={() => {
                     FormModel.current.branches?.splice(index, 1);
@@ -126,6 +125,19 @@ export default observer(() => {
           openShakeLimit={true}
           name={0}
           thenOptions={FormModel.current.branches ? FormModel.current.branches[0].then : []}
+          onAdd={(data) => {
+            if (FormModel.current.branches) {
+              FormModel.current.branches[0].then.push(data);
+            }
+          }}
+          onUpdate={(data, type) => {
+            const indexOf = FormModel.current.branches![0].then.findIndex(
+              (item) => item.parallel === type,
+            );
+            if (indexOf !== -1) {
+              FormModel.current.branches![0].then[indexOf] = data;
+            }
+          }}
         />
       )}
     </div>

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

@@ -146,6 +146,8 @@ const ParamsItem = observer((props: ParamsItemProps) => {
         time_lt_now: '距离当前时间小于_value秒',
         in: '在_value,_value2之中',
         nin: '不在_value,_value2之中',
+        like: '包含_value',
+        nlike: '不包含_value',
       };
       const typeKey = {
         and: '并且',

+ 13 - 0
src/pages/rule-engine/Scene/Save/timer/index.tsx

@@ -57,6 +57,19 @@ export default observer(() => {
             <Action
               thenOptions={FormModel.current.branches ? FormModel.current.branches[0].then : []}
               name={0}
+              onAdd={(data) => {
+                if (FormModel.current.branches) {
+                  FormModel.current.branches[0].then.push(data);
+                }
+              }}
+              onUpdate={(data, type) => {
+                const indexOf = FormModel.current.branches![0].then.findIndex(
+                  (item) => item.parallel === type,
+                );
+                if (indexOf !== -1) {
+                  FormModel.current.branches![0].then[indexOf] = data;
+                }
+              }}
             />
           )}
         </Observer>