default.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import common from '../../utils/util';
  2. import server from '../../utils/main';
  3. const app = getApp();
  4. var code;
  5. var imageIndex = 0;
  6. var arrBuildImageSource = [];
  7. var arrBuildImageTarget = [];
  8. var isMiaoguoADShow = false;
  9. Page({
  10. data: {
  11. version: app.globalData.Version,
  12. ProgramName:app.globalData.ProgramName,
  13. FileUrl: app.globalData.fileUrl,
  14. NickName: "陌生用户",
  15. IsMember: 1,
  16. AvatarUrl: "",
  17. IsAccredit: false,
  18. IsMiaoguoAD: false,
  19. IsMiaoguoAD2: 0,
  20. },
  21. onLoad: function () {
  22. var that = this;
  23. this.setData({
  24. Height: server.getWindowHeight(),
  25. ProgramList: server.getProgramListOld(),
  26. IsShowGift:app.globalData.userInfo.IsShowGift,
  27. });
  28. wx.login({
  29. success: function (res0) {
  30. code = res0.code;
  31. }
  32. });
  33. isMiaoguoADShow = false;
  34. },
  35. onUnload: function () {
  36. },
  37. onShow: function () {
  38. var that = this;
  39. var list = wx.getStorageSync("AnswerList");
  40. var answerLength = 0;
  41. if (list && list.length > 0) {
  42. answerLength = list.length;
  43. }
  44. var errorCount = 0;
  45. var listError = wx.getStorageSync("ErrorList");
  46. if (listError && listError.length > 0) {
  47. errorCount = listError.length;
  48. }
  49. this.setData({
  50. AnswerLength: answerLength,
  51. ErrorCount: errorCount,
  52. IsLocked: app.globalData.IsLocked,
  53. IsShow: app.globalData.userInfo.IsShow,
  54. IsMember: app.globalData.userInfo.IsMember,
  55. NickName: app.globalData.userInfo.NickName,
  56. AvatarUrl: app.globalData.userInfo.AvatarUrl,
  57. });
  58. if (app.globalData.userInfo.NickName=="陌生用户" && app.globalData.userInfo.IsShow>0) {
  59. this.setData({
  60. IsRemind:true,
  61. });
  62. }
  63. else{
  64. that.setData({
  65. IsAccredit: true,
  66. IsRemind:false,
  67. });
  68. that.downloadUserAvatar();
  69. common.getStorageValue(that, "HelpHidden1", false, function () {
  70. that.showHelp();
  71. });
  72. }
  73. },
  74. downloadUserAvatar: function () {
  75. var avatar = wx.getStorageSync("Avatar");
  76. if (!avatar) {
  77. var that = this;
  78. wx.downloadFile({
  79. url: app.globalData.userInfo.AvatarUrl,
  80. success(res) {
  81. if (res.statusCode === 200) {
  82. wx.setStorageSync("Avatar", res.tempFilePath);
  83. }
  84. }
  85. });
  86. }
  87. },
  88. gotoList: function (e) {
  89. server.playSound("/sounds/click.mp3");
  90. var id = e.currentTarget.dataset.id;
  91. var categoryArray = [{}, { Num: 1, Name: "一年级", Array: [1, 2] }, { Num: 2, Name: "二年级", Array: [3, 4] }, { Num: 3, Name: "三年级", Array: [5, 6] }, { Num: 4, Name: "四年级及以上", Array: [7] }];
  92. wx.navigateTo({
  93. url: '../main/list?id=' + categoryArray[id].Array.join(",") + "&name=" + categoryArray[id].Name + "&num=" + categoryArray[id].Num,
  94. });
  95. this.closeHelp();
  96. },
  97. goto: function (e) {
  98. var url = e.currentTarget.dataset.url;
  99. wx.navigateTo({
  100. url: url
  101. });
  102. if (e.currentTarget.dataset.id == "topAD") {
  103. this.setData({
  104. IsMiaoguoAD2: 0,
  105. });
  106. wx.setStorageSync('IsMiaoguoAD', false);
  107. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  108. }
  109. app.globalData.userInfo.IsShowGift=0;
  110. },
  111. gotoHelp: function () {
  112. wx.redirectTo({
  113. url: '../main/help',
  114. });
  115. },
  116. gotoAnswer: function () {
  117. wx.navigateTo({
  118. url: '../main/answer',
  119. });
  120. },
  121. gotoErrorList(e) {
  122. wx.navigateTo({
  123. url: '../main/detail?id=-1',
  124. });
  125. },
  126. switchProgram: function (e) {
  127. wx.navigateToMiniProgram({
  128. appId: e.currentTarget.dataset.appid,
  129. path: "pages/index/index?SourceID="+app.globalData.ProgramID,
  130. extraData: {
  131. },
  132. success(res) {
  133. // 打开成功
  134. }
  135. });
  136. },
  137. gotoMemberCenter: function () {
  138. if (app.globalData.userInfo.IsShow>=0) {
  139. wx.navigateTo({
  140. url: './userinfo',
  141. });
  142. }
  143. },
  144. gotoFeedback: function () {
  145. server.gotoFeedback();
  146. },
  147. showHelp: function () {
  148. if (!this.data.HelpHidden1) {
  149. this.audioCtx = wx.createAudioContext('myAudio');
  150. var str = "那么,就从选题目开始吧。在计算题工厂里包括了小学数学全年级最重要的知识点。其中“四年级及以上”,这个栏目囊括了四到六年级的题型。请选一个年级继续。";
  151. server.playAudio(this.audioCtx, str);
  152. }
  153. },
  154. closeHelp: function () {
  155. this.setData({
  156. HelpHidden1: true,
  157. });
  158. wx.setStorageSync("HelpHidden1", true);
  159. this.audioCtx = wx.createAudioContext('myAudio');
  160. this.audioCtx.pause();
  161. },
  162. buildShareImage: function () {
  163. this.closeMenu();
  164. imageIndex = 0;
  165. arrBuildImageSource = [];
  166. for (var i = 2; i < 6; i++)
  167. arrBuildImageSource.push("../images/programsystem_screenshot_pic0" + i + ".png");
  168. arrBuildImageTarget = [];
  169. this.buildImage();
  170. },
  171. buildImage: function () {
  172. var that = this;
  173. var ctx = wx.createCanvasContext("MyCanvas", this);
  174. ctx.drawImage(arrBuildImageSource[imageIndex], 0, 0, 400, 300);
  175. var avatar = wx.getStorageSync("Avatar");
  176. if (avatar) {
  177. ctx.drawImage(avatar, 15, 250, 40, 40);
  178. ctx.drawImage("../images/universalpic_mask_face_size01.png", 13, 248, 44, 44);
  179. ctx.fillStyle = "#ffffff";
  180. ctx.setFontSize(14);
  181. ctx.fillText(app.globalData.userInfo.NickName, 65, 264);
  182. }
  183. ctx.draw(true, function (n) {
  184. wx.canvasToTempFilePath({
  185. x: 0,
  186. y: 0,
  187. width: 400,
  188. height: 300,
  189. canvasId: 'MyCanvas',
  190. success: function (res2) {
  191. console.log(res2.tempFilePath);
  192. arrBuildImageTarget.push(res2.tempFilePath);
  193. if (arrBuildImageTarget.length < arrBuildImageSource.length) {
  194. imageIndex++;
  195. that.buildImage();
  196. }
  197. else {
  198. wx.previewImage({
  199. current: arrBuildImageTarget[0], // 当前显示图片的http链接
  200. urls: arrBuildImageTarget // 需要预览的图片http链接列表
  201. });
  202. }
  203. }
  204. })
  205. });
  206. },
  207. close: function (e) {
  208. this.setData({
  209. IsMiaoguoAD2: 0,
  210. IsShowGift:0,
  211. });
  212. var num = e.currentTarget.dataset.num;
  213. if (num > 0) {
  214. var time = common.addDate("d", Number(num), new Date());
  215. time = common.formatTime(time);
  216. wx.setStorageSync("miaoguoADTime", time);
  217. }
  218. app.globalData.userInfo.IsShowGift=0;
  219. },
  220. showMiaoguo:function(){
  221. this.setData({
  222. IsShowMiaoguo: 1,
  223. IsMiaoguoAD2: 0,
  224. });
  225. app.globalData.userInfo.IsShowGift=0;
  226. wx.setStorageSync("miaoguoADTime", common.formatTime(common.addDate("d", 15, new Date())));
  227. },
  228. closeMiaoguo:function(){
  229. this.setData({
  230. IsShowMiaoguo: 0,
  231. });
  232. },
  233. onShareAppMessage: function () {
  234. return {
  235. title: app.globalData.ShareTitle,
  236. path: 'pages/index/index?UserID=' + app.globalData.userInfo.UserID,
  237. imageUrl: app.globalData.ShareImage,
  238. }
  239. },
  240. })