detail.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  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. },
  767. setFinallyResult: function () {
  768. var that = this;
  769. that.setData({
  770. IsShowAnswer: [0, 0],
  771. NumberNew: 0,
  772. NumberReview: 0,
  773. NumberHistory: 0,
  774. CanUndo: 1,
  775. Recommend: 0,
  776. IsMore: false,
  777. });
  778. that.clearTimeoutEveryCard();
  779. that.setSoundFile(1);
  780. main.UpdateMiaoguoCardTodayAll(true, function () {
  781. listTaskFinished = [];
  782. that.getTaskTime();
  783. });
  784. },
  785. gotoCollect: function () {
  786. var that = this;
  787. if (!isCollecting) {
  788. isCollecting = true;
  789. setTimeout(function () {
  790. isCollecting = false;
  791. }, 3000);
  792. var that = this;
  793. if (!TaskList[0].IsCollect) {
  794. TaskList[0].IsCollect = 1;
  795. } else {
  796. TaskList[0].IsCollect = 0;
  797. }
  798. that.setData({
  799. TaskInfo: TaskList[0],
  800. });
  801. main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect);
  802. }
  803. },
  804. getTaskTime: function () {
  805. var that = this;
  806. var url = "GetMiaoguoTaskTime?";
  807. url += "UserID=" + app.globalData.userInfo.UserID;
  808. main.getData(url, function (data) {
  809. if (data) {
  810. var duration = data.Duration;
  811. if (duration > 0) {
  812. duration = Math.round(duration / 60);
  813. }
  814. var speed1 = 0;
  815. if (data.Duration > 0)
  816. speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100;
  817. var speed2 = 0 + "秒";
  818. if (data.Count > 0)
  819. speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true);
  820. app.globalData.TaskToday.DayNumber = data.DayNumber;
  821. that.setData({
  822. TodayTime: duration,
  823. Speed1: speed1 + "张题卡",
  824. Speed2: speed2,
  825. Title: "报告",
  826. });
  827. if (speed1 == "0张题卡" && speed2 == "0秒" && duration.toString() == "1") {
  828. wx.showModal({
  829. title: '提醒',
  830. showCancel: false,
  831. confirmText: '知道了',
  832. content: "也许您已经发现「报告」上的数据有些异样。这是由于本次练习从昨天开始到今天结束,发生了「跨天」的情况。虽然报告内容不够正确,但练习数据不会受到影响,这个问题将在日后得到改善。请不用担心。"
  833. });
  834. }
  835. }
  836. });
  837. },
  838. showNumberContainner: function () {
  839. var that=this;
  840. if (!this.data.Title) {
  841. this.setData({
  842. IsShowNumberInfo: true,
  843. IsMore: false,
  844. IsShowFolder: false,
  845. });
  846. this.setData({
  847. Title: "进度",
  848. });
  849. that.clearTimeoutEveryCard();
  850. }
  851. },
  852. closeNumberContainner: function () {
  853. this.setData({
  854. IsShowNumberInfo: false,
  855. IsMore: false,
  856. IsShowFolder: false,
  857. });
  858. this.setData({
  859. Title: "",
  860. });
  861. this.timeCompute();
  862. },
  863. showImage: function (e) {
  864. var name = e.currentTarget.dataset.name;
  865. if (name && name.length > 5) {
  866. if (name.indexOf("tmp") >= 0) {
  867. wx.previewImage({
  868. current: name,
  869. urls: [name],
  870. });
  871. } else {
  872. wx.previewImage({
  873. current: name,
  874. urls: arrImage
  875. });
  876. }
  877. }
  878. },
  879. onFontSize: function (e) {
  880. var value = e.currentTarget.dataset.value;
  881. TaskList[0].FontSize = value;
  882. this.setData({
  883. TaskInfo: TaskList[0],
  884. IsMore: false,
  885. Title: "",
  886. });
  887. },
  888. onBindError: function (e) {
  889. var that = this;
  890. var serverUrl = e.currentTarget.dataset.serverurl;
  891. var oldTempUrl = e.currentTarget.dataset.name;
  892. //console.log("serverUrl1:" + serverUrl);
  893. wx.downloadFile({
  894. url: serverUrl, // 仅为示例,并非真实的资源
  895. success(res) {
  896. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  897. if (res.statusCode === 200) {
  898. //console.log("serverUrl2:" + serverUrl);
  899. //console.log(res.tempFilePath);
  900. main.saveTempImage(serverUrl, res.tempFilePath);
  901. for (var i = 0; i < arrImage.length; i++) {
  902. if (arrImage[i] == oldTempUrl) {
  903. arrImage[i] = res.tempFilePath;
  904. }
  905. }
  906. }
  907. }
  908. });
  909. clearTimeout(intervalRefresh);
  910. intervalRefresh = setTimeout(function () {
  911. if (TaskList && TaskList[0]) {
  912. TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content);
  913. that.setData({
  914. TaskInfo: TaskList[0],
  915. });
  916. }
  917. }, 1000);
  918. for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) {
  919. for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) {
  920. if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") {
  921. this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content;
  922. }
  923. }
  924. }
  925. this.setData({
  926. TaskInfo: this.data.TaskInfo,
  927. });
  928. },
  929. onMore: function () {
  930. var that=this;
  931. for (var i = 0; i < this.data.FontSizeArray.length; i++) {
  932. if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize)
  933. this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";";
  934. else
  935. this.data.FontSizeArray[i].CSS = "";
  936. }
  937. this.setData({
  938. IsMore: true,
  939. FontSizeArray: this.data.FontSizeArray,
  940. Title: "调节",
  941. });
  942. that.clearTimeoutEveryCard();
  943. },
  944. showOtherButton: function () {
  945. var animation = wx.createAnimation();
  946. this.animation = animation;
  947. animation.translate(-710 + 'rpx', 0).step({
  948. duration: 200
  949. });
  950. this.setData({
  951. animationData: animation.export(),
  952. IsShowOtherButton: true,
  953. });
  954. },
  955. closeOtherButton: function () {
  956. var animation = wx.createAnimation();
  957. this.animation = animation;
  958. animation.translate(0, 0).step({
  959. duration: 200
  960. });
  961. this.setData({
  962. animationData: animation.export(),
  963. IsShowOtherButton: false,
  964. });
  965. },
  966. onShowFolder: function () {
  967. for (var j = 0; j < FolderList.length; j++) {
  968. FolderList[j].Total = 0;
  969. for (var i = 0; i < TaskList.length; i++) {
  970. if (TaskList[i].FolderID == FolderList[j].FolderID &&
  971. !TaskList[i].IsFinally) {
  972. FolderList[j].Total++;
  973. }
  974. }
  975. }
  976. var FolderListLength = FolderList.length;
  977. for (var j = 0; j < FolderList.length; j++) {
  978. if (FolderList[j].Total == 0) {
  979. FolderListLength--;
  980. }
  981. }
  982. var IsFinallyCount = 0;
  983. for (var j = 0; j < TaskList.length; j++) {
  984. if (TaskList[j].IsFinally) {
  985. IsFinallyCount++;
  986. }
  987. }
  988. this.setData({
  989. IsShowFolder: true,
  990. IsShowNumberInfo: false,
  991. IsMore: false,
  992. FolderList: FolderList,
  993. FolderListLength: FolderListLength,
  994. IsFinallyCount: IsFinallyCount,
  995. Title: " ",
  996. });
  997. },
  998. setCurrentFolder: function (e) {
  999. currentFolderID = e.currentTarget.dataset.folderid;
  1000. currentFolderStart = true;
  1001. this.gotoNext({
  1002. currentTarget: {
  1003. dataset: {
  1004. btnnumber: -3
  1005. }
  1006. }
  1007. });
  1008. this.closeNumberContainner();
  1009. },
  1010. onClose: function () {
  1011. var that=this;
  1012. console.log("close");
  1013. that.clearTimeoutEveryCard();
  1014. wx.navigateBack({
  1015. delta: 1,
  1016. });
  1017. },
  1018. getMemoryLevel: function () {
  1019. var index = wx.getStorageSync("MemoryLevel");
  1020. if (!index) {
  1021. index = 0;
  1022. }
  1023. if (index > 1)
  1024. index = 1;
  1025. app.globalData.MemoryLevel = index;
  1026. this.setData({
  1027. MemoryLevel: index,
  1028. });
  1029. },
  1030. buildShareImage: function () {
  1031. var that = this;
  1032. that.setData({
  1033. IsBuildReport:true,
  1034. });
  1035. wx.showLoading({
  1036. title: '生成中',
  1037. });
  1038. setTimeout(function () {
  1039. wx.hideLoading();
  1040. }, 5000);
  1041. //console.log(app.globalData.userInfo.AvatarUrl);
  1042. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  1043. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  1044. avatarUrl = avatarUrl + "0";
  1045. //console.log(avatarUrl);
  1046. wx.downloadFile({
  1047. url: avatarUrl,
  1048. success(resDownload) {
  1049. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  1050. if (resDownload.statusCode === 200) {
  1051. const query = wx.createSelectorQuery();
  1052. query.select('#shareCanvas')
  1053. .fields({
  1054. node: true,
  1055. size: true
  1056. })
  1057. .exec((res) => {
  1058. const canvas = res[0].node;
  1059. const ctx = canvas.getContext('2d');
  1060. const dpr = wx.getSystemInfoSync().pixelRatio;
  1061. canvas.width = res[0].width * dpr;
  1062. canvas.height = res[0].height * dpr;
  1063. ctx.scale(dpr, dpr);
  1064. var img = canvas.createImage();
  1065. img.src = resDownload.tempFilePath;
  1066. img.onerror = err =>{
  1067. console.log(err);
  1068. };
  1069. img.onload = e => {
  1070. ctx.drawImage(img, 0, 0, 360, 360);
  1071. var img2 = canvas.createImage();
  1072. img2.src = "../images/universalpic_screenshot_jl_bgimage_360x360.png";
  1073. img2.onload = e => {
  1074. ctx.drawImage(img2, 0, 0, 360, 360);
  1075. ctx.fillStyle = main.getShareImageBackColor();
  1076. ctx.fillRect(360, 0, 240, 360);
  1077. ctx.fillStyle = "#ffffff";
  1078. ctx.font = "24px";
  1079. ctx.fillText(app.globalData.userInfo.NickName, 30, 306);
  1080. var today = common.formatTime(new Date(), ".", true);
  1081. ctx.font = "18px";
  1082. ctx.fillText(today, 30, 335);
  1083. ctx.font = "20px";
  1084. ctx.fillText("秒过学习", 390, 40);
  1085. ctx.font = "44px";
  1086. ctx.fillText("勤勉接力", 390, 88);
  1087. ctx.font = "20px";
  1088. ctx.fillText("见证成长", 390, 140);
  1089. ctx.font = "68px";
  1090. if (!that.data.TodayTime)
  1091. that.data.TodayTime = 0;
  1092. ctx.fillText(that.data.TodayTime, 390, 209);
  1093. ctx.font = "normal 500 68px caption";
  1094. var metrics = ctx.measureText(that.data.TodayTime.toString());
  1095. //console.log(JSON.stringify(metrics));
  1096. var h = 209;
  1097. if (app.globalData.IsIOS)
  1098. h = 206;
  1099. ctx.font = "normal 500 32px caption";
  1100. ctx.fillText("分钟", 393 + Math.round(metrics.width), h);
  1101. ctx.font = "20px";
  1102. ctx.fillText("迄今已接力", 390, 295);
  1103. ctx.font = "32px";
  1104. ctx.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 333);
  1105. //console.log("生成前");
  1106. setTimeout(function () {
  1107. //console.log("生成后1");
  1108. wx.canvasToTempFilePath({
  1109. x: 0,
  1110. y: 0,
  1111. width: 600,
  1112. height: 360,
  1113. destWidth: 600,
  1114. destHeight: 360,
  1115. canvas: canvas,
  1116. success: function (res2) {
  1117. wx.hideLoading();
  1118. //console.log("生成后2");
  1119. wx.previewImage({
  1120. current: res2.tempFilePath, // 当前显示图片的http链接
  1121. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  1122. });
  1123. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) {});
  1124. },
  1125. fail: function (e) {
  1126. wx.hideLoading();
  1127. //console.log("生成错误:"+e);
  1128. }
  1129. })
  1130. }, 500);
  1131. };
  1132. };
  1133. });
  1134. } else {
  1135. wx.hideLoading();
  1136. }
  1137. },
  1138. fail: function (e) {
  1139. wx.hideLoading();
  1140. }
  1141. });
  1142. },
  1143. saveCardType: function (event) {
  1144. var that = this;
  1145. var foldertype = event.currentTarget.dataset.foldertype;
  1146. var url = 'UpdateMiaoguoCardType?UserID=' + app.globalData.userInfo.UserID;
  1147. url += "&CardType=-1";
  1148. url += "&FolderType=" + foldertype;
  1149. url += "&ID=" + TaskList[0].MiaoguoCardID;
  1150. main.getData(url, function (data) {
  1151. TaskList.splice(0, 1);
  1152. if (TaskList.length > 0) {
  1153. that.setData({
  1154. TaskInfo: TaskList[0],
  1155. IsShowAnswer: [0, 0],
  1156. });
  1157. if (that.data.IsShowOtherButton)
  1158. that.closeOtherButton();
  1159. that.closeNumberContainner();
  1160. if (foldertype == 1) {
  1161. wx.showToast({
  1162. title: '不练习',
  1163. mask: true,
  1164. image: "../images/universalpic_exclamation_white_120x120.png",
  1165. });
  1166. app.globalData.FolderList = [];
  1167. } else {
  1168. wx.showToast({
  1169. title: '归档成功',
  1170. mask: true,
  1171. image: "../images/universalpic_cupboard_white_120x120.png",
  1172. });
  1173. }
  1174. that.setSoundFile(3);
  1175. } else {
  1176. that.setFinallyResult();
  1177. }
  1178. });
  1179. },
  1180. saveIsFolderPractice: function (e) {
  1181. var that = this;
  1182. var IsFolderPractice = that.data.IsFolderPractice == 0 ? 1 : 0;
  1183. that.setData({
  1184. IsFolderPractice: IsFolderPractice,
  1185. });
  1186. wx.setStorageSync('IsFolderPractice', IsFolderPractice);
  1187. main.UploadUserConfig();
  1188. },
  1189. switchSound: function (e) {
  1190. var that = this;
  1191. var autoAudio = !that.data.IsAutoSound;
  1192. that.setData({
  1193. IsAutoSound: autoAudio,
  1194. });
  1195. if (autoAudio) {
  1196. wx.setStorageSync('IsAutoSound', 1);
  1197. wx.showModal({
  1198. title: '提醒',
  1199. content: '如果题卡里有朗读和录音内容,开启后会按段落顺序逐个自动播放。界面右侧有停止按键。如不想被声音干扰,请关闭该功能。',
  1200. showCancel: false,
  1201. confirmText: "知道了",
  1202. success(res) {
  1203. },
  1204. });
  1205. } else {
  1206. wx.setStorageSync('IsAutoSound', 0);
  1207. }
  1208. main.UploadUserConfig();
  1209. },
  1210. autoAudioPlayInit: function () {
  1211. var that = this;
  1212. common.getStorageValue(that, "IsAutoSound", 1, function () {
  1213. if (that.data.IsAutoSound == 1) {
  1214. var taskInfo = that.data.TaskInfo;
  1215. var field = [];
  1216. var fieldNumber = 1;
  1217. if (that.data.IsShowAnswer[0] == 1)
  1218. fieldNumber = 2;
  1219. if (that.data.IsShowAnswer[1] == 1 && taskInfo.ContentNew.Field[3].length > 0)
  1220. fieldNumber = 3;
  1221. if (taskInfo.ContentNew && taskInfo.ContentNew.Field && taskInfo.ContentNew.Field.length > 0)
  1222. field = taskInfo.ContentNew.Field[fieldNumber];
  1223. arrAutoAudio = [];
  1224. for (var i = 0; i < field.length; i++) {
  1225. if (field[i].Type == "sound" || field[i].Type == "recorder") {
  1226. field[i].FieldNumber = fieldNumber;
  1227. arrAutoAudio.push(field[i]);
  1228. }
  1229. }
  1230. if (arrAutoAudio.length > 0) {
  1231. that.setData({
  1232. IsAutoSoundStart: true,
  1233. });
  1234. that.autoAudioPlayStart();
  1235. }
  1236. }
  1237. });
  1238. },
  1239. autoAudioPlayStart: function () {
  1240. var that = this;
  1241. if (arrAutoAudio.length > 0) {
  1242. var item = arrAutoAudio[0];
  1243. if (item.Type == "recorder")
  1244. item.Content = item.Type;
  1245. that.playSound({
  1246. currentTarget: {
  1247. dataset: {
  1248. content: item.Content,
  1249. soundmark: item.SoundMark,
  1250. fieldid: item.FieldNumber,
  1251. }
  1252. }
  1253. });
  1254. arrAutoAudio.splice(0, 1);
  1255. }
  1256. },
  1257. autoAudioPlayEnd: function () {
  1258. var that = this;
  1259. arrAutoAudio = [];
  1260. if (innerAudioContext1) {
  1261. innerAudioContext1.stop();
  1262. }
  1263. that.audioCtx.pause();
  1264. that.setData({
  1265. IsAutoSoundStart: false,
  1266. });
  1267. },
  1268. //音频播放结束
  1269. audioBindEnded: function () {
  1270. var that = this;
  1271. isPlaying = false;
  1272. if (arrAutoAudio.length > 0) {
  1273. that.autoAudioPlayStart();
  1274. } else {
  1275. that.setData({
  1276. IsAutoSoundStart: false,
  1277. });
  1278. }
  1279. },
  1280. audioBindError: function (err) {
  1281. //console.log(err);
  1282. if (innerAudioContext1 && innerAudioContext1.src) {
  1283. innerAudioContext1.src = tempPlayUrlLocal;
  1284. innerAudioContext1.play();
  1285. }
  1286. },
  1287. playSound: function (e) {
  1288. clearTimeout(timeoutPlayAudio);
  1289. var that = this;
  1290. var str = e.currentTarget.dataset.content;
  1291. var url;
  1292. if (str == "recorder") {
  1293. url = e.currentTarget.dataset.soundmark;
  1294. } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  1295. str = str.replace("英 [", "[");
  1296. str = str.replace("美 [", "[");
  1297. url = e.currentTarget.dataset.soundmark;
  1298. } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
  1299. var soundmark = e.currentTarget.dataset.soundmark;
  1300. if (soundmark && soundmark.indexOf("http") < 0) {
  1301. url = app.globalData.audioUrlBaidu;
  1302. url = url.replace("[token]", app.globalData.BaiduToken);
  1303. url = url.replace("[word]", soundmark);
  1304. } else {
  1305. url = soundmark;
  1306. }
  1307. } else {
  1308. url = app.globalData.audioUrlBaidu;
  1309. url = url.replace("[token]", app.globalData.BaiduToken);
  1310. url = url.replace("[word]", str);
  1311. }
  1312. if (url.indexOf("http") > 0)
  1313. url = url.substr(url.indexOf("http"));
  1314. if (url.indexOf("'") > 0)
  1315. url = common.ReplaceAllString(url, "'", "");
  1316. url = url.replace("http://", "https://");
  1317. url = encodeURI(url);
  1318. if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) {
  1319. isPlaying = true;
  1320. timeoutPlayAudio = setTimeout(function () {
  1321. isPlaying = false;
  1322. }, 60000);
  1323. wx.showLoading({
  1324. title: '音频下载中',
  1325. mask: true,
  1326. });
  1327. setTimeout(function () {
  1328. wx.hideLoading();
  1329. }, 30000);
  1330. wx.downloadFile({
  1331. url: url,
  1332. success(res) {
  1333. wx.hideLoading();
  1334. tempPlayUrlLocal = res.tempFilePath;
  1335. // that.audioCtx.setSrc(res.tempFilePath);
  1336. // that.audioCtx.play();
  1337. innerAudioContext1.src = res.tempFilePath;
  1338. innerAudioContext1.play();
  1339. tempPlayUrl = url;
  1340. },
  1341. fail(err) {
  1342. wx.hideLoading();
  1343. if (url.indexOf("sp0.baidu.com") > 0) {
  1344. var soundmark = url.substring(url.indexOf("text=") + 5, url.indexOf("&spd"));
  1345. url = app.globalData.audioUrlYoudao;
  1346. url = url.replace("[word]", soundmark);
  1347. tempPlayUrlLocal = url;
  1348. that.audioCtx.setSrc(url);
  1349. that.audioCtx.play();
  1350. tempPlayUrl = url;
  1351. }
  1352. }
  1353. });
  1354. } else {
  1355. this.audioCtx.pause();
  1356. if (innerAudioContext1)
  1357. innerAudioContext1.stop();
  1358. isPlaying = false;
  1359. }
  1360. },
  1361. showBishunOrKaiti: function (e) {
  1362. var that = this;
  1363. main.downloadBishunKaitiImage(
  1364. e.currentTarget.dataset.url,
  1365. e.currentTarget.dataset.serverurl,
  1366. e.currentTarget.dataset.type,
  1367. that.data.TaskInfo.ContentNew.Field,
  1368. function (fields) {
  1369. that.data.TaskInfo.ContentNew.Field = fields;
  1370. that.setData({
  1371. TaskInfo: that.data.TaskInfo,
  1372. });
  1373. });
  1374. },
  1375. goto: function (e) {
  1376. var url = e.currentTarget.dataset.url;
  1377. wx.navigateTo({
  1378. url: url,
  1379. });
  1380. },
  1381. clearTimeoutEveryCard: function () {
  1382. for(var i=0;i<timeoutEveryCard.length;i++){
  1383. clearTimeout(timeoutEveryCard[i]);
  1384. }
  1385. timeoutEveryCard=[];
  1386. },
  1387. //获取导航栏高度
  1388. getBarInfo(e) {
  1389. var h = e.detail.topBarHeight;
  1390. h = h * 2;
  1391. if (app.globalData.IsIPad) {
  1392. h += 25;
  1393. }
  1394. this.setData({
  1395. topBarHeight: h,
  1396. })
  1397. },
  1398. onShareAppMessage: function () {
  1399. return {
  1400. title: app.globalData.ShareTitle,
  1401. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  1402. imageUrl: app.globalData.ShareImage,
  1403. }
  1404. },
  1405. });