detail.js 42 KB

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