chat-group.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/chat-group/chat-group.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgPath: app.globalData.imgPath,
  9. // groupList: [{
  10. // groupid: '178900372094977',
  11. // groupname: '测试'
  12. // }, {
  13. // groupid: '170301940891650',
  14. // groupname: '测试2'
  15. // }],
  16. search_btn: true,
  17. search_friend: false,
  18. show_mask: false,
  19. groupList: [], // 群聊列表
  20. myName: ""
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. this.setData({
  27. myName: options.myName
  28. });
  29. this.listGroups();
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow() {
  40. },
  41. /**
  42. * 生命周期函数--监听页面隐藏
  43. */
  44. onHide() {
  45. },
  46. /**
  47. * 生命周期函数--监听页面卸载
  48. */
  49. onUnload() {
  50. },
  51. /**
  52. * 页面相关事件处理函数--监听用户下拉动作
  53. */
  54. onPullDownRefresh() {
  55. },
  56. /**
  57. * 页面上拉触底事件的处理函数
  58. */
  59. onReachBottom() {
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage() {
  65. },
  66. listGroups() {
  67. var that = this;
  68. wx.WebIM.conn.getGroup({
  69. limit: 50,
  70. success: function (res) {
  71. console.info(res)
  72. that.setData({
  73. groupList: res.data
  74. });
  75. // 好像也没有别的官方通道共享数据啊
  76. getApp().globalData.groupList = res.data || [];
  77. },
  78. error: function (e) {
  79. console.info(e)
  80. }
  81. });
  82. },
  83. into_room: function (e) {
  84. var nameList = {
  85. myName: this.data.myName,
  86. your: e.currentTarget.dataset.username,
  87. groupId: e.currentTarget.dataset.roomid
  88. };
  89. wx.navigateTo({
  90. url: "../chat-group-detail/chat-group-detail?username=" + JSON.stringify(nameList)
  91. });
  92. },
  93. })