detail.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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 arrImage = [],
  12. arrImage2 = [];
  13. var intervalSound = 0,
  14. intervalRefresh = 0;
  15. var isCollecting = false;
  16. var isExit = true;
  17. var isPlaying = false;
  18. var timeoutPlayAudio;
  19. var tempPlayUrl = "";
  20. var tempPlayUrlLocal = "";
  21. var timeoutEveryCard = 0;
  22. var timeoutHide = 0;
  23. Page({
  24. data: {
  25. ImagePath: app.globalData.uploadImageUrl,
  26. NumberNew: 10,
  27. NumberReview: 0,
  28. NumberHistory: 30,
  29. IsShowNumberInfo: false,
  30. IsMore: false,
  31. FontSizeArray: constant.arrFontSize,
  32. StudyPlanArray: arrStudyPlan,
  33. TaskInfo: {},
  34. Color: {ID: 1},
  35. },
  36. onReady: function () {
  37. var that = this;
  38. innerAudioContext1 = wx.createInnerAudioContext();
  39. innerAudioContext1.onPlay(() => {
  40. console.log('开始播放')
  41. });
  42. innerAudioContext1.onError((res) => {
  43. console.log("innerAudioContext1.errMsg:" + res.errMsg);
  44. console.log("innerAudioContext1.errCode:" + res.errCode);
  45. that.audioCtx.setSrc(tempPlayUrl);
  46. that.audioCtx.play();
  47. });
  48. common.getStorageValue(that, "HasSound", true, function () {
  49. wx.setStorageSync("HasSound", that.data.HasSound);
  50. });
  51. },
  52. onLoad: function () {
  53. var that = this;
  54. var height = app.globalData.systemInfo.screenHeight * 2 - 90;
  55. var height2 = 750;
  56. if (app.globalData.IsIPad) {
  57. height = 960;
  58. height2 = 670;
  59. that.setData({
  60. IsIPad: "_iPad",
  61. });
  62. }
  63. that.setData({
  64. Containnerheight: height,
  65. Containnerheight2: height - height2,
  66. IsShowAnswer: [0, 0],
  67. CanUndo: 1,
  68. TaskInfo: {},
  69. ClickType: app.globalData.ClickType,
  70. Color: main.getDetailColor(app.globalData.ColorIndex),
  71. });
  72. this.audioCtx = wx.createAudioContext('myAudio');
  73. this.getList();
  74. this.getColor();
  75. this.getMemoryLevel();
  76. if (app.globalData.BaiduToken === "")
  77. main.getBaiduToken();
  78. },
  79. onShow: function () {
  80. var that = this;
  81. if (that.data.NumberNew == 0 &&
  82. that.data.NumberReview == 0 &&
  83. that.data.NumberHistory == 0) {
  84. that.setData({
  85. CanUndo: 0,
  86. TaskInfo: {},
  87. });
  88. listTaskFinished = [];
  89. that.getTaskTime();
  90. } else {
  91. that.setSoundFile(-1);
  92. var list = app.globalData.CardList;
  93. if (list && list.length > 0) {
  94. for (var i = 0; i < list.length; i++) {
  95. if (TaskList && TaskList[0] && TaskList[0].MiaoguoCardID == list[i].MiaoguoCardID) {
  96. TaskList[0].Content = list[i].Content;
  97. TaskList[0].ContentNew = main.changeStringToView(list[i].Content);
  98. that.setData({
  99. TaskInfo: TaskList[0],
  100. });
  101. app.globalData.CardList = [];
  102. break;
  103. }
  104. }
  105. }
  106. }
  107. if (that.data.IsMore){
  108. //关于更改学习计划后处理
  109. if (app.globalData.IsUpdateStudyPlan == 1){
  110. that.gotoNext({ currentTarget: { dataset: { btnnumber:-2}}});
  111. app.globalData.IsUpdateStudyPlan = 0;
  112. }
  113. that.setData({
  114. IsMore: false,
  115. });
  116. }
  117. clearTimeout(timeoutHide);
  118. //console.log("显示");
  119. },
  120. onUnload: function () {
  121. clearInterval(intervalSound);
  122. clearTimeout(timeoutEveryCard);
  123. clearTimeout(timeoutHide);
  124. listTaskFinished = [];
  125. isPlaying = false;
  126. if (innerAudioContext1) {
  127. innerAudioContext1.stop();
  128. }
  129. },
  130. onHide: function (e) {
  131. //console.log("隐藏");
  132. var that = this;
  133. if (isExit) {
  134. timeoutHide = setTimeout(function () {
  135. that.onClose();
  136. }, 60000);
  137. }
  138. isExit = true;
  139. },
  140. onPullDownRefresh: function () {
  141. this.onShowAnswer({
  142. currentTarget: {
  143. dataset: {
  144. start: true
  145. }
  146. }
  147. });
  148. wx.stopPullDownRefresh();
  149. },
  150. setSoundFile: function (isFinish) {
  151. //isFinish=3搁置 =2撤退 =1结束 =0正常 =-1开始
  152. var that = this;
  153. if (that.data.HasSound){
  154. var url = "/pages/sounds/";
  155. if (isFinish == 1) {
  156. url += "end.mp3";
  157. } else if (isFinish == 2) {
  158. url += "short3.mp3";
  159. } else if (isFinish == 3) {
  160. url += "short1.mp3";
  161. } else {
  162. url += "short2.mp3";
  163. }
  164. if (isFinish >= 0) {
  165. innerAudioContext1.src = url;
  166. innerAudioContext1.play();
  167. }
  168. }
  169. wx.pageScrollTo({
  170. scrollTop: 0,
  171. });
  172. },
  173. getColor: function () {
  174. var that = this;
  175. if (wx.setBackgroundColor) {
  176. wx.setBackgroundColor({
  177. backgroundColor: that.data.Color.BackColor,
  178. backgroundColorTop: that.data.Color.BackColor,
  179. backgroundColorBottom: that.data.Color.BackColor,
  180. });
  181. }
  182. if (wx.setNavigationBarColor) {
  183. wx.setNavigationBarColor({
  184. frontColor: "#ffffff",
  185. backgroundColor: that.data.Color.BackColor,
  186. })
  187. }
  188. },
  189. getList: function () {
  190. var task = app.globalData.TaskToday;
  191. var that = this;
  192. var arrNew = task.ListNew;
  193. var arrHistory = task.ListHistory;
  194. var listTaskReview = task.ListReview;
  195. var nMax = [1, 1];
  196. if (arrNew.length == 0 || arrHistory.length == 0) {
  197. if (arrNew.length == 0) {
  198. nMax[0] = 0;
  199. }
  200. if (arrHistory.length == 0) {
  201. nMax[1] = 0;
  202. }
  203. } else if (arrNew.length >= arrHistory.length) {
  204. nMax[0] = Math.floor(arrNew.length / arrHistory.length);
  205. } else if (arrNew.length < arrHistory.length) {
  206. nMax[1] = Math.floor(arrHistory.length / arrNew.length);
  207. }
  208. arrNew = common.randomArray(arrNew);
  209. arrHistory = common.randomArray(arrHistory);
  210. var Len = arrNew.length + arrHistory.length;
  211. TaskList = [];
  212. var indexNew = 0,
  213. indexHistory = 0;
  214. for (var i = 0; i < Len; i++) {
  215. for (var j = 0; j < nMax[0]; j++) {
  216. if (indexNew < arrNew.length) {
  217. arrNew[indexNew].IsNew = true;
  218. TaskList.push(arrNew[indexNew++]);
  219. }
  220. }
  221. for (var j = 0; j < nMax[1]; j++) {
  222. if (indexHistory < arrHistory.length) {
  223. arrHistory[indexHistory].IsHistory = true;
  224. TaskList.push(arrHistory[indexHistory++]);
  225. }
  226. }
  227. }
  228. that.data.NumberReview = listTaskReview.length;
  229. for (var i = 0; i < listTaskReview.length; i++) {
  230. listTaskReview[i].IsReview = true;
  231. TaskList.push(listTaskReview[i]);
  232. }
  233. TaskList = updateNumberStr(TaskList);
  234. //处理列表
  235. TaskList = formatList(TaskList);
  236. if (TaskList.length > 0) {
  237. arrImage = TaskList[0].ContentNew.Images;
  238. arrImage2 = TaskList[0].ContentNew.Images2;
  239. }
  240. var taskInfo = TaskList[0];
  241. if (!taskInfo)
  242. taskInfo = {};
  243. that.setData({
  244. NumberNew: arrNew.length,
  245. NumberReview: that.data.NumberReview,
  246. NumberHistory: arrHistory.length,
  247. TaskInfo: taskInfo,
  248. CanUndo: 0,
  249. });
  250. listTaskFinished = [];
  251. that.timeCompute(); //起始时间
  252. function formatList(list) {
  253. for (var i = 0; i < list.length; i++) {
  254. if (list[i].Content) {
  255. list[i].ContentNew = main.changeStringToView(list[i].Content);
  256. list[i].TagWidth = 0;
  257. if (list[i].ContentNew.Tags && list[i].ContentNew.Tags.length > 0) {
  258. list[i].TagWidth = 92 + (list[i].ContentNew.Tags.length - 1) * 122;
  259. for (var j = 0; j < list[i].ContentNew.Tags.length; j++) {
  260. if (list[i].ContentNew.Tags[j].length > 2) {
  261. list[i].TagWidth += 46 * (list[i].ContentNew.Tags[j].length - 2);
  262. }
  263. }
  264. }
  265. }
  266. }
  267. return list;
  268. }
  269. function updateNumberStr(list) {
  270. for (var i = 0; i < list.length; i++) {
  271. if (list[i].Number0)
  272. list[i].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, list[i].Number0);
  273. if (list[i].Number1)
  274. list[i].Number1Str = main.getMemoryLevel(app.globalData.MemoryLevel, 1, list[i].Number1);
  275. if (list[i].Number2)
  276. list[i].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, list[i].Number2);
  277. if (list[i].Number3)
  278. list[i].Number3Str = main.getMemoryLevel(app.globalData.MemoryLevel, 3, list[i].Number3);;
  279. }
  280. return list;
  281. }
  282. },
  283. onShowAnswer: function (e) {
  284. var clicktype = e.currentTarget.dataset.type;
  285. if (!(clicktype && clicktype == "all" && app.globalData.ClickType == 0)) {
  286. var start = e.currentTarget.dataset.start;
  287. var that = this;
  288. if (!(that.data.NumberNew == 0 &&
  289. that.data.NumberReview == 0 &&
  290. that.data.NumberHistory == 0) && !that.data.IsShowNumberInfo) {
  291. var recommend = 0;
  292. if (start) {
  293. that.data.IsShowAnswer[0] = 0;
  294. that.data.IsShowAnswer[1] = 0;
  295. } else {
  296. if (!that.data.IsShowAnswer)
  297. that.data.IsShowAnswer=[0,0];
  298. if (that.data.IsShowAnswer[0]==0 && that.data.IsShowAnswer[1]==0) {
  299. that.data.IsShowAnswer[0] = 1;
  300. if (TaskList[0].ContentNew.Field[3].length == 0) {
  301. that.data.IsShowAnswer[1] = 1;
  302. if (!that.data.TaskInfo.IsNew)
  303. recommend = getRecommendTime();
  304. that.setData({
  305. Recommend: recommend,
  306. });
  307. }
  308. } else if (that.data.IsShowAnswer[0] && !that.data.IsShowAnswer[1]) {
  309. that.data.IsShowAnswer[1] = 1;
  310. if (!that.data.TaskInfo.IsNew)
  311. recommend = getRecommendTime();
  312. that.setData({
  313. Recommend: recommend,
  314. });
  315. }
  316. }
  317. that.setData({
  318. IsShowAnswer: that.data.IsShowAnswer,
  319. });
  320. if (that.data.IsShowAnswer[1]){
  321. var query = wx.createSelectorQuery().in(that)
  322. query.select('#ViewField3').boundingClientRect(function(res){
  323. scroll(res.top-130);
  324. }).exec();
  325. }
  326. }
  327. function scroll(top) {
  328. wx.pageScrollTo({
  329. scrollTop: top,
  330. });
  331. }
  332. function getRecommendTime() {
  333. if (app.globalData.SecondConfigArray[0] > 0) {
  334. var duration = common.diffDate("s", timeStart, new Date());
  335. if (duration <= app.globalData.SecondConfigArray[0])
  336. return 3;
  337. else if (duration <= app.globalData.SecondConfigArray[1])
  338. return 2;
  339. else if (duration <= app.globalData.SecondConfigArray[2])
  340. return 1;
  341. else
  342. return 0;
  343. } else
  344. return 0;
  345. }
  346. }
  347. },
  348. gotoEdit: function () {
  349. var that = this;
  350. //console.log(res.tapIndex);
  351. var list = [];
  352. list.push(TaskList[0]);
  353. app.globalData.CardList = list;
  354. wx.navigateTo({
  355. url: './add?type=edit&id=' + TaskList[0].MiaoguoCardID,
  356. });
  357. isExit = false;
  358. },
  359. onFontSize: function (e) {
  360. var value = e.currentTarget.dataset.value;
  361. TaskList[0].FontSize = value;
  362. this.setData({
  363. TaskInfo: TaskList[0],
  364. IsMore: false,
  365. });
  366. },
  367. //回到上一张题卡
  368. gotoPrev: function () {
  369. var that = this;
  370. if (listTaskFinished.length > 0) {
  371. var card = listTaskFinished.pop();
  372. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  373. timeHistory = 0;
  374. that.timeCompute();
  375. card.Card.Number0 = card.Number0Old;
  376. card.Card.Number0Str = card.Number0StrOld;
  377. card.Card.Number1 = card.Number1Old;
  378. card.Card.Number1Str = card.Number1StrOld;
  379. card.Card.Number2 = card.Number2Old;
  380. card.Card.Number2Str = card.Number2StrOld;
  381. card.Card.Number3 = card.Number3Old;
  382. card.Card.Number3Str = card.Number3StrOld;
  383. if (card.IsReviewOld)
  384. card.Card.IsReview = card.IsReviewOld;
  385. //去除重复
  386. for (var i = 0; i < TaskList.length; i++) {
  387. if (TaskList[i].MiaoguoCardID == card.Card.MiaoguoCardID) {
  388. TaskList.splice(i, 1);
  389. }
  390. }
  391. TaskList.unshift(card.Card);
  392. var canUndo = 1;
  393. if (listTaskFinished.length == 0)
  394. canUndo = 0;
  395. arrImage = TaskList[0].ContentNew.Images;
  396. arrImage2 = TaskList[0].ContentNew.Images2;
  397. that.setData({
  398. IsShowAnswer: [0, 0],
  399. TaskInfo: TaskList[0],
  400. NumberNew: card.NumberNew,
  401. NumberReview: card.NumberReview,
  402. NumberHistory: card.NumberHistory,
  403. CanUndo: canUndo,
  404. Recommend: 0,
  405. });
  406. wx.showToast({
  407. title: '回到上一张',
  408. image: "../images/universalpic_undo_white_120x90.png",
  409. });
  410. that.setSoundFile(2);
  411. }
  412. },
  413. //进入下一张题卡
  414. gotoNext: function (e) {
  415. var that = this;
  416. //btnnumber可以有 5:秒过 4正常 3困难 2挪到最后 1搁置 0不过 -1今天要练 -2更改计划
  417. var btnnumber = e.currentTarget.dataset.btnnumber;
  418. //若是“挪到最后”
  419. if (btnnumber == 2) {
  420. var card = TaskList.splice(0, 1);
  421. card[0].IsFinally=true;
  422. card[0].LimitTime=common.formatTime(new Date(),"/",true)+" 23:59:59";
  423. TaskList.push(card[0]);
  424. that.setData({
  425. IsShowAnswer: [0, 0],
  426. TaskInfo: TaskList[0],
  427. CanUndo: 1,
  428. Recommend: 0,
  429. IsMore: false,
  430. });
  431. }
  432. else{
  433. var time = e.currentTarget.dataset.time;
  434. //处理当前卡片进入历史数组
  435. var finishCard = {};
  436. finishCard.Card = TaskList[0];
  437. finishCard.NumberNew = this.data.NumberNew;
  438. finishCard.NumberReview = this.data.NumberReview;
  439. finishCard.NumberHistory = this.data.NumberHistory;
  440. finishCard.Number0Old = TaskList[0].Number0;
  441. finishCard.Number0StrOld = TaskList[0].Number0Str;
  442. finishCard.Number1Old = TaskList[0].Number1;
  443. finishCard.Number1StrOld = TaskList[0].Number1Str;
  444. finishCard.Number2Old = TaskList[0].Number2;
  445. finishCard.Number2StrOld = TaskList[0].Number2Str;
  446. finishCard.Number3Old = TaskList[0].Number3;
  447. finishCard.Number3StrOld = TaskList[0].Number3Str;
  448. //若是当前题卡更改学习计划
  449. if (btnnumber==-2) {
  450. for (var i = 0,flag=true; i < listTaskFinished.length;flag?i++:i){
  451. if (listTaskFinished[i].Card.MiaoguoCardID==finishCard.Card.MiaoguoCardID){
  452. listTaskFinished.splice(i,1);
  453. flag=false;
  454. }
  455. else
  456. flag=true;
  457. }
  458. }
  459. else{
  460. //若不是搁置
  461. //算出下一次的时间
  462. if (btnnumber != "1") {
  463. //若是分钟,则进入复习列表
  464. if (time.lastIndexOf("m") == time.length - 1) {
  465. var minute = Number(time.substr(0, time.indexOf("m")));
  466. TaskList[0].LimitTime = common.formatTime(common.addDate("n", minute, new Date()));
  467. //若是新建,则10m 1d 4d
  468. if (TaskList[0].IsNew) {
  469. if (minute == 1) {
  470. TaskList[0].Number0 = "1m";
  471. TaskList[0].Number2 = "10m";
  472. }
  473. else {
  474. TaskList[0].Number0 = "10m";
  475. TaskList[0].Number2 = "1d";
  476. }
  477. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  478. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  479. delete TaskList[0].Number1;
  480. delete TaskList[0].Number1Str;
  481. delete TaskList[0].Number3;
  482. delete TaskList[0].Number3Str;
  483. TaskList[0].FirstTime = null;
  484. TaskList[0].LastTime = null;
  485. }
  486. //若是历史的,则10m 1d
  487. else if (TaskList[0].IsHistory) {
  488. TaskList[0].Number0 = "10m";
  489. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  490. delete TaskList[0].Number1;
  491. delete TaskList[0].Number1Str;
  492. TaskList[0].Number2 = "1d";
  493. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  494. delete TaskList[0].Number3;
  495. delete TaskList[0].Number3Str;
  496. }
  497. finishCard.IsReviewOld = TaskList[0].IsReview;
  498. TaskList[0].IsReview = true;
  499. TaskList.push(TaskList[0]);
  500. }
  501. //若是天月年
  502. else {
  503. var dayNum = Number(time.substr(0, time.indexOf("d")));
  504. var date = common.addDate("d", dayNum, new Date());
  505. TaskList[0].LimitTime = common.formatTime(date);
  506. }
  507. }
  508. //修改学习任务个数
  509. var learningType = 0;
  510. if (TaskList[0].IsReview) {
  511. learningType = 2;
  512. }
  513. if (TaskList[0].IsNew) {
  514. learningType = 0;
  515. } else if (TaskList[0].IsHistory) {
  516. learningType = 1;
  517. }
  518. if (btnnumber == "1") {
  519. learningType = 3;
  520. }
  521. finishCard.IntervalTime = time;
  522. finishCard.BtnNumber = btnnumber;
  523. finishCard.LearningType = learningType;
  524. var duration = common.diffDate("s", timeStart, new Date());
  525. if (finishCard.btnnumber == 1)
  526. duration = 0;
  527. finishCard.Duration = timeHistory + duration;
  528. console.log("CardTime:" + finishCard.Duration);
  529. timeHistory = 0;
  530. that.timeCompute();
  531. //添加完成列表,去掉任务列表数据
  532. listTaskFinished.push(finishCard);
  533. }
  534. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  535. TaskList.shift();
  536. that.data.NumberNew = 0;
  537. that.data.NumberHistory = 0;
  538. that.data.NumberReview = 0;
  539. for (var i = 0; i < TaskList.length; i++) {
  540. if (TaskList[i].IsReview) {
  541. if (TaskList[i].LimitTime < common.formatTime(new Date())) {
  542. var card = TaskList.splice(i, 1);
  543. TaskList.unshift(card[0]);
  544. }
  545. that.data.NumberReview++;
  546. } else if (TaskList[i].IsNew) {
  547. that.data.NumberNew++;
  548. } else if (TaskList[i].IsHistory) {
  549. that.data.NumberHistory++;
  550. }
  551. if (TaskList[i].IsFinally){
  552. var card = TaskList.splice(i, 1);
  553. TaskList.push(card[0]);
  554. }
  555. }
  556. //console.log(JSON.stringify(TaskList[0]));
  557. //如果所有任务完成
  558. if (that.data.NumberNew == 0 &&
  559. that.data.NumberReview == 0 &&
  560. that.data.NumberHistory == 0) {
  561. that.setData({
  562. IsShowAnswer: [0, 0],
  563. NumberNew: 0,
  564. NumberReview: 0,
  565. NumberHistory: 0,
  566. CanUndo: 1,
  567. Recommend: 0,
  568. IsMore: false,
  569. });
  570. clearTimeout(timeoutEveryCard);
  571. that.setSoundFile(1);
  572. main.UpdateMiaoguoCardTodayAll(true, function () {
  573. listTaskFinished = [];
  574. that.getTaskTime();
  575. });
  576. }
  577. //没有完成任务
  578. else {
  579. arrImage = TaskList[0].ContentNew.Images;
  580. arrImage2 = TaskList[0].ContentNew.Images2;
  581. //任务没有完成,下一张卡片
  582. that.setData({
  583. IsShowAnswer: [0, 0],
  584. TaskInfo: TaskList[0],
  585. NumberNew: that.data.NumberNew,
  586. NumberReview: that.data.NumberReview,
  587. NumberHistory: that.data.NumberHistory,
  588. CanUndo: 1,
  589. Recommend: 0,
  590. IsMore: false,
  591. });
  592. if (btnnumber == "1") {
  593. that.setSoundFile(3);
  594. if (time == "1d") {
  595. wx.showToast({
  596. title: '搁置一天',
  597. mask: true,
  598. image: "../images/universalpic_shelve_white_120x120.png",
  599. });
  600. } else {
  601. wx.showToast({
  602. title: '已推迟',
  603. mask: true,
  604. image: "../images/universalpic_bell_white_120x120.png",
  605. });
  606. }
  607. } else
  608. that.setSoundFile(0);
  609. }
  610. }
  611. },
  612. timeCompute: function () {
  613. var that = this;
  614. timeStart = new Date();
  615. clearTimeout(timeoutEveryCard);
  616. timeoutEveryCard = setTimeout(function () {
  617. //计算暂停时已经用掉的时长
  618. timeHistory += common.diffDate("s", timeStart, new Date());
  619. console.log("timeHistory:" + timeHistory);
  620. wx.showModal({
  621. title: '提醒',
  622. content: '您已等待了' + app.globalData.CardWaitTimeMax + '分钟',
  623. showCancel: false,
  624. confirmText: "知道了",
  625. success(res) {
  626. clearTimeout(timeoutEveryCard);
  627. if (res.confirm) {
  628. that.timeCompute();
  629. }
  630. },
  631. })
  632. }, app.globalData.CardWaitTimeMax * 60 * 1000);
  633. },
  634. gotoCollect: function () {
  635. var that = this;
  636. if (!isCollecting) {
  637. isCollecting = true;
  638. setTimeout(function () {
  639. isCollecting = false;
  640. }, 3000);
  641. var that = this;
  642. if (!TaskList[0].IsCollect) {
  643. TaskList[0].IsCollect = 1;
  644. } else {
  645. TaskList[0].IsCollect = 0;
  646. }
  647. that.setData({
  648. TaskInfo: TaskList[0],
  649. });
  650. main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect);
  651. }
  652. },
  653. playSound: function (e) {
  654. clearTimeout(timeoutPlayAudio);
  655. var that = this;
  656. var str = e.currentTarget.dataset.content;
  657. var url;
  658. if (str == "recorder") {
  659. url = e.currentTarget.dataset.soundmark;
  660. } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  661. str = str.replace("英 [", "[");
  662. str = str.replace("美 [", "[");
  663. url = e.currentTarget.dataset.soundmark;
  664. } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
  665. var soundmark = e.currentTarget.dataset.soundmark;
  666. if (soundmark && soundmark.indexOf("http") < 0) {
  667. url = app.globalData.audioUrlBaidu;
  668. url = url.replace("[token]", app.globalData.BaiduToken);
  669. url = url.replace("[word]", soundmark);
  670. } else {
  671. url = soundmark;
  672. }
  673. } else {
  674. url = app.globalData.audioUrlBaidu;
  675. url = url.replace("[token]", app.globalData.BaiduToken);
  676. url = url.replace("[word]", str);
  677. }
  678. if (url.indexOf("http") > 0)
  679. url = url.substr(url.indexOf("http"));
  680. if (url.indexOf("'") > 0)
  681. url = common.ReplaceAllString(url, "'", "");
  682. url = url.replace("http://", "https://");
  683. url = encodeURI(url);
  684. if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) {
  685. isPlaying = true;
  686. timeoutPlayAudio = setTimeout(function () {
  687. isPlaying = false;
  688. }, 60000);
  689. wx.showLoading({
  690. title: '音频下载中',
  691. mask: true,
  692. });
  693. setTimeout(function () {
  694. wx.hideLoading();
  695. }, 30000);
  696. wx.downloadFile({
  697. url: url,
  698. success(res) {
  699. wx.hideLoading();
  700. if (res.statusCode === 200) {
  701. tempPlayUrlLocal = res.tempFilePath;
  702. that.audioCtx.setSrc(res.tempFilePath);
  703. that.audioCtx.play();
  704. tempPlayUrl = url;
  705. }
  706. },
  707. fail(err) {
  708. wx.hideLoading();
  709. }
  710. });
  711. } else {
  712. this.audioCtx.pause();
  713. if (innerAudioContext1)
  714. innerAudioContext1.stop();
  715. isPlaying = false;
  716. }
  717. },
  718. audioBindEnded: function () {
  719. isPlaying = false;
  720. },
  721. audioBindError: function (err) {
  722. console.log(err);
  723. innerAudioContext1.src = tempPlayUrlLocal;
  724. innerAudioContext1.play();
  725. },
  726. getTaskTime: function () {
  727. var that = this;
  728. var url = "GetMiaoguoTaskTime?";
  729. url += "UserID=" + app.globalData.userInfo.UserID;
  730. main.getData(url, function (data) {
  731. if (data) {
  732. var duration = data.Duration;
  733. if (duration > 0) {
  734. duration = Math.round(duration / 60);
  735. }
  736. var speed1 = 0;
  737. if (data.Duration > 0)
  738. speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100;
  739. var speed2 = 0 + "秒";
  740. if (data.Count > 0)
  741. speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true);
  742. app.globalData.TaskToday.DayNumber = data.DayNumber;
  743. that.setData({
  744. TodayTime: duration,
  745. Speed1: speed1 + "张题卡",
  746. Speed2: speed2,
  747. });
  748. wx.setNavigationBarTitle({
  749. title: "报告"
  750. });
  751. }
  752. });
  753. },
  754. showNumberContainner: function () {
  755. this.setData({
  756. IsShowNumberInfo: true,
  757. });
  758. wx.setNavigationBarTitle({
  759. title: "进度"
  760. });
  761. },
  762. closeNumberContainner: function () {
  763. this.setData({
  764. IsShowNumberInfo: false,
  765. IsMore: false,
  766. });
  767. wx.setNavigationBarTitle({
  768. title: "学习中"
  769. });
  770. },
  771. showImage: function (e) {
  772. var name = e.currentTarget.dataset.name;
  773. if (name && name.length > 5) {
  774. wx.previewImage({
  775. current: name,
  776. urls: arrImage
  777. });
  778. }
  779. },
  780. onBindError: function (e) {
  781. var that = this;
  782. var serverUrl = e.currentTarget.dataset.serverurl;
  783. var oldTempUrl = e.currentTarget.dataset.name;
  784. //console.log("serverUrl1:" + serverUrl);
  785. wx.downloadFile({
  786. url: serverUrl, // 仅为示例,并非真实的资源
  787. success(res) {
  788. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  789. if (res.statusCode === 200) {
  790. //console.log("serverUrl2:" + serverUrl);
  791. //console.log(res.tempFilePath);
  792. main.saveTempImage(serverUrl, res.tempFilePath);
  793. for (var i = 0; i < arrImage.length; i++) {
  794. if (arrImage[i] == oldTempUrl) {
  795. arrImage[i] = res.tempFilePath;
  796. }
  797. }
  798. }
  799. }
  800. });
  801. clearTimeout(intervalRefresh);
  802. intervalRefresh = setTimeout(function () {
  803. TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content);
  804. that.setData({
  805. TaskInfo: TaskList[0],
  806. });
  807. }, 1000);
  808. for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) {
  809. for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) {
  810. if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") {
  811. this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content;
  812. }
  813. }
  814. }
  815. this.setData({
  816. TaskInfo: this.data.TaskInfo,
  817. });
  818. },
  819. onMore: function () {
  820. for (var i = 0; i < this.data.FontSizeArray.length; i++) {
  821. if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize)
  822. this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";";
  823. else
  824. this.data.FontSizeArray[i].CSS = "";
  825. }
  826. this.setData({
  827. IsMore: true,
  828. FontSizeArray: this.data.FontSizeArray,
  829. });
  830. },
  831. onClose: function () {
  832. wx.navigateBack({
  833. delta: 1,
  834. });
  835. },
  836. getMemoryLevel: function () {
  837. var index = wx.getStorageSync("MemoryLevel");
  838. if (!index) {
  839. index = 0;
  840. }
  841. if (index>1)
  842. index=1;
  843. app.globalData.MemoryLevel = index;
  844. this.setData({
  845. MemoryLevel:index,
  846. });
  847. },
  848. buildShareImage: function () {
  849. var that = this;
  850. wx.showLoading({
  851. title: '生成中',
  852. });
  853. setTimeout(function () {
  854. wx.hideLoading();
  855. }, 5000);
  856. //console.log(app.globalData.userInfo.AvatarUrl);
  857. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  858. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  859. avatarUrl = avatarUrl + "0";
  860. //console.log(avatarUrl);
  861. wx.downloadFile({
  862. url: avatarUrl, // 仅为示例,并非真实的资源
  863. success(res) {
  864. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  865. if (res.statusCode === 200) {
  866. var canvas = wx.createCanvasContext("shareCanvas", that);
  867. canvas.setFillStyle(main.getShareImageBackColor());
  868. canvas.fillRect(360, 0, 600, 360);
  869. canvas.drawImage(res.tempFilePath, 0, 0, 360, 360);
  870. canvas.drawImage("../images/universalpic_screenshot_jl_bgimage_360x360.png", 0, 0, 360, 360);
  871. canvas.fillStyle = "#ffffff";
  872. canvas.setTextBaseline('top');
  873. canvas.setFontSize(24);
  874. canvas.fillText(app.globalData.userInfo.NickName, 30, 282);
  875. var today = common.formatTime(new Date(), ".", true);
  876. canvas.setFontSize(18);
  877. canvas.fillText(today, 30, 315);
  878. canvas.setFontSize(20);
  879. canvas.fillText("秒过学习", 390, 30);
  880. canvas.setFontSize(44);
  881. canvas.fillText("勤勉接力", 390, 58);
  882. canvas.setFontSize(20);
  883. canvas.fillText("见证成长", 390, 120);
  884. canvas.setFontSize(68);
  885. if (!that.data.TodayTime)
  886. that.data.TodayTime=0;
  887. canvas.fillText(that.data.TodayTime, 390, 148);
  888. canvas.font = "normal 500 68px caption";
  889. var metrics = canvas.measureText(that.data.TodayTime.toString());
  890. //console.log(JSON.stringify(metrics));
  891. var h = 179;
  892. if (app.globalData.IsIOS)
  893. h = 176;
  894. canvas.font = "normal 500 32px caption";
  895. canvas.fillText("分钟", 393 + Math.round(metrics.width), h);
  896. canvas.setFontSize(20);
  897. canvas.fillText("迄今已接力", 390, 267);
  898. canvas.setFontSize(32);
  899. canvas.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 295);
  900. //console.log("生成前");
  901. canvas.draw(1, function (n) {
  902. //console.log("生成后1");
  903. wx.canvasToTempFilePath({
  904. x: 0,
  905. y: 0,
  906. width: 600,
  907. height: 360,
  908. destWidth: 600,
  909. destHeight: 360,
  910. canvasId: 'shareCanvas',
  911. success: function (res2) {
  912. wx.hideLoading();
  913. //console.log("生成后2");
  914. wx.previewImage({
  915. current: res2.tempFilePath, // 当前显示图片的http链接
  916. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  917. });
  918. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) { });
  919. },
  920. fail: function (e) {
  921. wx.hideLoading();
  922. //console.log("生成错误:"+e);
  923. }
  924. })
  925. });
  926. } else {
  927. wx.hideLoading();
  928. }
  929. },
  930. fail: function () {
  931. wx.hideLoading();
  932. }
  933. });
  934. },
  935. goto: function (e) {
  936. var url = e.currentTarget.dataset.url;
  937. wx.navigateTo({
  938. url: url,
  939. });
  940. },
  941. //获取导航栏高度
  942. getBarInfo(e) {
  943. var h=e.detail.topBarHeight;
  944. h=h*2;
  945. this.setData({
  946. topBarHeight: h,
  947. })
  948. },
  949. onShareAppMessage: function () {
  950. return {
  951. title: app.globalData.ShareTitle,
  952. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  953. imageUrl: app.globalData.ShareImage,
  954. }
  955. },
  956. });