app.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. const util = require('utils/util.js');
  2. App({
  3. globalData: {
  4. info:{}
  5. },
  6. onLaunch: function (options) {
  7. this.checkUpdate();
  8. this.globalData.path = options.path;
  9. util.refreshCount();
  10. },
  11. onShow(options) {
  12. // console.log("领队小程序传参", options);
  13. this.globalData.info=options.referrerInfo.extraData
  14. // this.getSafeTips();
  15. this.clearStorageData();
  16. this.getNps();
  17. this.clearCommentData()
  18. },
  19. // 对弹窗广告的上次进入次数清零
  20. clearStorageData(){
  21. let tipData = wx.getStorageSync("safeTips");
  22. if (tipData && !tipData.oldHours) {
  23. tipData.num = 0;
  24. wx.setStorageSync("safeTips", tipData);
  25. }
  26. },
  27. getSafeTips(){
  28. let newDate = util.getNowFormatDate('yyyy-MM-dd'), data = wx.getStorageSync("safeTips") || {},newHours = new Date().getHours();
  29. if (util.isObjEmpty(data) || (util.datedifference(newDate, data.oldDate) > 0 && data.num < 9999)) {
  30. this.globalData.openTipsNum = 0;
  31. data.oldDate = newDate;
  32. data.num = (data.num ? data.num : 0) + 1;
  33. data.todayNum = 1;
  34. data.oldHours = newHours;
  35. data.show = true;
  36. } else if((newHours - data.oldHours) >2 && data.todayNum < 2 && data.num < 9999){
  37. this.globalData.openTipsNum = 0;
  38. data.oldDate = newDate;
  39. data.num = (data.num ? data.num : 0) + 1;
  40. data.todayNum = 2;
  41. data.oldHours = newHours;
  42. data.show = true;
  43. }else
  44. data.show = false;
  45. wx.setStorageSync("safeTips", data);
  46. },
  47. // 确认评论是否过期
  48. clearCommentData(){
  49. let newDate = util.getNowFormatDate('yyyy-MM-dd hh:mm:ss'),
  50. commentData=wx.getStorageSync("orderComment");
  51. if (!util.isObjEmpty(commentData)&&util.datedifference(newDate, commentData.saveDate,true) > 86400) { //比较是否超出一天(精确至秒)
  52. wx.removeStorageSync('orderComment')
  53. }
  54. },
  55. getNps() {
  56. let newDate = util.getNowFormatDate('yyyy-MM-dd hh:mm:ss'), npsData = wx.getStorageSync("nps") || {};
  57. if (util.isObjEmpty(npsData) || (util.datedifference(newDate, npsData.oldDate) > 0)) { //比较天数是否大于一天
  58. npsData.oldDate = newDate;
  59. npsData.timesSec=newDate;
  60. npsData.num = 0;
  61. }
  62. wx.setStorageSync("nps", npsData);
  63. },
  64. checkUpdate(){
  65. if (wx.canIUse("getUpdateManager")) {
  66. let updateManager = wx.getUpdateManager();
  67. updateManager.onCheckForUpdate(function (res) {
  68. if (res.hasUpdate) {
  69. updateManager.onUpdateReady(function () {
  70. wx.showModal({
  71. title: '更新提示',
  72. content: '新版本已经准备好,是否重启应用?',
  73. success(res) {
  74. if (res.confirm) {
  75. updateManager.applyUpdate()
  76. }
  77. }
  78. })
  79. });
  80. updateManager.onUpdateFailed(function () {
  81. wx.showModal({
  82. title: '已经有新版本了哟!',
  83. content: '新版本已经上线啦,请您删除当前小程序,重新搜索打开。',
  84. showCancel: false
  85. });
  86. });
  87. }
  88. });
  89. } else {
  90. wx.showModal({
  91. title: '提示!',
  92. content: '当前微信版本过低,无法使用该功能,请升级至微信最新版本!',
  93. showCancel: false
  94. });
  95. }
  96. },
  97. // 底部导航栏
  98. editTabbar: function () {
  99. let tabbar = this.globalData.tabBar;
  100. let currentPages = getCurrentPages();
  101. let _this = currentPages[currentPages.length - 1];
  102. let pagePath = _this.route;
  103. (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
  104. for (let i in tabbar.list) {
  105. tabbar.list[i].selected = false;
  106. (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
  107. }
  108. _this.setData({
  109. tabbar: tabbar
  110. });
  111. },
  112. globalData: {
  113. tabBar: {
  114. "backgroundColor": "#ffffff",
  115. "color": "#979795",
  116. "selectedColor": "#1c1c1b",
  117. "list": [{
  118. "pagePath": "/pages/home/index",
  119. "iconPath": "https://img.bbztx.com/miniProgram/challengeFamily/homePageShort.jpg",
  120. "selectedIconPath": "https://img.bbztx.com/miniProgram/challengeFamily/homePageLong.jpg",
  121. "text": "首页"
  122. },
  123. {
  124. "pagePath": "/pages/home/account",
  125. "iconPath": "https://img.bbztx.com/miniProgram/challengeFamily/accountShort.jpg",
  126. "selectedIconPath": "https://img.bbztx.com/miniProgram/challengeFamily/accountLong.jpg",
  127. "text": "我的"
  128. }
  129. ]
  130. },
  131. userInfo: wx.getStorageSync("WXuserInfo"),
  132. city: {city:'永康'},
  133. previous:'',//选择前一个城市
  134. locationCity:'',//定位城市
  135. path:'',
  136. openTipsNum: 0 },
  137. });