server.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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): ExtensionInfo[] {
  61. const list: ExtensionInfo[] = [];
  62. switch (extensionID) {
  63. case TUIConstants.TUIChat.EXTENSION.CHAT_HEADER.EXT_ID:
  64. list.push({
  65. weight: 100,
  66. icon: settingSVG,
  67. text: '更多',
  68. data: {},
  69. listener: {
  70. onClicked: this.groupManage.bind(this),
  71. },
  72. });
  73. break;
  74. }
  75. return list;
  76. }
  77. private groupManage(params: any) {
  78. TUICore.callService({
  79. serviceName: TUIConstants.TUIGroup.SERVICE.NAME,
  80. method: TUIConstants.TUIGroup.SERVICE.METHOD.OPEN_GROUP_MANAGEMENT,
  81. params,
  82. callback: () => {
  83. isUniFrameWork && TUIGlobal?.navigateBack();
  84. },
  85. });
  86. }
  87. }