default.js 7.8 KB

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