detail.js 24 KB

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