detail.js 45 KB

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