Prechádzať zdrojové kódy

[Wip 0000] 沙坪均压与低氧页面联动控制功能开发

houzekong 1 deň pred
rodič
commit
f6cbaadff6

+ 183 - 46
src/views/vent/monitorManager/balancePressMonitor/components/balancePressHomeSP.vue

@@ -87,7 +87,7 @@
   </a-spin>
 </template>
 <script setup lang="ts">
-  import { ref, onMounted, onUnmounted, defineProps } from 'vue';
+  import { ref, onMounted, onUnmounted, defineProps, h } from 'vue';
   import { mountedThree, destroy, setModelType, updateText, play } from '../balancePress.threejs';
   import { list } from '../balancePress.api';
   import ModuleCommon from '../../../home/configurable/components/ModuleCommon.vue';
@@ -102,7 +102,12 @@
   // import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
   // import { getToken } from '/@/utils/auth';
   // import { useUserStore } from '/@/store/modules/user';
-  import { usePressControl } from '../hooks/useControl';
+  import { usePressControlSP } from '../hooks/useControl';
+  import { Modal } from 'ant-design-vue';
+  import dayjs from 'dayjs';
+  import { connectWebSocket, onWebSocket } from '/@/hooks/web/useWebSocket';
+  import { useUserStore } from '/@/store/modules/user';
+  import { getToken } from '/@/utils/auth';
   // import dayjs from 'dayjs';
   // import { Config } from '../../../deviceManager/configurationTable/types';
 
@@ -150,26 +155,6 @@
       (obj: any, e: any) => {
         obj[e.type] = e;
 
-        // if (true) {
-        if (sysOrgCode === 'sdmtjtswmk') {
-          if (e.type.startsWith('fanlocal')) {
-            obj.fanlocal.datalist.push(...e.datalist);
-          }
-          if (e.type.startsWith('safetymonitor')) {
-            e.datalist.forEach((ele) => {
-              if (ele.strinstallpos.includes('风门')) {
-                obj.gate.datalist.push(ele);
-              } else if (ele.strinstallpos.includes('风窗')) {
-                obj.window.datalist.push(ele);
-              } else if (ele.strinstallpos.includes('工作面')) {
-                obj.work_surface.datalist.push(ele);
-              } else {
-                obj.others.datalist.push(ele);
-              }
-            });
-          }
-        }
-
         return obj;
       },
       {
@@ -193,13 +178,13 @@
     // avePressLinkage,
     // gateLinkage,
     formData,
-    // getAvePress,
+    getAvePress,
     changePassword,
     // linkageControl,
-    // settingControl,
-    // autoControl,
-    // cancelControl,
-  } = usePressControl();
+    settingControl,
+    autoControl,
+    cancelControl,
+  } = usePressControlSP();
 
   const modalVisible = ref(false);
 
@@ -229,30 +214,30 @@
   //     });
   //   };
   // }
-  function changeAvePressState({ target }, __key) {
+  function changeAvePressState({ target }, key) {
     formData.value.temp = target.value;
     modalVisible.value = true;
-    // resolver = (password) => {
-    //   settingControl(
-    //     { password, id: avePressSetting.value.id },
-    //     {
-    //       [key]: formData.value.temp,
-    //     }
-    //   ).finally(() => {
-    //     modalVisible.value = false;
-    //   });
-    // };
+    resolver = (password) => {
+      settingControl(
+        { password, id: avePressSetting.value.id },
+        {
+          [key]: formData.value.temp,
+        }
+      ).finally(() => {
+        modalVisible.value = false;
+      });
+    };
   }
 
   // function submitLinkageForm(password) {}
   function submitSettingForm() {
     modalVisible.value = true;
-    // resolver = (password) => {
-    //   settingControl({ password, id: avePressSetting.value.id }, avePressSetting.value).finally(() => {
-    //     modalVisible.value = false;
-    //     settingFormDisabled.value = true;
-    //   });
-    // };
+    resolver = (password) => {
+      settingControl({ password, id: avePressSetting.value.id }, avePressSetting.value).finally(() => {
+        modalVisible.value = false;
+        settingFormDisabled.value = true;
+      });
+    };
   }
 
   let resolver: any = null;
@@ -281,13 +266,165 @@
     settingFormDisabled.value = !settingFormDisabled.value;
     /**  如果取消了编辑模式,那么需要重置表单 */
     if (settingFormDisabled.value) {
-      // getAvePress();
+      getAvePress();
     }
   }
 
+  // const [warnRegister1, warnModal1] = useModal();
+  // const [warnRegister2, warnModal2] = useModal();
+  // const [warnRegister3, warnModal3] = useModal();
+  let warnModal1: { destroy: () => void } | null = null;
+  let warnModal2: { destroy: () => void } | null = null;
+  let warnModal3: { destroy: () => void } | null = null;
+  // const warnModalText1 = ref('');
+  // const warnModalText2 = ref('');
+  // const warnModalText3 = ref('');
+
+  // 初始化 WebSocket
+  function initWebSocket() {
+    const token = getToken();
+    const userStore = useUserStore();
+    const glob = useGlobSetting();
+    // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https
+    const url = `${glob.wsUrl?.replace('https://', 'wss://').replace('http://', 'ws://')}/websocket/${userStore.getUserInfo.id}?token=${token}`;
+    connectWebSocket(url);
+    onWebSocket((data: any) => {
+      if (data.cmd !== 'topic' || data.topic !== 'warn') return;
+      if (!data.msgTxt) return;
+
+      const { info = '', type = '', avgPressureLogId, date } = JSON.parse(data.msgTxt);
+      const datestr = dayjs(date).format('YYYY-MM-DD HH:mm:ss');
+      switch (type) {
+        case 'o2':
+          // 如果已经存在报警模态框,则不需要处理
+          if (warnModal1) break;
+          warnModal1 = Modal.confirm({
+            title: data.msgTitle,
+            content: h('div', { style: { color: '#fff' } }, [h('p', datestr), h('p', info)]),
+            centered: true,
+            okText: '下发调节指令',
+            mask: true,
+            class: 'balancePress',
+            onOk() {
+              // 点击确定按钮后,执行调节指令。调节指令需要确认密码,所以需要先弹出密码框
+              return new Promise((resolve, reject) => {
+                modalVisible.value = true;
+                // 弹出密码框后,输入密码并验证成功则关闭密码弹窗和报警弹窗,失败则关闭密码弹窗但不关闭报警弹窗
+                resolver = (password) => {
+                  autoControl({ password, id: avePressSetting.value.id }, { avgPressLogId: avgPressureLogId })
+                    .then(() => {
+                      modalVisible.value = false;
+                      resolve(true);
+                      warnModal1?.destroy();
+                      warnModal1 = null;
+                    })
+                    .catch(() => {
+                      modalVisible.value = false;
+                      reject();
+                    });
+                };
+                // 弹出密码框取消操作则关闭密码弹窗但不关闭报警弹窗
+                rejecter = () => {
+                  modalVisible.value = false;
+                  reject();
+                };
+              });
+            },
+            onCancel() {
+              return cancelControl({}, { avgPressLogId: avgPressureLogId }).finally(() => {
+                warnModal1?.destroy();
+                warnModal1 = null;
+              });
+            },
+          });
+          // warnModalText1.value = info;
+          // warnModal1.openModal();
+
+          break;
+        case 'pressure':
+          // warnModalText1.value = info;
+          // warnModal1.openModal();
+          if (warnModal1) break;
+          warnModal1 = Modal.confirm({
+            title: data.msgTitle,
+            content: h('div', { style: { color: '#fff' } }, [h('p', datestr), h('p', info)]),
+            centered: true,
+            okText: '下发调节指令',
+            mask: true,
+            class: 'balancePress',
+            onOk() {
+              // 点击确定按钮后,执行调节指令。调节指令需要确认密码,所以需要先弹出密码框
+              return new Promise((resolve, reject) => {
+                modalVisible.value = true;
+                // 弹出密码框后,输入密码并验证成功则关闭密码弹窗和报警弹窗,失败则关闭密码弹窗但不关闭报警弹窗
+                resolver = (password) => {
+                  autoControl({ password, id: avePressSetting.value.id }, { avgPressLogId: avgPressureLogId })
+                    .then(() => {
+                      modalVisible.value = false;
+                      resolve(true);
+                      warnModal1?.destroy();
+                      warnModal1 = null;
+                    })
+                    .catch(() => {
+                      modalVisible.value = false;
+                      reject();
+                    });
+                };
+                // 弹出密码框取消操作则关闭密码弹窗但不关闭报警弹窗
+                rejecter = () => {
+                  modalVisible.value = false;
+                  reject();
+                };
+              });
+            },
+            onCancel() {
+              return cancelControl({}, { avgPressLogId: avgPressureLogId }).finally(() => {
+                warnModal1?.destroy();
+                warnModal1 = null;
+              });
+            },
+          });
+
+          break;
+        case 'gate':
+          if (warnModal2) break;
+          warnModal2 = Modal.warning({
+            title: data.msgTitle,
+            content: info,
+            mask: true,
+            class: 'balancePress',
+            onOk: () => {
+              warnModal2?.destroy();
+              warnModal2 = null;
+            },
+          });
+          break;
+        case 'fansys':
+          if (warnModal3) break;
+          warnModal3 = Modal.warning({
+            title: data.msgTitle,
+            content: info,
+            mask: true,
+            class: 'balancePress',
+            style: 'top: 700px',
+            onOk: () => {
+              warnModal3?.destroy();
+              warnModal3 = null;
+            },
+          });
+
+          break;
+
+        default:
+          break;
+      }
+    });
+  }
+
   onMounted(() => {
     fetchConfigs('balancePressHome');
-    // getAvePress();
+    initWebSocket();
+    getAvePress();
     loading.value = true;
     mountedThree().then(async () => {
       if (sysOrgCode === 'jsnyspmy') {

+ 136 - 0
src/views/vent/monitorManager/balancePressMonitor/hooks/useControl.ts

@@ -154,3 +154,139 @@ export function usePressControl() {
     formData,
   };
 }
+
+export function usePressControlSP() {
+  /** 参数与设置、风机风门联动表单数据 */
+  const formData = ref({
+    /** 风机风门联动的自动调控 */
+    isAuto: false,
+    /** 参数与设置的状态暂存字段 */
+    temp: false,
+  });
+  /** 参数与设置、风机风门联动的数据 */
+  const avePressSetting = ref<any>({ isAuto: false });
+
+  /** 获取 参数与设置、风机风门联动 的数据 */
+  function getAvePress() {
+    return Promise.all([
+      subList2({
+        strType: 'sp_pressure_to_window',
+      }),
+    ]).then(([settingData]) => {
+      avePressSetting.value = get(settingData, '[0]', {});
+    });
+  }
+
+  function changePassword({ password, oldpassword, id }) {
+    return updatePassword({
+      id,
+      newPassword: password,
+      oldPassword: oldpassword,
+    })
+      .then(() => {
+        message.success('操作成功');
+      })
+      .catch((e) => {
+        message.error(e);
+      })
+      .finally(() => {
+        getAvePress();
+      });
+  }
+
+  function linkageControl({ password, id }, formData) {
+    return validPassword({
+      id,
+      password,
+    })
+      .then(() => {
+        return submitEdit({
+          id,
+          ...formData,
+        })
+          .then(() => {
+            message.success('操作成功');
+          })
+          .catch(() => {
+            message.error('操作失败');
+          });
+      })
+      .catch((e) => {
+        message.error(e);
+      })
+      .finally(() => {
+        getAvePress();
+      });
+  }
+
+  function settingControl({ password, id }, formData) {
+    return validPassword({
+      id,
+      password,
+    })
+      .then(() => {
+        return submitEdit({
+          id,
+          ...formData,
+        })
+          .then(() => {
+            message.success('操作成功');
+          })
+          .catch(() => {
+            message.error('操作失败');
+          });
+      })
+      .catch((e) => {
+        message.error(e);
+      })
+      .finally(() => {
+        getAvePress();
+      });
+  }
+
+  function autoControl({ password, id }, { avgPressLogId }) {
+    return validPassword({
+      id,
+      password,
+    })
+      .then(() => {
+        return controlWindow({ avgPressId: avePressSetting.value.id, avgPressLogId })
+          .then(() => {
+            message.success('预警已处理');
+          })
+          .catch((e) => {
+            message.error('下发失败');
+            throw e;
+          });
+      })
+      .catch((e) => {
+        message.error(e);
+        throw e;
+      })
+      .finally(() => {
+        getAvePress();
+      });
+  }
+
+  function cancelControl(___, { avgPressLogId }) {
+    return cancelcontrolWindow({ avgPressId: avePressSetting.value.id, avgPressLogId })
+      .then(() => {
+        message.success('已取消');
+      })
+      .catch((e) => {
+        message.error('下发失败');
+        throw e;
+      });
+  }
+
+  return {
+    settingControl,
+    linkageControl,
+    changePassword,
+    getAvePress,
+    autoControl,
+    cancelControl,
+    avePressSetting,
+    formData,
+  };
+}