index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="view-other">
  3. <img class="view-off-icon" :src="viewOffImage" alt="" />
  4. <p>
  5. {{ file.name }}.{{ file.type
  6. }}<span class="size-item">{{ getFileSize }}</span>
  7. </p>
  8. <p>
  9. <big><strong>该类型文件不支持在线预览,请下载后查看。</strong></big>
  10. </p>
  11. </div>
  12. </template>
  13. <script setup>
  14. import { computed } from 'vue'
  15. import viewOffImage from "../../assets/view_off.svg"
  16. const props = defineProps({
  17. file: {
  18. type: Object,
  19. default: () => {
  20. return {}
  21. },
  22. },
  23. })
  24. const getFileSize = computed(() => {
  25. const size = Number(props.file.size)
  26. if (!Number.isFinite(size) || !size) return "0KB"
  27. const kbToMb = 1024
  28. const kbToGb = 1048576
  29. const abs = Math.abs(size)
  30. const sign = size < 0 ? "-" : ""
  31. if (abs >= kbToGb) return `${sign}${Math.floor((abs / kbToGb) * 100) / 100} GB`
  32. if (abs >= kbToMb) return `${sign}${Math.floor((abs / kbToMb) * 100) / 100} MB`
  33. return `${sign}${abs} KB`
  34. })
  35. </script>
  36. <style lang="less" scoped>
  37. .view-other {
  38. display: flex;
  39. flex-direction: column;
  40. align-items: center;
  41. justify-content: center;
  42. height: 100%;
  43. .size-item {
  44. margin-left: 10px;
  45. }
  46. .view-off-icon {
  47. width: 120px;
  48. height: 120px;
  49. object-fit: contain;
  50. }
  51. }
  52. </style>