import common from '../../utils/util'; import server from '../../utils/main'; const app = getApp(); var times=1; Page({ data: { version: app.globalData.version, FileUrl: app.globalData.fileUrl, IsShowMenu:false, filter:'horizontal', PageNumber:1, IsFinished: false, }, onLoad: function(options) { var id = options.id; this.setData({ Containnerheight: server.getWindowHeight(), ID:id, }); var systemInfo = wx.getSystemInfoSync(); if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) { times=2; } this.getDetail(id); }, getDetail: function(id) { var item; var data = wx.getStorageSync('QuestionTypeList'); for (var i = 0; i < data.length; i++) { for (var k = 0; k < data[i].List.length; k++) { if (id == data[i].List[k].ID) { item = data[i].List[k]; item.Example[0] = item.Example[0].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ "); item.Example[1] = item.Example[1].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ "); break; } } } this.setData({ QuestionTypeItem: item, }); }, gotoAnswer: function (e) { wx.navigateTo({ url: '../main/answer', }); }, getFinish:function(){ this.setData({ IsFinished: true, }); this.getList(this.data.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) { var w=1050,h=1485; wx.canvasToTempFilePath({ x: 0, y: 0, width: w*times, height: h*times, //destWidth: w*times, //destHeight: h*times, 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; } } }, changePageNumber: function (e) { var id = Number(e.currentTarget.dataset.id); this.data.PageNumber+=id; if (this.data.PageNumber<1) this.data.PageNumber=1; else if (this.data.PageNumber > 5) this.data.PageNumber = 5; this.setData({ PageNumber: this.data.PageNumber, }); }, menuClick: function (e) { this.data.filter = e.currentTarget.dataset.id; this.setData({ filter: this.data.filter, IsShowMenu: false, }); }, closeMenu: function () { this.setData({ IsShowMenu: false, }); }, openMenu: function () { this.setData({ IsShowMenu: true, }); }, onShareAppMessage: function() { return { title: '', path: 'pages/index/index', success: function(res) {}, fail: function(err) { console.log(err); }, complete: function(res) { console.log(res); }, } }, })