detail.js 41 KB

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