home-banner.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <script setup lang="ts">
  2. import ImageEvo from '@/components/image-evo.vue'
  3. import { updateSetIndexConfig } from '@/core/libs/requests'
  4. import { unix } from 'dayjs'
  5. const props = withDefaults(
  6. defineProps<{
  7. id: string | number
  8. url: string
  9. cover: string
  10. }>(),
  11. {},
  12. )
  13. const emits = defineEmits<{ play: [id: string | number] }>()
  14. const instance = getCurrentInstance()
  15. const playing = ref(false)
  16. const duration = ref(0)
  17. const durationText = computed(() => unix(duration.value).format('mm:ss'))
  18. const videoContext = ref<UniNamespace.VideoContext>()
  19. const handlePlay = async () => {
  20. videoContext.value?.play()
  21. playing.value = true
  22. emits('play', props.id)
  23. }
  24. const handleLoadedMetaData = ({ detail }) => {
  25. duration.value = detail.duration
  26. }
  27. onMounted(async () => {
  28. videoContext.value = uni.createVideoContext(`video-${props.id}`, instance)
  29. })
  30. </script>
  31. <template>
  32. <div class="w-full h-full relative">
  33. <video
  34. class="w-full h-full"
  35. :id="`video-${id}`"
  36. :src="url"
  37. :controls="'contimg'"
  38. :show-center-play-btn="false"
  39. @loadedmetadata="handleLoadedMetaData"
  40. ></video>
  41. <div v-if="!playing" class="absolute left-0 top-0 w-full h-full bg-black">
  42. <!-- <wd-img width="100%" height="100%" :src="cover" /> -->
  43. <ImageEvo :src="cover"></ImageEvo>
  44. </div>
  45. <div
  46. v-if="!playing"
  47. class="w-[375px] h-[90px] bg-gradient-to-t from-black to-black/0 absolute left-0 bottom-0 w-full flex items-center"
  48. >
  49. <view class="mx-7">
  50. <wd-button
  51. plain
  52. custom-class="bg-transparent! text-white! w-20.5! min-w-20! h-8.25! border! border-solid! border-white!"
  53. @click="handlePlay()"
  54. >
  55. <div class="flex items-center">
  56. <wd-icon name="play" size="22px"></wd-icon>
  57. <div class="text-white text-[13px] font-['Gotham'] leading-[10.18px]">
  58. {{ durationText }}
  59. </div>
  60. </div>
  61. </wd-button>
  62. </view>
  63. </div>
  64. </div>
  65. </template>