preview.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. card.FontSize=list[i].FontSize;
  42. break;
  43. }
  44. }
  45. this.setData({
  46. ID: card.MiaoguoCardID,
  47. Field: card.Field,
  48. Tags: card.Tags,
  49. PrevID:prevId,
  50. NextID:nextId,
  51. FontSize:card.FontSize,
  52. LimitTimeStr: common.formatDateCHS(card.LimitTime),
  53. });
  54. },
  55. practiceToday: function () {
  56. var that = this;
  57. wx.showModal({
  58. title: '要今天练吗?',
  59. content: '这条笔记今天必须练习',
  60. success(res) {
  61. if (res.confirm) {
  62. var obj = {
  63. ID: that.data.ID,
  64. BtnNumber: -1,
  65. LearningType: 2,
  66. }
  67. that.saveCard(obj, function () {
  68. var time = common.formatTime(new Date());
  69. that.setData({
  70. LimitTimeStr: common.formatDateCHS(time),
  71. });
  72. var list = wx.getStorageSync("CardList");
  73. for (var i = 0; i < list.length; i++) {
  74. if (that.data.ID == list[i].MiaoguoCardID) {
  75. list[i].LimitTime = time;
  76. list[i].LimitTimeStr = "今天";
  77. break;
  78. }
  79. }
  80. wx.setStorageSync("CardList", list);
  81. wx.showToast({
  82. title: '改为今天练',
  83. icon: 'none',
  84. });
  85. });
  86. }
  87. else if (res.cancel) {
  88. }
  89. }
  90. })
  91. },
  92. saveCard: function (obj, callback) {
  93. var url = "UpdateMiaoguoCardToday?";
  94. url += "ID=" + obj.ID;
  95. url += "&UserID=" + app.globalData.userInfo.UserID;
  96. url += "&BtnNumber=" + obj.BtnNumber;
  97. url += "&LearningType=" + obj.LearningType;
  98. main.getData(url, function (data) {
  99. callback();
  100. });
  101. },
  102. playSound: function (e) {
  103. var str = e.currentTarget.dataset.content;
  104. var url;
  105. if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  106. str = str.replace("英 [", "[");
  107. str = str.replace("美 [", "[");
  108. url = e.currentTarget.dataset.soundmark;
  109. }
  110. else {
  111. var url = app.globalData.audioUrlBaidu;
  112. url = url.replace("[token]", app.globalData.BaiduToken);
  113. url = url.replace("[word]", str);
  114. }
  115. this.audioCtx.setSrc(url);
  116. this.audioCtx.play();
  117. },
  118. onMore: function () {
  119. var that = this;
  120. wx.showActionSheet({
  121. itemList: ["详细信息", "编辑笔记", "删除笔记"],
  122. success(res) {
  123. //console.log(res.tapIndex);
  124. if (res.tapIndex == 0) {
  125. wx.navigateTo({
  126. url: './cardInfo?id=' + that.data.MiaoguoCardID,
  127. });
  128. }
  129. else if (res.tapIndex == 1) {
  130. wx.navigateTo({
  131. url: './add?type=edit2&id=' + that.data.MiaoguoCardID,
  132. });
  133. }
  134. else if (res.tapIndex == 2) {
  135. that.deleteCard();
  136. }
  137. },
  138. })
  139. },
  140. deleteCard: function () {
  141. var that = this;
  142. wx.showModal({
  143. title: '提醒',
  144. content: '这条笔记要删除吗?',
  145. success(res) {
  146. if (res.confirm) {
  147. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  148. url += "&ID=" + that.data.MiaoguoCardID;
  149. main.getData(url, function (data) {
  150. var list = wx.getStorageSync("CardList");
  151. for (var i = 0; i < list.length; i++) {
  152. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  153. list.splice(i, 1);
  154. break;
  155. }
  156. }
  157. wx.setStorageSync("CardList", list);
  158. wx.navigateBack({
  159. delta: 1,
  160. });
  161. });
  162. }
  163. }
  164. });
  165. },
  166. onPreview: function (e) {
  167. var id = e.currentTarget.dataset.id;
  168. wx.redirectTo({
  169. url: './preview?type=show&id=' + id,
  170. })
  171. },
  172. close: function () {
  173. wx.navigateBack({
  174. delta: 1,
  175. });
  176. },
  177. onShareAppMessage: function () {
  178. return {
  179. title: app.globalData.ShareTitle,
  180. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  181. imageUrl: app.globalData.ShareImage,
  182. }
  183. },
  184. })