common.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. export function pxToMm(value) {
  2. // var inch = value / getDPI()[0];
  3. let scale=1754/297;
  4. // var c_value = inch * 25.4;
  5. let result=value/scale;
  6. return parseFloat(result.toFixed(4));//保留四位小数
  7. }
  8. // /**
  9. // * 像素转换成毫米
  10. // * @param {number} px - 输入的像素值
  11. // * @returns {number} - 转换后的毫米值,保留四位小数
  12. // */
  13. // export function pxToMm(px) {
  14. // if (px) {
  15. // const DPI = getDPI(); // 获取当前设备的 DPI
  16. // const MM_PER_INCH = 25.4; // 每英寸毫米数
  17. // const mmValue = (px * MM_PER_INCH) / DPI;
  18. // return parseFloat(mmValue.toFixed(4)); // 保留四位小数
  19. // } else {
  20. // console.log("px", px);
  21. // return 0;
  22. // }
  23. // }
  24. // 保留整数 小数 四舍五入
  25. export function mmToPx(num) {
  26. if(num)
  27. {
  28. // console.log("num",num);
  29. // console.log("转换后",Math.round(1754/297*num));
  30. // let scale=1754/297;
  31. // let result=(scale*num).toFixed(4);
  32. // console.log("scale",scale,result);
  33. let scale=1754/297;
  34. return parseFloat((scale*num).toFixed(4)); //高 150dpi 1754 96dpi:1120 1754*2480
  35. // return Math.round(1754/297*num)
  36. }
  37. else
  38. {
  39. console.log("num",num);
  40. return 0;
  41. }
  42. }
  43. //获取考试背景颜色值
  44. export function getExamBackgroundColor(type){
  45. const examTypesColor = {
  46. "1": '#F56C6C',//期末
  47. "2": '#3ba272',//期中
  48. "3": '#ea7acb',//模拟
  49. "4": '#fac858',//月考
  50. "5": '#995fb3',//周测
  51. "6": '#72C0DD',//平时
  52. };
  53. const result = examTypesColor[type];
  54. return result;
  55. }
  56. // 获取分析报告成绩分析中默认的20个颜色
  57. export function getScorePerformanceAnalysis() {
  58. return [
  59. "#5470C6",
  60. "#3BA272",
  61. "#EE6666",
  62. "#FAC858",
  63. "#995FB3",
  64. "#72C0DD",
  65. "#90CB75",
  66. "#EA7ACB",
  67. "#FC8451",
  68. "#65789B",
  69. "#178BD3",
  70. "#26A616",
  71. "#A6129E",
  72. "#D3A141",
  73. "#234098",
  74. "#047640",
  75. "#B43535",
  76. "#848BDC",
  77. "#D6AF83",
  78. "#84313D",
  79. ]
  80. }
  81. // 去掉小数点后面为0的 如果不为0 最多只保留2位小数
  82. export function getFormatNumber(numberStr) {
  83. // 尝试将字符串转为数字
  84. const num = parseFloat(numberStr);
  85. // 检查是否为NaN(非数字情况)
  86. if (isNaN(num)) {
  87. return numberStr;
  88. }
  89. // 检查是否为整数(小数点后全为0)
  90. if (num % 1 === 0) {
  91. return num.toString();
  92. }
  93. // 保留最多2位小数,并去除末尾的0
  94. let formatted = num.toFixed(2);
  95. // 如果小数点后都是0,则返回整数形式
  96. if (formatted.endsWith('.00')) {
  97. return formatted.split('.')[0];
  98. }
  99. // 去除末尾的0(如1.50 → 1.5)
  100. formatted = formatted.replace(/\.?0+$/, '');
  101. return formatted;
  102. }