export function pxToMm(value) { // var inch = value / getDPI()[0]; let scale=1754/297; // var c_value = inch * 25.4; let result=value/scale; return parseFloat(result.toFixed(4));//保留四位小数 } // /** // * 像素转换成毫米 // * @param {number} px - 输入的像素值 // * @returns {number} - 转换后的毫米值,保留四位小数 // */ // export function pxToMm(px) { // if (px) { // const DPI = getDPI(); // 获取当前设备的 DPI // const MM_PER_INCH = 25.4; // 每英寸毫米数 // const mmValue = (px * MM_PER_INCH) / DPI; // return parseFloat(mmValue.toFixed(4)); // 保留四位小数 // } else { // console.log("px", px); // return 0; // } // } // 保留整数 小数 四舍五入 export function mmToPx(num) { if(num) { // console.log("num",num); // console.log("转换后",Math.round(1754/297*num)); // let scale=1754/297; // let result=(scale*num).toFixed(4); // console.log("scale",scale,result); let scale=1754/297; return parseFloat((scale*num).toFixed(4)); //高 150dpi 1754 96dpi:1120 1754*2480 // return Math.round(1754/297*num) } else { console.log("num",num); return 0; } } //获取考试背景颜色值 export function getExamBackgroundColor(type){ const examTypesColor = { "1": '#F56C6C',//期末 "2": '#3ba272',//期中 "3": '#ea7acb',//模拟 "4": '#fac858',//月考 "5": '#995fb3',//周测 "6": '#72C0DD',//平时 }; const result = examTypesColor[type]; return result; } // 获取分析报告成绩分析中默认的20个颜色 export function getScorePerformanceAnalysis() { return [ "#5470C6", "#3BA272", "#EE6666", "#FAC858", "#995FB3", "#72C0DD", "#90CB75", "#EA7ACB", "#FC8451", "#65789B", "#178BD3", "#26A616", "#A6129E", "#D3A141", "#234098", "#047640", "#B43535", "#848BDC", "#D6AF83", "#84313D", ] } // 文本截断:超过指定长度显示省略号 export function truncateText(text, maxLength) { if (!text) return ''; if (text.length > maxLength) { return text.substring(0, maxLength) + '...'; } return text; } // 去掉小数点后面为0的 如果不为0 最多只保留2位小数 export function getFormatNumber(numberStr) { // 尝试将字符串转为数字 const num = parseFloat(numberStr); // 检查是否为NaN(非数字情况) if (isNaN(num)) { return numberStr; } // 检查是否为整数(小数点后全为0) if (num % 1 === 0) { return num.toString(); } // 保留最多2位小数,并去除末尾的0 let formatted = num.toFixed(2); // 如果小数点后都是0,则返回整数形式 if (formatted.endsWith('.00')) { return formatted.split('.')[0]; } // 去除末尾的0(如1.50 → 1.5) formatted = formatted.replace(/\.?0+$/, ''); return formatted; } export function remainingDays(endTime) { if (!endTime) return null; const MS_PER_DAY = 24 * 60 * 60 * 1000; // 1) 将结束时间转为 Date 对象 const end = new Date(endTime); if (isNaN(end.getTime())) return null; // 2) 取今天的"零点"日期(精确到日,不考虑时分秒) const today = new Date(); const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 3) 取结束日期的"零点" const endStart = new Date(end.getFullYear(), end.getMonth(), end.getDate()); // 4) 计算天数差并 +1(含当天和结束天) const diffDays = Math.round((endStart.getTime() - todayStart.getTime()) / MS_PER_DAY); if (diffDays < 0) return 0; // 已过期:不显示剩余时间 return diffDays + 1; // 18号到22号:22-18=4,加1后=5天 } export function unioformDateTransform(date, param = "time"){ if(date){ let strDate = new Date(date).toLocaleString('zh-CN') let days = strDate.split(" ")[0] let time = strDate.split(" ")[1] let year = days.split("/")[0] let month = days.split("/")[1] let day = days.split("/")[2] if(Number(month)<10){ month = '0'+ month } if(Number(day)<10){ day = '0'+day } days = year+'-'+month+'-'+day switch(param){ case "day": return days case "time": return days + " " + time } }else{ return '' } } export const fileSizeConvert = (byte)=>{ let kbSize = 0 let mbSize = 0 let gbSize = 0 kbSize = (byte / 1024) if(kbSize > 1024){ mbSize = kbSize / 1024 if(mbSize > 1024){ gbSize = mbSize / 1024 return gbSize.toFixed(2) + 'GB' }else { return mbSize.toFixed(2) + 'MB' } }else{ return kbSize.toFixed(2) + 'KB' } }