server.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import TUICore, { TUIConstants, ExtensionInfo } from '@tencentcloud/tui-core';
  2. import {
  3. TUIStore,
  4. StoreName,
  5. TUIGroupService,
  6. } from '@tencentcloud/chat-uikit-engine';
  7. import { TUIGlobal } from '@tencentcloud/universal-api';
  8. import settingSVG from '../../assets/icon/setting.svg';
  9. import { isUniFrameWork } from '../../utils/env';
  10. export default class TUIGroupServer {
  11. static instance: TUIGroupServer;
  12. private onCallParamsMap: Map<string, any>;
  13. private onCallCallbackMap: Map<string, () => void>;
  14. public constants: typeof TUIConstants;
  15. constructor() {
  16. TUICore.registerService(TUIConstants.TUIGroup.SERVICE.NAME, this);
  17. TUICore.registerExtension(TUIConstants.TUIChat.EXTENSION.CHAT_HEADER.EXT_ID, this);
  18. this.onCallParamsMap = new Map();
  19. this.onCallCallbackMap = new Map();
  20. this.constants = TUIConstants;
  21. }
  22. static getInstance(): TUIGroupServer {
  23. if (!TUIGroupServer.instance) {
  24. TUIGroupServer.instance = new TUIGroupServer();
  25. }
  26. return TUIGroupServer.instance;
  27. }
  28. public getOnCallParams(method: string): any {
  29. return this.onCallParamsMap.get(method);
  30. }
  31. public getOnCallCallback(method: string): (() => void) | undefined {
  32. return this.onCallCallbackMap.get(method);
  33. }
  34. public async onCall(method: string, params: any, callback: () => void): Promise<void> {
  35. this.onCallParamsMap.set(method, params);
  36. this.onCallCallbackMap.set(method, callback);
  37. switch (method) {
  38. case TUIConstants.TUIGroup.SERVICE.METHOD.CREATE_GROUP:
  39. TUIStore.update(StoreName.GRP, 'isShowCreateComponent', true);
  40. isUniFrameWork && TUIGlobal?.reLaunch({
  41. url: '/TUIKit/components/TUIGroup/index',
  42. });
  43. break;
  44. case TUIConstants.TUIGroup.SERVICE.METHOD.OPEN_GROUP_MANAGEMENT:
  45. TUIGroupService.switchGroup(params.groupID);
  46. TUIStore.update(StoreName.GRP, 'isShowManageComponent', true);
  47. isUniFrameWork && TUIGlobal?.navigateTo({
  48. url: '/TUIKit/components/TUIGroup/index',
  49. });
  50. break;
  51. case TUIConstants.TUIGroup.SERVICE.METHOD.SELECT_GROUP_MEMBER:
  52. TUIGroupService.switchGroup(params.groupID);
  53. TUIStore.update(StoreName.GRP, 'isShowSelectComponent', true);
  54. isUniFrameWork && TUIGlobal?.navigateTo({
  55. url: '/TUIKit/components/TUIGroup/index',
  56. });
  57. break;
  58. }
  59. }
  60. public onGetExtension(extensionID: string, params: any): Array<ExtensionInfo> {
  61. const list: Array<ExtensionInfo> = [];
  62. switch (extensionID) {
  63. case TUIConstants.TUIChat.EXTENSION.CHAT_HEADER.EXT_ID:
  64. if (!params?.filterManageGroup) {
  65. list.push({
  66. weight: 100,
  67. icon: settingSVG,
  68. text: '更多',
  69. data: {},
  70. listener: {
  71. onClicked: this.groupManage.bind(this),
  72. },
  73. });
  74. }
  75. break;
  76. }
  77. return list;
  78. }
  79. private groupManage(params: any) {
  80. TUICore.callService({
  81. serviceName: TUIConstants.TUIGroup.SERVICE.NAME,
  82. method: TUIConstants.TUIGroup.SERVICE.METHOD.OPEN_GROUP_MANAGEMENT,
  83. params,
  84. callback: () => {
  85. isUniFrameWork && TUIGlobal?.navigateBack();
  86. },
  87. });
  88. }
  89. }