Преглед изворни кода

fix(triggerTerm): triggerTerm

lind пре 3 година
родитељ
комит
43bb7b5623

+ 30 - 9
src/components/FTermArrayCards/index.tsx

@@ -1,5 +1,5 @@
 import React from 'react';
-import { Card, Empty, Select } from 'antd';
+import { Card, Empty } from 'antd';
 import { CardProps } from 'antd/lib/card';
 import { ArrayField } from '@formily/core';
 import { observer, RecursionField, useField, useFieldSchema } from '@formily/react';
@@ -95,14 +95,35 @@ export const FTermArrayCards: ComposedArrayCards = observer((props) => {
         ArrayBase.Item && (
           <ArrayBase.Item key={index} index={index} record={item}>
             {index > 0 && (
-              <div style={{ margin: 10, display: 'flex', justifyContent: 'center' }}>
-                <Select
-                  value="or"
-                  style={{ width: '200px' }}
-                  options={[
-                    { label: '或者', value: 'or' },
-                    { label: '并且', value: 'and' },
-                  ]}
+              <div style={{ marginTop: 20, display: 'flex', justifyContent: 'center' }}>
+                <RecursionField
+                  schema={
+                    {
+                      type: 'object',
+                      properties: {
+                        termType: {
+                          'x-decorator': 'FormItem',
+                          'x-component': 'Select',
+                          'x-component-props': {
+                            style: {
+                              width: 100,
+                            },
+                          },
+                          default: 'and',
+                          enum: [
+                            { label: '并且', value: 'and' },
+                            { label: '或者', value: 'or' },
+                          ],
+                        },
+                      },
+                    } as any
+                  }
+                  name={index}
+                  filterProperties={(schema2) => {
+                    if (isIndexComponent(schema2)) return false;
+                    if (isOperationComponent(schema2)) return false;
+                    return true;
+                  }}
                 />
               </div>
             )}

+ 18 - 3
src/components/FTermTypeSelect/index.tsx

@@ -1,12 +1,27 @@
 import { ArrayItems, Select } from '@formily/antd';
 
-const FTermTypeSelect = () => {
+interface Props {
+  value: any;
+  onChange: (value: string) => void;
+}
+
+const FTermTypeSelect = (props: Props) => {
   const index = ArrayItems.useIndex!();
   return index > 0 ? (
-    <div style={{ width: '100%', marginBottom: 15, display: 'flex', justifyContent: 'center' }}>
+    <div
+      style={{
+        width: '100%',
+        marginTop: -20,
+        marginBottom: 15,
+        display: 'flex',
+        justifyContent: 'center',
+      }}
+    >
       <Select
+        onChange={(value) => props.onChange(value)}
+        value={props.value}
         style={{ width: '200px' }}
-        value="or"
+        defaultValue={'or'}
         options={[
           { label: '并且', value: 'and' },
           { label: '或者', value: 'or' },

+ 49 - 16
src/pages/rule-engine/Scene/TriggerTerm/index.tsx

@@ -30,7 +30,6 @@ import { useAsyncDataSource } from '@/utils/util';
 import { Store } from 'jetlinks-store';
 import { treeFilter } from '@/utils/tree';
 import FInputGroup from '@/components/FInputGroup';
-import { Button } from 'antd';
 
 const service = new Service('scene');
 
@@ -50,7 +49,10 @@ const TriggerTerm = (props: Props, ref: any) => {
       const handleName = (_data: any): any => (
         <Space>
           {_data.name}
-          <div style={{ color: 'grey', marginLeft: '5px' }}>{_data.description}</div>
+          <div style={{ color: 'grey', marginLeft: '5px' }}>{_data.fullName}</div>
+          {_data.description && (
+            <div style={{ color: 'grey', marginLeft: '5px' }}>({_data.description})</div>
+          )}
         </Space>
       );
       const handleChildrenName = (_data: any[]): any[] => {
@@ -71,7 +73,7 @@ const TriggerTerm = (props: Props, ref: any) => {
           return [];
         }
       };
-      return data.map((item: any) => {
+      return data?.map((item: any) => {
         const disabled = item.children?.length > 0;
         return {
           column: item.column,
@@ -122,8 +124,11 @@ const TriggerTerm = (props: Props, ref: any) => {
                 label: item.name,
                 value: item.id,
               }));
+              if (target?.termTypes?.length > 0) {
+                state.value = 'eq';
+              }
             });
-            form1.setFieldState(field.query('.source'), (state) => {
+            form1.setFieldState(field.query('.value.source'), (state) => {
               state.dataSource =
                 target && target.metrics && target.metrics.length > 0
                   ? [
@@ -131,11 +136,13 @@ const TriggerTerm = (props: Props, ref: any) => {
                       { label: '指标', value: 'metrics' },
                     ]
                   : [{ label: '手动输入', value: 'manual' }];
+              state.value = 'manual';
             });
           });
-          onFieldReact('trigger.*.terms.*.source', (field, form1) => {
-            const params = field.query('.column').value();
-            const value = field.query('.value');
+          onFieldReact('trigger.*.terms.*.value.source', (field, form1) => {
+            console.log(field, 'field');
+            const params = field.query('..column').value();
+
             // 找到选中的
             const _data = Store.get('trigger-parse-term');
             if (!_data) return;
@@ -148,6 +155,8 @@ const TriggerTerm = (props: Props, ref: any) => {
                 : treeValue[0];
 
             const source = (field as Field).value;
+            const value = field.query(source === 'manual' ? '.value' : '.metric');
+            console.log(value, source, '指标测试', target);
             if (target) {
               if (source === 'manual') {
                 // 手动输入
@@ -273,8 +282,8 @@ const TriggerTerm = (props: Props, ref: any) => {
                           placeholder: '操作符',
                         },
                       },
-                      inputGroup: {
-                        type: 'void',
+                      value: {
+                        type: 'object',
                         'x-component': 'FInputGroup',
                         'x-decorator': 'FormItem',
                         'x-decorator-props': {
@@ -309,6 +318,37 @@ const TriggerTerm = (props: Props, ref: any) => {
                                 width: 'calc(100% - 110px)',
                               },
                             },
+                            'x-reactions': {
+                              dependencies: ['.source'],
+                              fulfill: {
+                                state: {
+                                  visible: '{{$deps[0]==="manual"}}',
+                                },
+                              },
+                            },
+                          },
+                          metric: {
+                            type: 'string',
+                            'x-component': 'Select',
+                            'x-decorator': 'FormItem',
+                            'x-component-props': {
+                              style: {
+                                width: '100%',
+                              },
+                            },
+                            'x-decorator-props': {
+                              style: {
+                                width: 'calc(100% - 110px)',
+                              },
+                            },
+                            'x-reactions': {
+                              dependencies: ['.source'],
+                              fulfill: {
+                                state: {
+                                  visible: '{{$deps[0]==="metrics"}}',
+                                },
+                              },
+                            },
                           },
                         },
                       },
@@ -351,13 +391,6 @@ const TriggerTerm = (props: Props, ref: any) => {
   return (
     <Form form={form} layout="vertical" className={styles.form}>
       <SchemaField schema={schema} scope={{ useAsyncDataSource, getParseTerm }} />
-      <Button
-        onClick={async () => {
-          console.log(await form.submit(), '保存');
-        }}
-      >
-        保存
-      </Button>
     </Form>
   );
 };