detail.js 45 KB

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