index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <teleport to="body">
  3. <span class="close pc" @click="$emit('close')">
  4. <ui-icon type="close" ctrl />
  5. </span>
  6. <div class="pull-preview pc">
  7. <div class="preview-layer">
  8. <div class="pull-meta">
  9. <video v-if="type === MediaType.video" controls autoplay playsinline webkit-playsinline>
  10. <source :src="staticURL" />
  11. </video>
  12. <iframe v-else-if="type === MediaType.web" :src="staticURL"></iframe>
  13. <div v-if="type === MediaType.img" class="full-img pc">
  14. <img :src="staticURL" />
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. </teleport>
  20. </template>
  21. <script lang="ts">
  22. import { ref, watchEffect, defineComponent, PropType } from 'vue'
  23. import { getResource } from '@/env'
  24. export enum MediaType {
  25. video,
  26. img,
  27. web
  28. }
  29. export const Preview = defineComponent({
  30. name: 'static-preview',
  31. props: {
  32. url: {
  33. type: String as PropType<Blob | string>,
  34. required: true
  35. },
  36. type: {
  37. type: Number as PropType<MediaType>,
  38. required: true
  39. }
  40. },
  41. emits: {
  42. close: () => true
  43. },
  44. setup(props) {
  45. const staticURL = ref('')
  46. watchEffect(() => {
  47. const data = props.url
  48. const url = typeof data === 'string'
  49. ? getResource(data)
  50. : URL.createObjectURL(data)
  51. staticURL.value = url
  52. return () => URL.revokeObjectURL(url)
  53. })
  54. return {
  55. staticURL,
  56. MediaType
  57. }
  58. }
  59. })
  60. export default Preview
  61. </script>
  62. <style scoped lang="scss" src="./style.scss"></style>