// 创建 BroadcastChannel const channel = new BroadcastChannel('data_channel'); /** * @param {*value 当前日期基础上添加、减天数} value * @returns 返回天数后的日期 格式为:yyyy-MM-dd hh:mm:ss * 目前多为保存数据是取当前日期时间 */ function timescopePlus(AddDay) { if (AddDay == undefined) AddDay = 0; var date = new Date(); date.setDate(date.getDate() + Number(AddDay)); var year = date.getFullYear().toString(); var month = (date.getMonth() + 1); var day = date.getDate().toString(); var hour = date.getHours().toString(); var minutes = date.getMinutes().toString(); var seconds = date.getSeconds().toString(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (hour < 10) { hour = "0" + hour; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } /** * @param {*传入日期} mDate * @returns 返回日期 格式为:yyyy-MM-dd hh:mm:ss * 日前为显示dbgrid日期转换格式 */ Time_format = function (mDate) { let result = ''; if (mDate != '' && mDate != undefined) { var date = new Date(mDate); var year = date.getFullYear().toString(); var month = (date.getMonth() + 1); var day = date.getDate().toString(); var hour = date.getHours().toString(); var minutes = date.getMinutes().toString(); var seconds = date.getSeconds().toString(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (hour < 10) { hour = "0" + hour; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } if (mDate.toString().search('GMT') != -1) { result = year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } else if (mDate.toString() == '') { result = ' '; } else { result = year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } } return result; } Time_formats = function (mDate) { console.log(mDate); let result = ''; if (mDate != '' && mDate != undefined) { var date = new Date(mDate); console.log(date); var year = date.getFullYear().toString(); var month = (date.getMonth() + 1); var day = date.getDate().toString(); var hour = date.getHours().toString(); var minutes = date.getMinutes().toString(); var seconds = date.getSeconds().toString(); if (month < 10) { month = "0" + month; } if (day < 10) { day = "0" + day; } if (hour < 10) { hour = "0" + hour; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } if (mDate.toString().search('GMT') != -1) { result = year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } else if (mDate.toString() == '') { result = ' '; } else { result = year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } } console.log(result); return result; } class CountUp { constructor(element, startValue, endValue, duration, options = {}) { this.element = document.querySelector(element); console.log(element) this.startValue = startValue; this.endValue = endValue; this.duration = duration; this.options = options; this.frameDuration = 1000 / 60; // 每秒60帧 this.frameStart = null; this.currentValue = startValue; this.isRunning = false; } // 启动动画 start() { if (this.isRunning) return; this.isRunning = true; this.frameStart = null; requestAnimationFrame(this.animate.bind(this)); } // 动画函数 animate(timestamp) { if (!this.frameStart) { this.frameStart = timestamp; } const progress = Math.min((timestamp - this.frameStart) / this.duration, 1); // 计算动画进度 this.currentValue = this.lerp(this.startValue, this.endValue, progress); // 线性插值 this.updateDisplay(); if (progress < 1) { requestAnimationFrame(this.animate.bind(this)); // 继续动画 } else { this.isRunning = false; } } // 线性插值函数 lerp(start, end, progress) { return start + (end - start) * progress; } // 更新显示的数值 updateDisplay() { this.element.textContent = this.formatNumber(this.currentValue); } // 格式化数字(可以添加分隔符,保留小数等) formatNumber(number) { return this.options.useComma ? number.toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 0 }) : number.toFixed(0); } } // 视口滚动到底部 function is_scrollTop() { var communicationContainer = document.getElementById('communicationId'); // 检查元素是否存在 if (communicationContainer) { // 将滚动条位置设置为内容的高度,实现滚动到底部 communicationContainer.scrollTop = communicationContainer.scrollHeight; } else { console.error('聊天内容容器不存在'); } } // window.onerror = function(message, source, lineno, colno, error) { // console.log('资源加载失败:', message, source, lineno, colno, error); // // 进行相应处理,比如重定向到404页面 // window.location.href = '/src/blue/uimaker/404.html'; // }; // window.addEventListener('error', function (e) { // console.log(e); // // 进行相应处理,比如重定向到404页面 // window.location.href = '/src/blue/uimaker/404.html'; // }); // 消息提示框5秒内自动消失 /** * * @param {string} state 状态类型>>>>>>成功:succeedd|失败:error|警告: hint * @param {string} name 提示的内容 */ var isThrottled = false // 定义一个映射对象,用于存储不同状态的样式 const alertStyles = { succeed: { name: '成功', background: '#d4edda', color: '#155724', borderColor: '#c3e6cb' }, error: { name: '失败', background: '#f8d7da', color: '#721c24', borderColor: '#f5c6cb' }, hint: { name: '警告', background: '#fff3cd', color: '#856404', borderColor: '#ffeeba' } }; // 创建一个用于存储alertDiv引用的变量 let alertDiv; function showAlert(state, name) { // 如果alertDiv不存在,则创建并添加到body中 if (!alertDiv) { alertDiv = document.createElement('div'); alertDiv.id = 'alertDiv'; alertDiv.style.display = 'flex'; // 设置为Flexbox布局 alertDiv.style.flexDirection = 'column'; // 子元素垂直排列 document.body.appendChild(alertDiv); } // 获取状态对应的样式 const styleObj = alertStyles[state]; if (!styleObj) { console.error(`Unknown alert state: ${state}`); return; } // 创建alertContainer元素,并设置样式 const alertContainer = document.createElement('div'); alertContainer.className = 'alertContainer'; alertContainer.style.background = styleObj.background; alertContainer.style.color = styleObj.color; alertContainer.style.borderColor = styleObj.borderColor; alertContainer.innerHTML = name; alertContainer.style.opacity = 1; // 初始设置为完全可见 // 将新的alertContainer添加到alertDiv中,并显示 alertDiv.appendChild(alertContainer); alertContainer.classList.add('show'); // 为每条消息单独设置消失计时器 setTimeout(() => { fadeAndRemove(alertContainer); },2000); } // 添加一个函数来逐渐淡出并移除alertContainer function fadeAndRemove(element) { let opacity = 1; // 初始透明度 const fadeInterval = 50; // 淡出间隔(毫秒) const fadeSteps = 10; // 淡出步骤数 const fadeOut = setInterval(() => { opacity -= 1 / fadeSteps; // 减少透明度 if (opacity <= 0) { clearInterval(fadeOut); // 停止淡出 element.remove(); // 移除元素 } else { element.style.opacity = opacity; // 更新透明度 } }, fadeInterval); } let page = 1; let size = '10'; let ttlpage; /** * @param {*侧边栏用户列表calss类名} element_userUl * @param {*聊天内容class类名} element_communication * @param {*发送者IKEY} staff_IKEY * @param {*聊天内容class类名} scrollTop * **/ // 聊天侧边栏用户显示 async function isUserlsit(element_userUl, element_communication, staff_IKEY, scrollTop) { page = 1 console.log(page); // 获取 MQTT 列表 console.log(staff_IKEY); let rest = getMqttList(staff_IKEY).rows; console.log(rest); // 更新用户列表 rest.forEach(function (item, index) { console.log(item); let msgStatus = isReadMsg(item.SEND_STAFF_IKEY, true) let msgHtml = `
` let listItem = `