detail.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var times=1;
  5. Page({
  6. data: {
  7. version: app.globalData.version,
  8. FileUrl: app.globalData.fileUrl,
  9. IsShowMenu:false,
  10. filter:'horizontal',
  11. PageNumber:1,
  12. IsFinished: false,
  13. },
  14. onLoad: function(options) {
  15. var id = options.id;
  16. this.setData({
  17. Containnerheight: server.getWindowHeight(),
  18. ID:id,
  19. });
  20. var systemInfo = wx.getSystemInfoSync();
  21. if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  22. times=2;
  23. }
  24. this.getDetail(id);
  25. },
  26. getDetail: function(id) {
  27. var item;
  28. var data = wx.getStorageSync('QuestionTypeList');
  29. for (var i = 0; i < data.length; i++) {
  30. for (var k = 0; k < data[i].List.length; k++) {
  31. if (id == data[i].List[k].ID) {
  32. item = data[i].List[k];
  33. item.Example[0] = item.Example[0].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ ");
  34. item.Example[1] = item.Example[1].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ ");
  35. break;
  36. }
  37. }
  38. }
  39. this.setData({
  40. QuestionTypeItem: item,
  41. });
  42. },
  43. gotoAnswer: function (e) {
  44. wx.navigateTo({
  45. url: '../main/answer',
  46. });
  47. },
  48. getFinish:function(){
  49. this.setData({
  50. IsFinished: true,
  51. });
  52. this.getList(this.data.ID);
  53. },
  54. getList: function (id) {
  55. var that = this;
  56. server.getLocalHost(function () {
  57. server.getData('GetQuestionTypesPrint?ID=' + id, function (data) {
  58. //console.log("UserInfo:" + data);
  59. if (data) {
  60. that.saveImage(data);
  61. }
  62. });
  63. });
  64. },
  65. saveImage: function (item) {
  66. var that = this;
  67. var ctx = wx.createCanvasContext("Canvas", that);
  68. ctx.setFillStyle('white');
  69. ctx.fillRect(0, 0, 1050, 1485);
  70. ctx.setTextAlign('left');
  71. ctx.setTextBaseline('top');
  72. ctx.fillStyle = "#000000";
  73. ctx.setFontSize(32);
  74. ctx.fillText(item.Name, 60, 45);
  75. ctx.setFontSize(12);
  76. ctx.fillText(item.CagegoryName, 60, 90);
  77. ctx.fillText("共" + item.QuestionList.length + "道题", 60, 125);
  78. ctx.fillText("第 1 / 1 页", 60, 147);
  79. ctx.fillText("答案检索号", 768, 60);
  80. ctx.setTextAlign('right');
  81. ctx.fillText("出题时间 " + item.CreateTime, 875, 94);
  82. ctx.fillText("微信扫一扫 计时看答案", 875, 111);
  83. ctx.fillText("《数学计算题》选题 打印 扫码 批改", 875, 137);
  84. ctx.setFontSize(32);
  85. ctx.fillText("99", 875, 50);
  86. ctx.drawImage("../../images/answer.png", 890, 54, 100, 100);
  87. ctx.setTextBaseline('middle');
  88. var xStart = 60;
  89. var yStart = 247;
  90. var index = 0;
  91. for (var i = 0; i < 3; i++) {
  92. for (var j = 0; j < 20; j++) {
  93. index++;
  94. ctx.setTextAlign('left');
  95. ctx.setFontSize(12);
  96. ctx.fillText("(", xStart + i * 310, yStart + j * 59);
  97. ctx.setTextAlign('center');
  98. ctx.fillText(index, xStart + i * 310 + 13, yStart + j * 59);
  99. ctx.setTextAlign('left');
  100. ctx.fillText(")", xStart + i * 310 + 22, yStart + j * 59);
  101. ctx.setFontSize(24);
  102. var A = item.QuestionList[index - 1].A.toString();
  103. if (item.QuestionList[index - 1].HiddenColumn == "A")
  104. A = "____";
  105. var OperateAB = item.QuestionList[index - 1].OperateAB.toString();
  106. console.log(OperateAB);
  107. var B = item.QuestionList[index - 1].B.toString();
  108. if (item.QuestionList[index - 1].HiddenColumn == "B")
  109. B = "____";
  110. var equation = A + " " + OperateAB + " " + B;
  111. if (item.QuestionList[index - 1].C) {
  112. var OperateBC = item.QuestionList[index - 1].OperateBC.toString();
  113. var C = item.QuestionList[index - 1].C.toString();
  114. equation += " " + OperateBC + " " + C;
  115. if (item.QuestionList[index - 1].D) {
  116. var OperateCD = item.QuestionList[index - 1].OperateCD.toString();
  117. var D = item.QuestionList[index - 1].D.toString();
  118. equation += " " + OperateCD + " " + D;
  119. }
  120. }
  121. equation += " = ";
  122. var R = item.QuestionList[index - 1].R.toString();
  123. if (item.QuestionList[index - 1].HiddenColumn == "R")
  124. R = "";
  125. equation += R;
  126. var num = xStart + i * 310 + 31;
  127. ctx.setTextAlign('center');
  128. for (var n = 0; n < equation.length; n++) {
  129. var len = getLength(equation[n]);
  130. num += len;
  131. if (equation[n] == ".") {
  132. ctx.fillText(equation[n], num + 3, yStart + j * 59);
  133. } else {
  134. var h = 0;
  135. if (equation[n] == "_")
  136. h = 8;
  137. ctx.fillText(equation[n], num, yStart + j * 59 + h);
  138. }
  139. }
  140. }
  141. }
  142. ctx.draw(true, function (n) {
  143. var w=1050,h=1485;
  144. wx.canvasToTempFilePath({
  145. x: 0,
  146. y: 0,
  147. width: w*times,
  148. height: h*times,
  149. //destWidth: w*times,
  150. //destHeight: h*times,
  151. canvasId: 'Canvas',
  152. success: function (res2) {
  153. console.log(res2.tempFilePath);
  154. wx.previewImage({
  155. current: res2.tempFilePath, // 当前显示图片的http链接
  156. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  157. });
  158. }
  159. })
  160. });
  161. function getLength(str) {
  162. switch (str) {
  163. case "0":
  164. case "1":
  165. case "2":
  166. case "3":
  167. case "4":
  168. case "5":
  169. case "6":
  170. case "7":
  171. case "8":
  172. case "9":
  173. return 15;
  174. case ".":
  175. return 8;
  176. default:
  177. return 12;
  178. }
  179. }
  180. },
  181. changePageNumber: function (e) {
  182. var id = Number(e.currentTarget.dataset.id);
  183. this.data.PageNumber+=id;
  184. if (this.data.PageNumber<1)
  185. this.data.PageNumber=1;
  186. else if (this.data.PageNumber > 5)
  187. this.data.PageNumber = 5;
  188. this.setData({
  189. PageNumber: this.data.PageNumber,
  190. });
  191. },
  192. menuClick: function (e) {
  193. this.data.filter = e.currentTarget.dataset.id;
  194. this.setData({
  195. filter: this.data.filter,
  196. IsShowMenu: false,
  197. });
  198. },
  199. closeMenu: function () {
  200. this.setData({
  201. IsShowMenu: false,
  202. });
  203. },
  204. openMenu: function () {
  205. this.setData({
  206. IsShowMenu: true,
  207. });
  208. },
  209. onShareAppMessage: function() {
  210. return {
  211. title: '',
  212. path: 'pages/index/index',
  213. success: function(res) {},
  214. fail: function(err) {
  215. console.log(err);
  216. },
  217. complete: function(res) {
  218. console.log(res);
  219. },
  220. }
  221. },
  222. })