preview.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. },
  7. onLoad: function (options) {
  8. var that = this;
  9. var id = 0;
  10. if (options.id)
  11. id = options.id;
  12. that.setData({
  13. Containnerheight: main.getWindowHeight(),
  14. ShowType: options.type,
  15. MiaoguoCardID: id,
  16. });
  17. this.audioCtx = wx.createAudioContext('myAudio');
  18. },
  19. onShow: function () {
  20. this.init();
  21. },
  22. init: function () {
  23. var list = wx.getStorageSync("CardList");
  24. var card = {};
  25. var prevId=0;
  26. var nextId=0;
  27. for (var i = 0; i < list.length; i++) {
  28. if (this.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  29. wx.setStorageSync("TempCardInfo", list[i]);
  30. if (i > 0)
  31. prevId = list[i - 1].MiaoguoCardID;
  32. else
  33. prevId = 0;
  34. if (i < list.length-1)
  35. nextId = list[i + 1].MiaoguoCardID;
  36. else
  37. nextId = 0;
  38. card = main.changeStringToView(list[i].Content);
  39. card.MiaoguoCardID = list[i].MiaoguoCardID;
  40. card.LimitTime = list[i].LimitTime;
  41. break;
  42. }
  43. }
  44. this.setData({
  45. ID: card.MiaoguoCardID,
  46. Field: card.Field,
  47. Tags: card.Tags,
  48. PrevID:prevId,
  49. NextID:nextId,
  50. LimitTimeStr: common.formatDateCHS(card.LimitTime),
  51. });
  52. },
  53. practiceToday: function () {
  54. var that = this;
  55. wx.showModal({
  56. title: '要今天练吗?',
  57. content: '这条笔记今天必须练习',
  58. success(res) {
  59. if (res.confirm) {
  60. var obj = {
  61. ID: that.data.ID,
  62. BtnNumber: -1,
  63. LearningType: 2,
  64. }
  65. that.saveCard(obj, function () {
  66. var time = common.formatTime(new Date());
  67. that.setData({
  68. LimitTimeStr: common.formatDateCHS(time),
  69. });
  70. var list = wx.getStorageSync("CardList");
  71. for (var i = 0; i < list.length; i++) {
  72. if (that.data.ID == list[i].MiaoguoCardID) {
  73. list[i].LimitTime = time;
  74. list[i].LimitTimeStr = "今天";
  75. break;
  76. }
  77. }
  78. wx.setStorageSync("CardList", list);
  79. });
  80. }
  81. else if (res.cancel) {
  82. }
  83. }
  84. })
  85. },
  86. saveCard: function (obj, callback) {
  87. var url = "UpdateMiaoguoCardToday?";
  88. url += "ID=" + obj.ID;
  89. url += "&UserID=" + app.globalData.userInfo.UserID;
  90. url += "&BtnNumber=" + obj.BtnNumber;
  91. url += "&LearningType=" + obj.LearningType;
  92. main.getData(url, function (data) {
  93. callback();
  94. });
  95. },
  96. playSound: function (e) {
  97. var str = e.currentTarget.dataset.content;
  98. var url;
  99. if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  100. str = str.replace("英 [", "[");
  101. str = str.replace("美 [", "[");
  102. url = e.currentTarget.dataset.soundmark;
  103. }
  104. else {
  105. var url = app.globalData.audioUrlBaidu;
  106. url = url.replace("[token]", app.globalData.BaiduToken);
  107. url = url.replace("[word]", str);
  108. }
  109. this.audioCtx.setSrc(url);
  110. this.audioCtx.play();
  111. },
  112. onMore: function () {
  113. var that = this;
  114. wx.showActionSheet({
  115. itemList: ["详细信息", "编辑笔记", "删除笔记"],
  116. success(res) {
  117. console.log(res.tapIndex);
  118. if (res.tapIndex == 0) {
  119. wx.navigateTo({
  120. url: './cardInfo?id=' + that.data.MiaoguoCardID,
  121. });
  122. }
  123. else if (res.tapIndex == 1) {
  124. wx.navigateTo({
  125. url: './add?type=edit2&id=' + that.data.MiaoguoCardID,
  126. });
  127. }
  128. else if (res.tapIndex == 2) {
  129. that.deleteCard();
  130. }
  131. },
  132. })
  133. },
  134. deleteCard: function () {
  135. var that = this;
  136. wx.showModal({
  137. title: '提醒',
  138. content: '这条笔记要删除吗?',
  139. success(res) {
  140. if (res.confirm) {
  141. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  142. url += "&ID=" + that.data.MiaoguoCardID;
  143. main.getData(url, function (data) {
  144. var list = wx.getStorageSync("CardList");
  145. for (var i = 0; i < list.length; i++) {
  146. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  147. list.splice(i, 1);
  148. break;
  149. }
  150. }
  151. wx.setStorageSync("CardList", list);
  152. wx.navigateBack({
  153. delta: 1,
  154. });
  155. });
  156. }
  157. }
  158. });
  159. },
  160. onPreview: function (e) {
  161. var id = e.currentTarget.dataset.id;
  162. wx.redirectTo({
  163. url: './preview?type=show&id=' + id,
  164. })
  165. },
  166. close: function () {
  167. wx.navigateBack({
  168. delta: 1,
  169. });
  170. }
  171. })