detail.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. import pinyin from '../../utils/pinyin';
  4. const app = getApp();
  5. var isEditSetting = [];//是否修改设置
  6. var intervalAutoPage = 0;
  7. var insertID = 0, hanziNumber = 0;
  8. var isClickFinished = true;//可以点击学会了
  9. var isClickReview = true;//可以点击要复习
  10. Page({
  11. data: {
  12. IsAutoPlay: true,//是否自动播放
  13. IsAutoPage: false,//是否自动翻页
  14. SortTitle: "课本一致",//排序
  15. PlayChecked: "checked",
  16. PageChecked: "",
  17. IsFinished: false,//是否练会了
  18. arrIntervalSecond: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],//播放间隔秒数组
  19. audioPer: [0, 1, 3, 4],//音色
  20. IntervalSecondIndex: 2,//播放间隔秒数索引
  21. IsImageError: false,
  22. SpeakerArray: [{ name: "温柔姐姐(推荐)", value: "woman", isShow: true }, { name: "爽朗哥哥", value: "man", isShow: false }, { name: "古韵叔叔", value: "oldman", isShow: false }, { name: "可爱妹妹", value: "sister", isShow: false }],
  23. pinyinCss: "",
  24. },
  25. onLoad: function (options) {
  26. var bookID = options.bookid || 0;
  27. var unitID = options.unitid || 0;
  28. var wordID = options.wordid || 0;
  29. var indexID = options.indexID || 0;
  30. this.audioCtx = wx.createAudioContext('myAudio');
  31. hanziNumber = 0;
  32. isClickFinished = true;
  33. isClickReview = true;
  34. var isfinished = options.isfinished;
  35. if (!isfinished || isfinished == "false")
  36. isfinished = false;
  37. else if (isfinished == "true")
  38. isfinished = true;
  39. if (!options.Type) {
  40. options.Type = "normal";
  41. }
  42. this.setData({
  43. Height: common.getSystemHeight(),
  44. IsShowPrev: false,
  45. IsShowNext: true,
  46. CurrentIndex: wordID,
  47. IsFinished: isfinished,
  48. IsHelpPosition1: 0,
  49. IsReview: false,
  50. IsShowWordDetail: false,
  51. ShowMenu: "sort",
  52. UnitID: unitID,
  53. BookID: bookID,
  54. SelectedRandom: false,
  55. SpeakerTitle: this.data.SpeakerArray[0].name,
  56. SpeakerMan: 0,
  57. ShowPinyin: true,
  58. IsAudioLengthChecked: true,//显示组词播放音
  59. WordType: options.Type,
  60. });
  61. var that = this;
  62. common.getStorageValue(that, "IsAutoPlay", true, function () {
  63. common.getStorageValue(that, "IsAutoPage", false, function () {
  64. common.getStorageValue(that, "SelectedRandom", false, function () {
  65. common.getStorageValue(that, "ShowHanzi", true, function () {
  66. common.getStorageValue(that, "ShowPinyin", true, function () {
  67. common.getStorageValue(that, "IntervalSecondIndex", 2, function () {
  68. common.getStorageValue(that, "IsAudioLengthChecked", true, function () {
  69. common.getStorageValue(that, "SpeakerMan", 0, function () {
  70. that.settingPlay(null, that.data.IsAutoPlay);
  71. that.settingPage(null, that.data.IsAutoPage);
  72. that.settingSort(null, that.data.SelectedRandom.toString());
  73. that.settingShowPinyin(null, that.data.ShowPinyin);
  74. that.settingShowHanzi(null, that.data.ShowHanzi);
  75. that.settingAudioLength(null, that.data.IsAudioLengthChecked);
  76. that.settingSpeaker(null, that.data.SpeakerMan);
  77. if (that.data.WordType == "normal")
  78. that.init();
  79. else if (that.data.WordType == "review")
  80. that.initReview(indexID);
  81. else if (that.data.WordType == "search")
  82. that.initSearch();
  83. });
  84. });
  85. });
  86. });
  87. });
  88. });
  89. });
  90. });
  91. common.getStorageValue(that, "IsHelpPosition1", 1, function () { });
  92. if (this.data.WordType == "normal")
  93. this.submitData();
  94. var systemInfo = wx.getSystemInfoSync();
  95. if (systemInfo.model) {
  96. if (systemInfo.model.indexOf("iPad") >= 0) {
  97. this.setData({
  98. pinyinCss: "pinyinCssIpad",
  99. })
  100. }
  101. }
  102. },
  103. onShow: function (e) {
  104. if (app.globalData.IsSaveCustom) {
  105. isEditSetting.push("saveCustom");
  106. app.globalData.IsSaveCustom = false;
  107. }
  108. },
  109. onUnload: function () {
  110. clearInterval(intervalAutoPage);
  111. server.postData('UpdateHanziRecord', {
  112. RecordID: insertID,
  113. HanziNumber: hanziNumber,
  114. }, function (data) { });
  115. if (this.data.IsHelpPosition1 == 1) {
  116. this.setData({
  117. IsHelpPosition1: 2,
  118. });
  119. wx.setStorageSync('IsHelpPosition1', 2);
  120. }
  121. var IsRemindTest = wx.getStorageSync("IsRemindTest");
  122. if (!IsRemindTest)
  123. wx.setStorageSync('IsRemindTest', 1);
  124. },
  125. submitData: function (content) {
  126. if (app.globalData.userInfo && app.globalData.userInfo.UserID) {
  127. server.postData('AddHanziRecord', {
  128. UserID: app.globalData.userInfo.UserID,
  129. Category: this.data.BookID,
  130. Content: this.data.UnitID,
  131. }, function (data) {
  132. //console.log(data.insertId);
  133. insertID = data.insertId;
  134. });
  135. }
  136. },
  137. init: function () {
  138. var arr = JSON.parse(wx.getStorageSync("HanziAll"));
  139. var arrReview = wx.getStorageSync("ReviewList");
  140. var result;
  141. for (var i = 0; i < arr.length; i++) {
  142. if (arr[i].ID == this.data.BookID) {
  143. for (var j = 0; j < arr[i].Units.length; j++) {
  144. var item = arr[i].Units[j];
  145. if (item.ID == this.data.UnitID) {
  146. //查看用户有没有自定义
  147. var wordArr = wx.getStorageSync("UnitCustom");
  148. if (wordArr) {
  149. for (var k = 0; k < wordArr.length; k++) {
  150. if (wordArr[k].ID == this.data.UnitID) {
  151. item.Words = wordArr[k].List;
  152. }
  153. }
  154. }
  155. for (var k = 0; k < item.Words.length; k++) {
  156. item.Words[k].PinyinAll = item.Words[k].Pinyin;
  157. if (item.Words[k].Pinyin.indexOf(",") > 0)
  158. item.Words[k].Pinyin = item.Words[k].Pinyin.substr(0, item.Words[k].Pinyin.indexOf(","));
  159. item.Words[k].WordUrl = app.globalData.imageUrl + "/images/hanzi" + item.Words[k].Name + ".jpg";
  160. item.Words[k].IsReview = false;
  161. for (var l = 0; l < arrReview.length; l++) {
  162. if (arrReview[l].Name == item.Words[k].Name) {
  163. item.Words[k].IsReview = true;
  164. break;
  165. }
  166. }
  167. }
  168. result = item;
  169. break;
  170. }
  171. }
  172. break;
  173. }
  174. }
  175. if (this.data.SelectedRandom) {
  176. result.Words = common.randomArray(result.Words);
  177. }
  178. var obj = {
  179. Title: result.Name,
  180. Title2: "到底了",
  181. IsEnd: true,
  182. }
  183. result.Words.push(obj);
  184. this.setData({
  185. List: result.Words,
  186. });
  187. this.restart(this.data.CurrentIndex);
  188. wx.setNavigationBarTitle({
  189. title: "练习"
  190. });
  191. },
  192. initReview: function (indexID) {
  193. var arrReview = wx.getStorageSync("ReviewList");
  194. for (var l = 0; l < arrReview.length; l++) {
  195. var item = arrReview[l];
  196. item.PinyinAll = item.Pinyin;
  197. if (item.Pinyin.indexOf(",") > 0)
  198. item.Pinyin = item.Pinyin.substr(0, item.Pinyin.indexOf(","));
  199. item.WordUrl = app.globalData.imageUrl + "/images/hanzi" + item.Name + ".jpg";
  200. item.IsReview = true;
  201. }
  202. var result = arrReview;
  203. if (this.data.SelectedRandom) {
  204. result = common.randomArray(result);
  205. }
  206. var wordArr = wx.getStorageSync("UnitCustom");
  207. if (wordArr) {
  208. for (var k = 0; k < wordArr.length; k++) {
  209. for (var n = 0; n < wordArr[k].List.length; n++) {
  210. for (var i = 0; i < result.length; i++) {
  211. if (wordArr[k].List[n].ID == result[i].ID) {
  212. result[i].CombineWords = wordArr[k].List[n].CombineWords;
  213. break;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. var obj = {
  220. Title: "复习",
  221. Title2: "到底了",
  222. IsEnd: true,
  223. }
  224. result.push(obj);
  225. this.setData({
  226. List: result,
  227. CurrentIndex: indexID,
  228. });
  229. this.restart(this.data.CurrentIndex);
  230. wx.setNavigationBarTitle({
  231. title: "练习"
  232. });
  233. },
  234. initSearch: function () {
  235. var that = this;
  236. var result = wx.getStorageSync("CurrentSearchWord");
  237. result.WordUrl += "?" + new Date().getTime();
  238. result.PinyinAll = result.Pinyin;
  239. if (result.Pinyin && result.Pinyin.indexOf(",") > 0)
  240. result.Pinyin = result.Pinyin.substr(0, result.Pinyin.indexOf(","));
  241. var arr = JSON.parse(wx.getStorageSync("HanziAll"));
  242. var arrReview = wx.getStorageSync("ReviewList");
  243. var title = "汉字";
  244. for (var i = 0; i < arr.length; i++) {
  245. for (var j = 0; j < arr[i].Units.length; j++) {
  246. var item = arr[i].Units[j];
  247. for (var k = 0; k < item.Words.length; k++) {
  248. if (result.ID == item.Words[k].ID) {
  249. title = arr[i].Name.replace("识字能力", "");
  250. title += " " + item.Name;
  251. }
  252. result.IsReview = false;
  253. for (var l = 0; l < arrReview.length; l++) {
  254. if (arrReview[l].Name == result.Name) {
  255. result.IsReview = true;
  256. break;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. var resultArr = [];
  263. resultArr.push(result);
  264. var obj = {
  265. IsEnd: true,
  266. }
  267. resultArr.push(obj);
  268. wx.setNavigationBarTitle({
  269. title: title
  270. });
  271. if (result.IsNew) {
  272. wx.showLoading({
  273. title: '加载中',
  274. })
  275. setTimeout(function () {
  276. wx.hideLoading();
  277. that.setData({
  278. List: resultArr,
  279. });
  280. that.restart(that.data.CurrentIndex);
  281. }, 1000);
  282. }
  283. else {
  284. that.setData({
  285. List: resultArr,
  286. });
  287. that.restart(that.data.CurrentIndex);
  288. }
  289. },
  290. playAudio: function (e) {
  291. //console.log("playAudio");
  292. var click = false;
  293. if (e && e.currentTarget.dataset.click)
  294. click = e.currentTarget.dataset.click;
  295. if (click && this.data.IsHelpPosition1 == 1) {
  296. this.setData({
  297. IsHelpPosition1: 2,
  298. });
  299. wx.setStorageSync('IsHelpPosition1', 2);
  300. }
  301. var url = app.globalData.audioUrlBaidu;
  302. url = url.replace("[token]", app.globalData.BaiduToken);
  303. url = url.replace("per=0", "per=" + this.data.audioPer[this.data.SpeakerMan]);
  304. if ((click || this.data.IsAutoPlay) && !(click && this.data.IsAutoPage)) {
  305. if (this.data.CurrentIndex == this.data.List.length - 1) {
  306. if (this.data.WordType == "review")
  307. url = url.replace("[word]", "本次复习" + this.data.List[this.data.CurrentIndex].Title2);
  308. else
  309. url = url.replace("[word]", "本章节" + this.data.List[this.data.CurrentIndex].Title2);
  310. url = url.replace("spd=3", "spd=4");
  311. }
  312. else {
  313. var pinyinItem = this.data.List[this.data.CurrentIndex].PinyinAll;
  314. if (pinyinItem) {
  315. var pinyinStr = "";
  316. if (pinyinItem.indexOf(",") > 0) {
  317. pinyinItem = pinyinItem.substr(0, pinyinItem.indexOf(","));
  318. if (e && e.currentTarget.dataset.pinyin)
  319. pinyinItem = e.currentTarget.dataset.pinyin;
  320. pinyinStr = "(" + pinyin.getPinyinName(pinyinItem) + ")";
  321. }
  322. var Name = this.data.List[this.data.CurrentIndex].Name;
  323. if (!this.data.IsAudioLengthChecked || (e && e.currentTarget.dataset.pinyin)) {
  324. url = url.replace("[word]", e.currentTarget.dataset.pinyin);
  325. url = url.replace("spd=3", "spd=1");
  326. }
  327. else {
  328. var CombineWords = this.data.List[this.data.CurrentIndex].CombineWords;
  329. if (CombineWords && CombineWords.length>0){
  330. CombineWords = "," + CombineWords.replace(Name, Name + pinyinStr) + "的(de5)" + Name;
  331. url = url.replace("[word]", Name + pinyinStr + CombineWords + pinyinStr);
  332. }
  333. else{
  334. url = url.replace("[word]", pinyinItem);
  335. url = url.replace("spd=3", "spd=1");
  336. }
  337. }
  338. }
  339. }
  340. url = encodeURI(url);
  341. this.audioCtx.setSrc(url);
  342. this.audioCtx.play();
  343. }
  344. },
  345. startAutoPage: function () {
  346. var that = this;
  347. clearInterval(intervalAutoPage);
  348. var second = this.data.arrIntervalSecond[this.data.IntervalSecondIndex] * 1000;
  349. //console.log("second:" + second);
  350. intervalAutoPage = setInterval(function () {
  351. that.nextHandler();
  352. }, second);
  353. },
  354. prevHandler: function () {
  355. if (this.data.IsShowPrev && !this.data.IsAutoPage) {
  356. var index = this.data.CurrentIndex;
  357. var isShowPrev = true;
  358. var isShowNext = true;
  359. index--;
  360. if (index <= 0) {
  361. index = 0;
  362. isShowPrev = false;
  363. }
  364. this.setCurrentWord(index, isShowPrev, isShowNext);
  365. this.playAudio();
  366. hanziNumber++;
  367. }
  368. },
  369. nextHandler: function (e) {
  370. if (e && e.currentTarget.dataset.status == "click" && this.data.IsAutoPage) {
  371. }
  372. else if (this.data.IsShowNext) {
  373. var index = this.data.CurrentIndex;
  374. var isShowPrev = true;
  375. var isShowNext = true;
  376. index++;
  377. if (index >= this.data.List.length - 1) {
  378. index = this.data.List.length - 1;
  379. isShowNext = false;
  380. }
  381. this.setCurrentWord(index, isShowPrev, isShowNext);
  382. this.playAudio();
  383. hanziNumber++;
  384. }
  385. },
  386. restart: function (index) {
  387. var that = this;
  388. if (!index)
  389. index = 0;
  390. var isShowPrev = true;
  391. if (index == 0)
  392. isShowPrev = false;
  393. this.setCurrentWord(index, isShowPrev, true);
  394. this.playAudio();
  395. hanziNumber++;
  396. if (this.data.IsAutoPage) {
  397. this.startAutoPage();
  398. }
  399. },
  400. startAutoPage: function () {
  401. var that = this;
  402. clearInterval(intervalAutoPage);
  403. var second = this.data.arrIntervalSecond[this.data.IntervalSecondIndex] * 1000;
  404. //console.log("second:" + second);
  405. intervalAutoPage = setInterval(function () {
  406. that.nextHandler();
  407. }, second);
  408. },
  409. setCurrentWord: function (index, isShowPrev, isShowNext) {
  410. var that = this;
  411. that.setData({
  412. CurrentIndex: index,
  413. IsShowPrev: isShowPrev,
  414. IsShowNext: isShowNext,
  415. IsShowWordDetail: false,
  416. ShowHanzi: wx.getStorageSync("ShowHanzi"),
  417. });
  418. },
  419. getImageError: function () {
  420. var that = this;
  421. that.setData({
  422. IsImageError: true,
  423. });
  424. },
  425. getImageDownload: function () {
  426. var that = this;
  427. wx.showLoading({
  428. title: '请稍等',
  429. })
  430. server.getData('SearchHanzi?Word=' + that.data.List[that.data.CurrentIndex].Name, function (data) {
  431. setTimeout(function () {
  432. wx.hideLoading();
  433. wx.redirectTo({
  434. url: "../main/detail?Type=" + that.data.WordType + "&bookid=" + that.data.BookID + "&unitid=" + that.data.UnitID + "&wordid=" + that.data.CurrentIndex + "&isfinished=" + that.data.IsFinished,
  435. });
  436. }, 5000);
  437. });
  438. },
  439. showWordDetailHandler: function (e) {
  440. var that = this;
  441. if (this.data.IsShowNext && !this.data.IsAutoPage) {
  442. this.data.IsShowWordDetail = !this.data.IsShowWordDetail;
  443. this.setData({
  444. IsShowWordDetail: this.data.IsShowWordDetail,
  445. });
  446. if (!this.data.IsShowWordDetail) {
  447. this.setData({
  448. Detail: null,
  449. });
  450. }
  451. if (this.data.IsShowWordDetail) {
  452. if (this.data.WordType == "search") {
  453. var result = wx.getStorageSync("CurrentSearchWord");
  454. result = JSON.parse(result.Details);
  455. for (var i = 0; i < result.PinYin.length; i++) {
  456. var item = result.PinYin[i].explain;
  457. item = common.ReplaceAllString(item, "<p>", "");
  458. item = common.ReplaceAllString(item, "<span>", "");
  459. item = common.ReplaceAllString(item, "</span>", "");
  460. item = common.ReplaceAllString(item, "\r", "");
  461. item = common.ReplaceAllString(item, "\n", "");
  462. var arr = item.split("</p>");
  463. arr.pop();
  464. result.PinYin[i].explain = arr;
  465. }
  466. result.Antonym = result.Antonym.join(" ");
  467. result.Synonym = result.Synonym.join(" ");
  468. that.setData({
  469. Detail: result,
  470. });
  471. }
  472. else {
  473. var id = e.currentTarget.dataset.id;
  474. server.getData('GetHanziDetail?ID=' + id, function (data) {
  475. if (data) {
  476. //var data = common.Decrypt(data);
  477. //data=JSON.parse(data);
  478. data.Antonym = data.Antonym.join(" ");
  479. data.Synonym = data.Synonym.join(" ");
  480. that.setData({
  481. Detail: data,
  482. });
  483. }
  484. });
  485. }
  486. }
  487. }
  488. },
  489. //显示设置菜单
  490. showSettingMenu: function (e) {
  491. var status = e.currentTarget.dataset.status;
  492. this.setData({
  493. isShowSettingMenu: true,
  494. ShowMenu: status,
  495. });
  496. },
  497. //打开设置界面
  498. openSetting: function () {
  499. this.setData({
  500. IsShowSetting: true,
  501. });
  502. isEditSetting = [];
  503. clearInterval(intervalAutoPage);
  504. },
  505. closeSetting: function () {
  506. var that = this;
  507. this.setData({
  508. IsShowSetting: false,
  509. });
  510. if (isEditSetting.length > 0) {
  511. for (var i = 0; i < isEditSetting.length; i++) {
  512. if (isEditSetting[i] == "page" || isEditSetting[i] == "saveCustom" || isEditSetting[i] == "sort") {
  513. if (isEditSetting[i] != "saveCustom")
  514. that.data.CurrentIndex = 0;
  515. if (that.data.WordType == "normal")
  516. that.init();
  517. else if (that.data.WordType == "review")
  518. that.initReview();
  519. break;
  520. }
  521. else if (isEditSetting[i] == "speaker") {
  522. that.playAudio();
  523. break;
  524. }
  525. }
  526. }
  527. else {
  528. if (this.data.IsAutoPage) {
  529. this.startAutoPage();
  530. }
  531. }
  532. },
  533. closeSettingMenu: function () {
  534. this.setData({
  535. isShowSettingMenu: false,
  536. });
  537. },
  538. settingSort: function (e, b) {
  539. isEditSetting.push("sort");
  540. var result = b;
  541. if (e)
  542. result = e.currentTarget.dataset.id;
  543. var title = "";
  544. var SelectedRandom = true;
  545. if (result == "false") {
  546. title = "课本一致";
  547. SelectedRandom = false;
  548. }
  549. else {
  550. title = "随机";
  551. }
  552. this.setData({
  553. isShowSettingMenu: false,
  554. SortTitle: title,
  555. SelectedRandom: SelectedRandom,
  556. });
  557. wx.setStorageSync('SelectedRandom', SelectedRandom);
  558. },
  559. settingSpeaker: function (e, b) {
  560. isEditSetting.push("speaker");
  561. var result = b;
  562. if (e)
  563. result = e.currentTarget.dataset.id;
  564. for (var i = 0; i < this.data.SpeakerArray.length; i++) {
  565. this.data.SpeakerArray[i].isShow = false;
  566. if (i == result)
  567. this.data.SpeakerArray[i].isShow = true;
  568. }
  569. this.setData({
  570. SpeakerMan: result,
  571. isShowSettingMenu: false,
  572. SpeakerTitle: this.data.SpeakerArray[result].name,
  573. SpeakerArray: this.data.SpeakerArray,
  574. });
  575. wx.setStorageSync('SpeakerMan', result);
  576. },
  577. settingShowHanzi: function (e, b) {
  578. var result = !this.data.ShowHanzi;
  579. if (b != undefined)
  580. result = b;
  581. this.setData({
  582. ShowHanzi: result,
  583. });
  584. wx.setStorageSync('ShowHanzi', result);
  585. },
  586. showHanziFunction: function () {
  587. this.setData({
  588. ShowHanzi: true,
  589. });
  590. },
  591. settingShowPinyin: function (e, b) {
  592. var result = !this.data.ShowPinyin;
  593. if (b != undefined)
  594. result = b;
  595. this.setData({
  596. ShowPinyin: result,
  597. });
  598. wx.setStorageSync('ShowPinyin', result);
  599. },
  600. settingPlay: function (e, b) {
  601. isEditSetting.push("play");
  602. var result = !this.data.IsAutoPlay;
  603. if (b != undefined)
  604. result = b;
  605. var PlayChecked = "";
  606. if (result)
  607. PlayChecked = "checked";
  608. this.setData({
  609. IsAutoPlay: result,
  610. isShowSettingMenu: false,
  611. PlayChecked: PlayChecked,
  612. });
  613. wx.setStorageSync('IsAutoPlay', result);
  614. },
  615. settingAudioLength: function (e, b) {
  616. var result = !this.data.IsAudioLengthChecked;
  617. if (b != undefined)
  618. result = b;
  619. this.setData({
  620. IsAudioLengthChecked: result,
  621. });
  622. wx.setStorageSync('IsAudioLengthChecked', result);
  623. },
  624. settingPage: function (e, b) {
  625. isEditSetting.push("page");
  626. var result = !this.data.IsAutoPage;
  627. if (b != undefined)
  628. result = b;
  629. if (result) {
  630. this.data.PageChecked = "checked";
  631. this.data.IsAutoPlay = true;
  632. this.data.PlayChecked = "checked";
  633. }
  634. else {
  635. clearInterval(intervalAutoPage);
  636. this.data.PageChecked = "";
  637. }
  638. this.setData({
  639. IsAutoPlay: this.data.IsAutoPlay,
  640. IsAutoPage: result,
  641. isShowSettingMenu: false,
  642. PageChecked: this.data.PageChecked,
  643. IsAutoPlay: this.data.IsAutoPlay,
  644. PlayChecked: this.data.PlayChecked,
  645. });
  646. wx.setStorageSync('IsAutoPage', result);
  647. },
  648. bindPickerChange: function (e) {
  649. this.setData({
  650. IntervalSecondIndex: e.detail.value
  651. });
  652. wx.setStorageSync('IntervalSecondIndex', Number(e.detail.value));
  653. isEditSetting.push("page");
  654. },
  655. updateFinish: function () {
  656. var that = this;
  657. if (isClickFinished) {
  658. this.setData({
  659. IsFinished: !this.data.IsFinished,
  660. });
  661. isClickFinished = false;
  662. app.globalData.IsRefreshFinished = true;
  663. if (!this.data.IsFinished) {
  664. that.setRemind("取消", "");
  665. }
  666. else {
  667. that.setRemind("学过了", "Remind3");
  668. }
  669. server.postData('UpdateHanziFinished', {
  670. IsFinished: this.data.IsFinished,
  671. UserID: app.globalData.userInfo.UserID,
  672. Category: this.data.BookID,
  673. Title: this.data.UnitID,
  674. }, function (data) {
  675. server.getData('GetHanziFinishedData?UserID=' + app.globalData.userInfo.UserID, function (data) {
  676. if (data) {
  677. wx.setStorageSync("FinishedList", data);
  678. }
  679. });
  680. });
  681. }
  682. },
  683. setCombine: function (e) {
  684. var id = e.currentTarget.dataset.id;
  685. wx.navigateTo({
  686. url: '../main/setcombine?id=' + id,
  687. });
  688. },
  689. setRemind: function (str, css) {
  690. var that = this;
  691. that.setData({
  692. RemindStr: str,
  693. RemindCss: css,
  694. })
  695. that.animateOpacity(1, "animationData", 500);
  696. setTimeout(function () {
  697. isClickReview = true;
  698. isClickFinished = true;
  699. that.animateOpacity(0, "animationData", 500);
  700. }, 1000);
  701. },
  702. //动画淡入淡出
  703. animateOpacity: function (opacity, obj, duration) {
  704. var animation = wx.createAnimation({
  705. duration: duration,
  706. timingFunction: 'ease',
  707. });
  708. //this.animation = animation;
  709. animation.opacity(opacity).step();
  710. if (obj == "animationData") {
  711. this.setData({
  712. animationData: animation.export(),
  713. });
  714. }
  715. },
  716. reviewHandler: function () {
  717. var that = this;
  718. if (this.data.IsShowNext && !this.data.IsAutoPage) {
  719. if (isClickReview) {
  720. this.data.List[this.data.CurrentIndex].IsReview = !this.data.List[this.data.CurrentIndex].IsReview;
  721. this.setData({
  722. List: this.data.List,
  723. });
  724. isClickReview = false;
  725. var status = "add";
  726. if (!this.data.List[this.data.CurrentIndex].IsReview) {
  727. status = "delete";
  728. that.setRemind("取消", "");
  729. }
  730. else {
  731. that.setRemind("添加到复习", "Remind2");
  732. }
  733. server.postData('UpdateHanziReview', {
  734. UserID: app.globalData.userInfo.UserID,
  735. Word: this.data.List[this.data.CurrentIndex].Name,
  736. WordID: this.data.List[this.data.CurrentIndex].ID,
  737. Status: status,
  738. }, function (data) {
  739. if (data) {
  740. wx.setStorageSync("ReviewList", data);
  741. }
  742. });
  743. }
  744. }
  745. else {
  746. if (that.data.CurrentIndex == that.data.List.length - 1)
  747. that.restart();
  748. }
  749. },
  750. onShareAppMessage: function () {
  751. return {
  752. title: app.globalData.ShareTitle,
  753. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  754. imageUrl: app.globalData.ShareImage,
  755. }
  756. },
  757. });