xieyonghong hace 3 años
padre
commit
a727188001

+ 21 - 31
src/components/ProTableCard/CardItems/Scene/index.tsx

@@ -197,50 +197,40 @@ const notifyRender = (data: ActionsType | undefined) => {
 
 const deviceRender = (data: ActionsType | undefined) => {
   switch (data?.device?.selector) {
-    case 'relation':
+    case 'fixed':
       return (
         <div>
-          {data?.options?.type || ''}与
-          <span className={styles['notify-text-highlight']}>{data?.options?.deviceName || ''}</span>
-          具有相同
-          <span className={styles['notify-text-highlight']}>
-            {data?.options?.relationName || ''}
-          </span>
-          的
-          <span className={styles['notify-text-highlight']}>
-            {data?.options?.productName || ''}
-          </span>
-          设备的
-          <span className={styles['notify-text-highlight']}>
-            {data?.options?.propertyName || data?.options?.functionName || ''}
-          </span>
+          {data?.options?.type}
+          <span className={styles['notify-text-highlight']}>{data?.options?.name}</span>
+          {data?.options?.properties}
         </div>
       );
     case 'tag':
       return (
         <div>
-          {data?.options?.type || ''}
-          <span className={styles['notify-text-highlight']}>{data?.options?.deviceName || ''}</span>
-          为
-          <span className={styles['notify-text-highlight']}>
-            {data?.options?.productName || ''}
-          </span>
-          <span className={styles['notify-text-highlight']}>
-            {data?.options?.propertyName || data?.options?.functionName || ''}
-          </span>
+          {data?.options?.type}
+          {data.options?.taglist.map((item: any) => (
+            <span className={styles['notify-text-highlight']}>
+              {item.type}
+              {item.name}
+              {item.value}
+            </span>
+          ))}
+          {data?.options?.productName}
+          {data?.options?.properties}
         </div>
       );
-    default:
+    case 'relation':
       return (
         <div>
-          {/*{data?.options?.type || ''}*/}
-          {/*<span className={styles['notify-text-highlight']}>{data?.options?.deviceName || ''}</span>*/}
-          {/*<span className={styles['notify-text-highlight']}>*/}
-          {/*  {data?.options?.propertyName || data?.options?.functionName || ''}*/}
-          {/*</span>*/}
-          打开空调动作1执行结果=成功并且 湿度24
+          {data?.options?.type}与
+          <span className={styles['notify-text-highlight']}>{data?.options?.name}</span>具有相同
+          {data?.options?.relationName}的{data?.options?.productName}设备的
+          {data?.options?.properties}
         </div>
       );
+    default:
+      return null;
   }
 };
 

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

@@ -48,12 +48,12 @@ export default (props: ItemProps) => {
     setOp(props.options);
   }, [props.options]);
 
-  const notifyRender = (data: ActionsType | undefined) => {
+  const notifyRender = (data: ActionsType | undefined, options: any) => {
     switch (data?.notify?.notifyType) {
       case 'dingTalk':
         return (
           <div>
-            向<span>{data?.options?.notifierName || data?.notify?.notifierId}</span>
+            向<span>{options?.notifierName || data?.notify?.notifierId}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -61,16 +61,16 @@ export default (props: ItemProps) => {
             </span>
             发送
             <span className={'notify-text-highlight'}>
-              {data?.options?.templateName || data?.notify?.templateId}
+              {options?.templateName || data?.notify?.templateId}
             </span>
           </div>
         );
       case 'weixin':
         return (
           <div>
-            向<span className={'notify-text-highlight'}>{data?.options?.sendTo || ''}</span>
-            <span className={'notify-text-highlight'}>{data?.options?.orgName || ''}</span>
-            <span className={'notify-text-highlight'}>{data?.options?.tagName || ''}</span>
+            向<span className={'notify-text-highlight'}>{options?.sendTo || ''}</span>
+            <span className={'notify-text-highlight'}>{options?.orgName || ''}</span>
+            <span className={'notify-text-highlight'}>{options?.tagName || ''}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -78,14 +78,14 @@ export default (props: ItemProps) => {
             </span>
             发送
             <span className={'notify-text-highlight'}>
-              {data?.options?.templateName || data?.notify?.templateId}
+              {options?.templateName || data?.notify?.templateId}
             </span>
           </div>
         );
       case 'email':
         return (
           <div>
-            向<span className={'notify-text-highlight'}>{data?.options?.sendTo || ''}</span>
+            向<span className={'notify-text-highlight'}>{options?.sendTo || ''}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -93,14 +93,14 @@ export default (props: ItemProps) => {
             </span>
             发送
             <span className={'notify-text-highlight'}>
-              {data?.options?.templateName || data?.notify?.templateId}
+              {options?.templateName || data?.notify?.templateId}
             </span>
           </div>
         );
       case 'voice':
         return (
           <div>
-            向<span className={'notify-text-highlight'}>{data?.options?.calledNumber || ''}</span>
+            向<span className={'notify-text-highlight'}>{options?.calledNumber || ''}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -108,14 +108,14 @@ export default (props: ItemProps) => {
             </span>
             发送
             <span className={'notify-text-highlight'}>
-              {data?.options?.templateName || data?.notify?.templateId}
+              {options?.templateName || data?.notify?.templateId}
             </span>
           </div>
         );
       case 'sms':
         return (
           <div>
-            向<span className={'notify-text-highlight'}>{data?.options?.sendTo || ''}</span>
+            向<span className={'notify-text-highlight'}>{options?.sendTo || ''}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -123,7 +123,7 @@ export default (props: ItemProps) => {
             </span>
             发送
             <span className={'notify-text-highlight'}>
-              {data?.options?.templateName || data?.notify?.templateId}
+              {options?.templateName || data?.notify?.templateId}
             </span>
           </div>
         );
@@ -136,7 +136,7 @@ export default (props: ItemProps) => {
               webhook
             </span>
             发送
-            <span>{data?.options?.templateName || data?.notify?.templateId}</span>
+            <span>{options?.templateName || data?.notify?.templateId}</span>
           </div>
         );
       default:
@@ -223,7 +223,7 @@ export default (props: ItemProps) => {
             setVisible(true);
           }}
         >
-          {notifyRender(props?.data)}
+          {notifyRender(props?.data, props?.options)}
         </div>
       );
     } else if (props?.data?.executor === 'delay') {

+ 9 - 2
src/pages/rule-engine/Scene/Save/action/Modal/add.tsx

@@ -64,9 +64,16 @@ export default (props: Props) => {
         return (
           <Notify
             value={props.data?.notify || {}}
-            save={(data: any) => {
+            options={props.data?.options || {}}
+            save={(data: any, option: any) => {
               setActionType('');
-              props.save(data);
+              props.save(
+                {
+                  ...data,
+                  key: props.data.key || `notify_${new Date().getTime()}`,
+                },
+                option,
+              );
             }}
             name={props.name}
             cancel={() => {

+ 29 - 16
src/pages/rule-engine/Scene/Save/action/notify/VariableDefinitions.tsx

@@ -10,6 +10,7 @@ import { forwardRef, useCallback, useImperativeHandle } from 'react';
 
 interface Props {
   name: number;
+  value?: any;
 }
 
 export default forwardRef((props: Props, ref) => {
@@ -117,14 +118,17 @@ export default forwardRef((props: Props, ref) => {
 
   const saveBtn = () => {
     return new Promise(async (resolve) => {
-      const formData = await form.validateFields().catch(() => {
-        resolve(false);
-      });
-      if (formData) {
-        console.log(formData);
-        // resolve(formData);
+      if (NotifyModel.variable.length) {
+        const formData = await form.validateFields().catch(() => {
+          resolve(false);
+        });
+        if (formData) {
+          resolve(formData);
+        } else {
+          resolve(false);
+        }
       } else {
-        resolve(false);
+        resolve({});
       }
     });
   };
@@ -137,19 +141,28 @@ export default forwardRef((props: Props, ref) => {
     <div>
       <Form form={form} layout={'vertical'}>
         {(NotifyModel?.variable || []).map((item) => {
-          const type = item.expands?.businessType || item.type;
+          const type = item.expands?.businessType || item?.type;
           let initialValue = undefined;
           const rules = getRules(item, type);
           if (type === 'user') {
-            initialValue = {
-              source: 'relation',
-              value: undefined,
-            };
+            initialValue =
+              props?.value && item?.id && props?.value[item.id]
+                ? props?.value[item.id]
+                : {
+                    source: 'relation',
+                    value: undefined,
+                  };
           } else if (['date', 'number', 'string'].includes(type)) {
-            initialValue = {
-              source: 'fixed',
-              value: undefined,
-            };
+            initialValue =
+              props?.value && item?.id && props?.value[item.id]
+                ? props?.value[item.id]
+                : {
+                    source: 'fixed',
+                    value: undefined,
+                  };
+          } else {
+            initialValue =
+              props?.value && item?.id && props?.value[item.id] ? props?.value[item.id] : undefined;
           }
           return (
             <Form.Item

+ 21 - 7
src/pages/rule-engine/Scene/Save/action/notify/index.tsx

@@ -10,11 +10,11 @@ import './index.less';
 import { onlyMessage } from '@/utils/util';
 import { queryMessageTemplateDetail } from '@/pages/rule-engine/Scene/Save/action/service';
 import { NotifyProps } from '@/pages/rule-engine/Scene/typings';
-import { FormModel } from '@/pages/rule-engine/Scene/Save';
 
 interface Props {
   value: Partial<NotifyProps>;
-  save: (notify: Partial<NotifyProps>) => void;
+  save: (notify: any, options: any) => void;
+  options?: any;
   cancel: () => void;
   name: number;
 }
@@ -57,8 +57,11 @@ export default observer((props: Props) => {
   const VariableRef = useRef<{ save: any }>();
 
   useEffect(() => {
-    NotifyModel.notify = props.value;
-  }, [props.value]);
+    NotifyModel.notify = {
+      ...props.value,
+      options: { ...props.options },
+    };
+  }, [props.value, props.options]);
 
   const renderComponent = (type: string) => {
     switch (type) {
@@ -69,7 +72,13 @@ export default observer((props: Props) => {
       case 'template':
         return <NotifyTemplate type={NotifyModel.notify.notifyType || ''} />;
       case 'variable':
-        return <VariableDefinitions name={props.name} ref={VariableRef} />;
+        return (
+          <VariableDefinitions
+            value={NotifyModel.notify.variables}
+            name={props.name}
+            ref={VariableRef}
+          />
+        );
       default:
         return null;
     }
@@ -107,8 +116,13 @@ export default observer((props: Props) => {
       if (resp) {
         NotifyModel.notify.variables = resp;
         const { options, ...extra } = NotifyModel.notify;
-        FormModel.actions[props.name].options = options;
-        props.save(extra);
+        props.save(
+          {
+            notify: { ...extra },
+            type: 'notify',
+          },
+          options,
+        );
         NotifyModel.current = 0;
       }
     }

+ 11 - 16
src/pages/rule-engine/Scene/Save/save.tsx

@@ -32,29 +32,24 @@ export default (props: Props) => {
       }}
       onOk={async () => {
         const values = await form.validateFields();
-        // const obj = {...values}
-        // if(values.trigger?.type === 'device') {
-        //   obj.trigger = {
-        //     ...obj.trigger,
-        //     device: obj.trigger?.device || {}
-        //   }
-        // }
-        // if(values.trigger?.type === 'timer') {
-        //   obj.trigger = {
-        //     ...obj.trigger,
-        //     timer: obj.trigger?.timer || {}
-        //   }
-        // }
+        const obj = {
+          ...props.data,
+          ...values,
+          trigger: {
+            ...props.data?.trigger,
+            ...values.trigger,
+          },
+        };
         const resp = props.data?.id
-          ? await service.modify(props.data?.id, { ...values })
-          : await service.save(values);
+          ? await service.modify(props.data?.id, { ...obj })
+          : await service.save(obj);
         if (resp.status === 200) {
           props.close();
           const url = getMenuPathByCode('rule-engine/Scene/Save');
           if (props.data?.id) {
             history.push(`${url}?triggerType=${values.trigger?.type}&id=${props.data?.id}`);
           } else {
-            history.push(`${url}?triggerType=${values.trigger?.type}`);
+            history.push(`${url}?triggerType=${values.trigger?.type}&id=${resp.result?.id}`);
           }
         }
       }}

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

@@ -150,11 +150,7 @@ const Scene = () => {
         }}
         tooltip={{
           title:
-            record.state.value === 'started' ? (
-              <span>请先禁用该场景,再删除</span>
-            ) : (
-              <span>删除</span>
-            ),
+            record.state.value === 'started' ? <span>请先禁用该场景,再删除</span> : <span></span>,
         }}
       >
         <DeleteOutlined />
@@ -275,7 +271,6 @@ const Scene = () => {
           <SceneCard
             {...record}
             onClick={() => {
-              console.log(123);
               const url = getMenuPathByCode('rule-engine/Scene/Save');
               history.push(`${url}?triggerType=${record.trigger?.type}&id=${record?.id}`);
             }}