index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import IComponentServer from "../IComponentServer";
  2. import { TUIChatStoreType } from "../types";
  3. import { useStore } from "vuex";
  4. import store from "@/store";
  5. /**
  6. * class TUIGroupServer
  7. *
  8. * TUIGroupServer 逻辑主体
  9. */
  10. export default class TUIGroupServer extends IComponentServer {
  11. public TUICore: any;
  12. public store = store.state.timStore;
  13. public currentStore: any = {};
  14. constructor(TUICore: any) {
  15. super();
  16. this.TUICore = uni.$TUIKit;
  17. this.bindTIMEvent();
  18. }
  19. /**
  20. * 组件销毁
  21. */
  22. public destroyed() {
  23. this.unbindTIMEvent();
  24. }
  25. /**
  26. * 数据监听回调
  27. *
  28. * @param {any} newValue 新数据
  29. * @param {any} oldValue 旧数据
  30. */
  31. updateStore(newValue: any, oldValue: any) {
  32. this.currentStore.groupList = newValue.groupList;
  33. this.currentStore.searchGroup = newValue.searchGroup;
  34. }
  35. /**
  36. * /////////////////////////////////////////////////////////////////////////////////
  37. * //
  38. * // TIM 事件监听注册接口
  39. * //
  40. * /////////////////////////////////////////////////////////////////////////////////
  41. */
  42. private bindTIMEvent() {
  43. this.TUICore.on(
  44. uni.$TIM.EVENT.GROUP_LIST_UPDATED,
  45. this.handleGroupListUpdated,
  46. this
  47. );
  48. this.TUICore.on(
  49. uni.$TIM.EVENT.GROUP_ATTRIBUTES_UPDATED,
  50. this.handleGroupAttributesUpdated,
  51. this
  52. );
  53. }
  54. private unbindTIMEvent() {
  55. this.TUICore.off(
  56. uni.$TIM.EVENT.GROUP_LIST_UPDATED,
  57. this.handleGroupListUpdated
  58. );
  59. this.TUICore.off(
  60. uni.$TIM.EVENT.GROUP_ATTRIBUTES_UPDATED,
  61. this.handleGroupAttributesUpdated
  62. );
  63. }
  64. private handleGroupListUpdated(event: any) {}
  65. private handleGroupAttributesUpdated(event: any) {
  66. const { groupID, groupAttributes } = event.data; // 群组ID // 更新后的群属性
  67. console.log(groupID, groupAttributes);
  68. }
  69. }