index.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import TUIChatServer from './server';
  2. import TUIChatComponent from './index.vue';
  3. import Face from './plugin-components/face';
  4. import Image from './plugin-components/image';
  5. import Video from './plugin-components/video';
  6. import File from './plugin-components/file';
  7. import Forward from './plugin-components/forward';
  8. import Words from './plugin-components/words';
  9. import Evaluate from './plugin-components/evaluate';
  10. import TypingHeader from './plugin-components/typingHeader';
  11. import ReadReceiptDialog from './plugin-components/readReceiptDialog';
  12. import Replies from './plugin-components/replies';
  13. import Call from './plugin-components/call';
  14. import ImagePreviewer from './plugin-components/imagePreviewer';
  15. import MessageInput from './message-input';
  16. let sendComponents: any = {
  17. Face,
  18. Image,
  19. Video,
  20. File,
  21. Evaluate,
  22. Words,
  23. Call,
  24. };
  25. export const messageComponents: any = {
  26. Forward,
  27. };
  28. export const otherComponents: any = {
  29. TypingHeader,
  30. ReadReceiptDialog,
  31. Replies,
  32. ImagePreviewer,
  33. MessageInput
  34. };
  35. export function getComponents(type: string) {
  36. let options: any = {};
  37. switch (type) {
  38. case 'send':
  39. options = sendComponents;
  40. break;
  41. case 'message':
  42. options = messageComponents;
  43. break;
  44. case 'other':
  45. options = otherComponents;
  46. break;
  47. default:
  48. break;
  49. }
  50. return options;
  51. }
  52. const install = (app: any) => {
  53. const components: any = { ...sendComponents, ...messageComponents, ...otherComponents };
  54. Object.keys(components).forEach((name: any) => {
  55. components[name].TUIServer = TUIChat.server;
  56. });
  57. TUIChatComponent.TUIServer = TUIChat.server;
  58. TUIChatComponent.components = { ...TUIChatComponent.components, ...components };
  59. app.component(TUIChat.name, TUIChatComponent);
  60. };
  61. const plugin = (TUICore: any) => {
  62. (TUIChat.server as any) = new TUIChatServer(TUICore);
  63. TUICore.component(TUIChat.name, TUIChat);
  64. return TUIChat;
  65. };
  66. const setPluginComponents = (Components: any) => {
  67. sendComponents = { ...sendComponents, ...Components };
  68. };
  69. const removePluginComponents = (nameList: Array<string>) => {
  70. nameList.map((name: string) => {
  71. delete sendComponents[name];
  72. return name;
  73. });
  74. };
  75. const TUIChat = {
  76. name: 'TUIChat',
  77. component: TUIChatComponent,
  78. server: TUIChatServer,
  79. sendComponents,
  80. messageComponents,
  81. otherComponents,
  82. install,
  83. plugin,
  84. setPluginComponents,
  85. removePluginComponents,
  86. };
  87. export default TUIChat;