global.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  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. // 获取分析报告成绩分析中默认的20个颜色
  175. getCompareAnalysis() {
  176. return [
  177. "#EE6666",
  178. "#5470C6",
  179. "#3BA272",
  180. "#FAC858",
  181. "#995FB3",
  182. "#72C0DD",
  183. "#90CB75",
  184. "#EA7ACB",
  185. "#FC8451",
  186. "#65789B",
  187. "#178BD3",
  188. "#26A616",
  189. "#A6129E",
  190. "#D3A141",
  191. "#234098",
  192. "#047640",
  193. "#B43535",
  194. "#848BDC",
  195. "#D6AF83",
  196. "#84313D",
  197. //20个颜色一组
  198. "#EE6666",
  199. "#5470C6",
  200. "#3BA272",
  201. "#FAC858",
  202. "#995FB3",
  203. "#72C0DD",
  204. "#90CB75",
  205. "#EA7ACB",
  206. "#FC8451",
  207. "#65789B",
  208. "#178BD3",
  209. "#26A616",
  210. "#A6129E",
  211. "#D3A141",
  212. "#234098",
  213. "#047640",
  214. "#B43535",
  215. "#848BDC",
  216. "#D6AF83",
  217. "#84313D",
  218. ];
  219. },
  220. //获取G组 G10-G1对应的颜色值
  221. getGGroupColor() {
  222. return [
  223. {
  224. name: "G1",
  225. color: "#5470C6",
  226. },
  227. {
  228. name: "G2",
  229. color: "#90CB75",
  230. },
  231. {
  232. name: "G3",
  233. color: "#D3A141",
  234. },
  235. {
  236. name: "G4",
  237. color: "#EE6666",
  238. },
  239. {
  240. name: "G5",
  241. color: "#72C0DD",
  242. },
  243. {
  244. name: "G6",
  245. color: "#3BA272",
  246. },
  247. {
  248. name: "G7",
  249. color: "#FC8451",
  250. },
  251. {
  252. name: "G8",
  253. color: "#995FB3",
  254. },
  255. {
  256. name: "G9",
  257. color: "#EA7ACB",
  258. },
  259. {
  260. name: "G10",
  261. color: "#FAC858",
  262. },
  263. ];
  264. },
  265. //获取G组 g10-g1对应的颜色值
  266. getgGroupColor() {
  267. return [
  268. {
  269. name: "g1",
  270. color: "#5470C6",
  271. },
  272. {
  273. name: "g2",
  274. color: "#90CB75",
  275. },
  276. {
  277. name: "g3",
  278. color: "#D3A141",
  279. },
  280. {
  281. name: "g4",
  282. color: "#EE6666",
  283. },
  284. {
  285. name: "g5",
  286. color: "#72C0DD",
  287. },
  288. {
  289. name: "g6",
  290. color: "#3BA272",
  291. },
  292. {
  293. name: "g7",
  294. color: "#FC8451",
  295. },
  296. {
  297. name: "g8",
  298. color: "#995FB3",
  299. },
  300. {
  301. name: "g9",
  302. color: "#EA7ACB",
  303. },
  304. {
  305. name: "g10",
  306. color: "#FAC858",
  307. },
  308. ];
  309. },
  310. //G组颜色
  311. gGroupColor(){
  312. return [
  313. '#FAC858','#EA7ACB','#995FB3','#FC8451','#3BA272','#72C0DD','#EE6666','#D3A141','#90CB75','#5470C6',
  314. '#65789B','#178BD3','#26A616','#A6129E','#234098','#047640','#B43535','#848BDC','#D6AF83','#84313D',
  315. ]
  316. },
  317. // G组柱子颜色
  318. gGroupBarColor(){
  319. return ['#848BDC','#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC','#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC','#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0']
  320. },
  321. //知识点分层柱子颜色
  322. knowledgeBarColor(){
  323. return [
  324. '#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC',
  325. '#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC',
  326. '#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC',
  327. '#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC',
  328. '#E999AA','#8CCCB1','#B5DDEE','#F4DBC6','#D2B2E2','#F4DFA0','#848BDC',
  329. ];
  330. },
  331. //知识点分层层级颜色
  332. knowledgeLayeredColor(){
  333. return [
  334. '#5470C6','#3BA272','#FAC858','#995FB3','#EE6666','#72C0DD','#90CB75','#EA7ACB','#FC8451','#65789B',
  335. '#5470C6','#3BA272','#FAC858','#995FB3','#EE6666','#72C0DD','#90CB75','#EA7ACB','#FC8451','#65789B',
  336. '#5470C6','#3BA272','#FAC858','#995FB3','#EE6666','#72C0DD','#90CB75','#EA7ACB','#FC8451','#65789B'
  337. ]
  338. },
  339. //获取百分比 type progress 表示进度条使用
  340. getPercentage(num1, num2, type) {
  341. let result = 0;
  342. let percentage = 0;
  343. if (num1 && num2) {
  344. percentage = (parseFloat(num1) / parseFloat(num2)).toFixed(2);
  345. }
  346. result = Math.round(percentage * 100);
  347. // console.log("num1,num2",num1,num2,percentage,result);
  348. if (type == "progress") {
  349. //进度条的值不能超100%
  350. if (result > 100) {
  351. result = 100;
  352. }
  353. }
  354. if (result < 0) {
  355. result = 0;
  356. }
  357. // console.log("打印结果",result);
  358. return result;
  359. },
  360. //获取当前日期 返回的格式为yyyy-MM-dd hh:mm:ss
  361. getNowDate(format = "yyyy-mm-dd") {
  362. const now = new Date();
  363. const year = now.getFullYear();
  364. const month = String(now.getMonth() + 1).padStart(2, "0");
  365. const date = String(now.getDate()).padStart(2, "0");
  366. const hours = String(now.getHours()).padStart(2, "0");
  367. const minutes = String(now.getMinutes()).padStart(2, "0");
  368. const seconds = String(now.getSeconds()).padStart(2, "0");
  369. switch (format) {
  370. case "yyyy-mm-dd":
  371. return `${year}-${month}-${date}`;
  372. case "yyyy-mm-dd hh:mm:ss":
  373. return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
  374. case "yyyy-mm-dd hh:mm":
  375. return `${year}-${month}-${date} ${hours}:${minutes}`;
  376. // 可以根据需要添加更多格式
  377. case "yyyy年mm月dd日 hh:mm:ss":
  378. return `${year}年${month}月${date}日 ${hours}:${minutes}:${seconds}`;
  379. default:
  380. return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
  381. }
  382. },
  383. // 时间戳转换为时间字符串
  384. getTimestamp(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
  385. // console.log('timestamp', timestamp);
  386. if (!timestamp && timestamp !== 0) return '';
  387. // 处理不同格式的时间戳
  388. let timeValue = timestamp;
  389. // 如果是字符串,尝试转换为数字
  390. if (typeof timeValue === 'string') {
  391. timeValue = Number(timeValue);
  392. }
  393. // 检查是否为有效数字
  394. if (isNaN(timeValue) || timeValue < 0) return '';
  395. // 处理秒级时间戳(10位数字)
  396. if (timeValue.toString().length === 10) {
  397. timeValue = timeValue * 1000;
  398. }
  399. // 处理毫秒级时间戳(13位数字)
  400. const date = new Date(timeValue);
  401. // 检查日期是否有效
  402. if (isNaN(date.getTime())) return '';
  403. const year = date.getFullYear();
  404. const month = String(date.getMonth() + 1).padStart(2, '0');
  405. const day = String(date.getDate()).padStart(2, '0');
  406. const hours = String(date.getHours()).padStart(2, '0');
  407. const minutes = String(date.getMinutes()).padStart(2, '0');
  408. const seconds = String(date.getSeconds()).padStart(2, '0');
  409. return format
  410. .replace('YYYY', year)
  411. .replace('MM', month)
  412. .replace('DD', day)
  413. .replace('HH', hours)
  414. .replace('mm', minutes)
  415. .replace('ss', seconds);
  416. },
  417. // 保留小数点后几位 str 数值 fixed 小数点后保留位数
  418. floatNum(str, fixed) {
  419. // console.log("打印参数",str,fixed);
  420. if (str == null || str == undefined || str == "") {
  421. return 0;
  422. } else {
  423. const num = parseFloat(str);
  424. if (isNaN(num)) {
  425. throw new Error("Invalid number string");
  426. }
  427. return parseFloat(num.toFixed(fixed));
  428. }
  429. },
  430. // 去掉小数点后面为0的 如果不为0 最多只保留2位小数
  431. getFormatNumber(numberStr)
  432. {
  433. // 尝试将字符串转为数字
  434. const num = parseFloat(numberStr);
  435. // 检查是否为NaN(非数字情况)
  436. if (isNaN(num)) {
  437. return numberStr;
  438. }
  439. // 检查是否为整数(小数点后全为0)
  440. if (num % 1 === 0) {
  441. return num.toString();
  442. }
  443. // 保留最多2位小数,并去除末尾的0
  444. let formatted = num.toFixed(2);
  445. // 如果小数点后都是0,则返回整数形式
  446. if (formatted.endsWith('.00')) {
  447. return formatted.split('.')[0];
  448. }
  449. // 去除末尾的0(如1.50 → 1.5)
  450. formatted = formatted.replace(/\.?0+$/, '');
  451. return formatted;
  452. },
  453. //过滤掉html标签的方法
  454. getStripHtmlTags(str) {
  455. // 创建一个新的 div 元素
  456. const tempDiv = document.createElement("div");
  457. // 将 HTML 字符串设置为 div 的 innerHTML
  458. tempDiv.innerHTML = str;
  459. // 返回 div 的 textContent,这将去除所有 HTML 标签
  460. return tempDiv.textContent || tempDiv.innerText;
  461. },
  462. //获取评阅类型 单评还是双评等
  463. getRatingType(type) {
  464. let result = "单评";
  465. if (type == 1) {
  466. result = "单评";
  467. } else if (type == 2) {
  468. result = "2评0补0审";
  469. } else if (type == 3) {
  470. result = "2评1补0审";
  471. } else if (type == 4) {
  472. result = "2评0补1审";
  473. } else if (type == 5) {
  474. result = "2评1补1审";
  475. }
  476. return result;
  477. },
  478. //根据起始题号,结束题号,题号间隔获取题号列表
  479. getTopicNumberList(startNumber, endNumber, interval) {
  480. const topicNumberList = [];
  481. for (let i = startNumber; i <= endNumber; i += interval) {
  482. topicNumberList.push(i);
  483. }
  484. // console.log("打印题号列表",topicNumberList);
  485. return topicNumberList;
  486. },
  487. //获取科目图片名称 根据汉字
  488. getSubjectsName(value,count,type)
  489. {
  490. let name=value;
  491. if(count==0)
  492. {
  493. }
  494. else
  495. {
  496. switch (count) {
  497. case 1:
  498. name="其他";
  499. break;
  500. case 2:
  501. name="二科";
  502. break;
  503. case 3:
  504. name="三科";
  505. break;
  506. case 4:
  507. name="四科";
  508. break;
  509. case 5:
  510. name="五科";
  511. break;
  512. case 6:
  513. name="六科";
  514. break;
  515. case 7:
  516. name="七科";
  517. break;
  518. case 8:
  519. name="八科";
  520. break;
  521. case 9:
  522. name="九科";
  523. break;
  524. }
  525. }
  526. const subjectList = [
  527. {
  528. name: "生物",
  529. image: "biology.png",
  530. color: "#3BA272",
  531. },
  532. {
  533. name: "化学",
  534. image: "chemistry.png",
  535. color: "#73C0DE",
  536. },
  537. {
  538. name: "语文",
  539. image: "chinese.png",
  540. color: "#91CC75",
  541. },
  542. {
  543. name: "道德与法治",
  544. image: "daofa.png",
  545. color: "#FF869D",
  546. },
  547. {
  548. name: "八科",
  549. image: "eight_subject.png",
  550. color: "#3BA272",
  551. },
  552. {
  553. name: "英语",
  554. image: "english.png",
  555. color: "#EE6666",
  556. },
  557. {
  558. name: "五科",
  559. image: "five_subject.png",
  560. color: "#63A1FF",
  561. },
  562. {
  563. name: "四科",
  564. image: "four_subject.png",
  565. color: "#FF869D",
  566. },
  567. {
  568. name: "地理",
  569. image: "geography.png",
  570. color: "#9A60B4",
  571. },
  572. {
  573. name: "历史",
  574. image: "history.png",
  575. color: "#FC8452",
  576. },
  577. {
  578. name: "信息",
  579. image: "information.png",
  580. color: "#63A1FF",
  581. },
  582. {
  583. name: "数学",
  584. image: "math.png",
  585. color: "#FAC858",
  586. },
  587. {
  588. name: "九科",
  589. image: "nine_subject.png",
  590. color: "#EE6666",
  591. },
  592. {
  593. name: "其他",
  594. image: "other.png",
  595. color: "#C495FA",
  596. },
  597. {
  598. name: "物理",
  599. image: "physics.png",
  600. color: "#817BE2",
  601. },
  602. {
  603. name: "政治",
  604. image: "politics.png",
  605. color: "#63A1FF",
  606. },
  607. {
  608. name: "七科",
  609. image: "seven_subject.png",
  610. color: "#FC8452",
  611. },
  612. {
  613. name: "六科",
  614. image: "six_subject.png",
  615. color: "#9A60B4",
  616. },
  617. {
  618. name: "体育",
  619. image: "sport.png",
  620. color: "#FF8B8B",
  621. },
  622. {
  623. name: "三科",
  624. image: "three_subject.png",
  625. color: "#5CC1F6",
  626. },
  627. {
  628. name: "二科",
  629. image: "two_subject.webp",
  630. color: "#C495FA",
  631. },
  632. {
  633. name: "总分",
  634. image: "totalScore.png",
  635. color: "#325AD4",
  636. },
  637. {
  638. name: "通用",
  639. image: "tongyong.png",
  640. color: "#5CC1F6",
  641. },
  642. {
  643. name: "地理学考",
  644. image: "geography_exam.webp",
  645. color: "#9A60B4",
  646. },
  647. {
  648. name: "化学学考",
  649. image: "chemistry_exam.webp",
  650. color: "#73C0DE",
  651. },
  652. {
  653. name: "历史学考",
  654. image: "history_exam.webp",
  655. color: "#FC8452",
  656. },
  657. {
  658. name: "生物学考",
  659. image: "biology_exam.webp",
  660. color: "#3BA272",
  661. },
  662. {
  663. name: "物理学考",
  664. image: "physics_exam.webp",
  665. color: "#817BE2",
  666. },
  667. {
  668. name: "政治学考",
  669. image: "politics_exam.webp",
  670. color: "#63A1FF",
  671. }
  672. ];
  673. let result = subjectList.find((item) => item.name === name);
  674. if(result)
  675. {
  676. if(type && type == 'color') {
  677. return result.color;
  678. }else {
  679. return result.image;
  680. }
  681. }
  682. else
  683. {
  684. if(type && type == 'color') {
  685. return '#C495FA';
  686. }else {
  687. return "other.png"
  688. }
  689. }
  690. },
  691. //包含0的正整数 包含0的正整数但不是以0开头的多位正整数 '00'、'01' 和 '0001' 都不会被匹配
  692. isNumber(str){
  693. const regex = /^(?:[1-9][0-9]*|0)$/;
  694. return regex.test(str);
  695. },
  696. // 大于等于 0 的数字(含整数、小数都行,但不能有负号)
  697. isNotNegativeNumber(val){
  698. // return /^(?:0|[1-9]\d*)(?:\.\d+)?$/.test(val);
  699. // 先去除首尾空格和中间所有空格
  700. const trimmedVal = String(val).replace(/\s+/g, '');
  701. return /^(?:0|[1-9]\d*)(?:\.\d+)?$/.test(trimmedVal);
  702. },
  703. //根据当前值 获取最大值 echarts 图表使用
  704. getMaxValue(value)
  705. {
  706. const thresholdMap =[
  707. {
  708. maxThreshold:0.3,//最大阈值0-0.6
  709. bound:0.3,//边界值
  710. },
  711. {
  712. maxThreshold:0.6,//最大阈值0-0.6
  713. bound:0.6,//边界值
  714. },
  715. {
  716. maxThreshold:1,//最大阈值 0.6 - 1
  717. bound:1,//边界值
  718. },
  719. {
  720. maxThreshold:1.5,//最大阈值 0.6 - 1
  721. bound:1.5,//边界值
  722. },
  723. {
  724. maxThreshold:2,//最大阈值
  725. bound:2,//边界值
  726. },
  727. {
  728. maxThreshold:4,//最大阈值
  729. bound:4,//边界值
  730. },
  731. {
  732. maxThreshold:8,//最大阈值
  733. bound:8,//边界值
  734. },
  735. {
  736. maxThreshold:10,//最大阈值
  737. bound:10,//边界值
  738. },
  739. {
  740. maxThreshold:20,//最大阈值
  741. bound:20,//边界值
  742. },
  743. {
  744. maxThreshold:30,//最大阈值
  745. bound:30,//边界值
  746. },
  747. {
  748. maxThreshold:40,//最大阈值
  749. bound:40,//边界值
  750. },
  751. {
  752. maxThreshold:50,//最大阈值
  753. bound:50,//边界值
  754. },
  755. {
  756. maxThreshold:60,//最大阈值
  757. bound:60,//边界值
  758. },
  759. {
  760. maxThreshold:70,//最大阈值
  761. bound:70,//边界值
  762. },
  763. {
  764. maxThreshold:80,//最大阈值
  765. bound:80,//边界值
  766. },
  767. {
  768. maxThreshold:90,//最大阈值
  769. bound:90,//边界值
  770. },
  771. {
  772. maxThreshold:100,//最大阈值
  773. bound:100,//边界值
  774. },
  775. {
  776. maxThreshold:120,//最大阈值
  777. bound:120,//边界值
  778. },
  779. {
  780. maxThreshold:150,//最大阈值
  781. bound:150,//边界值
  782. },
  783. {
  784. maxThreshold:180,//最大阈值
  785. bound:180,//边界值
  786. },
  787. {
  788. maxThreshold:200,//最大阈值
  789. bound:200,//边界值
  790. },
  791. {
  792. maxThreshold:250,//最大阈值
  793. bound:250,//边界值
  794. },
  795. {
  796. maxThreshold:200,//最大阈值
  797. bound:200,//边界值
  798. },
  799. {
  800. maxThreshold:300,//最大阈值
  801. bound:300,//边界值
  802. },
  803. {
  804. maxThreshold:350,//最大阈值
  805. bound:350,//边界值
  806. },
  807. {
  808. maxThreshold:400,//最大阈值
  809. bound:400,//边界值
  810. },
  811. {
  812. maxThreshold:450,//最大阈值
  813. bound:450,//边界值
  814. },
  815. {
  816. maxThreshold:500,//最大阈值
  817. bound:500,//边界值
  818. },
  819. {
  820. maxThreshold:600,//最大阈值
  821. bound:600,//边界值
  822. },
  823. {
  824. maxThreshold:700,//最大阈值
  825. bound:700,//边界值
  826. },
  827. ];//配置区间规则
  828. //查找匹配的边界值
  829. const matchedRule = thresholdMap.find(({ maxThreshold }) => value < maxThreshold);
  830. // 处理超过阈值的情况(≥5)
  831. const bound = matchedRule
  832. ? matchedRule.bound
  833. : Math.ceil((value) / 10) * 10;
  834. // console.log("打印",value);
  835. // console.log("打印边界值",bound);
  836. return bound;
  837. },
  838. //中间截断显示文本,保留前后各n位字符
  839. truncateMiddleText(text,num,startStr,endStr) {
  840. //num:不超过多少字符,全部展示 startStr:开头保留多少字符 endStr:结尾保留多少字符
  841. if (text.length <= num) {
  842. return text;
  843. }
  844. // 保留开头和结尾各5位字符
  845. const start = text.substring(0, startStr);
  846. const end = text.substring(text.length - endStr);
  847. return `${start}...${end}`;
  848. },
  849. //根据题库的试卷题目信息 获取答题卡所有小题的数据
  850. getAllQuestionByKnowTopic(list)
  851. {
  852. console.log("公共方法库处理list:", list);
  853. for (let i = 0; i < list.length; i++)
  854. {
  855. const item = list[i];
  856. if(item.type==1)
  857. {
  858. //选择题 处理
  859. }
  860. }
  861. },
  862. //手阅卡 根据分值 生成对应的数组列表
  863. getNumberListByScore(score)
  864. {
  865. const TOTAL_SLOTS = 24;//格子数量 固定24个 后期可调整
  866. const result = [];
  867. // 初始化24个格子
  868. for (let i = 0; i < TOTAL_SLOTS; i++) {
  869. result.push({ index: i, value: '', type: -1 }); // type为-1表示空
  870. }
  871. if (score < 10) {
  872. // 规则1: 分数小于10,从右开始显示 0.5, 0, 1, 2, ..., 到score
  873. const values = ['0.5', '0'];
  874. // 添加1到score的所有整数
  875. for (let i = 1; i <= score; i++) {
  876. values.push(i.toString());
  877. }
  878. // 从右向左填充(从最后一个格子开始)
  879. for (let i = 0; i < values.length; i++) {
  880. const slotIndex = TOTAL_SLOTS - 1 - i; // 从索引23开始
  881. if (slotIndex >= 0) {
  882. result[slotIndex].value = values[i];
  883. // 设置type:0.5为小数(0),0-9为个位数(1)
  884. result[slotIndex].type = values[i] === '0.5' ? 0 : 1;
  885. }
  886. }
  887. } else if (score >= 10 && score <= 22) {
  888. // 规则2: 分数在10到22之间,从右开始显示 0.5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12...直到score
  889. const values = ['0.5', '0']; // 从0.5和0开始
  890. // 添加1到score的所有整数
  891. for (let i = 1; i <= score; i++) {
  892. values.push(i.toString());
  893. }
  894. // 从右向左填充
  895. for (let i = 0; i < values.length; i++) {
  896. const slotIndex = TOTAL_SLOTS - 1 - i;
  897. if (slotIndex >= 0) {
  898. result[slotIndex].value = values[i];
  899. // 规则2中,所有数值都是连续显示的,包括10-22,所以都视为个位数(1)
  900. // 0.5为小数(0)
  901. result[slotIndex].type = values[i] === '0.5' ? 0 : 1;
  902. }
  903. }
  904. } else if (score > 22) {
  905. // 规则3: 分数大于22,从右开始显示 0.5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,中间空一个格子,然后10,20,30...
  906. const values = [];
  907. // 第一部分:0.5, 0-9
  908. values.push('0.5'); // 最右边
  909. values.push('0');
  910. for (let i = 1; i <= 9; i++) {
  911. values.push(i.toString());
  912. }
  913. // 中间空一个格子
  914. values.push('');
  915. // 计算十位数的最大值(不超过分数)
  916. const maxTens = Math.floor(score / 10) * 10;
  917. // 添加十位数:10, 20, 30...
  918. for (let tens = 10; tens <= maxTens; tens += 10) {
  919. values.push(tens.toString());
  920. }
  921. // 从右向左填充
  922. for (let i = 0; i < values.length; i++) {
  923. const slotIndex = TOTAL_SLOTS - 1 - i;
  924. if (slotIndex >= 0) {
  925. result[slotIndex].value = values[i];
  926. // 设置type
  927. if (values[i] === '') {
  928. result[slotIndex].type = -1; // 空
  929. } else if (values[i] === '0.5') {
  930. result[slotIndex].type = 0; // 小数
  931. } else {
  932. const num = parseInt(values[i], 10);
  933. // 0-9为个位数,10,20,30...为十位数
  934. result[slotIndex].type = num >= 10 ? 2 : 1;
  935. }
  936. }
  937. }
  938. }
  939. return result;
  940. },
  941. };