detail.js 41 KB

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