preview.js 8.7 KB

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