detail.js 42 KB

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