resource.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div>
  3. <video
  4. v-if="type === MetaType.video"
  5. controls
  6. autoplay
  7. playsinline
  8. webkit-playsinline
  9. >
  10. <source :src="url" />
  11. </video>
  12. <iframe v-else-if="type === MetaType.other" :src="url"></iframe>
  13. <iframe
  14. v-else-if="type === MetaType.xfile"
  15. :src="`./xfile-viewer/index.html?file=${url}&time=${Date.now()}`"
  16. ></iframe>
  17. <img :src="url" v-if="type === MetaType.image" />
  18. <audio
  19. :src="url"
  20. v-if="type === MetaType.audio"
  21. controls
  22. autoplay
  23. playsinline
  24. webkit-playsinline
  25. />
  26. </div>
  27. </template>
  28. <script lang="ts" setup>
  29. import { getResource } from "@/env";
  30. import { computed } from "vue";
  31. import { getUrlType, MetaType } from "@/utils/meta";
  32. const props = defineProps<{ data: string | Blob | File; type?: MetaType }>();
  33. const url = computed(() =>
  34. typeof props.data === "string"
  35. ? getResource(props.data)
  36. : URL.createObjectURL(props.data)
  37. );
  38. const type = computed(() => {
  39. if (props.type) {
  40. return props.type;
  41. } else if (props.data instanceof File || typeof props.data === "string") {
  42. const d = props.data instanceof File ? props.data.name : props.data;
  43. return getUrlType(d);
  44. } else {
  45. return MetaType.other;
  46. }
  47. });
  48. </script>
  49. <style scoped>
  50. div {
  51. width: 100%;
  52. height: 100%;
  53. display: flex;
  54. align-items: center;
  55. justify-content: center;
  56. }
  57. audio,
  58. iframe {
  59. width: 100%;
  60. height: 100%;
  61. display: block;
  62. }
  63. video,
  64. img {
  65. max-width: 100%;
  66. max-height: 100%;
  67. display: block;
  68. object-fit: cover;
  69. }
  70. iframe {
  71. border: none;
  72. }
  73. </style>