message.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // pages/message/message.js
  2. const app = getApp()
  3. const host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. this.getData()
  15. },
  16. getData:function(){
  17. wx.request({
  18. url: host+'/api/wx/notice',
  19. success:res=>{
  20. if (res.statusCode == 403) {
  21. this.save()
  22. } else {
  23. this.setData({
  24. list:res.data.data
  25. })
  26. }
  27. }
  28. })
  29. },
  30. save: function () {
  31. var _this = this
  32. wx.showLoading({
  33. title: '正在登录',
  34. })
  35. wx.getStorage({
  36. key: 'userInfo',
  37. success: function (res) {
  38. console.log(res)
  39. wx.request({
  40. url: host + '/api/wx/auth',
  41. method: 'POST',
  42. data: {
  43. nickname: res.data.nickName,
  44. avatar: res.data.avatarUrl,
  45. openid: app.globalData.openid,
  46. },
  47. success: res => {
  48. wx.hideLoading()
  49. _this.getData();
  50. }
  51. })
  52. },
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面隐藏
  67. */
  68. onHide: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面卸载
  72. */
  73. onUnload: function () {
  74. },
  75. /**
  76. * 页面相关事件处理函数--监听用户下拉动作
  77. */
  78. onPullDownRefresh: function () {
  79. },
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {
  84. },
  85. /**
  86. * 用户点击右上角分享
  87. */
  88. onShareAppMessage: function () {
  89. }
  90. })