diff --git a/.env.development b/.env.development index 2d60cf6..1ff3f96 100644 --- a/.env.development +++ b/.env.development @@ -5,11 +5,11 @@ VITE_APP_TITLE = 云平台管理系统 VITE_APP_ENV = 'development' # 开发环境 -# VITE_APP_BASE_API = 'http://47.120.79.150/backend' - VITE_APP_BASE_API = 'http://192.168.110.56:8000' + #VITE_APP_BASE_API = 'https://fuyuanshen.com/backend' + VITE_APP_BASE_API = 'http://192.168.2.23:8000' #代永飞接口 -# VITE_APP_BASE_API = 'http://457102h2d6.qicp.vip:24689' +#VITE_APP_BASE_API = 'http://457102h2d6.qicp.vip:24689' # 应用访问路径 例如使用前缀 /admin/ diff --git a/src/api/equipmentAlarmRecord/types.ts b/src/api/equipmentAlarmRecord/types.ts index 74493a9..7dc85f0 100644 --- a/src/api/equipmentAlarmRecord/types.ts +++ b/src/api/equipmentAlarmRecord/types.ts @@ -16,6 +16,7 @@ export interface AlarmVO { deviceMac: string; devicePic:string; finishTime: string; + timeDiff:string } diff --git a/src/assets/index/IMG.png b/src/assets/index/IMG.png new file mode 100644 index 0000000..0d59558 Binary files /dev/null and b/src/assets/index/IMG.png differ diff --git a/src/utils/mqtt.ts b/src/utils/mqtt.ts index cfac351..13febdd 100644 --- a/src/utils/mqtt.ts +++ b/src/utils/mqtt.ts @@ -17,8 +17,10 @@ export interface SubscribeOptions { // 根据当前页面协议自动选择MQTT配置 const getMqttConfig = () => { // 检测当前页面协议(http: 或 https:) - const isHttps = window.location.protocol === 'https:'; - console.log(isHttps,'检测环境'); + //const isHttps = window.location.protocol === 'https:'; + + const isHttps = import.meta.env.VITE_APP_ENV === 'production' || window.location.protocol === 'https:'; + console.log(isHttps,'检测环境'); return { // 自动切换协议:https页面用wss,http页面用ws diff --git a/src/utils/timeConverter.ts b/src/utils/timeConverter.ts new file mode 100644 index 0000000..dcdb60c --- /dev/null +++ b/src/utils/timeConverter.ts @@ -0,0 +1,113 @@ +/** + * 时间转换工具类 + * 提供时间格式化、时间差计算等功能 + */ +export class TimeConverter { + /** + * 检查时间字符串是否有效 + * @param timeStr 时间字符串 + * @returns 是否有效的时间 + */ + static isValidTime(timeStr: string): boolean { + if (!timeStr) return false; + return !isNaN(new Date(timeStr).getTime()); + } + + /** + * 格式化时间 + * @param timeStr 时间字符串 + * @param format 格式,可选值: 'YYYY-MM-DD', 'HH:mm:ss', 'YYYY-MM-DD HH:mm:ss' + * @returns 格式化后的时间字符串 + */ + static formatTime(timeStr: string, format: 'YYYY-MM-DD' | 'HH:mm:ss' | 'YYYY-MM-DD HH:mm:ss' = 'YYYY-MM-DD HH:mm:ss'): string { + if (!this.isValidTime(timeStr)) return '无效时间'; + + const date = new Date(timeStr); + const year = date.getFullYear(); + const month = this.padZero(date.getMonth() + 1); + const day = this.padZero(date.getDate()); + const hours = this.padZero(date.getHours()); + const minutes = this.padZero(date.getMinutes()); + const seconds = this.padZero(date.getSeconds()); + + switch (format) { + case 'YYYY-MM-DD': + return `${year}-${month}-${day}`; + case 'HH:mm:ss': + return `${hours}:${minutes}:${seconds}`; + case 'YYYY-MM-DD HH:mm:ss': + default: + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; + } + } + + /** + * 计算与当前时间的差值(格式为 HH:mm:ss) + * @param startTimeStr 起始时间字符串 + * @returns 格式化的时间差字符串 + */ + static calculateTimeDiff(startTimeStr: string): string { + if (!this.isValidTime(startTimeStr)) return ''; + + const startTime = new Date(startTimeStr).getTime(); + const nowTime = new Date().getTime(); + const diffMs = nowTime - startTime; + + // 处理未来时间 + if (diffMs < 0) { + return '00:00:00'; + } + + // 计算总秒数 + const totalSeconds = Math.floor(diffMs / 1000); + + // 计算时、分、秒 + const hours = this.padZero(Math.floor(totalSeconds / 3600)); + const minutes = this.padZero(Math.floor((totalSeconds % 3600) / 60)); + const seconds = this.padZero(totalSeconds % 60); + + return `${hours}:${minutes}:${seconds}`; + } + + /** + * 数字补零 + * @param num 数字 + * @returns 补零后的字符串 + */ + private static padZero(num: number): string { + return num < 10 ? `0${num}` : num.toString(); + } + + /** + * 创建一个时间差更新定时器 + * @param startTimeStr 起始时间字符串 + * @param callback 回调函数,接收计算后的时间差 + * @param interval 刷新间隔(毫秒) + * @returns 定时器ID,用于清除定时器 + */ + static createTimeDiffTimer( + startTimeStr: string, + callback: (diffText: string) => void, + interval: number = 1000 + ): number { + // 立即执行一次 + callback(this.calculateTimeDiff(startTimeStr)); + + // 设置定时器 + const timerId = window.setInterval(() => { + callback(this.calculateTimeDiff(startTimeStr)); + }, interval); + + return timerId; + } + + /** + * 清除时间差更新定时器 + * @param timerId 定时器ID + */ + static clearTimeDiffTimer(timerId: number | null): void { + if (timerId) { + clearInterval(timerId); + } + } +} \ No newline at end of file diff --git a/src/views/equipmentAlarmRecord/index.vue b/src/views/equipmentAlarmRecord/index.vue index 2d841fd..2321232 100644 --- a/src/views/equipmentAlarmRecord/index.vue +++ b/src/views/equipmentAlarmRecord/index.vue @@ -89,16 +89,16 @@