selected.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var achievement = '成绩表';
  2. var backupData = [];
  3. var dataTd = {};
  4. function updateData(jsonData, type = 1) {
  5. var dataContainer = document.getElementById('dataContainer');
  6. var html = '';
  7. var data = jsonData;
  8. console.log('zhes' + type)
  9. if (type == 1) {
  10. backupData = data;
  11. dataTd = data[0].stepScroe;
  12. }
  13. var td = '';
  14. var i = 1;
  15. let dataTdLength = Object.keys(dataTd).length;
  16. let isPc = dataTdLength == 27 ? 'pc' : 'vr';
  17. let score = {
  18. "pc": [
  19. 0.2, 0.1, 0.5, 0.5, 1, 0, 0.1, 0.1, 0.1, 0.4, 0.4, 1, 0.1, 0.1, 0.1, 0.2, 0.1, 2.5, 0.5, 0.5, 0.4, 0.3, 0.3, 0.3, 0.1, 0.1, 0.4
  20. ],
  21. "vr": [
  22. 0, 1, 5, 5, 5, 5, 1, 1, 1, 4, 4, 10, 6, 1, 1, 1, 1, 2, 1, 24, 5, 4, 5, 3, 1, 3
  23. ],
  24. };
  25. // console.log(score.vr.length)
  26. // console.log(dataTd,Object.keys(dataTd),dataTdLeng)
  27. if (dataTd) {
  28. td += '<th>学号' + '</th>';
  29. for (obj in dataTd) {
  30. td += "<th><span class='span'>" + i + '</span>-' + obj + '-<span class="colour">' + score[isPc][i - 1] + '</span></th>';
  31. i++;
  32. }
  33. td += '<th>总得分' + '</th>';
  34. td += '<th class="time-th">创建时间' + '</th>';
  35. var tdContainer = document.getElementById('th');
  36. tdContainer.innerHTML = td;
  37. }
  38. // 根据您的JSON数据结构,循环遍历并构建HTML字符串
  39. // 这里假设jsonData是一个包含多个对象的数组,每个对象有学号、姓名、分数和考试时间属性
  40. // let dataTdArray = Object.keys(dataTd);
  41. console.log(data, type, 55656)
  42. data.forEach(function (item) {
  43. html += '<tr class="tr-after">';
  44. html += '<td>' + item.number + '</td>';
  45. let key = 1;
  46. if (dataTd) {
  47. for (obj in dataTd) {
  48. let colorSuccess = 'red'
  49. if (item.stepScroe[obj] == score[isPc][key - 1]) {
  50. colorSuccess = 'colour';
  51. }
  52. html += '<td class="' + colorSuccess + '">' + item.stepScroe[obj] + '</td>';
  53. key++;
  54. }
  55. }
  56. html += '<td class="score">' + item.score + '_' + '<span class="font-size11">(' + textChange(item.isExam) + ')</span> </td>';
  57. html += '<td class="time">' + item.time.slice(0, 17) + '</td>';
  58. html += '</tr>'; // 添加分隔线
  59. });
  60. dataContainer.innerHTML = html;
  61. }
  62. function textChange(state) {
  63. let text = state ? '考试' : '练习';
  64. return text;
  65. }
  66. function handleDragOver(e) {
  67. e.preventDefault();
  68. dropArea.classList.add('dragover');
  69. }
  70. function handleDragLeave(e) {
  71. e.preventDefault();
  72. dropArea.classList.remove('dragover');
  73. }
  74. function scanFiles(e) {
  75. const files = e.dataTransfer.files; // 获取拖拽的文件列表
  76. const fileInput = document.getElementById('fileUpload');
  77. for (let i = 0; i < files.length; i++) {
  78. const file = files[i];
  79. // 将文件输出到文件输入框中
  80. fileInput.files = files;
  81. // 在这里可以进行其他操作,例如上传到服务器或进行其他处理
  82. }
  83. }
  84. function handleDragOver(e) {
  85. e.stopPropagation();
  86. e.preventDefault();
  87. }
  88. function handleFileSelect(e) {
  89. // fileInput.files = files;
  90. // e.stopPropagation();
  91. e.preventDefault();
  92. let item = e.dataTransfer;
  93. scanFiles(e);
  94. var files = [];
  95. [].forEach.call(e.dataTransfer.files, function (file) {
  96. files.push(file);
  97. }, false);
  98. for (var f of files) {
  99. var reader = new FileReader();
  100. reader.readAsText(f);
  101. //读取文件的内容
  102. reader.onload = function () {
  103. var jsonData = JSON.parse(this.result);
  104. // console.log(jsonData,36)
  105. updateData(jsonData);
  106. // console.log(this.result, 9998)
  107. };
  108. }
  109. }
  110. function handSelect() {
  111. let id = document.getElementById('id').value;
  112. let time = document.getElementById('time').value;
  113. if (id || time) {
  114. let where = {
  115. id:[],
  116. time:[]
  117. };
  118. if (id) {
  119. where['id'] = id.split("/");
  120. }
  121. if (time) {
  122. time = time.split("一");
  123. let time1 = time[0]+ " 00:00:00";
  124. let time2 = time[1]+ " 23:59:59";
  125. where['time1'] = new Date(time1).getTime()/1000;
  126. where['time2'] = new Date(time2).getTime()/1000;
  127. }
  128. const result = filterateSearch(backupData, where)
  129. console.log(77777,result)
  130. if (result.length >= 1) {
  131. console.log(8888888)
  132. updateData(result, 2)
  133. return;
  134. }else ( alert('符合的数据为空,请更改数据搜索条件') )
  135. return;
  136. } else {
  137. if (backupData.length >= 1) {
  138. updateData(backupData)
  139. return;
  140. }
  141. }
  142. alert('符合的数据为空,请更改数据搜索条件');
  143. }
  144. function filterateSearch(data, searchTerm) {
  145. const conditions = searchTerm['id'];
  146. const time1 = searchTerm['time1']?searchTerm['time1']:'1674541121';
  147. const time2 = searchTerm['time2']?searchTerm['time2']:"33231449921";
  148. // 转换为 Date 对象
  149. console.log(time1,time2,6633);
  150. const filteredArr = data.filter(item => {
  151. let hasNameCondition = conditions.every(condition => item.number.includes(condition))
  152. const time = item.stamp;
  153. let hasTimeCondition = time >= time1 && time <= time2;
  154. return hasNameCondition && hasTimeCondition;
  155. });
  156. console.log(filteredArr);
  157. return filteredArr;
  158. }
粤ICP备19079148号