convert-content.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="message-convert-container">
  3. <div
  4. v-if="convertFinished"
  5. :class="{
  6. 'convert-content': true,
  7. 'occur': true,
  8. }"
  9. >
  10. {{ convertText }}
  11. </div>
  12. <div
  13. :class="{
  14. 'loading': true,
  15. 'loading-end': convertFinished
  16. }"
  17. >
  18. {{ TUITranslateService.t('TUIChat.转换中') }}...
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. import { ref, watch } from '../../../../../adapter-vue';
  24. import {
  25. IMessageModel,
  26. TUITranslateService,
  27. } from '@tencentcloud/chat-uikit-engine';
  28. import { convertor } from '../../../utils/convertVoiceToText';
  29. interface IProps {
  30. message: IMessageModel;
  31. contentVisible: boolean;
  32. }
  33. interface IEmits {
  34. (e: 'toggleErrorStatus', status: boolean): void;
  35. }
  36. const emits = defineEmits<IEmits>();
  37. const props = withDefaults(defineProps<IProps>(), {
  38. message: () => ({} as IMessageModel),
  39. isSingleConvert: false,
  40. });
  41. const convertFinished = ref<boolean>(false);
  42. const convertText = ref<string>('');
  43. watch(() => props.contentVisible, (newVal: boolean) => {
  44. if (newVal) {
  45. convertor.get(props.message)
  46. .then((text) => {
  47. convertFinished.value = true;
  48. convertText.value = text;
  49. })
  50. .catch((err) => {
  51. convertFinished.value = true;
  52. emits('toggleErrorStatus', true);
  53. convertText.value = err.message;
  54. });
  55. }
  56. }, {
  57. immediate: true,
  58. });
  59. </script>
  60. <style lang="scss" scoped>
  61. .message-convert-container {
  62. min-height: 20px;
  63. min-width: 80px;
  64. position: relative;
  65. transition: width 0.15s ease-out, height 0.15s ease-out, ;
  66. font-size: 14px;
  67. .loading {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. opacity: 1;
  72. transition: opacity 0.3s ease-out;
  73. &.loading-end {
  74. opacity: 0;
  75. }
  76. }
  77. .convert-content {
  78. opacity: 0;
  79. &.occur {
  80. animation: occur 0.3s ease-out 0.45s forwards;
  81. @keyframes occur {
  82. 100% {
  83. opacity: 1;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. </style>