detail.js 46 KB

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