message.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. wx.showLoading({
  15. title: '',
  16. })
  17. this.setData({
  18. openid: app.globalData.openid
  19. })
  20. this.getData()
  21. },
  22. getData:function(){
  23. wx.request({
  24. url: host+'/api/wx/notice',
  25. header: {
  26. openid: this.data.openid
  27. },
  28. success:res=>{
  29. wx.hideLoading()
  30. console.log(res,3333333333333)
  31. if (res.statusCode == 403) {
  32. this.save()
  33. } else {
  34. this.setData({
  35. list:res.data.data.list
  36. })
  37. if(res.data.data.new > 0){
  38. wx.setTabBarBadge({
  39. index: 2,
  40. text: String(res.data.data.new)
  41. });
  42. }
  43. }
  44. }
  45. })
  46. },
  47. save: function () {
  48. var _this = this
  49. wx.showLoading({
  50. title: '正在登录',
  51. })
  52. wx.getStorage({
  53. key: 'userInfo',
  54. success: function (res) {
  55. console.log(res)
  56. wx.request({
  57. url: host + '/api/wx/auth',
  58. method: 'POST',
  59. data: {
  60. nickname: res.data.nickName,
  61. avatar: res.data.avatarUrl,
  62. openid: app.globalData.openid,
  63. },
  64. success: res => {
  65. wx.hideLoading()
  66. _this.getData();
  67. }
  68. })
  69. },
  70. })
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. this.getData()
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. onReachBottom: function () {
  102. },
  103. /**
  104. * 用户点击右上角分享
  105. */
  106. onShareAppMessage: function () {
  107. }
  108. })