home-banner.vue 1.8 KB

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