detail.js 46 KB

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