From 6ecaed01cf576560a31ae960d0cdf1473e03c6b8 Mon Sep 17 00:00:00 2001
From: zhangchen <1652267879@qq.com>
Date: 星期一, 11 八月 2025 15:40:26 +0800
Subject: [PATCH] ID1975-自动更新流程zancun

---
 src/utils/utils.ts                                             |    8 ++
 src/store/type/bedsideAuxiliaryScreen.type.ts                  |   10 +++
 src/utils/httpApi.ts                                           |   17 +++++
 src/store/bedsideAuxiliaryScreen.ts                            |   28 ++++-----
 src/views/mobile/bedsideAuxiliaryScreen/index.vue              |   74 ++++++++++++++++++++++++
 src/views/mobile/bedsideAuxiliaryScreen/components/Version.vue |   18 ++++++
 6 files changed, 137 insertions(+), 18 deletions(-)

diff --git a/src/store/bedsideAuxiliaryScreen.ts b/src/store/bedsideAuxiliaryScreen.ts
index 63a739c..fbcd79c 100644
--- a/src/store/bedsideAuxiliaryScreen.ts
+++ b/src/store/bedsideAuxiliaryScreen.ts
@@ -18,11 +18,20 @@
     /** 设备编号 */
     const deviceCode = ref<string>(Local.get("devcieCode") || "");
 
+    /** 副屏版本号 */
+    const version = ref<string>(Local.get("version") || "0.0.0");
+
     /** 设备信息数据 */
     const deviceData = ref<BedsideAuxiliaryScreen>(defaultDeviceData());
 
     /** 任务列表 */
     const taskData = ref<Task[]>([]);
+
+    /** 设置副屏版本号 */
+    const setVersion = (val: string) => {
+      version.value = val;
+      Local.set("version", val);
+    }
 
     /**
      * 设置设备编号
@@ -47,22 +56,6 @@
     const pushTask = (taskItem: Task) => {
       taskData.value.push(taskItem);
     };
-
-    /**
-     * 是否将当前任务设置为已过期
-     * @param i
-     */
-    // const deleteTask = (i: number) => {
-    //   const task = taskData.value[i];
-    //   if (task) {
-    //     // 二次判断,判断任务时间是否早于或等于当前时间
-    //     const taskTime = dayjs(task.taskDate).second(0).millisecond(0);
-    //     const now = dayjs().second(0).millisecond(0); // 秒和毫秒都去掉
-    //     if (!taskTime.isAfter(now)) {
-    //       taskData.value[i].overdue = true
-    //     }
-    //   }
-    // };
 
     /** 设置当前定时任务 */
     const setSyncTask = (taskItem: Task) => {
@@ -154,6 +147,7 @@
           }
 
           deviceData.value = formatDeviceData(deviceData.value, dataBody);
+          setDeviceCode(dataBody.服务端版本号);
         }
       };
     };
@@ -180,6 +174,7 @@
     };
 
     return {
+      version,
       deviceCode,
       deviceData,
       setDeviceCode,
@@ -193,6 +188,7 @@
       pushTask,
       setSyncTask,
       clearTask,
+      setVersion,
     };
   }
 );
diff --git a/src/store/type/bedsideAuxiliaryScreen.type.ts b/src/store/type/bedsideAuxiliaryScreen.type.ts
index a4193f6..c89012a 100644
--- a/src/store/type/bedsideAuxiliaryScreen.type.ts
+++ b/src/store/type/bedsideAuxiliaryScreen.type.ts
@@ -177,6 +177,8 @@
   透析状态: DialysisStatus | null;
   床旁血压结果?: any;
   自定义配置项: Customconfiguration;
+  服务端版本号: string;
+  是否需要立即刷新: 0 | 1;
 }
 
 interface Customconfiguration {
@@ -192,6 +194,8 @@
 export interface BedsideAuxiliaryScreen {
   deviceCode: string;
   devicdeNo: string | number;
+  version: string;
+  isRefresh: number;
   recordCode: string;
   patientCode: string;
   patientName: string;
@@ -420,6 +424,8 @@
   return {
     deviceCode: "", // 设备code
     devicdeNo: "", // 设备号
+    version: "0.0.0", // 版本号
+    isRefresh: 0, // 是否立即刷新
     recordCode: "", // 透析单code
     patientCode: "", // 患者code
     patientName: "", // 患者姓名
@@ -453,6 +459,10 @@
 
   const result = deepClone(data);
 
+  // 版本号/是否立即刷新
+  result.version = seeMsg.服务端版本号;
+  result.isRefresh = seeMsg.是否需要立即刷新;
+
 
   // 默认床号(设备号)
   result.devicdeNo = seeMsg.IOT信息?.床号;
diff --git a/src/utils/httpApi.ts b/src/utils/httpApi.ts
index 4cbc6d7..0cbfeef 100644
--- a/src/utils/httpApi.ts
+++ b/src/utils/httpApi.ts
@@ -76,4 +76,21 @@
     } catch (error) {
         throw error;
     }
+}
+
+/**
+ * 获取副屏最新的版本号Api
+ * @returns 
+ */
+export const getServiceVersionApi = async() => {
+    try {
+        const response = await axios.post(`${apiBaseUrl}/system/version/subscreen/showVersionDiff`, {}, {
+            headers: {
+                'Content-Type': 'application/x-www-form-urlencoded'
+            }
+        });
+        return response.data;
+    } catch (error) {
+        throw error;
+    }
 }
\ No newline at end of file
diff --git a/src/utils/utils.ts b/src/utils/utils.ts
index d419c94..76d82bc 100644
--- a/src/utils/utils.ts
+++ b/src/utils/utils.ts
@@ -69,4 +69,12 @@
 
   chars[1] = masked
   return chars.join('')
+}
+
+/**
+ * 延时函数
+ * @param {number} ms - 延时时间,单位毫秒
+ */
+export function delay(ms: number) {
+  return new Promise((resolve) => setTimeout(resolve, ms));
 }
\ No newline at end of file
diff --git a/src/views/mobile/bedsideAuxiliaryScreen/components/Version.vue b/src/views/mobile/bedsideAuxiliaryScreen/components/Version.vue
new file mode 100644
index 0000000..27f1809
--- /dev/null
+++ b/src/views/mobile/bedsideAuxiliaryScreen/components/Version.vue
@@ -0,0 +1,18 @@
+<template>
+  <div class="version-container">
+    
+  </div>
+</template>
+
+<script lang="ts">
+export default {
+    name: 'Version',
+    setup() {
+        return {}
+    }
+}
+</script>
+
+<style lang="scss" scoped>
+
+</style>
\ No newline at end of file
diff --git a/src/views/mobile/bedsideAuxiliaryScreen/index.vue b/src/views/mobile/bedsideAuxiliaryScreen/index.vue
index 3154799..5aedcc5 100644
--- a/src/views/mobile/bedsideAuxiliaryScreen/index.vue
+++ b/src/views/mobile/bedsideAuxiliaryScreen/index.vue
@@ -18,13 +18,22 @@
 </template>
 
 <script lang="ts" setup>
-import { ref, watch, computed, onMounted, defineAsyncComponent } from "vue";
+import {
+  ref,
+  watch,
+  computed,
+  onMounted,
+  defineAsyncComponent,
+  onBeforeUnmount,
+} from "vue";
 // @ts-ignore
 import Header from "./components/Header.vue";
 import { useBedsideAuxiliaryScreenStore } from "@/store/bedsideAuxiliaryScreen";
 import { EPageType } from "@/store/type/bedsideAuxiliaryScreen.type";
-import { getAvailableHeightByClass } from "@/utils/utils";
+import { getAvailableHeightByClass, delay } from "@/utils/utils";
 import { useWindowSize } from "@/composables/useWindowSize";
+import { getServiceVersionApi } from "@/utils/httpApi";
+import { ElMessage } from "element-plus";
 // 未排班时的组件
 const UnplannedSchedule = defineAsyncComponent(
   () => import("./pages/UnplannedSchedule.vue")
@@ -47,6 +56,9 @@
 const bedsideAuxiliaryScreenStore = useBedsideAuxiliaryScreenStore();
 const cotentHeight = ref(0);
 const { width, height } = useWindowSize();
+
+const versionTimer = 1000 * 60 * 5; // 五分钟请求一次 getServiceVersionApi 接口,防止副屏关屏的时候收不到推送的消息
+let timer: ReturnType<typeof setInterval> | null = null;
 
 const backgroundColor = computed(() => {
   let color = "#DAE5EC";
@@ -104,6 +116,50 @@
   cotentHeight.value = getAvailableHeightByClass("content-position");
 });
 
+// 版本更新/手动刷新场景
+watch(
+  [
+    bedsideAuxiliaryScreenStore.version,
+    bedsideAuxiliaryScreenStore.deviceData.isRefresh,
+  ],
+  ([newVersion, newIsRefresh], [oldVersion, oldIsRefresh]) => {
+    // 如果远程版本号存在更新/设备列表页面进行了手动刷新
+    console.log('bedsideAuxiliaryScreenStore.version :', bedsideAuxiliaryScreenStore.version)
+    if (
+      newVersion !== bedsideAuxiliaryScreenStore.version ||
+      newIsRefresh === 1
+    ) {
+      refreshFun();
+    }
+  }
+);
+
+const getServiceVersionFun = async () => {
+  try {
+    const { version } = await getServiceVersionApi();
+    if (version !== bedsideAuxiliaryScreenStore.version) {
+      refreshFun(version);
+    }
+  } catch (error) {
+    ElMessage.error("获取版本号失败,请联系管理员!");
+  }
+};
+
+/** 副屏刷新的方法 */
+const refreshFun = (val?: string) => {
+  if (val) {
+    bedsideAuxiliaryScreenStore.setVersion(val);
+  }
+  ElMessage({
+    type: "success",
+    duration: 1000 * 3,
+    message: "系统更新···",
+    onClose: function () {
+      window.location.reload();
+    },
+  });
+};
+
 onMounted(() => {
   if (bedsideAuxiliaryScreenStore.deviceCode) {
     bedsideAuxiliaryScreenStore.connect(
@@ -112,8 +168,22 @@
       }`
     );
   }
+  // 先立即执行一次
+  getServiceVersionFun();
+
+  // 再每 5 分钟执行一次
+  timer = setInterval(() => {
+    getServiceVersionFun();
+  }, versionTimer);
   cotentHeight.value = getAvailableHeightByClass("content-position");
 });
+
+onBeforeUnmount(() => {
+  // 把定时器清除掉
+  if (timer) {
+    clearInterval(timer);
+  }
+});
 </script>
 
 <style lang="less" scoped>

--
Gitblit v1.8.0