xieyonghong 3 rokov pred
rodič
commit
e51fb3b50f

+ 58 - 10
src/pages/rule-engine/Scene/Save/action/device/ConditionalFiltering.tsx

@@ -12,6 +12,12 @@ interface ConditionalFilteringProps {
   propertiesId?: string;
 }
 
+const getFormValueByName = (name: string[], values: any) => {
+  return name.reduce((prev, next) => {
+    return prev ? prev[next] : values[next];
+  }, '');
+};
+
 export default (props: ConditionalFilteringProps) => {
   const [builtInList, setBuiltInList] = useState<any[]>([]);
   const [source, setSource] = useState<any>('fixed');
@@ -60,6 +66,22 @@ export default (props: ConditionalFilteringProps) => {
     );
   };
 
+  const getTreeItem = (data: any, id: string): any => {
+    let _item = undefined;
+    data.some((item: any) => {
+      if (item.id === id) {
+        _item = item;
+        return true;
+      }
+      if (item.children) {
+        _item = getTreeItem(item.children, id);
+        return !!_item;
+      }
+      return false;
+    });
+    return _item;
+  };
+
   const handleTreeData = (data: any): any[] => {
     if (data.length > 0) {
       return data.map((item: any) => {
@@ -180,16 +202,42 @@ export default (props: ConditionalFilteringProps) => {
           />
         </Form.Item>
       </Col>
-      <Col span={3}>
-        <Form.Item name={[props.name, 'terms', 0, 'termType']}>
-          <Select
-            style={{ width: '100%' }}
-            options={termTypes}
-            fieldNames={{ value: 'id', label: 'name' }}
-            placeholder={'操作符'}
-          />
-        </Form.Item>
-      </Col>
+      <Form.Item
+        noStyle
+        dependencies={[props.name, 'terms', 0, 'column']}
+        shouldUpdate={(prevValues, curValues) => {
+          console.log(['actions', `${props.name}`, 'terms', '0', 'column']);
+          const pValue = getFormValueByName(
+            ['actions', `${props.name}`, 'terms', '0', 'column'],
+            prevValues,
+          );
+          const cValue = getFormValueByName(
+            ['actions', `${props.name}`, 'terms', '0', 'column'],
+            curValues,
+          );
+          return pValue !== cValue;
+        }}
+      >
+        {({ getFieldValue }) => {
+          const column = getFieldValue(['actions', `${props.name}`, 'terms', '0', 'column']);
+          const columnItem = getTreeItem(builtInList, column);
+          return (
+            columnItem?.type !== 'boolean' && (
+              <Col span={3}>
+                <Form.Item name={[props.name, 'terms', 0, 'termType']}>
+                  <Select
+                    style={{ width: '100%' }}
+                    options={termTypes}
+                    fieldNames={{ value: 'id', label: 'name' }}
+                    placeholder={'操作符'}
+                  />
+                </Form.Item>
+              </Col>
+            )
+          );
+        }}
+      </Form.Item>
+
       <Col span={8}>
         <Form.Item noStyle>
           <ItemGroup>

+ 26 - 28
src/pages/rule-engine/Scene/Save/action/device/functionCall.tsx

@@ -25,28 +25,26 @@ export default (props: FunctionCallProps) => {
   const formRef = useRef<ProFormInstance<any>>();
 
   useEffect(() => {
-    setEditableRowKeys(props.functionData.map((d) => d.id));
-    console.log(formRef.current, props.functionData);
-    formRef.current?.setFieldsValue({
-      table: props.functionData,
-    });
-  }, [props.functionData]);
-
-  useEffect(() => {
-    if (props.functionData && props.functionData.length && props.value) {
-      formRef.current?.setFieldsValue({
-        table: props.functionData.map((item: any) => {
-          const oldValue = props.value.find((oldItem: any) => oldItem.name === item.id);
-          if (oldValue) {
-            return {
-              ...item,
-              value: oldValue.value,
-            };
-          }
-          console.log(item);
-          return item;
-        }),
-      });
+    if (props.functionData && props.functionData.length) {
+      setEditableRowKeys(props.functionData.map((d) => d.id));
+      if (props.value) {
+        formRef.current?.setFieldsValue({
+          table: props.functionData.map((item: any) => {
+            const oldValue = props.value.find((oldItem: any) => oldItem.name === item.id);
+            if (oldValue) {
+              return {
+                ...item,
+                value: oldValue.value,
+              };
+            }
+            return item;
+          }),
+        });
+      } else {
+        formRef.current?.setFieldsValue({
+          table: props.functionData,
+        });
+      }
     } else {
       formRef.current?.setFieldsValue({
         table: [],
@@ -60,7 +58,7 @@ export default (props: FunctionCallProps) => {
     }
   }, [props.productId]);
 
-  const getItemNode = (record: any) => {
+  const getItemNode = (record: any, config: any) => {
     const type = record.type;
     const name = record.name;
 
@@ -104,6 +102,7 @@ export default (props: FunctionCallProps) => {
             {
               // @ts-ignore
               <DatePickerFormat
+                {...config}
                 value={record.value}
                 format={record.format || 'YYYY-MM-DD HH:mm:ss'}
                 style={{ width: '100%' }}
@@ -134,12 +133,12 @@ export default (props: FunctionCallProps) => {
       dataIndex: 'value',
       align: 'center',
       width: 260,
-      renderFormItem: (_, row: any) => {
-        return getItemNode(row.record);
+      renderFormItem: (_, row) => {
+        return getItemNode(row.record, row);
       },
     },
   ];
-
+  console.log(editableKeys);
   return (
     <ProForm<{ table: FunctionTableDataType[] }>
       formRef={formRef}
@@ -159,9 +158,8 @@ export default (props: FunctionCallProps) => {
     >
       <EditableProTable
         rowKey="id"
-        name="table"
+        name={'table'}
         columns={columns}
-        recordCreatorProps={false}
         size={'small'}
         editable={{
           type: 'multiple',

+ 1 - 1
src/pages/rule-engine/Scene/Save/components/DatePickerFormat/index.tsx

@@ -8,7 +8,7 @@ interface DatePickerFormat extends Omit<DatePickerProps, 'onChange'> {
 
 export default (props: DatePickerFormat) => {
   const { value, onChange, ...extraProps } = props;
-
+  console.log(props);
   return (
     <>
       {

+ 6 - 1
src/pages/rule-engine/Scene/Save/trigger/index.tsx

@@ -11,6 +11,7 @@ import { observer } from '@formily/reactive-react';
 import OrgTreeSelect from './OrgTreeSelect';
 import { FormModel } from '../index';
 import AllDevice from '@/pages/rule-engine/Scene/Save/action/device/AllDevice';
+import encodeQuery from '@/utils/encodeQuery';
 
 interface TriggerProps {
   value?: any;
@@ -107,7 +108,11 @@ export default observer((props: TriggerProps) => {
   }, [functions, FormModel]);
 
   const getProducts = async () => {
-    const resp = await getProductList({ paging: false });
+    const params = encodeQuery({
+      paging: false,
+      sorts: { createTime: 'desc' },
+    });
+    const resp = await getProductList(params);
     if (resp && resp.status === 200) {
       setProductList(resp.result);
       if (FormModel.trigger && FormModel.trigger.device) {