sheet-view.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //查看原始题卡模块
  2. var sheet_view = function(option, success) {
  3. var object = new SheetView(option);
  4. success();
  5. return object;
  6. }
  7. function SheetView(option) {
  8. this.markControl = option.markControl;
  9. this.server = option.server;
  10. this.list = [];
  11. this.markControl.on('task.get.success', this, function(event, context, eventObject) {
  12. //开启原图显示
  13. if(option.showSheet===true){
  14. this.render(context.task.sheetUrls);
  15. }
  16. });
  17. this.markControl.on('task.get.none', this, function(event, context, eventObject) {
  18. this.render();
  19. });
  20. this.markControl.on('task.get.before', this, function(event, context, eventObject) {
  21. this.render();
  22. });
  23. }
  24. SheetView.prototype.render = function(urls) {
  25. if(urls != undefined && urls.length > 0) {
  26. for(var i = 0; i < urls.length; i++) {
  27. var url = urls[i];
  28. if(this.list.length > i) {
  29. var item = this.list[i];
  30. item.nav.show();
  31. this.renderContent(item.content, url, i);
  32. } else {
  33. var content = $(this.container_dom).appendTo(this.markControl.container.centerContent);
  34. this.renderContent(content, url, i);
  35. this.list.push({
  36. nav: this.markControl.addNavGroup('原卷' + (i + 1), content),
  37. content: content
  38. });
  39. }
  40. }
  41. } else {
  42. for(var i = 0; i < this.list.length; i++) {
  43. var item = this.list[i];
  44. item.nav.hide();
  45. item.content.empty();
  46. }
  47. }
  48. }
  49. SheetView.prototype.renderContent = function(content, url, i) {
  50. content.width(this.markControl.container.centerContent.width());
  51. content.height(this.markControl.container.centerContent.height());
  52. content.empty();
  53. // content.append($('<img src="'+this.server + url +'">'));
  54. var show = false;
  55. if(i%2==0){
  56. show = true;
  57. }
  58. content.append($('<canvas id="sheet-canvas'+i+'"></canvas>'));
  59. var image = new Image();
  60. image.crossOrigin = '';
  61. image.src = this.server + url ;
  62. image.canvas = document.getElementById('sheet-canvas'+i);
  63. image.content = content;
  64. image.onload = function() {
  65. var ctx = this.canvas.getContext("2d");
  66. this.canvas.width = Math.min(this.width, this.content.width());
  67. this.canvas.height = this.canvas.width * this.height / this.width;
  68. ctx.drawImage(image, 0,0,this.width,this.height,0, 0, this.canvas.width, this.canvas.height);
  69. if(show){
  70. ctx.fillStyle = "#FFFFFF";
  71. ctx.fillRect(0, 0, this.canvas.width/2, this.canvas.height*3.7/10);
  72. }
  73. this.canvas.toDataURL("image/jpeg");
  74. }
  75. }
  76. SheetView.prototype.container_dom = '<div style="display:none; overflow: scroll"></div>';