preview.js 6.0 KB

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