message-call-c2c.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. const props = defineProps({
  23. message: {
  24. type: Object,
  25. default: () => ({}),
  26. },
  27. signalingInfo: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. customContent: {
  32. type: Object,
  33. default: () => ({}),
  34. },
  35. });
  36. const TYPES = ref(TUIChatEngine.TYPES);
  37. const isCallMessage = computed(() => props.signalingInfo != null);
  38. const callInfo = computed((): { type: number; icon: string } => {
  39. const callType = JSONToObject(props.signalingInfo?.data)?.call_type;
  40. switch (callType) {
  41. case 1:
  42. return {
  43. type: 1,
  44. icon: callVoiceSVG,
  45. };
  46. case 2:
  47. return {
  48. type: 2,
  49. icon: callVideoSVG,
  50. };
  51. default:
  52. break;
  53. }
  54. return {
  55. type: 0,
  56. icon: '',
  57. };
  58. });
  59. const conversationType = computed(() => props.message?.conversationType);
  60. const custom = computed(() => props.customContent?.custom);
  61. const callAgain = () => {
  62. if (conversationType.value === TUIChatEngine.TYPES.CONV_C2C) {
  63. const userID = props.message?.flow === 'out' ? props.message?.to : props.message?.from;
  64. TUICore.callService({
  65. serviceName: TUIConstants.TUICalling.SERVICE.NAME,
  66. method: TUIConstants.TUICalling.SERVICE.METHOD.START_CALL,
  67. params: {
  68. userIDList: [userID],
  69. type: callInfo?.value?.type,
  70. },
  71. });
  72. }
  73. };
  74. </script>
  75. <style scoped lang="scss">
  76. .call {
  77. display: flex;
  78. flex-direction: row;
  79. align-items: center;
  80. &-C2C {
  81. cursor: pointer;
  82. }
  83. &-GROUP {
  84. cursor: default;
  85. }
  86. &-content {
  87. padding-left: 5px;
  88. }
  89. .icon {
  90. width: 20px;
  91. height: 20px;
  92. }
  93. &-reverse {
  94. flex-direction: row-reverse;
  95. .icon-reverse {
  96. transform: rotate(180deg);
  97. }
  98. .call-content {
  99. padding-right: 5px;
  100. padding-left: 0;
  101. }
  102. }
  103. }
  104. </style>