index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //获取应用实例
  2. const
  3. app = getApp(),
  4. Bmob = require('../../utils/Bmob-1.6.1.min.js'),
  5. Storage = require('../../utils/storage.js'),
  6. API = require('../../api/API.js'),
  7. utils = require('../../utils/util.js');
  8. let date = utils.Getdate(new Date());
  9. let timeout;
  10. Page({
  11. data: {
  12. date:date,
  13. showTime:''
  14. },
  15. onLoad: function () {
  16. let me = this;
  17. setTimeout(()=>{
  18. //监听页面显示
  19. if(app.globalData.userInfo.avatarUrl){
  20. let totalTime = 3;
  21. let interval = setInterval(function () {
  22. me.setData({
  23. showTime: totalTime
  24. },function () {
  25. totalTime--;
  26. })
  27. },1000);
  28. if(totalTime==1){
  29. window.clearInterval(interval);
  30. }
  31. timeout = setTimeout(function () {
  32. wx.switchTab({
  33. url: '../main/index'
  34. })
  35. },3000)
  36. }
  37. },2000)
  38. },
  39. onReady:function () {
  40. //监听页面初次渲染完成
  41. },
  42. onShow:function () {
  43. },
  44. onHide:function () {
  45. //监听页面隐藏
  46. },
  47. onPullDownRefresh: function() {
  48. console.log(1)
  49. },
  50. onReachBottom: function() {
  51. console.log(2)
  52. },
  53. getUserInfo(e){
  54. if(e.detail.errMsg=='getUserInfo:fail auth deny'){
  55. wx.showToast({
  56. title: '请授权进入',
  57. icon: 'none',
  58. duration: 3000
  59. })
  60. return;
  61. }
  62. //如果数据不存在
  63. if(!app.globalData.userInfo.avatarUrl){
  64. let options = {
  65. encryptedData: e.detail.encryptedData,
  66. errMsg: e.detail.errMsg,
  67. iv: e.detail.iv,
  68. rawData: e.detail.rawData,
  69. signature: e.detail.signature,
  70. avatarUrl: e.detail.userInfo.avatarUrl,
  71. city: e.detail.userInfo.city,
  72. country: e.detail.userInfo.country,
  73. gender: e.detail.userInfo.gender,
  74. language: e.detail.userInfo.language,
  75. nickName: e.detail.userInfo.nickName,
  76. province: e.detail.userInfo.province,
  77. };
  78. Object.assign(app.globalData.userInfo,options);
  79. Storage.set(app.globalData.userInfo.openid,app.globalData.userInfo);
  80. app.getUserInfoByStorage(app.globalData.userInfo,app);
  81. }
  82. clearTimeout(timeout);
  83. wx.switchTab({
  84. url: '../main/index'
  85. })
  86. },
  87. enter:function () {
  88. }
  89. })