detail.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var times = 1;
  5. var pageIndex = 0;
  6. var QuestionItem = [];
  7. var tempAnswerList = [];
  8. var arrAnswerID = [];
  9. var isAndroid = false;
  10. const waitTime = ["", "10秒钟", "15秒钟", "20秒钟", "25秒钟"];
  11. Page({
  12. data: {
  13. version: app.globalData.Version,
  14. IsShowMenu: false,
  15. filter: 'horizontal',
  16. //filter: 'vertical',
  17. PageNumber: 1,
  18. PageCount: 60,
  19. IsFinished: false,
  20. arrPage: [],
  21. ShowLoading: false,
  22. IsDistabled: "",
  23. NameClass: "",
  24. AddDisabled: "",
  25. SubDisabled: "btnAddSubDisabled",
  26. HelpHidden7: true,
  27. HelpHidden3: true,
  28. HelpHidden8: true,
  29. ShowAndroidNotice: false,
  30. },
  31. onLoad: function (options) {
  32. var that = this;
  33. var id = options.id;
  34. isAndroid = false;
  35. if (app.globalData.systemInfo.system && app.globalData.systemInfo.system.indexOf("Android") >= 0)
  36. isAndroid = true;
  37. this.setData({
  38. Containnerheight: server.getWindowHeight(),
  39. ID: id,
  40. ShowAndroidNotice: isAndroid,
  41. IsMember:app.globalData.userInfo.IsMember,
  42. });
  43. var systemInfo = wx.getSystemInfoSync();
  44. if (systemInfo.system && systemInfo.system.indexOf("Android") >= 0) {
  45. times = 2;
  46. }
  47. this.getDetail(id);
  48. if (id > 0) {
  49. common.getStorageValue(this, "HelpHidden3", false, function () {
  50. that.showHelp();
  51. });
  52. } else {
  53. common.getStorageValue(this, "HelpHidden8", false, function () {
  54. that.showHelp8();
  55. });
  56. }
  57. // common.getStorageValue(this, "IsShare", 0, function () {
  58. // if (that.data.IsShare == 0 &&
  59. // app.globalData.userInfo.IsMember == 0 &&
  60. // app.globalData.userInfo.IsShow == 1 &&
  61. // app.globalData.IsLocked == 1
  62. // ) {
  63. // wx.navigateTo({
  64. // url: '../../package4/main/share',
  65. // })
  66. // }
  67. // });
  68. },
  69. onShow: function () {
  70. if (this.data.ID == -1)
  71. this.getDetail(this.data.ID);
  72. },
  73. onUnload: function () {
  74. wx.hideLoading();
  75. this.closeHelp();
  76. },
  77. getDetail: function (id) {
  78. var item = {};
  79. if (id > 0) {
  80. var data = wx.getStorageSync('QuestionTypeList');
  81. for (var i = 0; i < data.length; i++) {
  82. for (var k = 0; k < data[i].List.length; k++) {
  83. if (id == data[i].List[k].ID) {
  84. item = data[i].List[k];
  85. item.Example[0] = item.Example[0].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ ");
  86. if (item.Example[1])
  87. item.Example[1] = item.Example[1].replace("+", " + ").replace("-", " - ").replace("×", " × ").replace("÷", " ÷ ");
  88. item.IconName = app.globalData.fileUrl + item.IconName;
  89. if (item.Name.length > 12)
  90. item.NameClass = "text2";
  91. break;
  92. }
  93. }
  94. }
  95. } else {
  96. item.Name = "我的错题集";
  97. var list = wx.getStorageSync('ErrorList');
  98. item.ErrorList = list;
  99. }
  100. this.setData({
  101. QuestionTypeItem: item,
  102. });
  103. //有竖式则缺省竖式
  104. if (item.QuestionNumber3 > 0) {
  105. this.menuClick({
  106. currentTarget: {
  107. dataset: {
  108. id: "vertical"
  109. }
  110. }
  111. })
  112. }
  113. },
  114. gotoError: function (e) {
  115. wx.navigateTo({
  116. url: '../main/errorlist',
  117. });
  118. },
  119. gotoAnswer: function (e) {
  120. wx.navigateTo({
  121. url: '../main/answer',
  122. });
  123. this.closeHelp2();
  124. },
  125. getFinish: function () {
  126. server.playSound("/sounds/click.mp3");
  127. var that=this;
  128. if (app.globalData.userInfo.IsMember==1){
  129. that.setData({
  130. ShowLoading: true,
  131. BtnText: "全部保存到相册",
  132. });
  133. wx.hideLoading();
  134. arrAnswerID = [];
  135. tempAnswerList = [];
  136. that.getAnswerID();
  137. if (that.data.ID > 0) {
  138. that.getList(that.data.ID);
  139. } else {
  140. that.getErrorList();
  141. }
  142. that.closeHelp();
  143. }
  144. else{
  145. // 若在开发者工具中无法预览广告,请切换开发者工具中的基础库版本
  146. // 在页面中定义激励视频广告
  147. let videoAd = null;
  148. // 在页面onLoad回调事件中创建激励视频广告实例
  149. if (wx.createRewardedVideoAd) {
  150. videoAd = wx.createRewardedVideoAd({
  151. adUnitId: 'adunit-5cc4270e78bbcf35'
  152. });
  153. videoAd.onLoad(() => {
  154. });
  155. videoAd.onError((err) => {
  156. console.error('激励视频光告加载失败', err)
  157. });
  158. videoAd.onClose((res) => {
  159. console.log(res);
  160. if (res.isEnded){
  161. that.setData({
  162. ShowLoading: true,
  163. BtnText: "全部保存到相册",
  164. });
  165. wx.hideLoading();
  166. arrAnswerID = [];
  167. tempAnswerList = [];
  168. that.getAnswerID();
  169. if (that.data.ID > 0) {
  170. that.getList(that.data.ID);
  171. } else {
  172. that.getErrorList();
  173. }
  174. that.closeHelp();
  175. }
  176. else{
  177. wx.showToast({
  178. title: '请播放完广告',
  179. });
  180. }
  181. });
  182. }
  183. // 用户触发广告后,显示激励视频广告
  184. if (videoAd) {
  185. videoAd.show().catch(() => {
  186. // 失败重试
  187. videoAd.load()
  188. .then(() => videoAd.show())
  189. .catch(err => {
  190. console.error('激励视频 广告显示失败', err)
  191. });
  192. });
  193. }
  194. }
  195. },
  196. //重新生成试卷
  197. ResetFinish: function () {
  198. var that = this;
  199. wx.showLoading({
  200. title: "正在重置",
  201. complete: function () {
  202. var list = that.data.arrPage;
  203. for (var i = 0; i < list.length; i++) {
  204. wx.removeSavedFile({
  205. filePath: list[i].TempImagePath
  206. });
  207. }
  208. that.setData({
  209. arrPage: [],
  210. PageNumber: 1,
  211. });
  212. var tempList = wx.getStorageSync("AnswerList");
  213. for (var i = 0; i < list.length; i++) {
  214. tempList.shift();
  215. }
  216. wx.setStorageSync("AnswerList", tempList);
  217. wx.hideLoading();
  218. that.getFinish();
  219. }
  220. });
  221. },
  222. //题卡数据列表
  223. getList: function (id) {
  224. var that = this;
  225. var pageNum = that.data.PageNumber;
  226. var QuestionTypeCategory = 3;
  227. if (that.data.filter == "horizontal")
  228. QuestionTypeCategory = 2;
  229. pageIndex = 0;
  230. server.getData('GetQuestionTypesPrint?ID=' + id + '&QuestionTypeCategory=' + QuestionTypeCategory + '&PageNum=' + pageNum, function (data) {
  231. //console.log("UserInfo:" + data);
  232. if (data) {
  233. that.setData({
  234. IsFinished: true,
  235. arrPage: [],
  236. IsDistabled: "",
  237. WaitTime: waitTime[that.data.PageNumber],
  238. });
  239. QuestionItem = data;
  240. QuestionItem.IconName = that.data.QuestionTypeItem.IconName;
  241. // if (isAndroid) {
  242. // console.log("android");
  243. // const query = wx.createSelectorQuery();
  244. // query.select('#Canvas')
  245. // .fields({ node: true, size: true })
  246. // .exec((res) => {
  247. // const canvas = res[0].node;
  248. // const ctx = canvas.getContext('2d');
  249. // canvas.width = 1050;
  250. // canvas.height = 1485;
  251. // wx.canvasToTempFilePath({
  252. // x: 0,
  253. // y: 0,
  254. // width: canvas.width,
  255. // height: canvas.height,
  256. // canvas: canvas,
  257. // success: function(res2) {
  258. // that.saveImage();
  259. // }
  260. // });
  261. // });
  262. // }
  263. // else {
  264. that.saveImage();
  265. // }
  266. }
  267. });
  268. },
  269. //错题列表
  270. getErrorList: function () {
  271. var that = this;
  272. QuestionItem = that.data.QuestionTypeItem;
  273. if (QuestionItem.ErrorList.length > 0) {
  274. QuestionItem.Category = -1; //错题集类别
  275. QuestionItem.QuestionTypeCategory = 2;
  276. QuestionItem.CategoryName = "";
  277. QuestionItem.Name = "我的错题集";
  278. QuestionItem.QuestionTypeLevel = "";
  279. QuestionItem.PageCount = QuestionItem.ErrorList.length > 60 ? 60 : QuestionItem.ErrorList.length;
  280. QuestionItem.QuestionList = QuestionItem.ErrorList;
  281. QuestionItem.CreateTime = common.formatDateCHSLong(new Date());
  282. QuestionItem.IconName = app.globalData.fileUrl + "questioncard_icon_grade0102_size01.png";
  283. QuestionItem.QuestionList = common.randomArray(QuestionItem.QuestionList);
  284. delete QuestionItem.ErrorList;
  285. pageIndex = 0;
  286. that.setData({
  287. IsFinished: true,
  288. arrPage: [],
  289. IsDistabled: "",
  290. WaitTime: waitTime[that.data.PageNumber],
  291. });
  292. // if (isAndroid) {
  293. // console.log("android");
  294. // const query = wx.createSelectorQuery();
  295. // query.select('#Canvas')
  296. // .fields({ node: true, size: true })
  297. // .exec((res) => {
  298. // const canvas = res[0].node;
  299. // const ctx = canvas.getContext('2d');
  300. // canvas.width = 1050;
  301. // canvas.height = 1485;
  302. // wx.canvasToTempFilePath({
  303. // x: 0,
  304. // y: 0,
  305. // width: canvas.width,
  306. // height: canvas.height,
  307. // canvas: canvas,
  308. // success: function(res2) {
  309. // that.saveImage();
  310. // }
  311. // });
  312. // });
  313. // }
  314. // else {
  315. that.saveImage();
  316. // }
  317. } else {
  318. this.setData({
  319. ShowLoading: false,
  320. });
  321. wx.showModal({
  322. title: "没有错题",
  323. showCancel: false,
  324. content: "先到“对答案”中给做错的题目打记号(点击题目序号)",
  325. });
  326. }
  327. },
  328. getAnswerID: function () {
  329. var list = wx.getStorageSync("AnswerList");
  330. var id = 1;
  331. if (list && list.length > 0) {
  332. list.sort(function (a, b) {
  333. return b.AnswerID - a.AnswerID;
  334. });
  335. id = list[0].AnswerID + 1;
  336. }
  337. for (var i = 0; i < this.data.PageNumber; i++)
  338. arrAnswerID.push(id + i);
  339. },
  340. saveImage: function () {
  341. var that = this;
  342. var item = QuestionItem;
  343. item.AnswerID = arrAnswerID.shift();
  344. const query = wx.createSelectorQuery();
  345. query.select('#Canvas')
  346. .fields({
  347. node: true,
  348. size: true
  349. })
  350. .exec((res) => {
  351. var canvas = res[0].node;
  352. var ctx = canvas.getContext('2d');
  353. canvas.width = 1050;
  354. canvas.height = 1485;
  355. ctx.textAlign="left";
  356. ctx.textBaseline="top";
  357. ctx.font = "12px";
  358. ctx.fillStyle="#ffffff";
  359. ctx.fillRect(0, 0, canvas.width, canvas.height);
  360. ctx.fillStyle = "#000000";
  361. var xStart = 60;
  362. var yStart = 247;
  363. var height = 150;
  364. if (item.QuestionTypeCategory == 2)
  365. height = 59;
  366. if (item.Category > 0) {
  367. if (item.PageCount == 18)
  368. height = 210;
  369. else if (item.PageCount == 15)
  370. height = 250;
  371. else if (item.PageCount == 9)
  372. height = 400;
  373. }
  374. //括号
  375. var index = 0;
  376. for (var i = 0; i < 3; i++) {
  377. for (var j = 0; j < item.PageCount / 3; j++) {
  378. index++;
  379. if (index <= item.QuestionList.length) {
  380. ctx.fillText("(", xStart + i * 310, yStart + j * height);
  381. ctx.fillText(")", xStart + i * 310 + 22, yStart + j * height);
  382. }
  383. }
  384. }
  385. //编号
  386. index = 0;
  387. ctx.textAlign="center";
  388. var numberLeft = 12;
  389. if (isAndroid)
  390. numberLeft = 14;
  391. for (var i = 0; i < 3; i++) {
  392. for (var j = 0; j < item.PageCount / 3; j++) {
  393. index++;
  394. if (index <= item.QuestionList.length) {
  395. ctx.fillText(index, xStart + i * 310 + numberLeft, yStart + j * height);
  396. }
  397. }
  398. }
  399. //算式
  400. index = that.data.arrPage.length * item.PageCount;
  401. //ctx.setFontSize(24);
  402. ctx.font = "24px";
  403. var urlDiv=[];
  404. for (var i = 0; i < 3; i++) {
  405. for (var j = 0; j < item.PageCount / 3; j++) {
  406. index++;
  407. if (index <= item.QuestionList.length) {
  408. //横式
  409. if (item.QuestionTypeCategory == 2) {
  410. var A = item.QuestionList[index - 1].A.toString();
  411. if (item.QuestionList[index - 1].HiddenColumn == "A")
  412. A = "____";
  413. var OperateAB = item.QuestionList[index - 1].OperateAB.toString();
  414. //console.log(OperateAB);
  415. var B = item.QuestionList[index - 1].B.toString();
  416. if (item.QuestionList[index - 1].HiddenColumn == "B")
  417. B = "____";
  418. var equation = A + " " + OperateAB + " " + B;
  419. if (item.QuestionList[index - 1].C) {
  420. var OperateBC = item.QuestionList[index - 1].OperateBC.toString();
  421. var C = item.QuestionList[index - 1].C.toString();
  422. equation += " " + OperateBC + " " + C;
  423. if (item.QuestionList[index - 1].D) {
  424. var OperateCD = item.QuestionList[index - 1].OperateCD.toString();
  425. var D = item.QuestionList[index - 1].D.toString();
  426. equation += " " + OperateCD + " " + D;
  427. }
  428. }
  429. equation += " = ";
  430. var R = item.QuestionList[index - 1].R.toString();
  431. if (item.QuestionList[index - 1].HiddenColumn == "R")
  432. R = "";
  433. equation += R;
  434. var num = xStart + i * 310 + 31;
  435. for (var n = 0; n < equation.length; n++) {
  436. var len = getLength(equation[n]);
  437. num += len;
  438. if (equation[n] == ".") {
  439. ctx.fillText(equation[n], num + 3, yStart + j * 59 - 5);
  440. } else {
  441. var h = -8;
  442. if (equation[n] == "_")
  443. h = 0;
  444. ctx.fillText(equation[n], num, yStart + j * 59 + h);
  445. }
  446. }
  447. }
  448. //竖式
  449. else if (item.QuestionTypeCategory == 3) {
  450. var num1 = item.QuestionList[index - 1];
  451. var isAnswer = false;
  452. var width = 250;
  453. if (num1.OperateAB == "÷")
  454. width = 240;
  455. for (var n = 0; n < num1.Vertical.length; n++) {
  456. var num = xStart + i * 310 + width;
  457. var num2 = 0;
  458. for (var m = num1.Vertical[n].Array.length - 1; m >= 0; m--) {
  459. var str = "";
  460. if (num1.Vertical[n].Type == "line") {
  461. if (num1.OperateAB != "÷") {
  462. //var lineLength = num1.Vertical[n].Array.length * 30 + 20;
  463. var lineLength = 6 * 30 + 20;
  464. var lineTop = 4;
  465. //console.log(yStart + j * height + n * 30 + lineTop);
  466. ctx.moveTo(num, yStart + j * height + n * 30 + lineTop);
  467. ctx.lineTo(num - lineLength, yStart + j * height + n * 30 + lineTop);
  468. ctx.stroke();
  469. isAnswer = true;
  470. break;
  471. }
  472. } else {
  473. str = num1.Vertical[n].Array[m];
  474. if (num1.OperateAB == "÷" && str == "√") {
  475. isAnswer = true;
  476. var lineLength = num1.A.toString().length;
  477. var lineWidth = Math.floor(57 * (1 + num1.A.toString().length) / 2);
  478. var obj={};
  479. obj.url="../images/formula_division_size0" + lineLength + ".png";
  480. obj.num1=num - (num1.Vertical[n].Array.length - m) * 30 - 8;
  481. obj.num2=yStart + j * height + n * 30 - 10;
  482. obj.num3=lineWidth;
  483. obj.num4=39;
  484. urlDiv.push(obj);
  485. // var img = canvas.createImage();
  486. // img.src = "../images/formula_division_size0" + lineLength + ".png";
  487. // console.log(img.src);
  488. // img.onload = e => {
  489. // ctx.drawImage(img, num - (num1.Vertical[n].Array.length - m) * 30 - 8, yStart + j * height + n * 30 - 10, lineWidth, 39);
  490. // };
  491. }
  492. else if (num1.OperateAB == "÷" && n == 0) {} else if (num1.OperateAB == "÷" && n == 1) {
  493. ctx.fillText(str, num - (num1.Vertical[n].Array.length - m) * 10, yStart + j * height + n * 30);
  494. }
  495. else {
  496. if (str == ".") {
  497. ctx.fillText(str, num - (num1.Vertical[n].Array.length - m) * 30 + 15, yStart + j * height + n * 30);
  498. num2 = 30;
  499. } else if (str == "+" || str == "-" || str == "−" || str == "×" || str == "÷") {
  500. var lineLength = 6 * 30;
  501. ctx.fillText(str, num - lineLength, yStart + j * height + n * 30);
  502. num2 = 30;
  503. } else
  504. ctx.fillText(str, num - (num1.Vertical[n].Array.length - m) * 30 + num2, yStart + j * height + n * 30);
  505. }
  506. }
  507. }
  508. if (isAnswer)
  509. break;
  510. }
  511. }
  512. }
  513. }
  514. }
  515. ctx.textAlign="left";
  516. //ctx.setFontSize(32);
  517. ctx.font = "32px";
  518. ctx.fillText(item.Name, 60, 45);
  519. //ctx.setFontSize(12);
  520. ctx.font = "12px";
  521. ctx.fillText(item.CategoryName, 60, 90);
  522. ctx.fillText("共" + item.PageCount + "道题", 60, 125);
  523. ctx.fillText("第 "+(pageIndex+1).toString()+" / "+that.data.PageNumber+" 页", 60, 147);
  524. ctx.fillText("答案检索号", 768, 60);
  525. ctx.textAlign="right";
  526. ctx.fillText("出题时间 " + item.CreateTime, 875, 94);
  527. ctx.fillText("微信扫一扫 计时看答案", 875, 111);
  528. ctx.fillText("《数学计算题》选题 打印 扫码 批改", 875, 137);
  529. ctx.font = "32px";
  530. ctx.fillText(item.AnswerID, 872, 50);
  531. var img=canvas.createImage();
  532. img.src="../images/answer.png";
  533. img.onload = e => {
  534. ctx.drawImage(img, 890, 54, 100, 100);
  535. if (urlDiv.length>0){
  536. var img2=canvas.createImage();
  537. img2.src=urlDiv[0].url;
  538. img2.onload = e => {
  539. for(var k=0;k<urlDiv.length;k++)
  540. ctx.drawImage(img2, urlDiv[k].num1, urlDiv[k].num2, urlDiv[k].num3, urlDiv[k].num4);
  541. build();
  542. };
  543. }
  544. else
  545. build();
  546. };
  547. function build(){
  548. var w = 1050,h = 1485;
  549. wx.canvasToTempFilePath({
  550. x: 0,
  551. y: 0,
  552. width: w * times,
  553. height: h * times,
  554. destWidth: w * times,
  555. destHeight: h * times,
  556. canvas: canvas,
  557. success: function (res2) {
  558. //console.log(res2.tempFilePath);
  559. that.data.arrPage.push(res2.tempFilePath);
  560. item.TempImagePath = res2.tempFilePath;
  561. tempAnswerList.push(JSON.parse(JSON.stringify(item)));
  562. that.setData({
  563. arrPage: that.data.arrPage,
  564. });
  565. if (that.data.arrPage.length < that.data.PageNumber) {
  566. pageIndex++;
  567. that.saveImage();
  568. } else {
  569. //生成图片完成
  570. setTimeout(function () {
  571. that.setData({
  572. ShowLoading: false,
  573. });
  574. wx.pageScrollTo({
  575. scrollTop: 0,
  576. duration: 300
  577. });
  578. //存列表
  579. var tempList = wx.getStorageSync("AnswerList");
  580. if (!tempList)
  581. tempList = [];
  582. for (var x = 0; x < tempList.length; x++) {
  583. tempList[x].IsNew = 0;
  584. }
  585. for (var x = 0; x < tempAnswerList.length; x++) {
  586. var tempItem = tempAnswerList[x];
  587. var id = x * tempItem.PageCount;
  588. var arr = [];
  589. for (var y = 0; y < tempItem.QuestionList.length; y++) {
  590. if (y >= id && y < id + tempItem.PageCount) {
  591. arr.push(tempItem.QuestionList[y]);
  592. }
  593. }
  594. tempItem.QuestionList = arr;
  595. tempItem.IsNew = 1;
  596. tempList.unshift(tempItem);
  597. }
  598. wx.setStorageSync("AnswerList", tempList);
  599. common.getStorageValue(that, "HelpHidden7", false, function () {
  600. that.showHelp2();
  601. });
  602. }, 3000);
  603. }
  604. }
  605. });
  606. };
  607. });
  608. function getLength(str) {
  609. switch (str) {
  610. case "0":
  611. case "1":
  612. case "2":
  613. case "3":
  614. case "4":
  615. case "5":
  616. case "6":
  617. case "7":
  618. case "8":
  619. case "9":
  620. return 15;
  621. case ".":
  622. return 8;
  623. default:
  624. return 12;
  625. }
  626. }
  627. },
  628. //保存图片文件
  629. saveImageFile: function () {
  630. if (this.data.IsDistabled == "") {
  631. wx.showLoading({
  632. title: "保存中..."
  633. });
  634. var that = this;
  635. var count = 0;
  636. for (var i = 0; i < that.data.arrPage.length; i++) {
  637. wx.saveImageToPhotosAlbum({
  638. filePath: that.data.arrPage[i],
  639. success(res3) {
  640. console.log("save:" + res3.savedFilePath);
  641. count++
  642. if (count == that.data.arrPage.length) {
  643. wx.hideLoading();
  644. wx.showModal({
  645. title: "保存完成",
  646. showCancel: false,
  647. content: "请打开手机相册查看图片!",
  648. });
  649. that.setData({
  650. IsDistabled: "Distabled",
  651. BtnText: "已保存",
  652. });
  653. wx.pageScrollTo({
  654. scrollTop: 400,
  655. duration: 300
  656. });
  657. }
  658. },
  659. fail(err3) {
  660. console.log(err3);
  661. wx.openSetting();
  662. },
  663. complete() {
  664. wx.hideLoading();
  665. }
  666. })
  667. }
  668. }
  669. },
  670. changePageNumber: function (e) {
  671. var id = Number(e.currentTarget.dataset.id);
  672. this.data.PageNumber += id;
  673. var addDisabled = "",
  674. subDisabled = "";
  675. if (this.data.PageNumber <= 1) {
  676. this.data.PageNumber = 1;
  677. subDisabled = "btnAddSubDisabled";
  678. } else if (this.data.PageNumber >= 4) {
  679. this.data.PageNumber = 4;
  680. addDisabled = "btnAddSubDisabled";
  681. }
  682. this.setData({
  683. PageNumber: this.data.PageNumber,
  684. AddDisabled: addDisabled,
  685. SubDisabled: subDisabled,
  686. });
  687. },
  688. showImage: function (e) {
  689. var that = this;
  690. var id = e.currentTarget.dataset.id;
  691. wx.previewImage({
  692. current: that.data.arrPage[id], // 当前显示图片的http链接
  693. urls: that.data.arrPage // 需要预览的图片http链接列表
  694. });
  695. },
  696. closeLoading: function () {
  697. var that = this;
  698. that.setData({
  699. ShowLoading: false,
  700. IsFinished: false,
  701. });
  702. },
  703. menuClick: function (e) {
  704. this.data.filter = e.currentTarget.dataset.id;
  705. if (this.data.filter == "horizontal") {
  706. this.data.PageCount = this.data.QuestionTypeItem.QuestionNumber2;
  707. } else if (this.data.filter == "vertical") {
  708. this.data.PageCount = this.data.QuestionTypeItem.QuestionNumber3;
  709. }
  710. this.setData({
  711. filter: this.data.filter,
  712. IsShowMenu: false,
  713. PageCount: this.data.PageCount,
  714. });
  715. },
  716. closeMenu: function () {
  717. this.setData({
  718. IsShowMenu: false,
  719. });
  720. },
  721. openMenu: function () {
  722. this.setData({
  723. IsShowMenu: true,
  724. });
  725. },
  726. showHelp: function () {
  727. if (!this.data.HelpHidden3) {
  728. this.audioCtx = wx.createAudioContext('myAudio');
  729. var str = "嘿嘿,找到我了吗?我在车间的窗户里制作例题呢。如果这是你要的题型,去点“出题”按钮就对了。还要告诉你,一张卷子就是一张图片,题目数量请看提示。";
  730. server.playAudio(this.audioCtx, str);
  731. }
  732. },
  733. closeHelp: function () {
  734. this.setData({
  735. HelpHidden3: true,
  736. });
  737. wx.setStorageSync("HelpHidden3", true);
  738. this.audioCtx = wx.createAudioContext('myAudio');
  739. this.audioCtx.pause();
  740. },
  741. showHelp2: function () {
  742. if (!this.data.HelpHidden7) {
  743. this.audioCtx = wx.createAudioContext('myAudio');
  744. var str = "卷子出炉咯,棒棒哒!快去手机相册打印吧。我会等在首页上的答案资料室为你继续带路的。";
  745. server.playAudio(this.audioCtx, str);
  746. }
  747. },
  748. closeHelp2: function () {
  749. this.setData({
  750. HelpHidden7: true,
  751. });
  752. wx.setStorageSync("HelpHidden7", true);
  753. this.audioCtx = wx.createAudioContext('myAudio');
  754. this.audioCtx.pause();
  755. },
  756. showHelp8: function () {
  757. if (!this.data.HelpHidden8) {
  758. this.audioCtx = wx.createAudioContext('myAudio');
  759. var str = "发现错误是提高成绩的第一步。点一下题目数量右侧的图标,当有错题后,能查看和整理错题清单。";
  760. server.playAudio(this.audioCtx, str);
  761. }
  762. },
  763. closeHelp8: function () {
  764. this.setData({
  765. HelpHidden8: true,
  766. });
  767. wx.setStorageSync("HelpHidden8", true);
  768. this.audioCtx = wx.createAudioContext('myAudio');
  769. this.audioCtx.pause();
  770. },
  771. onShareAppMessage: function () {
  772. return {
  773. title: app.globalData.ShareTitle,
  774. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  775. imageUrl: app.globalData.ShareImage,
  776. }
  777. },
  778. })