Browse Source

feat: merge

xieyonghong 3 years ago
parent
commit
218ddaddc8

+ 2 - 2
src/components/ProTableCard/CardItems/Scene/index.tsx

@@ -133,7 +133,7 @@ const notifyRender = (data: ActionsType | undefined) => {
     case 'dingTalk':
       if (data?.options?.provider === 'dingTalkRobotWebHook') {
         return (
-          <div>
+          <div className={styles['notify-img-highlight']}>
             通过<span className={'notify-text-highlight'}>群机器人消息</span>
             发送<span>{data?.options?.templateName || data?.notify?.templateId}</span>
           </div>
@@ -167,7 +167,7 @@ const notifyRender = (data: ActionsType | undefined) => {
     case 'voice':
       return (
         <div className={styles['notify-img-highlight']}>
-          向<span>{data?.options?.calledNumber || ''}</span>
+          向<span>{data?.options?.sendTo || ''}</span>
           通过<span>语音</span>发送
           <span>{data?.options?.templateName || data?.notify?.templateId}</span>
         </div>

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

@@ -118,7 +118,7 @@ export default (props: ItemProps) => {
       case 'voice':
         return (
           <div>
-            向<span className={'notify-text-highlight'}>{options?.calledNumber || ''}</span>
+            向<span className={'notify-text-highlight'}>{options?.sendTo || ''}</span>
             通过
             <span className={'notify-img-highlight'}>
               <img width={18} src={itemNotifyIconMap.get(data?.notify?.notifyType)} />
@@ -201,33 +201,35 @@ export default (props: ItemProps) => {
   };
 
   const contentRender = () => {
-    if (props?.data?.alarm?.mode === 'trigger') {
-      return (
-        <div className={'item-options-content'}>
-          满足条件后将触发
-          <a
-            onClick={(e) => {
-              e.stopPropagation();
-              setTriggerVisible(true);
-            }}
-          >
-            关联此场景的告警
-          </a>
-        </div>
-      );
-    } else if (props?.data?.alarm?.mode === 'relieve') {
-      return (
-        <div className={'item-options-content'}>
-          满足条件后将解除
-          <a
-            onClick={() => {
-              setTriggerVisible(true);
-            }}
-          >
-            关联此场景的告警
-          </a>
-        </div>
-      );
+    if (props?.data?.executor === 'alarm') {
+      if (props?.data?.alarm?.mode === 'trigger') {
+        return (
+          <div className={'item-options-content'}>
+            满足条件后将触发
+            <a
+              onClick={(e) => {
+                e.stopPropagation();
+                setTriggerVisible(true);
+              }}
+            >
+              关联此场景的告警
+            </a>
+          </div>
+        );
+      } else if (props?.data?.alarm?.mode === 'relieve') {
+        return (
+          <div className={'item-options-content'}>
+            满足条件后将解除
+            <a
+              onClick={() => {
+                setTriggerVisible(true);
+              }}
+            >
+              关联此场景的告警
+            </a>
+          </div>
+        );
+      }
     } else if (props?.data?.executor === 'notify') {
       return (
         <div

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

@@ -20,7 +20,6 @@ export default (props: ListProps) => {
 
   useEffect(() => {
     setActions(props.actions);
-    // console.log('list-change', props.actions);
   }, [props.actions]);
 
   return (
@@ -67,26 +66,12 @@ export default (props: ListProps) => {
             setVisible(false);
           }}
           save={(data: any, options) => {
-            console.log(data);
-
             const { type, ...extra } = data;
-            console.log('list', options);
             const item: ActionsType = {
               ...extra,
-              executor: data.type === 'trigger' || data.type === 'relieve' ? 'alarm' : data.type,
               key: data.key,
               options,
             };
-
-            if (data.type === 'trigger' || data.type === 'relieve') {
-              item.alarm = {
-                mode: data.type,
-              };
-            }
-            // const index = FormModel?.actions.findIndex((i) => {
-            //   return i.key === item.key ? item : i;
-            // });
-            // FormModel.actions[index] = { ...item };
             props.onAdd(item);
             setVisible(false);
           }}

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

@@ -123,7 +123,7 @@ export default (props: Props) => {
         const values = await form.validateFields();
         setActionType(values.type);
         if (values.type === 'relieve' || values.type === 'trigger') {
-          props.save({ ...props.data, type: values.type, executor: 'alarm' });
+          props.save({ ...props.data, executor: 'alarm', alarm: { mode: values.type } }, {});
         }
       }}
     >
@@ -141,7 +141,7 @@ export default (props: Props) => {
         {...props}
         type={actionType}
         save={(data: any, options?: any) => {
-          props.save(data, options);
+          props.save({ ...data, executor: data.type }, options);
           setActionType('');
         }}
         close={() => {

+ 2 - 0
src/pages/rule-engine/Scene/Save/action/notify/NotifyConfig.tsx

@@ -71,6 +71,8 @@ export default observer((props: Props) => {
             onChange: (selectedRowKeys, list) => {
               if (selectedRowKeys.length) {
                 NotifyModel.notify.notifierId = String(selectedRowKeys[selectedRowKeys.length - 1]);
+                NotifyModel.notify.templateId = '';
+                NotifyModel.variable = [];
                 NotifyModel.notify.options = {
                   ...NotifyModel.notify.options,
                   provider: list[list.length - 1]?.provider,

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

@@ -71,6 +71,7 @@ export default observer((props: Props) => {
             onChange: (selectedRowKeys, list) => {
               if (selectedRowKeys.length) {
                 NotifyModel.notify.templateId = String(selectedRowKeys[selectedRowKeys.length - 1]);
+                NotifyModel.variable = [];
                 NotifyModel.notify.options = {
                   ...NotifyModel.notify.options,
                   templateName: list[list.length - 1]?.name,

+ 43 - 2
src/pages/rule-engine/Scene/Save/action/notify/index.tsx

@@ -24,6 +24,7 @@ export const NotifyModel = model<{
   current: number;
   notify: Partial<NotifyProps>;
   variable: any[];
+  loading: boolean;
 }>({
   steps: [
     {
@@ -50,6 +51,7 @@ export const NotifyModel = model<{
     templateId: '',
   },
   variable: [],
+  loading: false,
 });
 
 export default observer((props: Props) => {
@@ -89,10 +91,16 @@ export default observer((props: Props) => {
   };
 
   const next = async () => {
+    NotifyModel.loading = true;
     if (NotifyModel.current === 0) {
       const val = await WayRef.current?.save();
       if (val) {
-        NotifyModel.notify.notifyType = val;
+        NotifyModel.notify = {
+          notifyType: val,
+          notifierId: '',
+          templateId: '',
+        };
+        NotifyModel.variable = [];
         NotifyModel.current += 1;
       }
     } else if (NotifyModel.current === 1) {
@@ -126,6 +134,7 @@ export default observer((props: Props) => {
         NotifyModel.current = 0;
       }
     }
+    NotifyModel.loading = false;
   };
 
   return (
@@ -157,6 +166,7 @@ export default observer((props: Props) => {
           {NotifyModel.current < NotifyModel.steps.length - 1 && (
             <Button
               type="primary"
+              loading={NotifyModel.loading}
               onClick={() => {
                 next();
               }}
@@ -178,7 +188,38 @@ export default observer((props: Props) => {
       }
     >
       <div className="steps-steps">
-        <Steps current={NotifyModel.current} items={NotifyModel.steps} />
+        <Steps
+          onChange={async (value: number) => {
+            if (value === 0) {
+              NotifyModel.current = value;
+            }
+            if (value === 1) {
+              if (NotifyModel.notify.notifyType) {
+                NotifyModel.current = value;
+              } else {
+                onlyMessage('请选择通知方式', 'error');
+              }
+            } else if (value === 2) {
+              if (NotifyModel.notify.notifierId) {
+                NotifyModel.current = value;
+              } else {
+                onlyMessage('请选择通知配置', 'error');
+              }
+            } else if (value === 3) {
+              if (NotifyModel.notify.templateId) {
+                const resp = await queryMessageTemplateDetail(NotifyModel.notify.templateId);
+                if (resp.status === 200) {
+                  NotifyModel.variable = resp.result?.variableDefinitions || [];
+                  NotifyModel.current = value;
+                }
+              } else {
+                onlyMessage('请选择通知模板', 'error');
+              }
+            }
+          }}
+          current={NotifyModel.current}
+          items={NotifyModel.steps}
+        />
       </div>
       <div className="steps-content">
         {renderComponent(NotifyModel.steps[NotifyModel.current]?.key)}