global.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. // 全局公共js方法库 2024-12-08
  2. export default {
  3. //获取考试背景对应的颜色
  4. getExamBackgroundColor(type) {
  5. let result = "#F56C6C";
  6. const examTypesColor = [
  7. {
  8. type: 1,
  9. title: "期末",
  10. color: "#F56C6C",
  11. background: "#F56C6C",
  12. }, //期末
  13. {
  14. type: 2,
  15. title: "期中",
  16. color: "#3ba272",
  17. background: "#3ba272",
  18. }, //期中
  19. {
  20. type: 3,
  21. title: "模拟",
  22. color: "#ea7acb",
  23. background: "#ea7acb",
  24. }, //模拟
  25. {
  26. type: 4,
  27. title: "月考",
  28. color: "#fac858",
  29. background: "#fac858",
  30. }, //月考
  31. {
  32. type: 5,
  33. title: "周测",
  34. color: "#995fb3",
  35. background: "#995fb3",
  36. }, //周测
  37. {
  38. type: 6,
  39. title: "平时",
  40. color: "#72C0DD",
  41. background: "#72C0DD",
  42. }, //平时
  43. ];
  44. for (let i = 0; i < examTypesColor.length; i++) {
  45. if (examTypesColor[i].type == type || examTypesColor[i].title == type) {
  46. result = examTypesColor[i].background;
  47. break;
  48. }
  49. }
  50. // console.log("打印颜色值",type,result);
  51. return result;
  52. },
  53. //获取五率对应的颜色值
  54. getFiveRateColor(type)
  55. {
  56. let list=[
  57. {
  58. name: "top",
  59. color: "#5470C6",
  60. },
  61. {
  62. name: "excellent",
  63. color: "#3BA272",
  64. },
  65. {
  66. name: "good",
  67. color: "#FAC858",
  68. },
  69. {
  70. name: "pass",
  71. color: "#995FB3",
  72. },
  73. {
  74. name: "low",
  75. color: "#EE6666",
  76. }
  77. ];//五率颜色配置
  78. return list.find((item) => item.name === type)?.color || "#5470C6";//默认5470C6颜色
  79. },
  80. //获取五率对应的颜色值
  81. getSchoolFiveRateColor(type)
  82. {
  83. let list=[
  84. {
  85. name: "high",
  86. color: "#5470C6",
  87. },
  88. {
  89. name: "good",
  90. color: "#3BA272",
  91. },
  92. {
  93. name: "fine",
  94. color: "#FAC858",
  95. },
  96. {
  97. name: "pass",
  98. color: "#995FB3",
  99. },
  100. {
  101. name: "low",
  102. color: "#EE6666",
  103. }
  104. ];//五率颜色配置
  105. return list.find((item) => item.name === type)?.color || "#5470C6";//默认5470C6颜色
  106. },
  107. // 获取分析报告成绩分析中默认的20个颜色
  108. getScorePerformanceAnalysis() {
  109. return [
  110. "#5470C6",
  111. "#3BA272",
  112. "#EE6666",
  113. "#FAC858",
  114. "#995FB3",
  115. "#72C0DD",
  116. "#90CB75",
  117. "#EA7ACB",
  118. "#FC8451",
  119. "#65789B",
  120. "#178BD3",
  121. "#26A616",
  122. "#A6129E",
  123. "#D3A141",
  124. "#234098",
  125. "#047640",
  126. "#B43535",
  127. "#848BDC",
  128. "#D6AF83",
  129. "#84313D",
  130. //20个颜色一组
  131. "#5470C6",
  132. "#3BA272",
  133. "#EE6666",
  134. "#FAC858",
  135. "#995FB3",
  136. "#72C0DD",
  137. "#90CB75",
  138. "#EA7ACB",
  139. "#FC8451",
  140. "#65789B",
  141. "#178BD3",
  142. "#26A616",
  143. "#A6129E",
  144. "#D3A141",
  145. "#234098",
  146. "#047640",
  147. "#B43535",
  148. "#848BDC",
  149. "#D6AF83",
  150. "#84313D",
  151. //
  152. "#5470C6",
  153. "#3BA272",
  154. "#EE6666",
  155. "#FAC858",
  156. "#995FB3",
  157. "#72C0DD",
  158. "#90CB75",
  159. "#EA7ACB",
  160. "#FC8451",
  161. "#65789B",
  162. "#178BD3",
  163. "#26A616",
  164. "#A6129E",
  165. "#D3A141",
  166. "#234098",
  167. "#047640",
  168. "#B43535",
  169. "#848BDC",
  170. "#D6AF83",
  171. "#84313D",
  172. ];
  173. },
  174. //获取G组 G10-G1对应的颜色值
  175. getGGroupColor() {
  176. return [
  177. {
  178. name: "G1",
  179. color: "#5470C6",
  180. },
  181. {
  182. name: "G2",
  183. color: "#90CB75",
  184. },
  185. {
  186. name: "G3",
  187. color: "#D3A141",
  188. },
  189. {
  190. name: "G4",
  191. color: "#EE6666",
  192. },
  193. {
  194. name: "G5",
  195. color: "#72C0DD",
  196. },
  197. {
  198. name: "G6",
  199. color: "#3BA272",
  200. },
  201. {
  202. name: "G7",
  203. color: "#FC8451",
  204. },
  205. {
  206. name: "G8",
  207. color: "#995FB3",
  208. },
  209. {
  210. name: "G9",
  211. color: "#EA7ACB",
  212. },
  213. {
  214. name: "G10",
  215. color: "#FAC858",
  216. },
  217. ];
  218. },
  219. //获取G组 g10-g1对应的颜色值
  220. getgGroupColor() {
  221. return [
  222. {
  223. name: "g1",
  224. color: "#5470C6",
  225. },
  226. {
  227. name: "g2",
  228. color: "#90CB75",
  229. },
  230. {
  231. name: "g3",
  232. color: "#D3A141",
  233. },
  234. {
  235. name: "g4",
  236. color: "#EE6666",
  237. },
  238. {
  239. name: "g5",
  240. color: "#72C0DD",
  241. },
  242. {
  243. name: "g6",
  244. color: "#3BA272",
  245. },
  246. {
  247. name: "g7",
  248. color: "#FC8451",
  249. },
  250. {
  251. name: "g8",
  252. color: "#995FB3",
  253. },
  254. {
  255. name: "g9",
  256. color: "#EA7ACB",
  257. },
  258. {
  259. name: "g10",
  260. color: "#FAC858",
  261. },
  262. ];
  263. },
  264. //获取百分比 type progress 表示进度条使用
  265. getPercentage(num1, num2, type) {
  266. let result = 0;
  267. let percentage = 0;
  268. if (num1 && num2) {
  269. percentage = (parseFloat(num1) / parseFloat(num2)).toFixed(2);
  270. }
  271. result = Math.round(percentage * 100);
  272. // console.log("num1,num2",num1,num2,percentage,result);
  273. if (type == "progress") {
  274. //进度条的值不能超100%
  275. if (result > 100) {
  276. result = 100;
  277. }
  278. }
  279. if (result < 0) {
  280. result = 0;
  281. }
  282. // console.log("打印结果",result);
  283. return result;
  284. },
  285. //获取当前日期 返回的格式为yyyy-MM-dd hh:mm:ss
  286. getNowDate(format = "yyyy-mm-dd") {
  287. const now = new Date();
  288. const year = now.getFullYear();
  289. const month = String(now.getMonth() + 1).padStart(2, "0");
  290. const date = String(now.getDate()).padStart(2, "0");
  291. const hours = String(now.getHours()).padStart(2, "0");
  292. const minutes = String(now.getMinutes()).padStart(2, "0");
  293. const seconds = String(now.getSeconds()).padStart(2, "0");
  294. switch (format) {
  295. case "yyyy-mm-dd":
  296. return `${year}-${month}-${date}`;
  297. case "yyyy-mm-dd hh:mm:ss":
  298. return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
  299. case "yyyy-mm-dd hh:mm":
  300. return `${year}-${month}-${date} ${hours}:${minutes}`;
  301. // 可以根据需要添加更多格式
  302. case "yyyy年mm月dd日 hh:mm:ss":
  303. return `${year}年${month}月${date}日 ${hours}:${minutes}:${seconds}`;
  304. default:
  305. return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
  306. }
  307. },
  308. // 时间戳转换为时间字符串
  309. getTimestamp(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
  310. // console.log('timestamp', timestamp);
  311. if (!timestamp && timestamp !== 0) return '';
  312. // 处理不同格式的时间戳
  313. let timeValue = timestamp;
  314. // 如果是字符串,尝试转换为数字
  315. if (typeof timeValue === 'string') {
  316. timeValue = Number(timeValue);
  317. }
  318. // 检查是否为有效数字
  319. if (isNaN(timeValue) || timeValue < 0) return '';
  320. // 处理秒级时间戳(10位数字)
  321. if (timeValue.toString().length === 10) {
  322. timeValue = timeValue * 1000;
  323. }
  324. // 处理毫秒级时间戳(13位数字)
  325. const date = new Date(timeValue);
  326. // 检查日期是否有效
  327. if (isNaN(date.getTime())) return '';
  328. const year = date.getFullYear();
  329. const month = String(date.getMonth() + 1).padStart(2, '0');
  330. const day = String(date.getDate()).padStart(2, '0');
  331. const hours = String(date.getHours()).padStart(2, '0');
  332. const minutes = String(date.getMinutes()).padStart(2, '0');
  333. const seconds = String(date.getSeconds()).padStart(2, '0');
  334. return format
  335. .replace('YYYY', year)
  336. .replace('MM', month)
  337. .replace('DD', day)
  338. .replace('HH', hours)
  339. .replace('mm', minutes)
  340. .replace('ss', seconds);
  341. },
  342. // 保留小数点后几位 str 数值 fixed 小数点后保留位数
  343. floatNum(str, fixed) {
  344. // console.log("打印参数",str,fixed);
  345. if (str == null || str == undefined || str == "") {
  346. return 0;
  347. } else {
  348. const num = parseFloat(str);
  349. if (isNaN(num)) {
  350. throw new Error("Invalid number string");
  351. }
  352. return parseFloat(num.toFixed(fixed));
  353. }
  354. },
  355. // 去掉小数点后面为0的 如果不为0 最多只保留2位小数
  356. getFormatNumber(numberStr)
  357. {
  358. // 尝试将字符串转为数字
  359. const num = parseFloat(numberStr);
  360. // 检查是否为NaN(非数字情况)
  361. if (isNaN(num)) {
  362. return numberStr;
  363. }
  364. // 检查是否为整数(小数点后全为0)
  365. if (num % 1 === 0) {
  366. return num.toString();
  367. }
  368. // 保留最多2位小数,并去除末尾的0
  369. let formatted = num.toFixed(2);
  370. // 如果小数点后都是0,则返回整数形式
  371. if (formatted.endsWith('.00')) {
  372. return formatted.split('.')[0];
  373. }
  374. // 去除末尾的0(如1.50 → 1.5)
  375. formatted = formatted.replace(/\.?0+$/, '');
  376. return formatted;
  377. },
  378. //过滤掉html标签的方法
  379. getStripHtmlTags(str) {
  380. // 创建一个新的 div 元素
  381. const tempDiv = document.createElement("div");
  382. // 将 HTML 字符串设置为 div 的 innerHTML
  383. tempDiv.innerHTML = str;
  384. // 返回 div 的 textContent,这将去除所有 HTML 标签
  385. return tempDiv.textContent || tempDiv.innerText;
  386. },
  387. //获取评阅类型 单评还是双评等
  388. getRatingType(type) {
  389. let result = "单评";
  390. if (type == 1) {
  391. result = "单评";
  392. } else if (type == 2) {
  393. result = "2评0补0审";
  394. } else if (type == 3) {
  395. result = "2评1补0审";
  396. } else if (type == 4) {
  397. result = "2评0补1审";
  398. } else if (type == 5) {
  399. result = "2评1补1审";
  400. }
  401. return result;
  402. },
  403. //根据起始题号,结束题号,题号间隔获取题号列表
  404. getTopicNumberList(startNumber, endNumber, interval) {
  405. const topicNumberList = [];
  406. for (let i = startNumber; i <= endNumber; i += interval) {
  407. topicNumberList.push(i);
  408. }
  409. // console.log("打印题号列表",topicNumberList);
  410. return topicNumberList;
  411. },
  412. //获取科目图片名称 根据汉字
  413. getSubjectsName(value,count,type)
  414. {
  415. let name=value;
  416. if(count==0)
  417. {
  418. }
  419. else
  420. {
  421. switch (count) {
  422. case 1:
  423. name="其他";
  424. break;
  425. case 2:
  426. name="二科";
  427. break;
  428. case 3:
  429. name="三科";
  430. break;
  431. case 4:
  432. name="四科";
  433. break;
  434. case 5:
  435. name="五科";
  436. break;
  437. case 6:
  438. name="六科";
  439. break;
  440. case 7:
  441. name="七科";
  442. break;
  443. case 8:
  444. name="八科";
  445. break;
  446. case 9:
  447. name="九科";
  448. break;
  449. }
  450. }
  451. const subjectList = [
  452. {
  453. name: "生物",
  454. image: "biology.png",
  455. color: "#3BA272",
  456. },
  457. {
  458. name: "化学",
  459. image: "chemistry.png",
  460. color: "#73C0DE",
  461. },
  462. {
  463. name: "语文",
  464. image: "chinese.png",
  465. color: "#91CC75",
  466. },
  467. {
  468. name: "道德与法治",
  469. image: "daofa.png",
  470. color: "#FF869D",
  471. },
  472. {
  473. name: "八科",
  474. image: "eight_subject.png",
  475. color: "#3BA272",
  476. },
  477. {
  478. name: "英语",
  479. image: "english.png",
  480. color: "#EE6666",
  481. },
  482. {
  483. name: "五科",
  484. image: "five_subject.png",
  485. color: "#63A1FF",
  486. },
  487. {
  488. name: "四科",
  489. image: "four_subject.png",
  490. color: "#FF869D",
  491. },
  492. {
  493. name: "地理",
  494. image: "geography.png",
  495. color: "#9A60B4",
  496. },
  497. {
  498. name: "历史",
  499. image: "history.png",
  500. color: "#FC8452",
  501. },
  502. {
  503. name: "信息",
  504. image: "information.png",
  505. color: "#63A1FF",
  506. },
  507. {
  508. name: "数学",
  509. image: "math.png",
  510. color: "#FAC858",
  511. },
  512. {
  513. name: "九科",
  514. image: "nine_subject.png",
  515. color: "#EE6666",
  516. },
  517. {
  518. name: "其他",
  519. image: "other.png",
  520. color: "#C495FA",
  521. },
  522. {
  523. name: "物理",
  524. image: "physics.png",
  525. color: "#817BE2",
  526. },
  527. {
  528. name: "政治",
  529. image: "politics.png",
  530. color: "#63A1FF",
  531. },
  532. {
  533. name: "七科",
  534. image: "seven_subject.png",
  535. color: "#FC8452",
  536. },
  537. {
  538. name: "六科",
  539. image: "six_subject.png",
  540. color: "#9A60B4",
  541. },
  542. {
  543. name: "体育",
  544. image: "sport.png",
  545. color: "#FF8B8B",
  546. },
  547. {
  548. name: "三科",
  549. image: "three_subject.png",
  550. color: "#5CC1F6",
  551. },
  552. {
  553. name: "二科",
  554. image: "two_subject.webp",
  555. color: "#C495FA",
  556. },
  557. {
  558. name: "总分",
  559. image: "totalScore.png",
  560. color: "#325AD4",
  561. },
  562. {
  563. name: "通用",
  564. image: "tongyong.png",
  565. color: "#5CC1F6",
  566. },
  567. {
  568. name: "地理学考",
  569. image: "geography_exam.webp",
  570. color: "#9A60B4",
  571. },
  572. {
  573. name: "化学学考",
  574. image: "chemistry_exam.webp",
  575. color: "#73C0DE",
  576. },
  577. {
  578. name: "历史学考",
  579. image: "history_exam.webp",
  580. color: "#FC8452",
  581. },
  582. {
  583. name: "生物学考",
  584. image: "biology_exam.webp",
  585. color: "#3BA272",
  586. },
  587. {
  588. name: "物理学考",
  589. image: "physics_exam.webp",
  590. color: "#817BE2",
  591. },
  592. {
  593. name: "政治学考",
  594. image: "politics_exam.webp",
  595. color: "#63A1FF",
  596. }
  597. ];
  598. let result = subjectList.find((item) => item.name === name);
  599. if(result)
  600. {
  601. if(type && type == 'color') {
  602. return result.color;
  603. }else {
  604. return result.image;
  605. }
  606. }
  607. else
  608. {
  609. if(type && type == 'color') {
  610. return '#C495FA';
  611. }else {
  612. return "other.png"
  613. }
  614. }
  615. },
  616. //包含0的正整数 包含0的正整数但不是以0开头的多位正整数 '00'、'01' 和 '0001' 都不会被匹配
  617. isNumber(str){
  618. const regex = /^(?:[1-9][0-9]*|0)$/;
  619. return regex.test(str);
  620. },
  621. //根据当前值 获取最大值 echarts 图表使用
  622. getMaxValue(value)
  623. {
  624. const thresholdMap =[
  625. {
  626. maxThreshold:0.3,//最大阈值0-0.6
  627. bound:0.3,//边界值
  628. },
  629. {
  630. maxThreshold:0.6,//最大阈值0-0.6
  631. bound:0.6,//边界值
  632. },
  633. {
  634. maxThreshold:1,//最大阈值 0.6 - 1
  635. bound:1,//边界值
  636. },
  637. {
  638. maxThreshold:1.5,//最大阈值 0.6 - 1
  639. bound:1.5,//边界值
  640. },
  641. {
  642. maxThreshold:2,//最大阈值
  643. bound:2,//边界值
  644. },
  645. {
  646. maxThreshold:4,//最大阈值
  647. bound:4,//边界值
  648. },
  649. {
  650. maxThreshold:8,//最大阈值
  651. bound:8,//边界值
  652. },
  653. {
  654. maxThreshold:10,//最大阈值
  655. bound:10,//边界值
  656. },
  657. {
  658. maxThreshold:20,//最大阈值
  659. bound:20,//边界值
  660. },
  661. {
  662. maxThreshold:30,//最大阈值
  663. bound:30,//边界值
  664. },
  665. {
  666. maxThreshold:40,//最大阈值
  667. bound:40,//边界值
  668. },
  669. {
  670. maxThreshold:50,//最大阈值
  671. bound:50,//边界值
  672. },
  673. {
  674. maxThreshold:60,//最大阈值
  675. bound:60,//边界值
  676. },
  677. {
  678. maxThreshold:70,//最大阈值
  679. bound:70,//边界值
  680. },
  681. {
  682. maxThreshold:80,//最大阈值
  683. bound:80,//边界值
  684. },
  685. {
  686. maxThreshold:90,//最大阈值
  687. bound:90,//边界值
  688. },
  689. {
  690. maxThreshold:100,//最大阈值
  691. bound:100,//边界值
  692. },
  693. {
  694. maxThreshold:120,//最大阈值
  695. bound:120,//边界值
  696. },
  697. {
  698. maxThreshold:150,//最大阈值
  699. bound:150,//边界值
  700. },
  701. {
  702. maxThreshold:180,//最大阈值
  703. bound:180,//边界值
  704. },
  705. {
  706. maxThreshold:200,//最大阈值
  707. bound:200,//边界值
  708. },
  709. {
  710. maxThreshold:250,//最大阈值
  711. bound:250,//边界值
  712. },
  713. {
  714. maxThreshold:200,//最大阈值
  715. bound:200,//边界值
  716. },
  717. {
  718. maxThreshold:300,//最大阈值
  719. bound:300,//边界值
  720. },
  721. {
  722. maxThreshold:350,//最大阈值
  723. bound:350,//边界值
  724. },
  725. {
  726. maxThreshold:400,//最大阈值
  727. bound:400,//边界值
  728. },
  729. {
  730. maxThreshold:450,//最大阈值
  731. bound:450,//边界值
  732. },
  733. {
  734. maxThreshold:500,//最大阈值
  735. bound:500,//边界值
  736. },
  737. {
  738. maxThreshold:600,//最大阈值
  739. bound:600,//边界值
  740. },
  741. {
  742. maxThreshold:700,//最大阈值
  743. bound:700,//边界值
  744. },
  745. ];//配置区间规则
  746. //查找匹配的边界值
  747. const matchedRule = thresholdMap.find(({ maxThreshold }) => value < maxThreshold);
  748. // 处理超过阈值的情况(≥5)
  749. const bound = matchedRule
  750. ? matchedRule.bound
  751. : Math.ceil((value) / 10) * 10;
  752. // console.log("打印",value);
  753. // console.log("打印边界值",bound);
  754. return bound;
  755. },
  756. };