单应用项目,可以创建很多独立工具类页面 ,不用登录 初始化的页面
zhangchen
2025-08-11 6eb0d4b25ae436574dd4b2c756e6678c1feda890
ID1975-副屏自动更新流程完成
2个文件已修改
100 ■■■■■ 已修改文件
src/store/bedsideAuxiliaryScreen.ts 52 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/mobile/bedsideAuxiliaryScreen/index.vue 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/bedsideAuxiliaryScreen.ts
@@ -2,7 +2,10 @@
import { ref } from "vue";
import dayjs from "dayjs";
import { EventSourcePolyfill } from "event-source-polyfill";
import type { BedsideAuxiliaryScreen, SseMsgData } from "./type/bedsideAuxiliaryScreen.type";
import type {
  BedsideAuxiliaryScreen,
  SseMsgData,
} from "./type/bedsideAuxiliaryScreen.type";
import type { Task } from "./type/task.type";
import {
  defaultDeviceData,
@@ -31,7 +34,7 @@
    const setVersion = (val: string) => {
      version.value = val;
      Local.set("version", val);
    }
    };
    /**
     * 设置设备编号
@@ -127,29 +130,57 @@
          const dataBody = JSON.parse(datax) as SseMsgData;
          console.log("dataBody: ", dataBody);
          // 倒计时提示文本
          if (dataBody.倒计时?.提醒文本 && Number(dataBody.倒计时?.设定提醒倒计时 > 0)) {
          if (
            dataBody.倒计时?.提醒文本 &&
            Number(dataBody.倒计时?.设定提醒倒计时 > 0)
          ) {
            const serverTimeRaw = dataBody.倒计时?.当前服务器时间;
            const reminderMinutes = Number(dataBody.倒计时?.设定提醒倒计时 ?? 0);
            const serverTimeFormatted = serverTimeRaw.replace(' ', 'T');
            const reminderMinutes = Number(
              dataBody.倒计时?.设定提醒倒计时 ?? 0
            );
            const serverTimeFormatted = serverTimeRaw.replace(" ", "T");
            const taskTime = dayjs(serverTimeFormatted).add(reminderMinutes, 'second');
            const taskTime = dayjs(serverTimeFormatted).add(
              reminderMinutes,
              "second"
            );
            setSyncTask({
              deviceCode: dataBody.IOT信息.设备唯一编号,
              recordCode: dataBody.透析状态?.透析单编号,
              taskDate: taskTime.format('YYYY-MM-DD HH:mm'),
              taskDate: taskTime.format("YYYY-MM-DD HH:mm"),
              taskName: dataBody.倒计时?.提醒文本,
              overdue: false,
              sync: true,
              countdown: dataBody.倒计时?.设定提醒倒计时
            })
              countdown: dataBody.倒计时?.设定提醒倒计时,
            });
          } else {
            clearTask();
          }
          deviceData.value = formatDeviceData(deviceData.value, dataBody);
          setDeviceCode(dataBody.服务端版本号);
          // 判断本地的版本号与远程的版本号是否一致,如果不一致则执行刷新操作
          if (dataBody.服务端版本号 !== version.value) {
            refreshVersion(dataBody.服务端版本号);
          } else if (dataBody.是否需要立即刷新 === 1) {
            refreshVersion(dataBody.服务端版本号);
          }
        }
      };
    };
    /** 刷新副屏 */
    const refreshVersion = (val?: string) => {
      if (val) {
        setVersion(val);
      }
      ElMessage({
        type: "success",
        duration: 1000 * 3,
        message: "系统更新···",
        onClose: function () {
          window.location.reload();
        },
      });
    };
    /**
@@ -189,6 +220,7 @@
      setSyncTask,
      clearTask,
      setVersion,
      refreshVersion,
    };
  }
);
src/views/mobile/bedsideAuxiliaryScreen/index.vue
@@ -117,48 +117,34 @@
});
// 版本更新/手动刷新场景
watch(
  [
    bedsideAuxiliaryScreenStore.version,
    bedsideAuxiliaryScreenStore.deviceData.isRefresh,
  ],
  ([newVersion, newIsRefresh], [oldVersion, oldIsRefresh]) => {
    // 如果远程版本号存在更新/设备列表页面进行了手动刷新
    console.log('bedsideAuxiliaryScreenStore.version :', bedsideAuxiliaryScreenStore.version)
    if (
      newVersion !== bedsideAuxiliaryScreenStore.version ||
      newIsRefresh === 1
    ) {
      refreshFun();
    }
  }
);
// watch(
//   [
//     bedsideAuxiliaryScreenStore.version,
//     bedsideAuxiliaryScreenStore.deviceData.isRefresh,
//   ],
//   ([newVersion, newIsRefresh], [oldVersion, oldIsRefresh]) => {
//     // 如果远程版本号存在更新/设备列表页面进行了手动刷新
//     console.log('bedsideAuxiliaryScreenStore.version :', bedsideAuxiliaryScreenStore.version)
//     if (
//       newVersion !== oldVersion||
//       newIsRefresh === 1
//     ) {
//       refreshFun();
//     }
//   }
// );
const getServiceVersionFun = async () => {
  try {
    const { version } = await getServiceVersionApi();
    if (version !== bedsideAuxiliaryScreenStore.version) {
      refreshFun(version);
      bedsideAuxiliaryScreenStore.refreshVersion(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) {