preview.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. if (!card.FontSize)
  58. card.FontSize = 46;
  59. this.setData({
  60. ID: card.MiaoguoCardID,
  61. Field: card.Field,
  62. Tags: card.Tags,
  63. PrevID: prevId,
  64. NextID: nextId,
  65. FontSize: card.FontSize,
  66. LimitTimeStr: common.formatDateCHS(card.LimitTime),
  67. });
  68. },
  69. practiceToday: function () {
  70. var that = this;
  71. wx.showModal({
  72. title: '要今天练吗?',
  73. content: '这张题卡今天必须练习',
  74. success(res) {
  75. if (res.confirm) {
  76. var obj = {
  77. ID: that.data.ID,
  78. BtnNumber: -1,
  79. LearningType: 2,
  80. }
  81. that.saveCard(obj, function () {
  82. var time = common.formatTime(new Date());
  83. that.setData({
  84. LimitTimeStr: common.formatDateCHS(time),
  85. });
  86. var list = wx.getStorageSync("CardList");
  87. for (var i = 0; i < list.length; i++) {
  88. if (that.data.ID == list[i].MiaoguoCardID) {
  89. list[i].LimitTime = time;
  90. list[i].LimitTimeStr = "今天";
  91. break;
  92. }
  93. }
  94. wx.setStorageSync("CardList", list);
  95. wx.showToast({
  96. title: '改为今天练',
  97. icon: 'none',
  98. });
  99. });
  100. }
  101. else if (res.cancel) {
  102. }
  103. }
  104. })
  105. },
  106. saveCard: function (obj, callback) {
  107. var url = "UpdateMiaoguoCardToday?";
  108. url += "ID=" + obj.ID;
  109. url += "&UserID=" + app.globalData.userInfo.UserID;
  110. url += "&BtnNumber=" + obj.BtnNumber;
  111. url += "&LearningType=" + obj.LearningType;
  112. main.getData(url, function (data) {
  113. callback();
  114. });
  115. },
  116. copyCard: function () {
  117. wx.showLoading({
  118. title: '处理中',
  119. })
  120. var that = this;
  121. var url = "CollectMiaoguoCard?";
  122. url += "MiaoguoCardID=" + that.data.MiaoguoCardID;
  123. url += "&UserIDSource=" + app.globalData.introducer;
  124. url += "&UserIDTarget=" + app.globalData.userInfo.UserID;
  125. main.getData(url, function (data) {
  126. wx.hideLoading();
  127. var title = "题卡已存在!";
  128. if (data == 1) {
  129. title = "收藏成功!";
  130. }
  131. wx.showToast({
  132. title: title,
  133. mask: true,
  134. duration: 3000,
  135. success: function () {
  136. that.setData({
  137. ShowType: 'preview'
  138. });
  139. }
  140. });
  141. });
  142. },
  143. playSound: function (e) {
  144. var str = e.currentTarget.dataset.content;
  145. var url;
  146. if (str.indexOf("英 [") >= 0 || str.indexOf("美 [") >= 0) {
  147. str = str.replace("英 [", "[");
  148. str = str.replace("美 [", "[");
  149. url = e.currentTarget.dataset.soundmark;
  150. }
  151. else if (e.currentTarget.dataset.soundmark && e.currentTarget.dataset.soundmark == "undefined") {
  152. url = e.currentTarget.dataset.soundmark;
  153. }
  154. else {
  155. var url = app.globalData.audioUrlBaidu;
  156. url = url.replace("[token]", app.globalData.BaiduToken);
  157. url = url.replace("[word]", str);
  158. }
  159. this.audioCtx.setSrc(url);
  160. this.audioCtx.play();
  161. },
  162. onMore: function () {
  163. var that = this;
  164. wx.showActionSheet({
  165. itemList: ["详细信息", "编辑题卡", "删除题卡"],
  166. success(res) {
  167. //console.log(res.tapIndex);
  168. if (res.tapIndex == 0) {
  169. wx.navigateTo({
  170. url: './cardInfo?id=' + that.data.MiaoguoCardID,
  171. });
  172. }
  173. else if (res.tapIndex == 1) {
  174. wx.navigateTo({
  175. url: './add?type=edit2&id=' + that.data.MiaoguoCardID,
  176. });
  177. }
  178. else if (res.tapIndex == 2) {
  179. that.deleteCard();
  180. }
  181. },
  182. })
  183. },
  184. deleteCard: function () {
  185. var that = this;
  186. wx.showModal({
  187. title: '提醒',
  188. content: '这张题卡要删除吗?',
  189. success(res) {
  190. if (res.confirm) {
  191. var url = 'DeleteMiaoguoCard?UserID=' + app.globalData.userInfo.UserID;
  192. url += "&ID=" + that.data.MiaoguoCardID;
  193. main.getData(url, function (data) {
  194. var list = wx.getStorageSync("CardList");
  195. for (var i = 0; i < list.length; i++) {
  196. if (that.data.MiaoguoCardID == list[i].MiaoguoCardID) {
  197. list.splice(i, 1);
  198. break;
  199. }
  200. }
  201. wx.setStorageSync("CardList", list);
  202. var taskToday = wx.getStorageSync("TaskToday");
  203. taskToday.CardNumber--;
  204. wx.setStorageSync("TaskToday", taskToday);
  205. wx.navigateBack({
  206. delta: 1,
  207. });
  208. });
  209. }
  210. }
  211. });
  212. },
  213. onPreview: function (e) {
  214. var id = e.currentTarget.dataset.id;
  215. wx.redirectTo({
  216. url: './preview?type=show&id=' + id,
  217. })
  218. },
  219. close: function () {
  220. wx.navigateBack({
  221. delta: 1,
  222. });
  223. },
  224. editField: function (e) {
  225. if (this.data.ShowType == "show") {
  226. var that = this;
  227. var fieldid = e.currentTarget.dataset.id;
  228. wx.navigateTo({
  229. url: './add?type=edit3&id=' + that.data.MiaoguoCardID + '&fieldid=' + fieldid,
  230. });
  231. }
  232. },
  233. onShareAppMessage: function () {
  234. var that = this;
  235. this.setData({
  236. ShowType: 'preview'
  237. });
  238. setTimeout(function () {
  239. that.setData({
  240. ShowType: 'show'
  241. });
  242. }, 1000);
  243. return {
  244. title: '分享题卡',
  245. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID + '&Share=1&MiaoguoCardID=' + this.data.MiaoguoCardID,
  246. imageUrl: app.globalData.ShareImage,
  247. }
  248. },
  249. })