MsgContent.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div
  3. class="msg-content"
  4. @click="handleContent"
  5. >
  6. <div
  7. class="msg-content__inner"
  8. @click="emits('back')"
  9. v-html="curMsg"
  10. />
  11. <img
  12. style="width: 100%"
  13. src="@/assets/images/Group-420.png"
  14. >
  15. <img
  16. v-if="_curIndex < list.length - 1"
  17. class="msg-content__more"
  18. src="@/assets/images/tbn_nex.png"
  19. >
  20. <div
  21. v-if="showTips"
  22. class="msg-content__tips"
  23. >
  24. <img
  25. src="@/assets/images/hotspot-relic/tipsbox-min.png"
  26. >
  27. <p>点击对话框关闭对话</p>
  28. </div>
  29. </div>
  30. </template>
  31. <script setup>
  32. import { computed, onBeforeUnmount, watch, ref } from 'vue'
  33. const {
  34. windowSizeInCssForRef,
  35. windowSizeWhenDesignForRef,
  36. } = useSizeAdapt(1920, 970)
  37. const props = defineProps(['list', 'curIndex'])
  38. const emits = defineEmits(['update:cur-index', 'end', 'back'])
  39. const TIPS_KEY = 'ydd-msg-tips'
  40. const showTips = ref(!localStorage.getItem(TIPS_KEY))
  41. const _curIndex = computed({
  42. get() {
  43. return props.curIndex
  44. },
  45. set(v) {
  46. emits('update:cur-index', v)
  47. }
  48. })
  49. const curMsg = computed(() => {
  50. const item = props.list[_curIndex.value]
  51. return typeof item === 'string' ? item : item.inner
  52. })
  53. let audio = null
  54. const removeAudio = () => {
  55. if (!audio) return
  56. audio.pause()
  57. audio.remove()
  58. audio = null
  59. }
  60. const handleAudio = () => {
  61. const item = props.list[_curIndex.value]
  62. if (typeof item === 'object') {
  63. audio = new Audio(require(`@/assets/audios/${props.list[_curIndex.value].audio}`))
  64. audio.volume = 0.7
  65. audio.play()
  66. }
  67. }
  68. const handleContent = () => {
  69. if (_curIndex.value < props.list.length - 1) {
  70. _curIndex.value += 1
  71. } else {
  72. _curIndex.value = 0
  73. emits('end')
  74. }
  75. removeAudio()
  76. if (showTips.value) {
  77. showTips.value = false
  78. localStorage.setItem(TIPS_KEY, 1)
  79. }
  80. }
  81. onBeforeUnmount(() => {
  82. removeAudio()
  83. })
  84. watch(curMsg, handleAudio, {
  85. immediate: true
  86. })
  87. </script>
  88. <style lang="less">
  89. .msg-content {
  90. position: absolute;
  91. left: 0;
  92. right: 0;
  93. bottom: 0;
  94. cursor: pointer;
  95. font-size: 0;
  96. z-index: 3;
  97. &__tips {
  98. position: absolute;
  99. top: -167px;
  100. right: 109px;
  101. width: 298px;
  102. img {
  103. width: inherit;
  104. }
  105. p {
  106. position: absolute;
  107. top: 20px;
  108. left: 0;
  109. right: 0;
  110. font-size: 18px;
  111. color: rgba(255,255,255,0.85);
  112. text-align: center;
  113. }
  114. }
  115. &__inner {
  116. display: flex;
  117. flex-direction: column;
  118. justify-content: center;
  119. position: absolute;
  120. top: 0;
  121. left: calc(21vw + constant(safe-area-inset-left));
  122. left: calc(21vw + env(safe-area-inset-left));
  123. right: 10vw;
  124. bottom: 0;
  125. color: #FFF1BE;
  126. font-size: calc(22 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  127. letter-spacing: 4px;
  128. line-height: 37px;
  129. text-indent: 2em;
  130. p {
  131. font-family: "Source Han Sans SC Normal" !important;
  132. }
  133. }
  134. img:first-child {
  135. width: 100%;
  136. }
  137. &__more {
  138. position: absolute;
  139. right: 36px;
  140. bottom: 23px;
  141. width: calc(121 / v-bind('windowSizeWhenDesignForRef') * v-bind('windowSizeInCssForRef'));
  142. }
  143. }
  144. </style>