sign.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div class="preview-layer">
  3. <div class="pull-meta">
  4. <ResourceView :data="media.url" :type="media.type" />
  5. </div>
  6. </div>
  7. </template>
  8. <script lang="ts">
  9. import { ref, watchEffect, defineComponent, PropType } from "vue";
  10. import { getResource } from "@/env";
  11. import { MediaType } from "./index.vue";
  12. import ResourceView from "./resource.vue";
  13. import type { MediaItem } from "./index.vue";
  14. export const Preview = defineComponent({
  15. name: "static-preview",
  16. props: {
  17. media: {
  18. type: Object as PropType<MediaItem>,
  19. required: true,
  20. },
  21. },
  22. emits: {
  23. close: () => true,
  24. },
  25. setup(props) {
  26. const staticURL = ref("");
  27. watchEffect(() => {
  28. const data = props.media.url;
  29. const url =
  30. typeof data === "string" ? getResource(data) : URL.createObjectURL(data);
  31. staticURL.value = url;
  32. return () => URL.revokeObjectURL(url);
  33. });
  34. return {
  35. staticURL,
  36. MediaType,
  37. };
  38. },
  39. });
  40. export default Preview;
  41. </script>
  42. <style scoped lang="scss" src="./style.scss"></style>