detail.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. import constant from '../../utils/constant';
  4. const app = getApp();
  5. const arrStudyPlan = ["日常", "紧急"];
  6. var innerAudioContext1;
  7. var listTaskFinished = []; //完成的任务
  8. var timeStart; //计算时长
  9. var timeHistory = 0; //已经过去的时间
  10. var TaskList = []; //任务列表
  11. var FolderList = []; //卡单列表
  12. var arrImage = [],
  13. arrImage2 = [];
  14. var intervalSound = 0,
  15. intervalRefresh = 0;
  16. var isCollecting = false;
  17. var isExit = true;
  18. var isPlaying = false;
  19. var currentFolderID = -1; //当前练习卡单ID,没有时为-1
  20. var currentFolderStart = false;
  21. var timeoutPlayAudio;
  22. var tempPlayUrl = "";
  23. var tempPlayUrlLocal = "";
  24. var timeoutEveryCard = 0;
  25. var timeoutHide = 0;
  26. var arrAutoAudio = [];
  27. Page({
  28. data: {
  29. ImagePath: app.globalData.uploadImageUrl,
  30. NumberNew: 10,
  31. NumberReview: 0,
  32. NumberHistory: 30,
  33. IsShowNumberInfo: false,
  34. IsMore: false,
  35. IsShowFolder: false,
  36. StudyPlanArray: arrStudyPlan,
  37. TaskInfo: {},
  38. Color: {
  39. ID: 1
  40. },
  41. IsAutoSound: false, //是否设置了自动播放
  42. IsAutoSoundStart: false, //是否开始自动播放
  43. Title: "",
  44. FontSizeArray: constant.arrFontSize,
  45. IsBuildReport:false,
  46. },
  47. onReady: function () {
  48. var that = this;
  49. innerAudioContext1 = wx.createInnerAudioContext();
  50. innerAudioContext1.onPlay(() => {
  51. //console.log('开始播放')
  52. });
  53. innerAudioContext1.onError((res) => {
  54. console.log("innerAudioContext1.errMsg:" + res.errMsg);
  55. console.log("innerAudioContext1.errCode:" + res.errCode);
  56. that.audioCtx.setSrc(tempPlayUrl);
  57. that.audioCtx.play();
  58. });
  59. innerAudioContext1.onEnded((res) => {
  60. that.audioBindEnded();
  61. });
  62. common.getStorageValue(that, "HasSound", true, function () {
  63. wx.setStorageSync("HasSound", that.data.HasSound);
  64. });
  65. },
  66. onLoad: function (options) {
  67. var that = this;
  68. var height = app.globalData.systemInfo.screenHeight * 2 - 90;
  69. var height2 = 750;
  70. if (app.globalData.IsIPad) {
  71. height = app.globalData.systemInfo.screenHeight;
  72. height2 = 670;
  73. that.setData({
  74. IsIPad: "_iPad",
  75. });
  76. }
  77. that.setData({
  78. IsBuildReport:false,
  79. Containnerheight: height,
  80. Containnerheight2: height - height2,
  81. IsShowAnswer: [0, 0],
  82. CanUndo: 1,
  83. TaskInfo: {},
  84. ClickType: app.globalData.ClickType,
  85. Color: main.getDetailColor(app.globalData.ColorIndex),
  86. });
  87. if (that.data.IsShowOtherButton)
  88. that.closeOtherButton();
  89. this.audioCtx = wx.createAudioContext('myAudio');
  90. this.startTask();
  91. this.getList();
  92. this.getColor();
  93. this.getMemoryLevel();
  94. if (app.globalData.BaiduToken === "")
  95. main.getBaiduToken();
  96. if (app.globalData.IsOppo) {
  97. that.setData({
  98. TextSpace: "nbsp",
  99. });
  100. }
  101. },
  102. onShow: function () {
  103. var that = this;
  104. if (that.data.NumberNew == 0 &&
  105. that.data.NumberReview == 0 &&
  106. that.data.NumberHistory == 0) {
  107. that.setData({
  108. CanUndo: 0,
  109. TaskInfo: {},
  110. });
  111. listTaskFinished = [];
  112. that.getTaskTime();
  113. } else {
  114. that.setSoundFile(-1);
  115. var list = app.globalData.CardList;
  116. if (list && list.length > 0) {
  117. for (var i = 0; i < list.length; i++) {
  118. if (TaskList && TaskList[0] && TaskList[0].MiaoguoCardID == list[i].MiaoguoCardID) {
  119. TaskList[0].Content = list[i].Content;
  120. TaskList[0].ContentNew = main.changeStringToView(list[i].Content);
  121. that.setData({
  122. TaskInfo: TaskList[0],
  123. });
  124. app.globalData.CardList = [];
  125. break;
  126. }
  127. }
  128. }
  129. }
  130. if (that.data.IsMore) {
  131. //关于更改学习计划后处理
  132. if (app.globalData.IsUpdateStudyPlan == 1) {
  133. that.gotoNext({
  134. currentTarget: {
  135. dataset: {
  136. btnnumber: -2
  137. }
  138. }
  139. });
  140. app.globalData.IsUpdateStudyPlan = 0;
  141. }
  142. that.setData({
  143. IsMore: false,
  144. });
  145. }
  146. clearTimeout(timeoutHide);
  147. //console.log("显示");
  148. },
  149. startTask: function () {
  150. var url = 'StartMiaoguoTask?UserID=' + app.globalData.userInfo.UserID;
  151. main.getData(url, function (data) {});
  152. },
  153. onUnload: function () {
  154. clearInterval(intervalSound);
  155. clearTimeout(timeoutEveryCard);
  156. clearTimeout(timeoutHide);
  157. listTaskFinished = [];
  158. isPlaying = false;
  159. if (innerAudioContext1) {
  160. innerAudioContext1.stop();
  161. }
  162. },
  163. onHide: function (e) {
  164. console.log("隐藏");
  165. var that = this;
  166. if (isExit) {
  167. timeoutHide = setTimeout(function () {
  168. that.onClose();
  169. }, 200000);
  170. }
  171. isExit = true;
  172. },
  173. onPullDownRefresh: function () {
  174. this.onShowAnswer({
  175. currentTarget: {
  176. dataset: {
  177. start: true
  178. }
  179. }
  180. });
  181. wx.stopPullDownRefresh();
  182. },
  183. setSoundFile: function (isFinish) {
  184. //isFinish=3搁置 =2撤退 =1结束 =0正常 =-1开始
  185. var that = this;
  186. if (that.data.HasSound) {
  187. var url = "/pages/sounds/";
  188. if (isFinish == 1) {
  189. url += "end.mp3";
  190. } else if (isFinish == 2) {
  191. url += "short3.mp3";
  192. } else if (isFinish == 3) {
  193. url += "short1.mp3";
  194. } else {
  195. url += "short2.mp3";
  196. }
  197. if (isFinish >= 0) {
  198. innerAudioContext1.src = url;
  199. innerAudioContext1.play();
  200. }
  201. }
  202. wx.pageScrollTo({
  203. scrollTop: 0,
  204. });
  205. },
  206. getColor: function () {
  207. var that = this;
  208. if (wx.setBackgroundColor) {
  209. wx.setBackgroundColor({
  210. backgroundColor: that.data.Color.BackColor,
  211. backgroundColorTop: that.data.Color.BackColor,
  212. backgroundColorBottom: that.data.Color.BackColor,
  213. });
  214. }
  215. if (wx.setNavigationBarColor) {
  216. wx.setNavigationBarColor({
  217. frontColor: "#ffffff",
  218. backgroundColor: that.data.Color.BackColor,
  219. })
  220. }
  221. },
  222. getList: function () {
  223. var task = app.globalData.TaskToday;
  224. FolderList = task.FolderName;
  225. var that = this;
  226. var arrNew = task.ListNew || [];
  227. var arrHistory = task.ListHistory || [];
  228. var listTaskReview = task.ListReview || [];
  229. var nMax = [1, 1];
  230. if (arrNew.length == 0 || arrHistory.length == 0) {
  231. if (arrNew.length == 0) {
  232. nMax[0] = 0;
  233. }
  234. if (arrHistory.length == 0) {
  235. nMax[1] = 0;
  236. }
  237. } else if (arrNew.length >= arrHistory.length) {
  238. nMax[0] = Math.floor(arrNew.length / arrHistory.length);
  239. } else if (arrNew.length < arrHistory.length) {
  240. nMax[1] = Math.floor(arrHistory.length / arrNew.length);
  241. }
  242. arrNew = common.randomArray(arrNew);
  243. arrHistory = common.randomArray(arrHistory);
  244. var Len = arrNew.length + arrHistory.length;
  245. TaskList = [];
  246. var indexNew = 0,
  247. indexHistory = 0;
  248. for (var i = 0; i < Len; i++) {
  249. for (var j = 0; j < nMax[0]; j++) {
  250. if (indexNew < arrNew.length) {
  251. arrNew[indexNew].IsNew = true;
  252. delete arrNew[indexNew].IsHistory;
  253. TaskList.push(arrNew[indexNew++]);
  254. }
  255. }
  256. for (var j = 0; j < nMax[1]; j++) {
  257. if (indexHistory < arrHistory.length) {
  258. arrHistory[indexHistory].IsHistory = true;
  259. delete arrHistory[indexHistory].IsNew;
  260. TaskList.push(arrHistory[indexHistory++]);
  261. }
  262. }
  263. }
  264. that.data.NumberReview = listTaskReview.length;
  265. for (var i = 0; i < listTaskReview.length; i++) {
  266. listTaskReview[i].IsReview = true;
  267. delete listTaskReview[i].IsNew;
  268. delete listTaskReview[i].IsHistory;
  269. TaskList.push(listTaskReview[i]);
  270. }
  271. TaskList = updateNumberStr(TaskList);
  272. //处理列表
  273. TaskList = formatList(TaskList);
  274. var taskInfo = {};
  275. if (TaskList.length > 0) {
  276. arrImage = TaskList[0].ContentNew.Images;
  277. arrImage2 = TaskList[0].ContentNew.Images2;
  278. that.autoAudioPlayInit();
  279. taskInfo = TaskList[0];
  280. common.getStorageValue(that, "IsFolderPractice", 0, function () {
  281. if (that.data.IsFolderPractice == 1)
  282. that.onShowFolder();
  283. });
  284. }
  285. that.setData({
  286. NumberNew: arrNew.length,
  287. NumberReview: that.data.NumberReview,
  288. NumberHistory: arrHistory.length,
  289. TaskInfo: taskInfo,
  290. CanUndo: 0,
  291. });
  292. listTaskFinished = [];
  293. that.timeCompute(); //起始时间
  294. function formatList(list) {
  295. for (var i = 0; i < list.length; i++) {
  296. if (list[i].Content) {
  297. list[i].ContentNew = main.changeStringToView(list[i].Content);
  298. list[i].TagWidth = 0;
  299. if (list[i].ContentNew.Tags && list[i].ContentNew.Tags.length > 0) {
  300. list[i].TagWidth = 92 + (list[i].ContentNew.Tags.length - 1) * 122;
  301. for (var j = 0; j < list[i].ContentNew.Tags.length; j++) {
  302. if (list[i].ContentNew.Tags[j].length > 2) {
  303. list[i].TagWidth += 46 * (list[i].ContentNew.Tags[j].length - 2);
  304. }
  305. }
  306. }
  307. }
  308. }
  309. return list;
  310. }
  311. function updateNumberStr(list) {
  312. for (var i = 0; i < list.length; i++) {
  313. if (list[i].Number0)
  314. list[i].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, list[i].Number0);
  315. if (list[i].Number1)
  316. list[i].Number1Str = main.getMemoryLevel(app.globalData.MemoryLevel, 1, list[i].Number1);
  317. if (list[i].Number2)
  318. list[i].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, list[i].Number2);
  319. if (list[i].Number3)
  320. list[i].Number3Str = main.getMemoryLevel(app.globalData.MemoryLevel, 3, list[i].Number3);;
  321. }
  322. return list;
  323. }
  324. },
  325. onShowAnswer: function (e) {
  326. var that = this;
  327. var clicktype = e.currentTarget.dataset.type;
  328. if (!(clicktype && clicktype == "all" && app.globalData.ClickType == 0)) {
  329. var start = e.currentTarget.dataset.start;
  330. if (!(that.data.NumberNew == 0 &&
  331. that.data.NumberReview == 0 &&
  332. that.data.NumberHistory == 0) && !that.data.IsShowNumberInfo) {
  333. if (!that.data.IsShowAnswer)
  334. that.data.IsShowAnswer = [0, 0];
  335. var recommend = 0;
  336. if (start) {
  337. that.data.IsShowAnswer[0] = 0;
  338. that.data.IsShowAnswer[1] = 0;
  339. } else {
  340. if (!that.data.IsShowAnswer) {
  341. that.data.IsShowAnswer = [0, 0];
  342. }
  343. if (that.data.IsShowAnswer[0] == 0 && that.data.IsShowAnswer[1] == 0) {
  344. that.data.IsShowAnswer[0] = 1;
  345. if (TaskList[0].ContentNew && TaskList[0].ContentNew.Field && TaskList[0].ContentNew.Field.length > 0) {
  346. if (TaskList[0].ContentNew.Field[3].length == 0) {
  347. that.data.IsShowAnswer[1] = 1;
  348. if (!that.data.TaskInfo.IsNew)
  349. recommend = getRecommendTime();
  350. that.setData({
  351. Recommend: recommend,
  352. });
  353. }
  354. }
  355. } else if (that.data.IsShowAnswer[0] && !that.data.IsShowAnswer[1]) {
  356. that.data.IsShowAnswer[1] = 1;
  357. if (!that.data.TaskInfo.IsNew)
  358. recommend = getRecommendTime();
  359. that.setData({
  360. Recommend: recommend,
  361. });
  362. }
  363. }
  364. that.setData({
  365. IsShowAnswer: that.data.IsShowAnswer,
  366. });
  367. that.autoAudioPlayInit();
  368. if (that.data.IsShowAnswer[0] == 1 && that.data.IsShowAnswer[1] == 0) {
  369. startScroll(2);
  370. } else if (that.data.IsShowAnswer[0] == 1 && that.data.IsShowAnswer[1] == 1) {
  371. if (that.data.TaskInfo.Content[3].Content) {
  372. startScroll(3);
  373. } else {
  374. startScroll(2);
  375. }
  376. }
  377. }
  378. function startScroll(t) {
  379. var num = 0;
  380. setHeight("#ViewField1", function (h1) {
  381. num += h1;
  382. setHeight("#ViewFieldTag", function (hTag) {
  383. if (hTag > 0)
  384. num += hTag + 60;
  385. //console.log("hTag:"+(hTag));
  386. setHeight("#ViewField2", function (h2) {
  387. if (t == 2) {
  388. if (h2 > (app.globalData.systemInfo.screenHeight / 3))
  389. scroll(num);
  390. } else {
  391. num += h2 + 20;
  392. scroll(num);
  393. }
  394. });
  395. });
  396. });
  397. }
  398. function setHeight(obj, callback) {
  399. var query = wx.createSelectorQuery().in(that);
  400. query.select(obj).boundingClientRect(function (res) {
  401. if (res && res.height) {
  402. //console.log(obj+".height:"+res.height);
  403. callback(res.height);
  404. } else {
  405. callback(0);
  406. }
  407. }).exec();
  408. }
  409. function scroll(top) {
  410. wx.pageScrollTo({
  411. scrollTop: top,
  412. });
  413. }
  414. function getRecommendTime() {
  415. if (app.globalData.SecondConfigArray[0] > 0) {
  416. var duration = common.diffDate("s", timeStart, new Date());
  417. if (duration <= app.globalData.SecondConfigArray[0])
  418. return 3;
  419. else if (duration <= app.globalData.SecondConfigArray[1])
  420. return 2;
  421. else if (duration <= app.globalData.SecondConfigArray[2])
  422. return 1;
  423. else
  424. return 0;
  425. } else
  426. return 0;
  427. }
  428. }
  429. },
  430. gotoEdit: function () {
  431. var that = this;
  432. //console.log(res.tapIndex);
  433. var list = [];
  434. list.push(TaskList[0]);
  435. app.globalData.CardList = list;
  436. wx.navigateTo({
  437. url: './add?type=edit1&id=' + TaskList[0].MiaoguoCardID,
  438. });
  439. isExit = false;
  440. clearTimeout(timeoutEveryCard);
  441. },
  442. //回到上一张题卡
  443. gotoPrev: function () {
  444. var that = this;
  445. if (listTaskFinished.length > 0) {
  446. var card = listTaskFinished.pop();
  447. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  448. timeHistory = 0;
  449. that.timeCompute();
  450. card.Card.Number0 = card.Number0Old;
  451. card.Card.Number0Str = card.Number0StrOld;
  452. card.Card.Number1 = card.Number1Old;
  453. card.Card.Number1Str = card.Number1StrOld;
  454. card.Card.Number2 = card.Number2Old;
  455. card.Card.Number2Str = card.Number2StrOld;
  456. card.Card.Number3 = card.Number3Old;
  457. card.Card.Number3Str = card.Number3StrOld;
  458. delete card.Card.IsNew;
  459. delete card.Card.IsHistory;
  460. delete card.Card.IsReview;
  461. if (card.IsNewOld)
  462. card.Card.IsNew = card.IsNewOld;
  463. else if (card.IsHistoryOld)
  464. card.Card.IsHistory = card.IsHistoryOld;
  465. else if (card.IsReviewOld)
  466. card.Card.IsReview = card.IsReviewOld;
  467. //去除重复
  468. for (var i = 0; i < TaskList.length; i++) {
  469. if (TaskList[i].MiaoguoCardID == card.Card.MiaoguoCardID) {
  470. TaskList.splice(i, 1);
  471. }
  472. }
  473. TaskList.unshift(card.Card);
  474. var canUndo = 1;
  475. if (listTaskFinished.length == 0)
  476. canUndo = 0;
  477. arrImage = TaskList[0].ContentNew.Images;
  478. arrImage2 = TaskList[0].ContentNew.Images2;
  479. that.setData({
  480. IsShowAnswer: [0, 0],
  481. TaskInfo: TaskList[0],
  482. NumberNew: card.NumberNew,
  483. NumberReview: card.NumberReview,
  484. NumberHistory: card.NumberHistory,
  485. CanUndo: canUndo,
  486. Recommend: 0,
  487. });
  488. if (that.data.IsShowOtherButton)
  489. that.closeOtherButton();
  490. that.autoAudioPlayInit();
  491. wx.showToast({
  492. title: '回到上一张',
  493. image: "../images/universalpic_undo_white_120x90.png",
  494. });
  495. that.setSoundFile(2);
  496. }
  497. },
  498. //进入下一张题卡
  499. gotoNext: function (e) {
  500. var that = this;
  501. //btnnumber可以有 5:秒过 4正常 3困难 2挪到最后 1搁置 0不过 -1今天要练 -2更改计划 -3卡单练习
  502. var btnnumber = e.currentTarget.dataset.btnnumber;
  503. //若是“挪到最后”
  504. if (btnnumber == 2) {
  505. if (TaskList.length > 0) {
  506. var card = TaskList.splice(0, 1);
  507. card[0].IsFinally = true;
  508. card[0].LimitTime = common.formatTime(new Date(), "/", true) + " 23:59:59";
  509. TaskList.push(card[0]);
  510. if (currentFolderID >= 0) {
  511. that.setCurrentFolder({
  512. currentTarget: {
  513. dataset: {
  514. folderid: currentFolderID
  515. }
  516. }
  517. });
  518. }
  519. that.setData({
  520. IsShowAnswer: [0, 0],
  521. TaskInfo: TaskList[0],
  522. CanUndo: 1,
  523. Recommend: 0,
  524. Title: "",
  525. });
  526. if (that.data.IsShowOtherButton)
  527. that.closeOtherButton();
  528. wx.showToast({
  529. title: '挪到最后',
  530. mask: true,
  531. image: "../images/universalpic_movetoend_white_120x120.png",
  532. });
  533. that.setSoundFile(3);
  534. } else {
  535. that.setFinallyResult();
  536. }
  537. } else {
  538. //若是没有选择了卡单,或者刚刚选择卡单
  539. if (currentFolderID == -1 || !currentFolderStart) {
  540. var time = e.currentTarget.dataset.time;
  541. //处理当前卡片进入历史数组
  542. var finishCard = {};
  543. finishCard.Card = TaskList[0];
  544. finishCard.NumberNew = this.data.NumberNew;
  545. finishCard.NumberReview = this.data.NumberReview;
  546. finishCard.NumberHistory = this.data.NumberHistory;
  547. finishCard.Number0Old = TaskList[0].Number0;
  548. finishCard.Number0StrOld = TaskList[0].Number0Str;
  549. finishCard.Number1Old = TaskList[0].Number1;
  550. finishCard.Number1StrOld = TaskList[0].Number1Str;
  551. finishCard.Number2Old = TaskList[0].Number2;
  552. finishCard.Number2StrOld = TaskList[0].Number2Str;
  553. finishCard.Number3Old = TaskList[0].Number3;
  554. finishCard.Number3StrOld = TaskList[0].Number3Str;
  555. if (TaskList[0].IsNew)
  556. finishCard.IsNewOld = TaskList[0].IsNew;
  557. if (TaskList[0].IsHistory)
  558. finishCard.IsHistoryOld = TaskList[0].IsHistory;
  559. if (TaskList[0].IsReview)
  560. finishCard.IsReviewOld = TaskList[0].IsReview;
  561. //若是当前题卡更改学习计划
  562. if (btnnumber == -2) {
  563. for (var i = 0, flag = true; i < listTaskFinished.length; flag ? i++ : i) {
  564. if (listTaskFinished[i].Card.MiaoguoCardID == finishCard.Card.MiaoguoCardID) {
  565. listTaskFinished.splice(i, 1);
  566. flag = false;
  567. } else
  568. flag = true;
  569. }
  570. } else {
  571. //若不是搁置
  572. //算出下一次的时间
  573. if (btnnumber != "1") {
  574. //若是分钟,则进入复习列表
  575. if (time.lastIndexOf("m") == time.length - 1) {
  576. var minute = Number(time.substr(0, time.indexOf("m")));
  577. TaskList[0].LimitTime = common.formatTime(common.addDate("n", minute, new Date()));
  578. //若是新建,则10m 1d 4d
  579. if (TaskList[0].IsNew || TaskList[0].IsReview) {
  580. if (minute == 1) {
  581. TaskList[0].Number0 = "1m";
  582. TaskList[0].Number2 = "10m";
  583. } else {
  584. TaskList[0].Number0 = "10m";
  585. TaskList[0].Number2 = "1d";
  586. }
  587. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  588. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  589. delete TaskList[0].Number1;
  590. delete TaskList[0].Number1Str;
  591. delete TaskList[0].Number3;
  592. delete TaskList[0].Number3Str;
  593. TaskList[0].FirstTime = null;
  594. TaskList[0].LastTime = null;
  595. }
  596. //若是历史的,则10m 1d
  597. else if (TaskList[0].IsHistory) {
  598. TaskList[0].Number0 = "10m";
  599. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  600. delete TaskList[0].Number1;
  601. delete TaskList[0].Number1Str;
  602. TaskList[0].Number2 = "1d";
  603. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  604. delete TaskList[0].Number3;
  605. delete TaskList[0].Number3Str;
  606. }
  607. TaskList[0].IsReview = true;
  608. delete TaskList[0].IsNew;
  609. delete TaskList[0].IsHistory;
  610. TaskList.push(TaskList[0]);
  611. }
  612. //若是天月年
  613. else {
  614. var dayNum = Number(time.substr(0, time.indexOf("d")));
  615. var date = common.addDate("d", dayNum, new Date());
  616. TaskList[0].LimitTime = common.formatTime(date);
  617. }
  618. }
  619. //修改学习任务个数
  620. var learningType = 0;
  621. if (TaskList[0].IsReview) {
  622. learningType = 2;
  623. }
  624. if (TaskList[0].IsNew) {
  625. learningType = 0;
  626. } else if (TaskList[0].IsHistory) {
  627. learningType = 1;
  628. }
  629. if (btnnumber == "1") {
  630. learningType = 3;
  631. }
  632. finishCard.IntervalTime = time;
  633. finishCard.BtnNumber = btnnumber;
  634. finishCard.LearningType = learningType;
  635. var duration = common.diffDate("s", timeStart, new Date());
  636. if (finishCard.btnnumber == 1)
  637. duration = 0;
  638. finishCard.Duration = timeHistory + duration;
  639. //console.log("CardTime:" + finishCard.Duration);
  640. timeHistory = 0;
  641. that.timeCompute();
  642. finishCard.LastTime = common.formatTime(new Date());
  643. //添加完成列表,去掉任务列表数据
  644. listTaskFinished.push(finishCard);
  645. }
  646. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  647. TaskList.shift();
  648. }
  649. that.data.NumberNew = 0;
  650. that.data.NumberHistory = 0;
  651. that.data.NumberReview = 0;
  652. for (var i = 0; i < TaskList.length; i++) {
  653. if (TaskList[i].IsReview) {
  654. that.data.NumberReview++;
  655. } else if (TaskList[i].IsNew) {
  656. that.data.NumberNew++;
  657. } else if (TaskList[i].IsHistory) {
  658. that.data.NumberHistory++;
  659. }
  660. }
  661. //到时题卡马上显示
  662. for (var i = 0; i < TaskList.length; i++) {
  663. if (TaskList[i].IsReview) {
  664. if (TaskList[i].LimitTime < common.formatTime(new Date())) {
  665. var card = TaskList.splice(i, 1);
  666. TaskList.unshift(card[0]);
  667. }
  668. }
  669. }
  670. currentFolderStart = false;
  671. //若选择了卡单
  672. var bFolder = false;
  673. if (currentFolderID >= 0) {
  674. for (var i = 0; i < TaskList.length; i++) {
  675. if (TaskList[i].FolderID == currentFolderID && !TaskList[i].IsFinally) {
  676. var card = TaskList.splice(i, 1);
  677. TaskList.unshift(card[0]);
  678. bFolder = true;
  679. break;
  680. }
  681. }
  682. }
  683. //挪到最后题卡继续挪到最后
  684. for (var i = 0; i < TaskList.length; i++) {
  685. if (TaskList[i].IsFinally) {
  686. var card = TaskList.splice(i, 1);
  687. TaskList.push(card[0]);
  688. }
  689. }
  690. //console.log(JSON.stringify(TaskList[0]));
  691. //如果所有任务完成
  692. if (that.data.NumberNew == 0 &&
  693. that.data.NumberReview == 0 &&
  694. that.data.NumberHistory == 0) {
  695. that.setFinallyResult();
  696. }
  697. //没有完成任务
  698. else {
  699. //如果卡单内题卡已经练习完毕,则重新选择卡单
  700. if (currentFolderID >= 0 && !bFolder) {
  701. currentFolderID = -1;
  702. that.onShowFolder();
  703. }
  704. arrImage = TaskList[0].ContentNew.Images;
  705. arrImage2 = TaskList[0].ContentNew.Images2;
  706. //任务没有完成,下一张卡片
  707. that.setData({
  708. IsShowAnswer: [0, 0],
  709. TaskInfo: TaskList[0],
  710. NumberNew: that.data.NumberNew,
  711. NumberReview: that.data.NumberReview,
  712. NumberHistory: that.data.NumberHistory,
  713. CanUndo: 1,
  714. Recommend: 0,
  715. IsMore: false,
  716. });
  717. if (that.data.IsShowOtherButton)
  718. that.closeOtherButton();
  719. //console.log("MiaoguoCardID:"+TaskList[0].MiaoguoCardID);
  720. //console.log("FolderID:"+TaskList[0].FolderID);
  721. that.autoAudioPlayInit();
  722. if (btnnumber == "1") {
  723. that.setSoundFile(3);
  724. if (time == "1d") {
  725. wx.showToast({
  726. title: '搁置一天',
  727. mask: true,
  728. image: "../images/universalpic_bell_white_120x120.png",
  729. });
  730. }
  731. } else
  732. that.setSoundFile(0);
  733. }
  734. }
  735. },
  736. timeCompute: function () {
  737. var that = this;
  738. timeStart = new Date();
  739. clearTimeout(timeoutEveryCard);
  740. timeoutEveryCard = setTimeout(function () {
  741. //计算暂停时已经用掉的时长
  742. timeHistory += common.diffDate("s", timeStart, new Date());
  743. console.log("timeHistory:" + timeHistory);
  744. if (!(that.data.NumberNew == 0 &&
  745. that.data.NumberReview == 0 &&
  746. that.data.NumberHistory == 0)) {
  747. wx.showModal({
  748. title: '提醒',
  749. content: '您已等待了' + app.globalData.CardWaitTimeMax + '分钟',
  750. showCancel: false,
  751. confirmText: "知道了",
  752. success(res) {
  753. clearTimeout(timeoutEveryCard);
  754. clearTimeout(timeoutHide);
  755. if (res.confirm) {
  756. that.timeCompute();
  757. }
  758. },
  759. });
  760. }
  761. }, app.globalData.CardWaitTimeMax * 60 * 1000);
  762. },
  763. setFinallyResult: function () {
  764. var that = this;
  765. that.setData({
  766. IsShowAnswer: [0, 0],
  767. NumberNew: 0,
  768. NumberReview: 0,
  769. NumberHistory: 0,
  770. CanUndo: 1,
  771. Recommend: 0,
  772. IsMore: false,
  773. });
  774. clearTimeout(timeoutEveryCard);
  775. that.setSoundFile(1);
  776. main.UpdateMiaoguoCardTodayAll(true, function () {
  777. listTaskFinished = [];
  778. that.getTaskTime();
  779. });
  780. },
  781. gotoCollect: function () {
  782. var that = this;
  783. if (!isCollecting) {
  784. isCollecting = true;
  785. setTimeout(function () {
  786. isCollecting = false;
  787. }, 3000);
  788. var that = this;
  789. if (!TaskList[0].IsCollect) {
  790. TaskList[0].IsCollect = 1;
  791. } else {
  792. TaskList[0].IsCollect = 0;
  793. }
  794. that.setData({
  795. TaskInfo: TaskList[0],
  796. });
  797. main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect);
  798. }
  799. },
  800. getTaskTime: function () {
  801. var that = this;
  802. var url = "GetMiaoguoTaskTime?";
  803. url += "UserID=" + app.globalData.userInfo.UserID;
  804. main.getData(url, function (data) {
  805. if (data) {
  806. var duration = data.Duration;
  807. if (duration > 0) {
  808. duration = Math.round(duration / 60);
  809. }
  810. var speed1 = 0;
  811. if (data.Duration > 0)
  812. speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100;
  813. var speed2 = 0 + "秒";
  814. if (data.Count > 0)
  815. speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true);
  816. app.globalData.TaskToday.DayNumber = data.DayNumber;
  817. that.setData({
  818. TodayTime: duration,
  819. Speed1: speed1 + "张题卡",
  820. Speed2: speed2,
  821. Title: "报告",
  822. });
  823. if (speed1 == "0张题卡" && speed2 == "0秒" && duration.toString() == "1") {
  824. wx.showModal({
  825. title: '提醒',
  826. showCancel: false,
  827. confirmText: '知道了',
  828. content: "也许您已经发现「报告」上的数据有些异样。这是由于本次练习从昨天开始到今天结束,发生了「跨天」的情况。虽然报告内容不够正确,但练习数据不会受到影响,这个问题将在日后得到改善。请不用担心。"
  829. });
  830. }
  831. }
  832. });
  833. },
  834. showNumberContainner: function () {
  835. if (!this.data.Title) {
  836. this.setData({
  837. IsShowNumberInfo: true,
  838. IsMore: false,
  839. IsShowFolder: false,
  840. });
  841. this.setData({
  842. Title: "进度",
  843. });
  844. clearTimeout(timeoutEveryCard);
  845. }
  846. },
  847. closeNumberContainner: function () {
  848. this.setData({
  849. IsShowNumberInfo: false,
  850. IsMore: false,
  851. IsShowFolder: false,
  852. });
  853. this.setData({
  854. Title: "",
  855. });
  856. this.timeCompute();
  857. },
  858. showImage: function (e) {
  859. var name = e.currentTarget.dataset.name;
  860. if (name && name.length > 5) {
  861. if (name.indexOf("tmp") >= 0) {
  862. wx.previewImage({
  863. current: name,
  864. urls: [name],
  865. });
  866. } else {
  867. wx.previewImage({
  868. current: name,
  869. urls: arrImage
  870. });
  871. }
  872. }
  873. },
  874. onFontSize: function (e) {
  875. var value = e.currentTarget.dataset.value;
  876. TaskList[0].FontSize = value;
  877. this.setData({
  878. TaskInfo: TaskList[0],
  879. IsMore: false,
  880. Title: "",
  881. });
  882. },
  883. onBindError: function (e) {
  884. var that = this;
  885. var serverUrl = e.currentTarget.dataset.serverurl;
  886. var oldTempUrl = e.currentTarget.dataset.name;
  887. //console.log("serverUrl1:" + serverUrl);
  888. wx.downloadFile({
  889. url: serverUrl, // 仅为示例,并非真实的资源
  890. success(res) {
  891. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  892. if (res.statusCode === 200) {
  893. //console.log("serverUrl2:" + serverUrl);
  894. //console.log(res.tempFilePath);
  895. main.saveTempImage(serverUrl, res.tempFilePath);
  896. for (var i = 0; i < arrImage.length; i++) {
  897. if (arrImage[i] == oldTempUrl) {
  898. arrImage[i] = res.tempFilePath;
  899. }
  900. }
  901. }
  902. }
  903. });
  904. clearTimeout(intervalRefresh);
  905. intervalRefresh = setTimeout(function () {
  906. if (TaskList && TaskList[0]) {
  907. TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content);
  908. that.setData({
  909. TaskInfo: TaskList[0],
  910. });
  911. }
  912. }, 1000);
  913. for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) {
  914. for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) {
  915. if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") {
  916. this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content;
  917. }
  918. }
  919. }
  920. this.setData({
  921. TaskInfo: this.data.TaskInfo,
  922. });
  923. },
  924. onMore: function () {
  925. for (var i = 0; i < this.data.FontSizeArray.length; i++) {
  926. if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize)
  927. this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";";
  928. else
  929. this.data.FontSizeArray[i].CSS = "";
  930. }
  931. this.setData({
  932. IsMore: true,
  933. FontSizeArray: this.data.FontSizeArray,
  934. Title: "调节",
  935. });
  936. clearTimeout(timeoutEveryCard);
  937. },
  938. showOtherButton: function () {
  939. var animation = wx.createAnimation();
  940. this.animation = animation;
  941. animation.translate(-710 + 'rpx', 0).step({
  942. duration: 200
  943. });
  944. this.setData({
  945. animationData: animation.export(),
  946. IsShowOtherButton: true,
  947. });
  948. },
  949. closeOtherButton: function () {
  950. var animation = wx.createAnimation();
  951. this.animation = animation;
  952. animation.translate(0, 0).step({
  953. duration: 200
  954. });
  955. this.setData({
  956. animationData: animation.export(),
  957. IsShowOtherButton: false,
  958. });
  959. },
  960. onShowFolder: function () {
  961. for (var j = 0; j < FolderList.length; j++) {
  962. FolderList[j].Total = 0;
  963. for (var i = 0; i < TaskList.length; i++) {
  964. if (TaskList[i].FolderID == FolderList[j].FolderID &&
  965. !TaskList[i].IsFinally) {
  966. FolderList[j].Total++;
  967. }
  968. }
  969. }
  970. var FolderListLength = FolderList.length;
  971. for (var j = 0; j < FolderList.length; j++) {
  972. if (FolderList[j].Total == 0) {
  973. FolderListLength--;
  974. }
  975. }
  976. var IsFinallyCount = 0;
  977. for (var j = 0; j < TaskList.length; j++) {
  978. if (TaskList[j].IsFinally) {
  979. IsFinallyCount++;
  980. }
  981. }
  982. this.setData({
  983. IsShowFolder: true,
  984. IsShowNumberInfo: false,
  985. IsMore: false,
  986. FolderList: FolderList,
  987. FolderListLength: FolderListLength,
  988. IsFinallyCount: IsFinallyCount,
  989. Title: " ",
  990. });
  991. },
  992. setCurrentFolder: function (e) {
  993. currentFolderID = e.currentTarget.dataset.folderid;
  994. currentFolderStart = true;
  995. this.gotoNext({
  996. currentTarget: {
  997. dataset: {
  998. btnnumber: -3
  999. }
  1000. }
  1001. });
  1002. this.closeNumberContainner();
  1003. },
  1004. onClose: function () {
  1005. console.log("close");
  1006. wx.navigateBack({
  1007. delta: 1,
  1008. });
  1009. },
  1010. getMemoryLevel: function () {
  1011. var index = wx.getStorageSync("MemoryLevel");
  1012. if (!index) {
  1013. index = 0;
  1014. }
  1015. if (index > 1)
  1016. index = 1;
  1017. app.globalData.MemoryLevel = index;
  1018. this.setData({
  1019. MemoryLevel: index,
  1020. });
  1021. },
  1022. buildShareImage: function () {
  1023. var that = this;
  1024. that.setData({
  1025. IsBuildReport:true,
  1026. });
  1027. wx.showLoading({
  1028. title: '生成中',
  1029. });
  1030. setTimeout(function () {
  1031. wx.hideLoading();
  1032. }, 5000);
  1033. //console.log(app.globalData.userInfo.AvatarUrl);
  1034. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  1035. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  1036. avatarUrl = avatarUrl + "0";
  1037. //console.log(avatarUrl);
  1038. wx.downloadFile({
  1039. url: avatarUrl,
  1040. success(resDownload) {
  1041. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1042. if (resDownload.statusCode === 200) {
  1043. const query = wx.createSelectorQuery();
  1044. query.select('#shareCanvas')
  1045. .fields({
  1046. node: true,
  1047. size: true
  1048. })
  1049. .exec((res) => {
  1050. const canvas = res[0].node;
  1051. const ctx = canvas.getContext('2d');
  1052. const dpr = wx.getSystemInfoSync().pixelRatio;
  1053. canvas.width = res[0].width * dpr;
  1054. canvas.height = res[0].height * dpr;
  1055. ctx.scale(dpr, dpr);
  1056. var img = canvas.createImage();
  1057. img.src = resDownload.tempFilePath;
  1058. img.onerror = err =>{
  1059. console.log(err);
  1060. };
  1061. img.onload = e => {
  1062. ctx.drawImage(img, 0, 0, 360, 360);
  1063. var img2 = canvas.createImage();
  1064. img2.src = "../images/universalpic_screenshot_jl_bgimage_360x360.png";
  1065. img2.onload = e => {
  1066. ctx.drawImage(img2, 0, 0, 360, 360);
  1067. ctx.fillStyle = main.getShareImageBackColor();
  1068. ctx.fillRect(360, 0, 240, 360);
  1069. ctx.fillStyle = "#ffffff";
  1070. ctx.font = "24px";
  1071. ctx.fillText(app.globalData.userInfo.NickName, 30, 306);
  1072. var today = common.formatTime(new Date(), ".", true);
  1073. ctx.font = "18px";
  1074. ctx.fillText(today, 30, 335);
  1075. ctx.font = "20px";
  1076. ctx.fillText("秒过学习", 390, 40);
  1077. ctx.font = "44px";
  1078. ctx.fillText("勤勉接力", 390, 88);
  1079. ctx.font = "20px";
  1080. ctx.fillText("见证成长", 390, 140);
  1081. ctx.font = "68px";
  1082. if (!that.data.TodayTime)
  1083. that.data.TodayTime = 0;
  1084. ctx.fillText(that.data.TodayTime, 390, 209);
  1085. ctx.font = "normal 500 68px caption";
  1086. var metrics = ctx.measureText(that.data.TodayTime.toString());
  1087. //console.log(JSON.stringify(metrics));
  1088. var h = 209;
  1089. if (app.globalData.IsIOS)
  1090. h = 206;
  1091. ctx.font = "normal 500 32px caption";
  1092. ctx.fillText("分钟", 393 + Math.round(metrics.width), h);
  1093. ctx.font = "20px";
  1094. ctx.fillText("迄今已接力", 390, 295);
  1095. ctx.font = "32px";
  1096. ctx.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 333);
  1097. //console.log("生成前");
  1098. setTimeout(function () {
  1099. //console.log("生成后1");
  1100. wx.canvasToTempFilePath({
  1101. x: 0,
  1102. y: 0,
  1103. width: 600,
  1104. height: 360,
  1105. destWidth: 600,
  1106. destHeight: 360,
  1107. canvas: canvas,
  1108. success: function (res2) {
  1109. wx.hideLoading();
  1110. //console.log("生成后2");
  1111. wx.previewImage({
  1112. current: res2.tempFilePath, // 当前显示图片的http链接
  1113. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  1114. });
  1115. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) {});
  1116. },
  1117. fail: function (e) {
  1118. wx.hideLoading();
  1119. //console.log("生成错误:"+e);
  1120. }
  1121. })
  1122. }, 500);
  1123. };
  1124. };
  1125. });
  1126. // var canvas = wx.createCanvasContext("shareCanvas", that);
  1127. // canvas.setFillStyle(main.getShareImageBackColor());
  1128. // canvas.fillRect(360, 0, 600, 360);
  1129. // canvas.drawImage(res.tempFilePath, 0, 0, 360, 360);
  1130. // canvas.drawImage("../images/universalpic_screenshot_jl_bgimage_360x360.png", 0, 0, 360, 360);
  1131. // canvas.fillStyle = "#ffffff";
  1132. // canvas.setTextBaseline('top');
  1133. // canvas.setFontSize(24);
  1134. // canvas.fillText(app.globalData.userInfo.NickName, 30, 282);
  1135. // var today = common.formatTime(new Date(), ".", true);
  1136. // canvas.setFontSize(18);
  1137. // canvas.fillText(today, 30, 315);
  1138. // canvas.setFontSize(20);
  1139. // canvas.fillText("秒过学习", 390, 30);
  1140. // canvas.setFontSize(44);
  1141. // canvas.fillText("勤勉接力", 390, 58);
  1142. // canvas.setFontSize(20);
  1143. // canvas.fillText("见证成长", 390, 120);
  1144. // canvas.setFontSize(68);
  1145. // if (!that.data.TodayTime)
  1146. // that.data.TodayTime = 0;
  1147. // canvas.fillText(that.data.TodayTime, 390, 148);
  1148. // canvas.font = "normal 500 68px caption";
  1149. // var metrics = canvas.measureText(that.data.TodayTime.toString());
  1150. // //console.log(JSON.stringify(metrics));
  1151. // var h = 179;
  1152. // if (app.globalData.IsIOS)
  1153. // h = 176;
  1154. // canvas.font = "normal 500 32px caption";
  1155. // canvas.fillText("分钟", 393 + Math.round(metrics.width), h);
  1156. // canvas.setFontSize(20);
  1157. // canvas.fillText("迄今已接力", 390, 267);
  1158. // canvas.setFontSize(32);
  1159. // canvas.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 295);
  1160. // //console.log("生成前");
  1161. // canvas.draw(1, function (n) {
  1162. // //console.log("生成后1");
  1163. // wx.canvasToTempFilePath({
  1164. // x: 0,
  1165. // y: 0,
  1166. // width: 600,
  1167. // height: 360,
  1168. // destWidth: 600,
  1169. // destHeight: 360,
  1170. // canvasId: 'shareCanvas',
  1171. // success: function (res2) {
  1172. // wx.hideLoading();
  1173. // //console.log("生成后2");
  1174. // wx.previewImage({
  1175. // current: res2.tempFilePath, // 当前显示图片的http链接
  1176. // urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  1177. // });
  1178. // main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) {});
  1179. // },
  1180. // fail: function (e) {
  1181. // wx.hideLoading();
  1182. // //console.log("生成错误:"+e);
  1183. // }
  1184. // })
  1185. // });
  1186. } else {
  1187. wx.hideLoading();
  1188. }
  1189. },
  1190. fail: function (e) {
  1191. wx.hideLoading();
  1192. }
  1193. });
  1194. },
  1195. saveCardType: function (event) {
  1196. var that = this;
  1197. var foldertype = event.currentTarget.dataset.foldertype;
  1198. var url = 'UpdateMiaoguoCardType?UserID=' + app.globalData.userInfo.UserID;
  1199. url += "&CardType=-1";
  1200. url += "&FolderType=" + foldertype;
  1201. url += "&ID=" + TaskList[0].MiaoguoCardID;
  1202. main.getData(url, function (data) {
  1203. TaskList.splice(0, 1);
  1204. if (TaskList.length > 0) {
  1205. that.setData({
  1206. TaskInfo: TaskList[0],
  1207. IsShowAnswer: [0, 0],
  1208. });
  1209. if (that.data.IsShowOtherButton)
  1210. that.closeOtherButton();
  1211. that.closeNumberContainner();
  1212. if (foldertype == 1) {
  1213. wx.showToast({
  1214. title: '不练习',
  1215. mask: true,
  1216. image: "../images/universalpic_exclamation_white_120x120.png",
  1217. });
  1218. app.globalData.FolderList = [];
  1219. } else {
  1220. wx.showToast({
  1221. title: '归档成功',
  1222. mask: true,
  1223. image: "../images/universalpic_cupboard_white_120x120.png",
  1224. });
  1225. }
  1226. that.setSoundFile(3);
  1227. } else {
  1228. that.setFinallyResult();
  1229. }
  1230. });
  1231. },
  1232. saveIsFolderPractice: function (e) {
  1233. var that = this;
  1234. var IsFolderPractice = that.data.IsFolderPractice == 0 ? 1 : 0;
  1235. that.setData({
  1236. IsFolderPractice: IsFolderPractice,
  1237. });
  1238. wx.setStorageSync('IsFolderPractice', IsFolderPractice);
  1239. main.UploadUserConfig();
  1240. },
  1241. switchSound: function (e) {
  1242. var that = this;
  1243. var autoAudio = !that.data.IsAutoSound;
  1244. that.setData({
  1245. IsAutoSound: autoAudio,
  1246. });
  1247. if (autoAudio) {
  1248. wx.setStorageSync('IsAutoSound', 1);
  1249. wx.showModal({
  1250. title: '提醒',
  1251. content: '如果题卡里有朗读和录音内容,开启后会按段落顺序逐个自动播放。界面右侧有停止按键。如不想被声音干扰,请关闭该功能。',
  1252. showCancel: false,
  1253. confirmText: "知道了",
  1254. success(res) {
  1255. },
  1256. });
  1257. } else {
  1258. wx.setStorageSync('IsAutoSound', 0);
  1259. }
  1260. main.UploadUserConfig();
  1261. },
  1262. autoAudioPlayInit: function () {
  1263. var that = this;
  1264. common.getStorageValue(that, "IsAutoSound", 1, function () {
  1265. if (that.data.IsAutoSound == 1) {
  1266. var taskInfo = that.data.TaskInfo;
  1267. var field = [];
  1268. var fieldNumber = 1;
  1269. if (that.data.IsShowAnswer[0] == 1)
  1270. fieldNumber = 2;
  1271. if (that.data.IsShowAnswer[1] == 1 && taskInfo.ContentNew.Field[3].length > 0)
  1272. fieldNumber = 3;
  1273. if (taskInfo.ContentNew && taskInfo.ContentNew.Field && taskInfo.ContentNew.Field.length > 0)
  1274. field = taskInfo.ContentNew.Field[fieldNumber];
  1275. arrAutoAudio = [];
  1276. for (var i = 0; i < field.length; i++) {
  1277. if (field[i].Type == "sound" || field[i].Type == "recorder") {
  1278. field[i].FieldNumber = fieldNumber;
  1279. arrAutoAudio.push(field[i]);
  1280. }
  1281. }
  1282. if (arrAutoAudio.length > 0) {
  1283. that.setData({
  1284. IsAutoSoundStart: true,
  1285. });
  1286. that.autoAudioPlayStart();
  1287. }
  1288. }
  1289. });
  1290. },
  1291. autoAudioPlayStart: function () {
  1292. var that = this;
  1293. if (arrAutoAudio.length > 0) {
  1294. var item = arrAutoAudio[0];
  1295. if (item.Type == "recorder")
  1296. item.Content = item.Type;
  1297. that.playSound({
  1298. currentTarget: {
  1299. dataset: {
  1300. content: item.Content,
  1301. soundmark: item.SoundMark,
  1302. fieldid: item.FieldNumber,
  1303. }
  1304. }
  1305. });
  1306. arrAutoAudio.splice(0, 1);
  1307. }
  1308. },
  1309. autoAudioPlayEnd: function () {
  1310. var that = this;
  1311. arrAutoAudio = [];
  1312. if (innerAudioContext1) {
  1313. innerAudioContext1.stop();
  1314. }
  1315. that.audioCtx.pause();
  1316. that.setData({
  1317. IsAutoSoundStart: false,
  1318. });
  1319. },
  1320. //音频播放结束
  1321. audioBindEnded: function () {
  1322. var that = this;
  1323. isPlaying = false;
  1324. if (arrAutoAudio.length > 0) {
  1325. that.autoAudioPlayStart();
  1326. } else {
  1327. that.setData({
  1328. IsAutoSoundStart: false,
  1329. });
  1330. }
  1331. },
  1332. audioBindError: function (err) {
  1333. //console.log(err);
  1334. if (innerAudioContext1 && innerAudioContext1.src) {
  1335. innerAudioContext1.src = tempPlayUrlLocal;
  1336. innerAudioContext1.play();
  1337. }
  1338. },
  1339. playSound: function (e) {
  1340. clearTimeout(timeoutPlayAudio);
  1341. var that = this;
  1342. var str = e.currentTarget.dataset.content;
  1343. var url;
  1344. if (str == "recorder") {
  1345. url = e.currentTarget.dataset.soundmark;
  1346. } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  1347. str = str.replace("英 [", "[");
  1348. str = str.replace("美 [", "[");
  1349. url = e.currentTarget.dataset.soundmark;
  1350. } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
  1351. var soundmark = e.currentTarget.dataset.soundmark;
  1352. if (soundmark && soundmark.indexOf("http") < 0) {
  1353. url = app.globalData.audioUrlBaidu;
  1354. url = url.replace("[token]", app.globalData.BaiduToken);
  1355. url = url.replace("[word]", soundmark);
  1356. } else {
  1357. url = soundmark;
  1358. }
  1359. } else {
  1360. url = app.globalData.audioUrlBaidu;
  1361. url = url.replace("[token]", app.globalData.BaiduToken);
  1362. url = url.replace("[word]", str);
  1363. }
  1364. if (url.indexOf("http") > 0)
  1365. url = url.substr(url.indexOf("http"));
  1366. if (url.indexOf("'") > 0)
  1367. url = common.ReplaceAllString(url, "'", "");
  1368. url = url.replace("http://", "https://");
  1369. url = encodeURI(url);
  1370. if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) {
  1371. isPlaying = true;
  1372. timeoutPlayAudio = setTimeout(function () {
  1373. isPlaying = false;
  1374. }, 60000);
  1375. wx.showLoading({
  1376. title: '音频下载中',
  1377. mask: true,
  1378. });
  1379. setTimeout(function () {
  1380. wx.hideLoading();
  1381. }, 30000);
  1382. wx.downloadFile({
  1383. url: url,
  1384. success(res) {
  1385. wx.hideLoading();
  1386. tempPlayUrlLocal = res.tempFilePath;
  1387. that.audioCtx.setSrc(res.tempFilePath);
  1388. that.audioCtx.play();
  1389. tempPlayUrl = url;
  1390. },
  1391. fail(err) {
  1392. wx.hideLoading();
  1393. if (url.indexOf("sp0.baidu.com") > 0) {
  1394. var soundmark = url.substring(url.indexOf("text=") + 5, url.indexOf("&spd"));
  1395. url = app.globalData.audioUrlYoudao;
  1396. url = url.replace("[word]", soundmark);
  1397. tempPlayUrlLocal = url;
  1398. that.audioCtx.setSrc(url);
  1399. that.audioCtx.play();
  1400. tempPlayUrl = url;
  1401. }
  1402. }
  1403. });
  1404. } else {
  1405. this.audioCtx.pause();
  1406. if (innerAudioContext1)
  1407. innerAudioContext1.stop();
  1408. isPlaying = false;
  1409. }
  1410. },
  1411. showBishunOrKaiti: function (e) {
  1412. var that = this;
  1413. main.downloadBishunKaitiImage(
  1414. e.currentTarget.dataset.url,
  1415. e.currentTarget.dataset.serverurl,
  1416. e.currentTarget.dataset.type,
  1417. that.data.TaskInfo.ContentNew.Field,
  1418. function (fields) {
  1419. that.data.TaskInfo.ContentNew.Field = fields;
  1420. that.setData({
  1421. TaskInfo: that.data.TaskInfo,
  1422. });
  1423. });
  1424. },
  1425. goto: function (e) {
  1426. var url = e.currentTarget.dataset.url;
  1427. wx.navigateTo({
  1428. url: url,
  1429. });
  1430. },
  1431. getNull: function () {
  1432. },
  1433. //获取导航栏高度
  1434. getBarInfo(e) {
  1435. var h = e.detail.topBarHeight;
  1436. h = h * 2;
  1437. if (app.globalData.IsIPad) {
  1438. h += 25;
  1439. }
  1440. this.setData({
  1441. topBarHeight: h,
  1442. })
  1443. },
  1444. onShareAppMessage: function () {
  1445. return {
  1446. title: app.globalData.ShareTitle,
  1447. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1448. imageUrl: app.globalData.ShareImage,
  1449. }
  1450. },
  1451. });