detail.js 34 KB

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