MsgContent.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div
  3. class="msg-content"
  4. @click="() => {
  5. if (_curIndex < list.length - 1) {
  6. _curIndex += 1
  7. } else {
  8. _curIndex = 0
  9. emits('end')
  10. }
  11. }"
  12. >
  13. <div
  14. class="msg-content__inner"
  15. v-html="curMsg"
  16. />
  17. <img
  18. style="width: 100%"
  19. src="@/assets/images/Group-420.png"
  20. >
  21. <img
  22. v-if="_curIndex < list.length - 1"
  23. class="msg-content__more"
  24. src="@/assets/images/tbn_nex.png"
  25. >
  26. </div>
  27. </template>
  28. <script setup>
  29. import { computed, onBeforeUnmount, watch } from 'vue'
  30. const props = defineProps(['list', 'curIndex'])
  31. const emits = defineEmits(['update:cur-index', 'end'])
  32. const _curIndex = computed({
  33. get() {
  34. return props.curIndex
  35. },
  36. set(v) {
  37. emits('update:cur-index', v)
  38. }
  39. })
  40. const curMsg = computed(() => {
  41. const item = props.list[_curIndex.value]
  42. return typeof item === 'string' ? item : item.inner
  43. })
  44. let audio = null
  45. const removeAudio = () => {
  46. audio?.pause()
  47. audio = null
  48. }
  49. onBeforeUnmount(() => {
  50. removeAudio()
  51. })
  52. watch(curMsg, () => {
  53. const item = props.list[_curIndex.value]
  54. audio?.pause()
  55. if (typeof item === 'object') {
  56. audio = new Audio(require(`@/assets/audios/${props.list[_curIndex.value].audio}`))
  57. audio.volume = 0.7
  58. audio.play()
  59. }
  60. }, {
  61. immediate: true
  62. })
  63. </script>
  64. <style lang="less" scoped>
  65. .msg-content {
  66. position: absolute;
  67. left: 0;
  68. right: 0;
  69. bottom: 0;
  70. cursor: pointer;
  71. font-size: 0;
  72. z-index: 3;
  73. &__inner {
  74. display: flex;
  75. flex-direction: column;
  76. justify-content: center;
  77. position: absolute;
  78. top: 0;
  79. left: 21vw;
  80. right: 10vw;
  81. bottom: 0;
  82. color: #FFF1BE;
  83. font-size: 22px;
  84. letter-spacing: 4px;
  85. line-height: 37px;
  86. font-family: Source Han Serif CN, Source Han Serif CN;
  87. text-indent: 2em;
  88. }
  89. img:first-child {
  90. width: 100%;
  91. }
  92. &__more {
  93. position: absolute;
  94. right: 36px;
  95. bottom: 23px;
  96. }
  97. }
  98. </style>