default.js 7.4 KB

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