detail.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  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 arrImage = [],
  12. arrImage2 = [];
  13. var intervalSound = 0,
  14. intervalRefresh = 0;
  15. var isCollecting = false;
  16. var isExit = true;
  17. var isPlaying = false;
  18. var timeoutPlayAudio;
  19. var tempPlayUrl = "";
  20. var tempPlayUrlLocal = "";
  21. var timeoutEveryCard = 0;
  22. var timeoutHide = 0;
  23. Page({
  24. data: {
  25. ImagePath: app.globalData.uploadImageUrl,
  26. NumberNew: 10,
  27. NumberReview: 0,
  28. NumberHistory: 30,
  29. IsShowNumberInfo: false,
  30. IsMore: false,
  31. FontSizeArray: constant.arrFontSize,
  32. StudyPlanArray: arrStudyPlan,
  33. TaskInfo: {},
  34. Color: {ID: 1},
  35. },
  36. onReady: function () {
  37. var that = this;
  38. innerAudioContext1 = wx.createInnerAudioContext();
  39. innerAudioContext1.onPlay(() => {
  40. console.log('开始播放')
  41. });
  42. innerAudioContext1.onError((res) => {
  43. console.log("innerAudioContext1.errMsg:" + res.errMsg);
  44. console.log("innerAudioContext1.errCode:" + res.errCode);
  45. that.audioCtx.setSrc(tempPlayUrl);
  46. that.audioCtx.play();
  47. });
  48. common.getStorageValue(that, "HasSound", true, function () {
  49. wx.setStorageSync("HasSound", that.data.HasSound);
  50. });
  51. },
  52. onLoad: function () {
  53. var that = this;
  54. var height = app.globalData.systemInfo.screenHeight * 2 - 90;
  55. var height2 = 750;
  56. if (app.globalData.IsIPad) {
  57. height = 960;
  58. height2 = 670;
  59. that.setData({
  60. IsIPad: "_iPad",
  61. });
  62. }
  63. that.setData({
  64. Containnerheight: height,
  65. Containnerheight2: height - height2,
  66. IsShowAnswer: [0, 0],
  67. CanUndo: 1,
  68. TaskInfo: {},
  69. ClickType: app.globalData.ClickType,
  70. Color: main.getDetailColor(app.globalData.ColorIndex),
  71. });
  72. this.audioCtx = wx.createAudioContext('myAudio');
  73. this.getList();
  74. this.getColor();
  75. this.getMemoryLevel();
  76. if (app.globalData.BaiduToken === "")
  77. main.getBaiduToken();
  78. if (app.globalData.IsOppo){
  79. that.setData({
  80. TextSpace:"nbsp",
  81. });
  82. }
  83. },
  84. onShow: function () {
  85. var that = this;
  86. if (that.data.NumberNew == 0 &&
  87. that.data.NumberReview == 0 &&
  88. that.data.NumberHistory == 0) {
  89. that.setData({
  90. CanUndo: 0,
  91. TaskInfo: {},
  92. });
  93. listTaskFinished = [];
  94. that.getTaskTime();
  95. } else {
  96. that.setSoundFile(-1);
  97. var list = app.globalData.CardList;
  98. if (list && list.length > 0) {
  99. for (var i = 0; i < list.length; i++) {
  100. if (TaskList && TaskList[0] && TaskList[0].MiaoguoCardID == list[i].MiaoguoCardID) {
  101. TaskList[0].Content = list[i].Content;
  102. TaskList[0].ContentNew = main.changeStringToView(list[i].Content);
  103. that.setData({
  104. TaskInfo: TaskList[0],
  105. });
  106. app.globalData.CardList = [];
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. if (that.data.IsMore){
  113. //关于更改学习计划后处理
  114. if (app.globalData.IsUpdateStudyPlan == 1){
  115. that.gotoNext({ currentTarget: { dataset: { btnnumber:-2}}});
  116. app.globalData.IsUpdateStudyPlan = 0;
  117. }
  118. that.setData({
  119. IsMore: false,
  120. });
  121. }
  122. clearTimeout(timeoutHide);
  123. //console.log("显示");
  124. },
  125. onUnload: function () {
  126. clearInterval(intervalSound);
  127. clearTimeout(timeoutEveryCard);
  128. clearTimeout(timeoutHide);
  129. listTaskFinished = [];
  130. isPlaying = false;
  131. if (innerAudioContext1) {
  132. innerAudioContext1.stop();
  133. }
  134. },
  135. onHide: function (e) {
  136. //console.log("隐藏");
  137. var that = this;
  138. if (isExit) {
  139. timeoutHide = setTimeout(function () {
  140. that.onClose();
  141. }, 60000);
  142. }
  143. isExit = true;
  144. },
  145. onPullDownRefresh: function () {
  146. this.onShowAnswer({
  147. currentTarget: {
  148. dataset: {
  149. start: true
  150. }
  151. }
  152. });
  153. wx.stopPullDownRefresh();
  154. },
  155. setSoundFile: function (isFinish) {
  156. //isFinish=3搁置 =2撤退 =1结束 =0正常 =-1开始
  157. var that = this;
  158. if (that.data.HasSound){
  159. var url = "/pages/sounds/";
  160. if (isFinish == 1) {
  161. url += "end.mp3";
  162. } else if (isFinish == 2) {
  163. url += "short3.mp3";
  164. } else if (isFinish == 3) {
  165. url += "short1.mp3";
  166. } else {
  167. url += "short2.mp3";
  168. }
  169. if (isFinish >= 0) {
  170. innerAudioContext1.src = url;
  171. innerAudioContext1.play();
  172. }
  173. }
  174. wx.pageScrollTo({
  175. scrollTop: 0,
  176. });
  177. },
  178. getColor: function () {
  179. var that = this;
  180. if (wx.setBackgroundColor) {
  181. wx.setBackgroundColor({
  182. backgroundColor: that.data.Color.BackColor,
  183. backgroundColorTop: that.data.Color.BackColor,
  184. backgroundColorBottom: that.data.Color.BackColor,
  185. });
  186. }
  187. if (wx.setNavigationBarColor) {
  188. wx.setNavigationBarColor({
  189. frontColor: "#ffffff",
  190. backgroundColor: that.data.Color.BackColor,
  191. })
  192. }
  193. },
  194. getList: function () {
  195. var task = app.globalData.TaskToday;
  196. var that = this;
  197. var arrNew = task.ListNew;
  198. var arrHistory = task.ListHistory;
  199. var listTaskReview = task.ListReview;
  200. var nMax = [1, 1];
  201. if (arrNew.length == 0 || arrHistory.length == 0) {
  202. if (arrNew.length == 0) {
  203. nMax[0] = 0;
  204. }
  205. if (arrHistory.length == 0) {
  206. nMax[1] = 0;
  207. }
  208. } else if (arrNew.length >= arrHistory.length) {
  209. nMax[0] = Math.floor(arrNew.length / arrHistory.length);
  210. } else if (arrNew.length < arrHistory.length) {
  211. nMax[1] = Math.floor(arrHistory.length / arrNew.length);
  212. }
  213. arrNew = common.randomArray(arrNew);
  214. arrHistory = common.randomArray(arrHistory);
  215. var Len = arrNew.length + arrHistory.length;
  216. TaskList = [];
  217. var indexNew = 0,
  218. indexHistory = 0;
  219. for (var i = 0; i < Len; i++) {
  220. for (var j = 0; j < nMax[0]; j++) {
  221. if (indexNew < arrNew.length) {
  222. arrNew[indexNew].IsNew = true;
  223. TaskList.push(arrNew[indexNew++]);
  224. }
  225. }
  226. for (var j = 0; j < nMax[1]; j++) {
  227. if (indexHistory < arrHistory.length) {
  228. arrHistory[indexHistory].IsHistory = true;
  229. TaskList.push(arrHistory[indexHistory++]);
  230. }
  231. }
  232. }
  233. that.data.NumberReview = listTaskReview.length;
  234. for (var i = 0; i < listTaskReview.length; i++) {
  235. listTaskReview[i].IsReview = true;
  236. TaskList.push(listTaskReview[i]);
  237. }
  238. TaskList = updateNumberStr(TaskList);
  239. //处理列表
  240. TaskList = formatList(TaskList);
  241. if (TaskList.length > 0) {
  242. arrImage = TaskList[0].ContentNew.Images;
  243. arrImage2 = TaskList[0].ContentNew.Images2;
  244. }
  245. var taskInfo = TaskList[0];
  246. if (!taskInfo)
  247. taskInfo = {};
  248. that.setData({
  249. NumberNew: arrNew.length,
  250. NumberReview: that.data.NumberReview,
  251. NumberHistory: arrHistory.length,
  252. TaskInfo: taskInfo,
  253. CanUndo: 0,
  254. });
  255. listTaskFinished = [];
  256. that.timeCompute(); //起始时间
  257. function formatList(list) {
  258. for (var i = 0; i < list.length; i++) {
  259. if (list[i].Content) {
  260. list[i].ContentNew = main.changeStringToView(list[i].Content);
  261. list[i].TagWidth = 0;
  262. if (list[i].ContentNew.Tags && list[i].ContentNew.Tags.length > 0) {
  263. list[i].TagWidth = 92 + (list[i].ContentNew.Tags.length - 1) * 122;
  264. for (var j = 0; j < list[i].ContentNew.Tags.length; j++) {
  265. if (list[i].ContentNew.Tags[j].length > 2) {
  266. list[i].TagWidth += 46 * (list[i].ContentNew.Tags[j].length - 2);
  267. }
  268. }
  269. }
  270. }
  271. }
  272. return list;
  273. }
  274. function updateNumberStr(list) {
  275. for (var i = 0; i < list.length; i++) {
  276. if (list[i].Number0)
  277. list[i].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, list[i].Number0);
  278. if (list[i].Number1)
  279. list[i].Number1Str = main.getMemoryLevel(app.globalData.MemoryLevel, 1, list[i].Number1);
  280. if (list[i].Number2)
  281. list[i].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, list[i].Number2);
  282. if (list[i].Number3)
  283. list[i].Number3Str = main.getMemoryLevel(app.globalData.MemoryLevel, 3, list[i].Number3);;
  284. }
  285. return list;
  286. }
  287. },
  288. onShowAnswer: function (e) {
  289. var clicktype = e.currentTarget.dataset.type;
  290. if (!(clicktype && clicktype == "all" && app.globalData.ClickType == 0)) {
  291. var start = e.currentTarget.dataset.start;
  292. var that = this;
  293. if (!(that.data.NumberNew == 0 &&
  294. that.data.NumberReview == 0 &&
  295. that.data.NumberHistory == 0) && !that.data.IsShowNumberInfo) {
  296. var recommend = 0;
  297. if (start) {
  298. that.data.IsShowAnswer[0] = 0;
  299. that.data.IsShowAnswer[1] = 0;
  300. } else {
  301. if (!that.data.IsShowAnswer)
  302. that.data.IsShowAnswer=[0,0];
  303. if (that.data.IsShowAnswer[0]==0 && that.data.IsShowAnswer[1]==0) {
  304. that.data.IsShowAnswer[0] = 1;
  305. if (TaskList[0].ContentNew.Field[3].length == 0) {
  306. that.data.IsShowAnswer[1] = 1;
  307. if (!that.data.TaskInfo.IsNew)
  308. recommend = getRecommendTime();
  309. that.setData({
  310. Recommend: recommend,
  311. });
  312. }
  313. } else if (that.data.IsShowAnswer[0] && !that.data.IsShowAnswer[1]) {
  314. that.data.IsShowAnswer[1] = 1;
  315. if (!that.data.TaskInfo.IsNew)
  316. recommend = getRecommendTime();
  317. that.setData({
  318. Recommend: recommend,
  319. });
  320. }
  321. }
  322. that.setData({
  323. IsShowAnswer: that.data.IsShowAnswer,
  324. });
  325. if (that.data.IsShowAnswer[1]){
  326. var query = wx.createSelectorQuery().in(that)
  327. query.select('#ViewField3').boundingClientRect(function(res){
  328. if (res && res.top && res.top>130)
  329. scroll(res.top-130);
  330. }).exec();
  331. }
  332. }
  333. function scroll(top) {
  334. wx.pageScrollTo({
  335. scrollTop: top,
  336. });
  337. }
  338. function getRecommendTime() {
  339. if (app.globalData.SecondConfigArray[0] > 0) {
  340. var duration = common.diffDate("s", timeStart, new Date());
  341. if (duration <= app.globalData.SecondConfigArray[0])
  342. return 3;
  343. else if (duration <= app.globalData.SecondConfigArray[1])
  344. return 2;
  345. else if (duration <= app.globalData.SecondConfigArray[2])
  346. return 1;
  347. else
  348. return 0;
  349. } else
  350. return 0;
  351. }
  352. }
  353. },
  354. gotoEdit: function () {
  355. var that = this;
  356. //console.log(res.tapIndex);
  357. var list = [];
  358. list.push(TaskList[0]);
  359. app.globalData.CardList = list;
  360. wx.navigateTo({
  361. url: './add?type=edit&id=' + TaskList[0].MiaoguoCardID,
  362. });
  363. isExit = false;
  364. },
  365. onFontSize: function (e) {
  366. var value = e.currentTarget.dataset.value;
  367. TaskList[0].FontSize = value;
  368. this.setData({
  369. TaskInfo: TaskList[0],
  370. IsMore: false,
  371. });
  372. },
  373. //回到上一张题卡
  374. gotoPrev: function () {
  375. var that = this;
  376. if (listTaskFinished.length > 0) {
  377. var card = listTaskFinished.pop();
  378. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  379. timeHistory = 0;
  380. that.timeCompute();
  381. card.Card.Number0 = card.Number0Old;
  382. card.Card.Number0Str = card.Number0StrOld;
  383. card.Card.Number1 = card.Number1Old;
  384. card.Card.Number1Str = card.Number1StrOld;
  385. card.Card.Number2 = card.Number2Old;
  386. card.Card.Number2Str = card.Number2StrOld;
  387. card.Card.Number3 = card.Number3Old;
  388. card.Card.Number3Str = card.Number3StrOld;
  389. if (card.IsReviewOld)
  390. card.Card.IsReview = card.IsReviewOld;
  391. //去除重复
  392. for (var i = 0; i < TaskList.length; i++) {
  393. if (TaskList[i].MiaoguoCardID == card.Card.MiaoguoCardID) {
  394. TaskList.splice(i, 1);
  395. }
  396. }
  397. TaskList.unshift(card.Card);
  398. var canUndo = 1;
  399. if (listTaskFinished.length == 0)
  400. canUndo = 0;
  401. arrImage = TaskList[0].ContentNew.Images;
  402. arrImage2 = TaskList[0].ContentNew.Images2;
  403. that.setData({
  404. IsShowAnswer: [0, 0],
  405. TaskInfo: TaskList[0],
  406. NumberNew: card.NumberNew,
  407. NumberReview: card.NumberReview,
  408. NumberHistory: card.NumberHistory,
  409. CanUndo: canUndo,
  410. Recommend: 0,
  411. });
  412. wx.showToast({
  413. title: '回到上一张',
  414. image: "../images/universalpic_undo_white_120x90.png",
  415. });
  416. that.setSoundFile(2);
  417. }
  418. },
  419. //进入下一张题卡
  420. gotoNext: function (e) {
  421. var that = this;
  422. //btnnumber可以有 5:秒过 4正常 3困难 2挪到最后 1搁置 0不过 -1今天要练 -2更改计划
  423. var btnnumber = e.currentTarget.dataset.btnnumber;
  424. //若是“挪到最后”
  425. if (btnnumber == 2) {
  426. var card = TaskList.splice(0, 1);
  427. card[0].IsFinally=true;
  428. card[0].LimitTime=common.formatTime(new Date(),"/",true)+" 23:59:59";
  429. TaskList.push(card[0]);
  430. that.setData({
  431. IsShowAnswer: [0, 0],
  432. TaskInfo: TaskList[0],
  433. CanUndo: 1,
  434. Recommend: 0,
  435. IsMore: false,
  436. });
  437. }
  438. else{
  439. var time = e.currentTarget.dataset.time;
  440. //处理当前卡片进入历史数组
  441. var finishCard = {};
  442. finishCard.Card = TaskList[0];
  443. finishCard.NumberNew = this.data.NumberNew;
  444. finishCard.NumberReview = this.data.NumberReview;
  445. finishCard.NumberHistory = this.data.NumberHistory;
  446. finishCard.Number0Old = TaskList[0].Number0;
  447. finishCard.Number0StrOld = TaskList[0].Number0Str;
  448. finishCard.Number1Old = TaskList[0].Number1;
  449. finishCard.Number1StrOld = TaskList[0].Number1Str;
  450. finishCard.Number2Old = TaskList[0].Number2;
  451. finishCard.Number2StrOld = TaskList[0].Number2Str;
  452. finishCard.Number3Old = TaskList[0].Number3;
  453. finishCard.Number3StrOld = TaskList[0].Number3Str;
  454. //若是当前题卡更改学习计划
  455. if (btnnumber==-2) {
  456. for (var i = 0,flag=true; i < listTaskFinished.length;flag?i++:i){
  457. if (listTaskFinished[i].Card.MiaoguoCardID==finishCard.Card.MiaoguoCardID){
  458. listTaskFinished.splice(i,1);
  459. flag=false;
  460. }
  461. else
  462. flag=true;
  463. }
  464. }
  465. else{
  466. //若不是搁置
  467. //算出下一次的时间
  468. if (btnnumber != "1") {
  469. //若是分钟,则进入复习列表
  470. if (time.lastIndexOf("m") == time.length - 1) {
  471. var minute = Number(time.substr(0, time.indexOf("m")));
  472. TaskList[0].LimitTime = common.formatTime(common.addDate("n", minute, new Date()));
  473. //若是新建,则10m 1d 4d
  474. if (TaskList[0].IsNew) {
  475. if (minute == 1) {
  476. TaskList[0].Number0 = "1m";
  477. TaskList[0].Number2 = "10m";
  478. }
  479. else {
  480. TaskList[0].Number0 = "10m";
  481. TaskList[0].Number2 = "1d";
  482. }
  483. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  484. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  485. delete TaskList[0].Number1;
  486. delete TaskList[0].Number1Str;
  487. delete TaskList[0].Number3;
  488. delete TaskList[0].Number3Str;
  489. TaskList[0].FirstTime = null;
  490. TaskList[0].LastTime = null;
  491. }
  492. //若是历史的,则10m 1d
  493. else if (TaskList[0].IsHistory) {
  494. TaskList[0].Number0 = "10m";
  495. TaskList[0].Number0Str = main.getMemoryLevel(app.globalData.MemoryLevel, 0, TaskList[0].Number0);
  496. delete TaskList[0].Number1;
  497. delete TaskList[0].Number1Str;
  498. TaskList[0].Number2 = "1d";
  499. TaskList[0].Number2Str = main.getMemoryLevel(app.globalData.MemoryLevel, 2, TaskList[0].Number2);
  500. delete TaskList[0].Number3;
  501. delete TaskList[0].Number3Str;
  502. }
  503. finishCard.IsReviewOld = TaskList[0].IsReview;
  504. TaskList[0].IsReview = true;
  505. TaskList.push(TaskList[0]);
  506. }
  507. //若是天月年
  508. else {
  509. var dayNum = Number(time.substr(0, time.indexOf("d")));
  510. var date = common.addDate("d", dayNum, new Date());
  511. TaskList[0].LimitTime = common.formatTime(date);
  512. }
  513. }
  514. //修改学习任务个数
  515. var learningType = 0;
  516. if (TaskList[0].IsReview) {
  517. learningType = 2;
  518. }
  519. if (TaskList[0].IsNew) {
  520. learningType = 0;
  521. } else if (TaskList[0].IsHistory) {
  522. learningType = 1;
  523. }
  524. if (btnnumber == "1") {
  525. learningType = 3;
  526. }
  527. finishCard.IntervalTime = time;
  528. finishCard.BtnNumber = btnnumber;
  529. finishCard.LearningType = learningType;
  530. var duration = common.diffDate("s", timeStart, new Date());
  531. if (finishCard.btnnumber == 1)
  532. duration = 0;
  533. finishCard.Duration = timeHistory + duration;
  534. console.log("CardTime:" + finishCard.Duration);
  535. timeHistory = 0;
  536. that.timeCompute();
  537. //添加完成列表,去掉任务列表数据
  538. listTaskFinished.push(finishCard);
  539. }
  540. wx.setStorageSync("ListTaskFinished", listTaskFinished);
  541. TaskList.shift();
  542. that.data.NumberNew = 0;
  543. that.data.NumberHistory = 0;
  544. that.data.NumberReview = 0;
  545. for (var i = 0; i < TaskList.length; i++) {
  546. if (TaskList[i].IsReview) {
  547. if (TaskList[i].LimitTime < common.formatTime(new Date())) {
  548. var card = TaskList.splice(i, 1);
  549. TaskList.unshift(card[0]);
  550. }
  551. that.data.NumberReview++;
  552. } else if (TaskList[i].IsNew) {
  553. that.data.NumberNew++;
  554. } else if (TaskList[i].IsHistory) {
  555. that.data.NumberHistory++;
  556. }
  557. if (TaskList[i].IsFinally){
  558. var card = TaskList.splice(i, 1);
  559. TaskList.push(card[0]);
  560. }
  561. }
  562. //console.log(JSON.stringify(TaskList[0]));
  563. //如果所有任务完成
  564. if (that.data.NumberNew == 0 &&
  565. that.data.NumberReview == 0 &&
  566. that.data.NumberHistory == 0) {
  567. that.setData({
  568. IsShowAnswer: [0, 0],
  569. NumberNew: 0,
  570. NumberReview: 0,
  571. NumberHistory: 0,
  572. CanUndo: 1,
  573. Recommend: 0,
  574. IsMore: false,
  575. });
  576. clearTimeout(timeoutEveryCard);
  577. that.setSoundFile(1);
  578. main.UpdateMiaoguoCardTodayAll(true, function () {
  579. listTaskFinished = [];
  580. that.getTaskTime();
  581. });
  582. }
  583. //没有完成任务
  584. else {
  585. arrImage = TaskList[0].ContentNew.Images;
  586. arrImage2 = TaskList[0].ContentNew.Images2;
  587. //任务没有完成,下一张卡片
  588. that.setData({
  589. IsShowAnswer: [0, 0],
  590. TaskInfo: TaskList[0],
  591. NumberNew: that.data.NumberNew,
  592. NumberReview: that.data.NumberReview,
  593. NumberHistory: that.data.NumberHistory,
  594. CanUndo: 1,
  595. Recommend: 0,
  596. IsMore: false,
  597. });
  598. if (btnnumber == "1") {
  599. that.setSoundFile(3);
  600. if (time == "1d") {
  601. wx.showToast({
  602. title: '搁置一天',
  603. mask: true,
  604. image: "../images/universalpic_shelve_white_120x120.png",
  605. });
  606. } else {
  607. wx.showToast({
  608. title: '已推迟',
  609. mask: true,
  610. image: "../images/universalpic_bell_white_120x120.png",
  611. });
  612. }
  613. } else
  614. that.setSoundFile(0);
  615. }
  616. }
  617. },
  618. timeCompute: function () {
  619. var that = this;
  620. timeStart = new Date();
  621. clearTimeout(timeoutEveryCard);
  622. timeoutEveryCard = setTimeout(function () {
  623. //计算暂停时已经用掉的时长
  624. timeHistory += common.diffDate("s", timeStart, new Date());
  625. console.log("timeHistory:" + timeHistory);
  626. wx.showModal({
  627. title: '提醒',
  628. content: '您已等待了' + app.globalData.CardWaitTimeMax + '分钟',
  629. showCancel: false,
  630. confirmText: "知道了",
  631. success(res) {
  632. clearTimeout(timeoutEveryCard);
  633. if (res.confirm) {
  634. that.timeCompute();
  635. }
  636. },
  637. })
  638. }, app.globalData.CardWaitTimeMax * 60 * 1000);
  639. },
  640. gotoCollect: function () {
  641. var that = this;
  642. if (!isCollecting) {
  643. isCollecting = true;
  644. setTimeout(function () {
  645. isCollecting = false;
  646. }, 3000);
  647. var that = this;
  648. if (!TaskList[0].IsCollect) {
  649. TaskList[0].IsCollect = 1;
  650. } else {
  651. TaskList[0].IsCollect = 0;
  652. }
  653. that.setData({
  654. TaskInfo: TaskList[0],
  655. });
  656. main.setCollect(TaskList[0].MiaoguoCardID, TaskList[0].IsCollect);
  657. }
  658. },
  659. playSound: function (e) {
  660. clearTimeout(timeoutPlayAudio);
  661. var that = this;
  662. var str = e.currentTarget.dataset.content;
  663. var url;
  664. if (str == "recorder") {
  665. url = e.currentTarget.dataset.soundmark;
  666. } else if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  667. str = str.replace("英 [", "[");
  668. str = str.replace("美 [", "[");
  669. url = e.currentTarget.dataset.soundmark;
  670. } else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark != "undefined") {
  671. var soundmark = e.currentTarget.dataset.soundmark;
  672. if (soundmark && soundmark.indexOf("http") < 0) {
  673. url = app.globalData.audioUrlBaidu;
  674. url = url.replace("[token]", app.globalData.BaiduToken);
  675. url = url.replace("[word]", soundmark);
  676. } else {
  677. url = soundmark;
  678. }
  679. } else {
  680. url = app.globalData.audioUrlBaidu;
  681. url = url.replace("[token]", app.globalData.BaiduToken);
  682. url = url.replace("[word]", str);
  683. }
  684. if (url.indexOf("http") > 0)
  685. url = url.substr(url.indexOf("http"));
  686. if (url.indexOf("'") > 0)
  687. url = common.ReplaceAllString(url, "'", "");
  688. url = url.replace("http://", "https://");
  689. url = encodeURI(url);
  690. if (!isPlaying || tempPlayUrl == "" || url != tempPlayUrl) {
  691. isPlaying = true;
  692. timeoutPlayAudio = setTimeout(function () {
  693. isPlaying = false;
  694. }, 60000);
  695. wx.showLoading({
  696. title: '音频下载中',
  697. mask: true,
  698. });
  699. setTimeout(function () {
  700. wx.hideLoading();
  701. }, 30000);
  702. wx.downloadFile({
  703. url: url,
  704. success(res) {
  705. wx.hideLoading();
  706. if (res.statusCode === 200) {
  707. tempPlayUrlLocal = res.tempFilePath;
  708. that.audioCtx.setSrc(res.tempFilePath);
  709. that.audioCtx.play();
  710. tempPlayUrl = url;
  711. }
  712. },
  713. fail(err) {
  714. wx.hideLoading();
  715. }
  716. });
  717. } else {
  718. this.audioCtx.pause();
  719. if (innerAudioContext1)
  720. innerAudioContext1.stop();
  721. isPlaying = false;
  722. }
  723. },
  724. audioBindEnded: function () {
  725. isPlaying = false;
  726. },
  727. audioBindError: function (err) {
  728. console.log(err);
  729. innerAudioContext1.src = tempPlayUrlLocal;
  730. innerAudioContext1.play();
  731. },
  732. getTaskTime: function () {
  733. var that = this;
  734. var url = "GetMiaoguoTaskTime?";
  735. url += "UserID=" + app.globalData.userInfo.UserID;
  736. main.getData(url, function (data) {
  737. if (data) {
  738. var duration = data.Duration;
  739. if (duration > 0) {
  740. duration = Math.round(duration / 60);
  741. }
  742. var speed1 = 0;
  743. if (data.Duration > 0)
  744. speed1 = Math.round(100 * data.Count / (data.Duration / 60)) / 100;
  745. var speed2 = 0 + "秒";
  746. if (data.Count > 0)
  747. speed2 = common.getMinuteSecond(Math.round(data.Duration / data.Count), true);
  748. app.globalData.TaskToday.DayNumber = data.DayNumber;
  749. that.setData({
  750. TodayTime: duration,
  751. Speed1: speed1 + "张题卡",
  752. Speed2: speed2,
  753. });
  754. wx.setNavigationBarTitle({
  755. title: "报告"
  756. });
  757. }
  758. });
  759. },
  760. showNumberContainner: function () {
  761. this.setData({
  762. IsShowNumberInfo: true,
  763. });
  764. wx.setNavigationBarTitle({
  765. title: "进度"
  766. });
  767. },
  768. closeNumberContainner: function () {
  769. this.setData({
  770. IsShowNumberInfo: false,
  771. IsMore: false,
  772. });
  773. wx.setNavigationBarTitle({
  774. title: "学习中"
  775. });
  776. },
  777. showImage: function (e) {
  778. var name = e.currentTarget.dataset.name;
  779. if (name && name.length > 5) {
  780. wx.previewImage({
  781. current: name,
  782. urls: arrImage
  783. });
  784. }
  785. },
  786. onBindError: function (e) {
  787. var that = this;
  788. var serverUrl = e.currentTarget.dataset.serverurl;
  789. var oldTempUrl = e.currentTarget.dataset.name;
  790. //console.log("serverUrl1:" + serverUrl);
  791. wx.downloadFile({
  792. url: serverUrl, // 仅为示例,并非真实的资源
  793. success(res) {
  794. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  795. if (res.statusCode === 200) {
  796. //console.log("serverUrl2:" + serverUrl);
  797. //console.log(res.tempFilePath);
  798. main.saveTempImage(serverUrl, res.tempFilePath);
  799. for (var i = 0; i < arrImage.length; i++) {
  800. if (arrImage[i] == oldTempUrl) {
  801. arrImage[i] = res.tempFilePath;
  802. }
  803. }
  804. }
  805. }
  806. });
  807. clearTimeout(intervalRefresh);
  808. intervalRefresh = setTimeout(function () {
  809. TaskList[0].ContentNew = main.changeStringToView(TaskList[0].Content);
  810. that.setData({
  811. TaskInfo: TaskList[0],
  812. });
  813. }, 1000);
  814. for (var i = 1; i < this.data.TaskInfo.ContentNew.Field.length; i++) {
  815. for (var j = 0; j < this.data.TaskInfo.ContentNew.Field[i].length; j++) {
  816. if (this.data.TaskInfo.ContentNew.Field[i][j].Type == "image") {
  817. this.data.TaskInfo.ContentNew.Field[i][j].Url = this.data.TaskInfo.ContentNew.Field[i][j].Content;
  818. }
  819. }
  820. }
  821. this.setData({
  822. TaskInfo: this.data.TaskInfo,
  823. });
  824. },
  825. onMore: function () {
  826. for (var i = 0; i < this.data.FontSizeArray.length; i++) {
  827. if (this.data.FontSizeArray[i].Value == this.data.TaskInfo.FontSize)
  828. this.data.FontSizeArray[i].CSS = "color:#1E1E1E;background-color:" + this.data.Color.LineColor + ";border:3rpx solid " + this.data.Color.LineColor + ";";
  829. else
  830. this.data.FontSizeArray[i].CSS = "";
  831. }
  832. this.setData({
  833. IsMore: true,
  834. FontSizeArray: this.data.FontSizeArray,
  835. });
  836. },
  837. onClose: function () {
  838. wx.navigateBack({
  839. delta: 1,
  840. });
  841. },
  842. getMemoryLevel: function () {
  843. var index = wx.getStorageSync("MemoryLevel");
  844. if (!index) {
  845. index = 0;
  846. }
  847. if (index>1)
  848. index=1;
  849. app.globalData.MemoryLevel = index;
  850. this.setData({
  851. MemoryLevel:index,
  852. });
  853. },
  854. buildShareImage: function () {
  855. var that = this;
  856. wx.showLoading({
  857. title: '生成中',
  858. });
  859. setTimeout(function () {
  860. wx.hideLoading();
  861. }, 5000);
  862. //console.log(app.globalData.userInfo.AvatarUrl);
  863. var avatarUrl = app.globalData.userInfo.AvatarUrl;
  864. avatarUrl = avatarUrl.substring(0, avatarUrl.lastIndexOf("/") + 1);
  865. avatarUrl = avatarUrl + "0";
  866. //console.log(avatarUrl);
  867. wx.downloadFile({
  868. url: avatarUrl, // 仅为示例,并非真实的资源
  869. success(res) {
  870. // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
  871. if (res.statusCode === 200) {
  872. var canvas = wx.createCanvasContext("shareCanvas", that);
  873. canvas.setFillStyle(main.getShareImageBackColor());
  874. canvas.fillRect(360, 0, 600, 360);
  875. canvas.drawImage(res.tempFilePath, 0, 0, 360, 360);
  876. canvas.drawImage("../images/universalpic_screenshot_jl_bgimage_360x360.png", 0, 0, 360, 360);
  877. canvas.fillStyle = "#ffffff";
  878. canvas.setTextBaseline('top');
  879. canvas.setFontSize(24);
  880. canvas.fillText(app.globalData.userInfo.NickName, 30, 282);
  881. var today = common.formatTime(new Date(), ".", true);
  882. canvas.setFontSize(18);
  883. canvas.fillText(today, 30, 315);
  884. canvas.setFontSize(20);
  885. canvas.fillText("秒过学习", 390, 30);
  886. canvas.setFontSize(44);
  887. canvas.fillText("勤勉接力", 390, 58);
  888. canvas.setFontSize(20);
  889. canvas.fillText("见证成长", 390, 120);
  890. canvas.setFontSize(68);
  891. if (!that.data.TodayTime)
  892. that.data.TodayTime=0;
  893. canvas.fillText(that.data.TodayTime, 390, 148);
  894. canvas.font = "normal 500 68px caption";
  895. var metrics = canvas.measureText(that.data.TodayTime.toString());
  896. //console.log(JSON.stringify(metrics));
  897. var h = 179;
  898. if (app.globalData.IsIOS)
  899. h = 176;
  900. canvas.font = "normal 500 32px caption";
  901. canvas.fillText("分钟", 393 + Math.round(metrics.width), h);
  902. canvas.setFontSize(20);
  903. canvas.fillText("迄今已接力", 390, 267);
  904. canvas.setFontSize(32);
  905. canvas.fillText(app.globalData.TaskToday.DayNumber + "次", 390, 295);
  906. //console.log("生成前");
  907. canvas.draw(1, function (n) {
  908. //console.log("生成后1");
  909. wx.canvasToTempFilePath({
  910. x: 0,
  911. y: 0,
  912. width: 600,
  913. height: 360,
  914. destWidth: 600,
  915. destHeight: 360,
  916. canvasId: 'shareCanvas',
  917. success: function (res2) {
  918. wx.hideLoading();
  919. //console.log("生成后2");
  920. wx.previewImage({
  921. current: res2.tempFilePath, // 当前显示图片的http链接
  922. urls: [res2.tempFilePath] // 需要预览的图片http链接列表
  923. });
  924. main.getData("ShareMiaoguoTask?UserID=" + app.globalData.userInfo.UserID, function (data) { });
  925. },
  926. fail: function (e) {
  927. wx.hideLoading();
  928. //console.log("生成错误:"+e);
  929. }
  930. })
  931. });
  932. } else {
  933. wx.hideLoading();
  934. }
  935. },
  936. fail: function () {
  937. wx.hideLoading();
  938. }
  939. });
  940. },
  941. goto: function (e) {
  942. var url = e.currentTarget.dataset.url;
  943. wx.navigateTo({
  944. url: url,
  945. });
  946. },
  947. //获取导航栏高度
  948. getBarInfo(e) {
  949. var h=e.detail.topBarHeight;
  950. h=h*2;
  951. this.setData({
  952. topBarHeight: h,
  953. })
  954. },
  955. onShareAppMessage: function () {
  956. return {
  957. title: app.globalData.ShareTitle,
  958. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  959. imageUrl: app.globalData.ShareImage,
  960. }
  961. },
  962. });