| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- import common from '../../utils/util';
- import server from '../../utils/main';
- const app = getApp();
- var QuestionList = [];
- var isAndroid = false;
- Page({
- data: {
- Left: 0,
- },
- onLoad: function (options) {
- var id = options.id;
- id = 183;
- var QuestionTypeCategory=3;
- this.getList(id, QuestionTypeCategory);
- isAndroid = false;
- if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0)
- isAndroid = true;
- },
- getList: function (id, QuestionTypeCategory) {
- var that = this;
- server.getLocalHost(function () {
- server.getData('GetQuestionTypesPrint?QuestionTypeCategory=' + QuestionTypeCategory+'&ID=' + id, function (data) {
- //console.log("UserInfo:" + data);
- if (data) {
- //var data=wx.getStorageSync("TestPrint");
- QuestionList = data;
- var ctx = wx.createCanvasContext("Canvas", that);
- ctx.setFillStyle('white');
- ctx.fillRect(0, 0, 1050, 1485);
- 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);
- that.saveImage();
- }
- })
- });
- }
- });
- });
- },
- saveImage: function () {
- var item = QuestionList;
- var that = this;
- var ctx = wx.createCanvasContext("Canvas", that);
- ctx.setFillStyle('white');
- //ctx.fillRect(0, 0, 1050, 1485);
- ctx.fillRect(0, 0, 1050, 1485);
- ctx.fillStyle = "#000000";
- //计算数组最大长度
- var maxLength = 0;
- for (var l = 0; l < item.QuestionList.length; l++) {
- var num1 = item.QuestionList[l];
- if (num1.Vertical) {
- for (var n = 0; n < num1.Vertical.length; n++) {
- if (maxLength < num1.Vertical[n].Array.length)
- maxLength = num1.Vertical[n].Array.length;
- }
- }
- }
- var xStart = 60;
- var yStart = 247;
- var height = 150;
- if (item.QuestionTypeCategory == 2)
- height = 59;
- if (item.PageCount == 18)
- height = 210;
- else if (item.PageCount == 15)
- height = 250;
- //括号
- var index = 0;
- ctx.setFontSize(12);
- for (var i = 0; i < 3; i++) {
- for (var j = 0; j < item.PageCount / 3; j++) {
- index++;
- ctx.fillText("(", xStart + i * 310, yStart + j * height);
- ctx.fillText(")", xStart + i * 310 + 22, yStart + j * height);
- }
- }
- //编号
- index = 0;
- ctx.setTextAlign('center');
- var numberLeft = 12;
- if (isAndroid)
- numberLeft = 14;
- for (var i = 0; i < 3; i++) {
- for (var j = 0; j < item.PageCount / 3; j++) {
- index++;
- ctx.fillText(index, xStart + i * 310 + numberLeft, yStart + j * height);
- }
- }
- //算式
- index = 0;
- ctx.setFontSize(24);
- for (var i = 0; i < 3; i++) {
- for (var j = 0; j < item.PageCount / 3; j++) {
- index++;
- //横式
- if (item.QuestionTypeCategory == 2) {
- 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;
-
- 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);
- }
- }
- }
- //竖式
- else if (item.QuestionTypeCategory == 3) {
- var num1 = item.QuestionList[index - 1];
- var isAnswer = false;
- var width = 250;
- if (num1.OperateAB == "÷")
- width=240;
- //console.log(num1);
- for (var n = 0; n < num1.Vertical.length; n++) {
- if (maxLength > num1.Vertical[n].Array.length) {
- if (num1.OperateAB != "÷")
- num1.Vertical[n].Array.splice(1, 0, "");
- }
- }
- console.log(num1);
- for (var n = 0; n < num1.Vertical.length; n++) {
- var num = xStart + i * 310 + width;
- for (var m = num1.Vertical[n].Array.length - 1; m >= 0; m--) {
- var str = "";
- if (num1.Vertical[n].Type == "line") {
- var lineLength = num1.Vertical[n].Array.length * 30+20;
- var lineTop=-15;
- if (num1.OperateAB == "÷") {
- lineLength = num1.A.toString().length * 30;
- lineTop=0;
- }
-
- ctx.moveTo(num, yStart + j * height + n * 30 + lineTop);
- ctx.lineTo(num - lineLength, yStart + j * height + n * 30 + lineTop);
- ctx.stroke();
- if (num1.OperateAB != "÷")
- isAnswer = true;
- break;
- }
- else {
- str = num1.Vertical[n].Array[m];
- if (num1.OperateAB == "÷" && str == "√") {
- isAnswer = true;
- ctx.drawImage("../../images/formula_division_size02.png", num - (num1.Vertical[n].Array.length - m) * 30 - 20, yStart + j * height + n * 30 - 31, 56, 76);
- //break;
- }
- else if (num1.OperateAB == "÷" && n == 0) {
- }
- else if (num1.OperateAB == "÷" && n == 1) {
- ctx.fillText(str, num - (num1.Vertical[n].Array.length - m) * 10, yStart + j * height + n * 30);
- }
- else {
- ctx.fillText(str, num - (num1.Vertical[n].Array.length - m) * 30, yStart + j * height + n * 30);
- }
- }
- }
- if (isAnswer)
- break;
- }
- }
- }
- }
- ctx.setTextAlign('left');
- ctx.setTextBaseline('top');
- ctx.setFontSize(32);
- ctx.fillText(item.Name, 60, 45);
- ctx.fillText("99", 835, 50);
- 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.drawImage("../../images/answer.png", 890, 54, 100, 100);
- 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,
- });
- }
- });
|