import common from '../../utils/util'; import server from '../../utils/main'; const app = getApp() Page({ data: { Left: 0, }, onLoad: function(options) { var id = options.id; id = 179; this.getList(id); }, getList: function(id) { var that = this; server.getLocalHost(function() { server.getData('GetQuestionTypesPrint?ID=' + id, function(data) { //console.log("UserInfo:" + data); if (data) { that.saveImage(data); } }); }); }, saveImage: function(item) { var that = this; var ctx = wx.createCanvasContext("Canvas", that); ctx.setFillStyle('white'); ctx.fillRect(0, 0, 1050, 1485); ctx.setTextAlign('left'); ctx.setTextBaseline('top'); ctx.fillStyle = "#000000"; ctx.setFontSize(32); ctx.fillText(item.Name, 60, 45); ctx.setFontSize(12); ctx.fillText(item.CagegoryName, 60, 90); ctx.fillText("共" + item.QuestionList.length + "道题", 60, 125); ctx.fillText("第 1 / 1 页", 60, 147); ctx.fillText("答案检索号", 768, 60); ctx.setTextAlign('right'); ctx.fillText("出题时间 " + item.CreateTime, 875, 94); ctx.fillText("微信扫一扫 计时看答案", 875, 111); ctx.fillText("《数学计算题》选题 打印 扫码 批改", 875, 137); ctx.setFontSize(32); ctx.fillText("99", 875, 50); ctx.drawImage("../../images/answer.png", 890, 54, 100, 100); ctx.setTextBaseline('middle'); var xStart = 60; var yStart = 247; var index = 0; for (var i = 0; i < 3; i++) { for (var j = 0; j < 20; j++) { index++; ctx.setTextAlign('left'); ctx.setFontSize(12); ctx.fillText("(", xStart + i * 310, yStart + j * 59); ctx.setTextAlign('center'); ctx.fillText(index, xStart + i * 310 + 13, yStart + j * 59); ctx.setTextAlign('left'); ctx.fillText(")", xStart + i * 310 + 22, yStart + j * 59); ctx.setFontSize(24); var A = item.QuestionList[index - 1].A.toString(); if (item.QuestionList[index - 1].HiddenColumn == "A") A = "____"; var OperateAB = item.QuestionList[index - 1].OperateAB.toString(); console.log(OperateAB); var B = item.QuestionList[index - 1].B.toString(); if (item.QuestionList[index - 1].HiddenColumn == "B") B = "____"; var equation = A + " " + OperateAB + " " + B; if (item.QuestionList[index - 1].C) { var OperateBC = item.QuestionList[index - 1].OperateBC.toString(); var C = item.QuestionList[index - 1].C.toString(); equation += " " + OperateBC + " " + C; if (item.QuestionList[index - 1].D) { var OperateCD = item.QuestionList[index - 1].OperateCD.toString(); var D = item.QuestionList[index - 1].D.toString(); equation += " " + OperateCD + " " + D; } } equation += " = "; var R = item.QuestionList[index - 1].R.toString(); if (item.QuestionList[index - 1].HiddenColumn == "R") R = ""; equation += R; var num = xStart + i * 310 + 31; ctx.setTextAlign('center'); for (var n = 0; n < equation.length; n++) { var len = getLength(equation[n]); num += len; if (equation[n] == ".") { ctx.fillText(equation[n], num + 3, yStart + j * 59); } else { var h=0; if (equation[n]=="_") h=8; ctx.fillText(equation[n], num, yStart + j * 59+h); } } } } ctx.draw(true, function(n) { wx.canvasToTempFilePath({ x: 0, y: 0, width: 2100, height: 2970, destWidth: 2100, destHeight: 2970, canvasId: 'Canvas', success: function (res2) { console.log(res2.tempFilePath); wx.previewImage({ current: res2.tempFilePath, // 当前显示图片的http链接 urls: [res2.tempFilePath] // 需要预览的图片http链接列表 }); } }) }); function getLength(str) { switch (str) { case "0": case "1": case "2": case "3": case "4": case "5": case "6": case "7": case "8": case "9": return 15; case ".": return 8; default: return 12; } } }, moveLeft: function() { this.setData({ Left: this.data.Left + 375, }); }, moveRight: function() { this.setData({ Left: this.data.Left - 375, }); } });