preview.js 7.0 KB

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