From 092bef3e26d4a5b49235fb9dccd50ad6807d10e4 Mon Sep 17 00:00:00 2001
From: zhangchen <1652267879@qq.com>
Date: 星期二, 16 九月 2025 17:31:54 +0800
Subject: [PATCH] 修改vite.config文件
---
src/store/bedsideAuxiliaryScreen.ts | 112 ++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 84 insertions(+), 28 deletions(-)
diff --git a/src/store/bedsideAuxiliaryScreen.ts b/src/store/bedsideAuxiliaryScreen.ts
index 11ff7fa..d40dbc8 100644
--- a/src/store/bedsideAuxiliaryScreen.ts
+++ b/src/store/bedsideAuxiliaryScreen.ts
@@ -1,9 +1,11 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import dayjs from "dayjs";
-import cache from "../utils/cache";
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,
@@ -11,12 +13,18 @@
formatDeviceData,
} from "./type/bedsideAuxiliaryScreen.type";
import { ElMessage } from "element-plus/es";
+import { Local } from "@/utils/storage";
+import type { DeviceLoginRecord } from './type/user.type';
+import { logOutApi } from "@/api/user";
export const useBedsideAuxiliaryScreenStore = defineStore(
"bedsideAuxiliaryScreen",
() => {
/** 设备编号 */
- const deviceCode = ref<string>(cache.get("devcieCode") || "");
+ const deviceCode = ref<string>(Local.get("devcieCode") || "");
+
+ /** 副屏版本号 */
+ const version = ref<string>(Local.get("version") || "0.0.0");
/** 设备信息数据 */
const deviceData = ref<BedsideAuxiliaryScreen>(defaultDeviceData());
@@ -24,13 +32,22 @@
/** 任务列表 */
const taskData = ref<Task[]>([]);
+ /** 用户信息 */
+ const userInfo = ref<DeviceLoginRecord | null>(null);
+
+ /** 设置副屏版本号 */
+ const setVersion = (val: string) => {
+ version.value = val;
+ Local.set("version", val);
+ };
+
/**
* 设置设备编号
* @param code
*/
const setDeviceCode = (code: string) => {
deviceCode.value = code;
- cache.set("devcieCode", code);
+ Local.set("devcieCode", code);
};
/**
@@ -48,22 +65,6 @@
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) => {
taskData.value = [taskItem];
@@ -74,6 +75,18 @@
taskData.value = [];
};
+ /** 设置用户信息 */
+ const setUserInfo = (user: DeviceLoginRecord | null) => {
+ userInfo.value = user;
+ };
+
+
+ /** 退出登录 */
+ const logout = async (deviceCodeStr: string) => {
+ await logOutApi(deviceCodeStr);
+ setUserInfo(null);
+ };
+
// SSE 相关状态
const source = ref<EventSource | null>(null);
const message = ref<string | null>(null);
@@ -81,7 +94,7 @@
// 重连控制
let retryCount = 0;
- const maxRetryCount = 60;
+ const maxRetryCount = 6000 * 60 * 24 * 30;
const baseRetryDelay = 1000; // 1秒开始重连延迟
/**
@@ -110,7 +123,7 @@
if (retryCount < maxRetryCount) {
const delay = baseRetryDelay * Math.pow(2, retryCount); // 指数退避
retryCount++;
- console.log(`[SSE] 第${retryCount}次重连,延迟${delay}ms`);
+ console.log(`[SSE] 第${retryCount}次重连,延迟${baseRetryDelay}ms`);
ElMessage.warning(
`链接服务失败, 第${retryCount}次重连,请耐心等待重连。。`
);
@@ -134,23 +147,60 @@
const dataBody = JSON.parse(datax) as SseMsgData;
console.log("dataBody: ", dataBody);
// 倒计时提示文本
- if (dataBody.倒计时?.提醒文本) {
- const taskTime = dayjs(dataBody.倒计时?.当前服务器时间).add(dataBody.倒计时?.设定提醒倒计时, 'minute')
+ if (
+ dataBody.倒计时?.提醒文本 &&
+ Number(dataBody.倒计时?.设定提醒倒计时 > 0)
+ ) {
+ const serverTimeRaw = dataBody.倒计时?.当前服务器时间;
+ const reminderMinutes = Number(
+ dataBody.倒计时?.设定提醒倒计时 ?? 0
+ );
+ const serverTimeFormatted = serverTimeRaw.replace(" ", "T");
+
+ 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,
- countdown: dataBody.倒计时?.设定提醒倒计时
- })
+ sync: true,
+ countdown: dataBody.倒计时?.设定提醒倒计时,
+ });
} else {
clearTask();
}
- deviceData.value = formatDeviceData(dataBody);
+ deviceData.value = formatDeviceData(deviceData.value, dataBody);
+ // 当前登录的用户信息
+ setUserInfo(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();
+ },
+ });
};
/**
@@ -175,6 +225,7 @@
};
return {
+ version,
deviceCode,
deviceData,
setDeviceCode,
@@ -188,6 +239,11 @@
pushTask,
setSyncTask,
clearTask,
+ setVersion,
+ refreshVersion,
+ userInfo,
+ setUserInfo,
+ logout,
};
}
);
--
Gitblit v1.8.0