index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. Page({
  9. data: { // 初始化页面渲染数据
  10. logs: [],
  11. src : '',
  12. username:'',
  13. pages:[]
  14. },
  15. onLoad: function () {
  16. console.error(app.globalData.userInfo.avatarUrl);
  17. this.setData({
  18. src:app.globalData.userInfo.avatarUrl,
  19. username:app.globalData.userInfo.nickName
  20. })
  21. },
  22. onReady:function () {
  23. //监听页面初次渲染完成
  24. },
  25. onShow:function () {
  26. //监听页面显示
  27. let me = this;
  28. API.getPesonalPost().then(res =>{
  29. for (let i = 0;i<res.length;i++){
  30. res[i].post = JSON.parse( res[i].post);
  31. }
  32. console.error(res)
  33. if(res.length>0){
  34. me.setData({
  35. pages:res
  36. })
  37. }
  38. })
  39. },
  40. onHide:function () {
  41. //监听页面隐藏
  42. },
  43. onReachBottom:function () {
  44. //页面上拉触底事件的处理函数
  45. },
  46. onShareAppMessage:function () {
  47. //用户点击右上角转发
  48. },
  49. onPullDownRefresh:function () {
  50. //监听用户下拉动作
  51. },
  52. pageToTest:function () {
  53. wx.navigateTo({
  54. url: '../testPage/index'
  55. })
  56. },
  57. onShareAppMessage:function () {
  58. //用户点击右上角转发
  59. return {
  60. title: '回到你的幸福時光',
  61. path: '../personal/index'
  62. }
  63. },
  64. viewTap:function () {
  65. this.setData({
  66. text: 'Set some data for updating view.'
  67. }, function() {
  68. // this is setData callback
  69. })
  70. },
  71. editEvent:function (e) {
  72. console.error(e)
  73. wx.navigateTo({
  74. url: `../edit/index`,
  75. success:function () {
  76. }
  77. });
  78. },
  79. enter_detail:function (e) {
  80. console.log(e)
  81. let objectId = e.target.dataset.objectid
  82. if(objectId) {
  83. wx.navigateTo({
  84. url: `../detail/index?objectId=${objectId}`,
  85. success:function () {
  86. }
  87. });
  88. }
  89. },
  90. getUserInfo: function(e) {
  91. // app.globalData.userInfo = e.detail.userInfo
  92. console.log(e);
  93. let options = {
  94. encryptedData: e.detail.encryptedData,
  95. errMsg: e.detail.errMsg,
  96. iv: e.detail.iv,
  97. rawData: e.detail.rawData,
  98. signature: e.detail.signature,
  99. avatarUrl: e.detail.userInfo.avatarUrl,
  100. city: e.detail.userInfo.city,
  101. country: e.detail.userInfo.country,
  102. gender: e.detail.userInfo.gender,
  103. language: e.detail.userInfo.language,
  104. nickName: e.detail.userInfo.nickName,
  105. province: e.detail.userInfo.province,
  106. };
  107. Object.assign(app.globalData.userInfo,options);
  108. Storage.set(app.globalData.userInfo.openid,app.globalData.userInfo);
  109. app.getUserInfoByStorage(app.globalData.userInfo,app);
  110. this.setData({
  111. src: e.detail.userInfo.avatarUrl,
  112. username:e.detail.userInfo.nickName
  113. })
  114. }
  115. })