chat-group.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. listGroups() {
  62. var that = this;
  63. wx.WebIM.conn.getGroup({
  64. limit: 50,
  65. success: function (res) {
  66. console.info(res)
  67. that.setData({
  68. groupList: res.data
  69. });
  70. // 好像也没有别的官方通道共享数据啊
  71. getApp().globalData.groupList = res.data || [];
  72. },
  73. error: function (e) {
  74. console.info(e)
  75. }
  76. });
  77. },
  78. into_room: function (e) {
  79. var nameList = {
  80. myName: this.data.myName,
  81. your: e.currentTarget.dataset.username,
  82. groupId: e.currentTarget.dataset.roomid
  83. };
  84. wx.navigateTo({
  85. url: "../chat-group-detail/chat-group-detail?username=" + JSON.stringify(nameList)
  86. });
  87. },
  88. })