preview.js 9.1 KB

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