check-bak.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>作业批改 - 旧版</title>
  5. <link rel="stylesheet" href="css/index.css">
  6. <link rel="stylesheet" href="http://cdn.staticfile.org/semantic-ui/2.3.1/semantic.css">
  7. </head>
  8. <body style="background-color: #E5E4E5;overflow-x: hidden;">
  9. <div style="margin-top:10px;">
  10. <div style="width:50px;float:left;">
  11. <ul id="toolsul" class="tools">
  12. <li data-type="right" class="active" title="整题正确">
  13. <i class="icon-right-select" data-default='icon-right-black'></i>
  14. </li>
  15. <li data-type="wrong" title="整题错误">
  16. <i class="icon-wrong-black" data-default='icon-wrong-black'></i>
  17. </li>
  18. <li data-type="smallright" title="题目内单个正确">
  19. <i class="icon-right-small-black" data-default='icon-right-small-black'></i>
  20. </li>
  21. <li data-type="smallwrong" title="题目内单个错误">
  22. <i class="icon-wrong-small-black" data-default='icon-wrong-small-black'></i>
  23. </li>
  24. <li data-type="rectangle" title="错题圈定">
  25. <i class="icon-tools icon-square-black" data-default="icon-tools icon-square-black"></i>
  26. </li>
  27. <li data-type="remove" title="橡皮擦">
  28. <i class="icon-tools icon-remove-black" data-default='icon-tools icon-remove-black'></i>
  29. </li>
  30. <li onclick="cutFun()" title="成绩查看">
  31. <i class="icon-submit-black" data-default='icon-submit-black'></i>
  32. </li>
  33. </ul>
  34. </div>
  35. <div id="canvasDiv" class="canvasDiv" style="width:auto;height: auto;">
  36. <canvas id="c" height="890">请使用支持HTML5的浏览器</canvas>
  37. </div>
  38. <div style="color:red;margin-top: 10px;margin-left: 60px;">注意:错题必须使用工具栏“错题圈定”圈定错题。</div>
  39. <div id="wrongImg"></div>
  40. </div>
  41. <script src="/js/jquery.min.js"></script>
  42. <script src="/js/fabric.min.js"></script>
  43. <script src="js/check-bak.js"></script>
  44. <script src="js/canvasZoom.js"></script>
  45. <script src="https://unpkg.com/qiniu-js@2.2.2/dist/qiniu.min.js"></script>
  46. <script src="http://cdn.staticfile.org/semantic-ui/2.3.1/semantic.js"></script>
  47. <script>
  48. var qiniuToken = undefined;
  49. jQuery.ajax({
  50. type: "GET",
  51. cache: false,
  52. dataType: "jsonp",
  53. url: 'http://127.0.0.1:8360/qiniu/gettoken',
  54. data: {},
  55. success: function (res) {
  56. qiniuToken = res.token;
  57. }
  58. });
  59. canvas.on("mouse:up", function () {
  60. if (window.drawType && (window.drawType == "wrong" || window.drawType == "smallwrong")) {
  61. //错题批注
  62. // $('.ui.modal').modal();
  63. }
  64. });
  65. function cutFun() {
  66. var objs = canvas.getObjects();
  67. var checkObj = [];
  68. for (var i = 0; i < objs.length; i++) {
  69. if (objs[i].type && objs[i].type != 'image') {
  70. checkObj.push(objs[i]);
  71. }
  72. }
  73. checkObj.sort(function (x, y) { return x.top - y.top; }); //根据控件top排序
  74. var checkJson = [];
  75. var itemSmallRight = 0, itemSmallWrong = 0, prevSmallType = true;
  76. for (var i = 0; i < checkObj.length; i++) {
  77. switch (checkObj[i].type) {
  78. case 'smallright':
  79. ++itemSmallRight;
  80. break;
  81. case 'smallwrong':
  82. ++itemSmallWrong;
  83. break;
  84. case 'right':
  85. case 'wrong':
  86. case 'rectangle': //框
  87. prevSmallType = false;
  88. break;
  89. default:
  90. break;
  91. }
  92. if (prevSmallType == false || i == (checkObj.length - 1)) {
  93. //上一个为整题对/错 || 最后一题
  94. if (itemSmallRight > 0 || itemSmallWrong > 0) {
  95. checkJson.push({ 'r': 0, 'w': 0, 'sr': itemSmallRight, 'sw': itemSmallWrong, 'url': '' });
  96. itemSmallRight = 0, itemSmallWrong = 0;
  97. }
  98. prevSmallType = true;
  99. }
  100. //录入本次大题
  101. if (checkObj[i].type == 'right') {
  102. checkJson.push({ 'r': 1, 'w': 0, 'sr': 0, 'sw': 0, 'url': '' });
  103. } else if (checkObj[i].type == 'wrong') {
  104. checkJson.push({ 'r': 0, 'w': 1, 'sr': 0, 'sw': 0, 'url': '' });
  105. }
  106. //圈定的错图上传
  107. if (checkObj[i].type == 'rectangle') {
  108. toImgUpload(checkObj[i], checkObj[i].left, checkObj[i].top, checkObj[i].width, checkObj[i].height);
  109. }
  110. }
  111. // var msg = "";
  112. // for (var i = 0; i < checkJson.length; i++) {
  113. // msg += ("第" + (i + 1) + "题:");
  114. // if (checkJson[i].r) {
  115. // msg += "全对";
  116. // } else if (checkJson[i].w) {
  117. // msg += "全错";
  118. // } else {
  119. // msg += "对:" + checkJson[i].sr + "个" + ",错:" + checkJson[i].sw + "个";
  120. // }
  121. // msg += "\n";
  122. // }
  123. // if (msg) {
  124. // alert(msg);
  125. // }
  126. }
  127. //转换成图片并上传
  128. function toImgUpload(cObj, left, top, width, height) {
  129. canvas.remove(cObj);
  130. var base64 = canvas.toDataURL({
  131. format: 'png',
  132. left: left - 12,
  133. top: top - 10,
  134. width: width,
  135. height: height
  136. });
  137. // data:image/png;base64,
  138. jQuery("#wrongImg").append('<img src="' + base64 + '"/><br />');
  139. canvas.add(cObj);
  140. //上传,返回地址
  141. var putExtra = {
  142. fname: "",
  143. params: {},
  144. mimeType: [] || null
  145. };
  146. var config = {
  147. useCdnDomain: true
  148. };
  149. // var contentType = 'image/png';
  150. // var blob = base64ToBlob(base64.replace('data:image/png;base64,', ''), contentType);
  151. // var observable = qiniu.upload(blob, "test5.png", qiniuToken, putExtra, config);
  152. // var subscription = observable.subscribe({
  153. // next(res) {
  154. // console.log(res);
  155. // },
  156. // error(err) {
  157. // console.log(err);
  158. // },
  159. // complete(res) {
  160. // console.log(res);
  161. // }
  162. // });
  163. // return "";
  164. }
  165. //base64转blob
  166. function base64ToBlob(base64, contentType, sliceSize) {
  167. contentType = contentType || '';
  168. sliceSize = sliceSize || 512;
  169. var byteCharacters = atob(base64);
  170. var byteArrays = [];
  171. for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
  172. var slice = byteCharacters.slice(offset, offset + sliceSize);
  173. var byteNumbers = new Array(slice.length);
  174. for (var i = 0; i < slice.length; i++) {
  175. byteNumbers[i] = slice.charCodeAt(i);
  176. }
  177. var byteArray = new Uint8Array(byteNumbers);
  178. byteArrays.push(byteArray);
  179. }
  180. var blob = new Blob(byteArrays, { type: contentType });
  181. return blob;
  182. }
  183. </script>
  184. </body>
  185. </html>