detail.js 31 KB

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