message-call-c2c.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div
  3. v-if="isCallMessage && conversationType === TYPES.CONV_C2C"
  4. class="call"
  5. :class="['call-' + conversationType, message.flow === 'out' && 'call-reverse']"
  6. @click="callAgain"
  7. >
  8. <div :class="['icon', message.flow === 'out' && callInfo.type === 2 && 'icon-reverse']">
  9. <Icon :file="callInfo.icon" />
  10. </div>
  11. <span class="call-content">{{ custom }}</span>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import TUICore, { TUIConstants } from '@tencentcloud/tui-core';
  16. import TUIChatEngine from '@tencentcloud/chat-uikit-engine';
  17. import { computed, ref } from '../../../adapter-vue';
  18. import { JSONToObject } from '../../../utils/index';
  19. import Icon from '../../../components/common/Icon.vue';
  20. import callVideoSVG from '../../../assets/icon/call-video.svg';
  21. import callVoiceSVG from '../../../assets/icon/call-voice.svg';
  22. import OfflinePushInfoManager, { PUSH_SCENE } from '../../../components/TUIChat/offlinePushInfoManager/index';
  23. const props = defineProps({
  24. message: {
  25. type: Object,
  26. default: () => ({}),
  27. },
  28. signalingInfo: {
  29. type: Object,
  30. default: () => ({}),
  31. },
  32. customContent: {
  33. type: Object,
  34. default: () => ({}),
  35. },
  36. });
  37. const TYPES = ref(TUIChatEngine.TYPES);
  38. const isCallMessage = computed(() => props.signalingInfo != null);
  39. const callInfo = computed((): { type: number; icon: string } => {
  40. const callType = JSONToObject(props.signalingInfo?.data)?.call_type;
  41. switch (callType) {
  42. case 1:
  43. return {
  44. type: 1,
  45. icon: callVoiceSVG,
  46. };
  47. case 2:
  48. return {
  49. type: 2,
  50. icon: callVideoSVG,
  51. };
  52. default:
  53. break;
  54. }
  55. return {
  56. type: 0,
  57. icon: '',
  58. };
  59. });
  60. const conversationType = computed(() => props.message?.conversationType);
  61. const custom = computed(() => props.customContent?.custom);
  62. const callAgain = () => {
  63. if (conversationType.value === TUIChatEngine.TYPES.CONV_C2C) {
  64. const userID = props.message?.flow === 'out' ? props.message?.to : props.message?.from;
  65. TUICore.callService({
  66. serviceName: TUIConstants.TUICalling.SERVICE.NAME,
  67. method: TUIConstants.TUICalling.SERVICE.METHOD.START_CALL,
  68. params: {
  69. userIDList: [userID],
  70. type: callInfo?.value?.type,
  71. callParams: {
  72. offlinePushInfo: OfflinePushInfoManager.getOfflinePushInfo(PUSH_SCENE.CALL),
  73. },
  74. },
  75. });
  76. }
  77. };
  78. </script>
  79. <style scoped lang="scss">
  80. .call {
  81. display: flex;
  82. flex-direction: row;
  83. align-items: center;
  84. &-C2C {
  85. cursor: pointer;
  86. }
  87. &-GROUP {
  88. cursor: default;
  89. }
  90. &-content {
  91. padding-left: 5px;
  92. }
  93. .icon {
  94. width: 20px;
  95. height: 20px;
  96. }
  97. &-reverse {
  98. flex-direction: row-reverse;
  99. .icon-reverse {
  100. transform: rotate(180deg);
  101. }
  102. .call-content {
  103. padding-right: 5px;
  104. padding-left: 0;
  105. }
  106. }
  107. }
  108. </style>