detail.js 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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. if (res.confirm) {
  627. that.timeCompute();
  628. }
  629. },
  630. })
  631. }, app.globalData.CardWaitTimeMax * 60 * 1000);
  632. },
  633. gotoCollect: function () {
  634. var that = this;
  635. if (!isCollecting) {
  636. isCollecting = true;
  637. setTimeout(function () {
  638. isCollecting = false;
  639. }, 3000);
  640. var that = this;
  641. if (!TaskList[0].IsCollect) {
  642. TaskList[0].IsCollect = 1;
  643. } else {
  644. TaskList[0].IsCollect = 0;
  645. }
  646. that.setData({
  647. TaskInfo: TaskList[0],
  648. });
  649. main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect);
  650. }
  651. },
  652. playSound: function (e) {
  653. clearTimeout(timeoutPlayAudio);
  654. var that = this;
  655. var str = e.currentTarget.dataset.content;
  656. var url;
  657. if (str == "recorder") {
  658. url = e.currentTarget.dataset.soundmark;
  659. } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  660. str = str.replace("英 [", "[");
  661. str = str.replace("美 [", "[");
  662. url = e.currentTarget.dataset.soundmark;
  663. } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
  664. var soundmark = e.currentTarget.dataset.soundmark;
  665. if (soundmark && soundmark.indexOf("http") < 0) {
  666. url = app.globalData.audioUrlBaidu;
  667. url = url.replace("[token]", app.globalData.BaiduToken);
  668. url = url.replace("[word]", soundmark);
  669. } else {
  670. url = soundmark;
  671. }
  672. } else {
  673. url = app.globalData.audioUrlBaidu;
  674. url = url.replace("[token]", app.globalData.BaiduToken);
  675. url = url.replace("[word]", str);
  676. }
  677. if (url.indexOf("http") > 0)
  678. url = url.substr(url.indexOf("http"));
  679. if (url.indexOf("'") > 0)
  680. url = common.ReplaceAllString(url, "'", "");
  681. url = url.replace("http://", "https://");
  682. url = encodeURI(url);
  683. if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) {
  684. isPlaying = true;
  685. timeoutPlayAudio = setTimeout(function () {
  686. isPlaying = false;
  687. }, 60000);
  688. wx.showLoading({
  689. title: '音频下载中',
  690. mask: true,
  691. });
  692. setTimeout(function () {
  693. wx.hideLoading();
  694. }, 30000);
  695. wx.downloadFile({
  696. url: url,
  697. success(res) {
  698. wx.hideLoading();
  699. if (res.statusCode === 200) {
  700. tempPlayUrlLocal = res.tempFilePath;
  701. that.audioCtx.setSrc(res.tempFilePath);
  702. that.audioCtx.play();
  703. tempPlayUrl = url;
  704. }
  705. },
  706. fail(err) {
  707. wx.hideLoading();
  708. }
  709. });
  710. } else {
  711. this.audioCtx.pause();
  712. if (innerAudioContext1)
  713. innerAudioContext1.stop();
  714. isPlaying = false;
  715. }
  716. },
  717. audioBindEnded: function () {
  718. isPlaying = false;
  719. },
  720. audioBindError: function (err) {
  721. console.log(err);
  722. innerAudioContext1.src = tempPlayUrlLocal;
  723. innerAudioContext1.play();
  724. },
  725. getTaskTime: function () {
  726. var that = this;
  727. var url = "GetMiaoguoTaskTime?";
  728. url += "UserID=" + app.globalData.userInfo.UserID;
  729. main.getData(url, function (data) {
  730. if (data) {
  731. var duration = data.Duration;
  732. if (duration > 0) {
  733. duration = Math.round(duration / 60);
  734. }
  735. var speed1 = 0;
  736. if (data.Duration > 0)
  737. speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100;
  738. var speed2 = 0 + "秒";
  739. if (data.Count > 0)
  740. speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true);
  741. app.globalData.TaskToday.DayNumber = data.DayNumber;
  742. that.setData({
  743. TodayTime: duration,
  744. Speed1: speed1 + "张题卡",
  745. Speed2: speed2,
  746. });
  747. wx.setNavigationBarTitle({
  748. title: "报告"
  749. });
  750. }
  751. });
  752. },
  753. showNumberContainner: function () {
  754. this.setData({
  755. IsShowNumberInfo: true,
  756. });
  757. wx.setNavigationBarTitle({
  758. title: "进度"
  759. });
  760. },
  761. closeNumberContainner: function () {
  762. this.setData({
  763. IsShowNumberInfo: false,
  764. IsMore: false,
  765. });
  766. wx.setNavigationBarTitle({
  767. title: "学习中"
  768. });
  769. },
  770. showImage: function (e) {
  771. var name = e.currentTarget.dataset.name;
  772. if (name && name.length > 5) {
  773. wx.previewImage({
  774. current: name,
  775. urls: arrImage
  776. });
  777. }
  778. },
  779. onBindError: function (e) {
  780. var that = this;
  781. var serverUrl = e.currentTarget.dataset.serverurl;
  782. var oldTempUrl = e.currentTarget.dataset.name;
  783. //console.log("serverUrl1:" + serverUrl);
  784. wx.downloadFile({
  785. url: serverUrl, // 仅为示例,并非真实的资源
  786. success(res) {
  787. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  788. if (res.statusCode === 200) {
  789. //console.log("serverUrl2:" + serverUrl);
  790. //console.log(res.tempFilePath);
  791. main.saveTempImage(serverUrl, res.tempFilePath);
  792. for (var i = 0; i < arrImage.length; i++) {
  793. if (arrImage[i] == oldTempUrl) {
  794. arrImage[i] = res.tempFilePath;
  795. }
  796. }
  797. }
  798. }
  799. });
  800. clearTimeout(intervalRefresh);
  801. intervalRefresh = setTimeout(function () {
  802. TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content);
  803. that.setData({
  804. TaskInfo: TaskList[0],
  805. });
  806. }, 1000);
  807. for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) {
  808. for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) {
  809. if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") {
  810. this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content;
  811. }
  812. }
  813. }
  814. this.setData({
  815. TaskInfo: this.data.TaskInfo,
  816. });
  817. },
  818. onMore: function () {
  819. for (var i = 0; i < this.data.FontSizeArray.length; i++) {
  820. if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize)
  821. this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";";
  822. else
  823. this.data.FontSizeArray[i].CSS = "";
  824. }
  825. this.setData({
  826. IsMore: true,
  827. FontSizeArray: this.data.FontSizeArray,
  828. });
  829. },
  830. onClose: function () {
  831. wx.navigateBack({
  832. delta: 1,
  833. });
  834. },
  835. getMemoryLevel: function () {
  836. var index = wx.getStorageSync("MemoryLevel");
  837. if (!index) {
  838. index = 0;
  839. }
  840. if (index>1)
  841. index=1;
  842. app.globalData.MemoryLevel = index;
  843. this.setData({
  844. MemoryLevel:index,
  845. });
  846. },
  847. buildShareImage: function () {
  848. var that = this;
  849. wx.showLoading({
  850. title: '生成中',
  851. });
  852. setTimeout(function () {
  853. wx.hideLoading();
  854. }, 5000);
  855. //console.log(app.globalData.userInfo.AvatarUrl);
  856. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  857. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  858. avatarUrl = avatarUrl + "0";
  859. //console.log(avatarUrl);
  860. wx.downloadFile({
  861. url: avatarUrl, // 仅为示例,并非真实的资源
  862. success(res) {
  863. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  864. if (res.statusCode === 200) {
  865. var canvas = wx.createCanvasContext("shareCanvas", that);
  866. canvas.setFillStyle(main.getShareImageBackColor());
  867. canvas.fillRect(360, 0, 600, 360);
  868. canvas.drawImage(res.tempFilePath, 0, 0, 360, 360);
  869. canvas.drawImage("../images/universalpic_screenshot_jl_bgimage_360x360.png", 0, 0, 360, 360);
  870. canvas.fillStyle = "#ffffff";
  871. canvas.setTextBaseline('top');
  872. canvas.setFontSize(24);
  873. canvas.fillText(app.globalData.userInfo.NickName, 30, 282);
  874. var today = common.formatTime(new Date(), ".", true);
  875. canvas.setFontSize(18);
  876. canvas.fillText(today, 30, 315);
  877. canvas.setFontSize(20);
  878. canvas.fillText("秒过学习", 390, 30);
  879. canvas.setFontSize(44);
  880. canvas.fillText("勤勉接力", 390, 58);
  881. canvas.setFontSize(20);
  882. canvas.fillText("见证成长", 390, 120);
  883. canvas.setFontSize(68);
  884. if (!that.data.TodayTime)
  885. that.data.TodayTime=0;
  886. canvas.fillText(that.data.TodayTime, 390, 148);
  887. canvas.font = "normal 500 68px caption";
  888. var metrics = canvas.measureText(that.data.TodayTime.toString());
  889. //console.log(JSON.stringify(metrics));
  890. var h = 179;
  891. if (app.globalData.IsIOS)
  892. h = 176;
  893. canvas.font = "normal 500 32px caption";
  894. canvas.fillText("分钟", 393 + Math.round(metrics.width), h);
  895. canvas.setFontSize(20);
  896. canvas.fillText("迄今已接力", 390, 267);
  897. canvas.setFontSize(32);
  898. canvas.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 295);
  899. //console.log("生成前");
  900. canvas.draw(1, function (n) {
  901. //console.log("生成后1");
  902. wx.canvasToTempFilePath({
  903. x: 0,
  904. y: 0,
  905. width: 600,
  906. height: 360,
  907. destWidth: 600,
  908. destHeight: 360,
  909. canvasId: 'shareCanvas',
  910. success: function (res2) {
  911. wx.hideLoading();
  912. //console.log("生成后2");
  913. wx.previewImage({
  914. current: res2.tempFilePath, // 当前显示图片的http链接
  915. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  916. });
  917. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) { });
  918. },
  919. fail: function (e) {
  920. wx.hideLoading();
  921. //console.log("生成错误:"+e);
  922. }
  923. })
  924. });
  925. } else {
  926. wx.hideLoading();
  927. }
  928. },
  929. fail: function () {
  930. wx.hideLoading();
  931. }
  932. });
  933. },
  934. goto: function (e) {
  935. var url = e.currentTarget.dataset.url;
  936. wx.navigateTo({
  937. url: url,
  938. });
  939. },
  940. //获取导航栏高度
  941. getBarInfo(e) {
  942. var h=e.detail.topBarHeight;
  943. h=h*2;
  944. this.setData({
  945. topBarHeight: h,
  946. })
  947. },
  948. onShareAppMessage: function () {
  949. return {
  950. title: app.globalData.ShareTitle,
  951. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  952. imageUrl: app.globalData.ShareImage,
  953. }
  954. },
  955. });