preview.js 5.3 KB

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