FileLook.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <transition-group class="upload-file-list" name="el-fade-in-linear flex1 ov-hd" tag="div">
  3. <el-row :gutter="60">
  4. <el-col :span="span" v-for="(file, index) in fileList" :key="index">
  5. <div class="upload-list-item">
  6. <el-link class="flex1 right-item" :href="`${file.url}`" :underline="false" target="_blank">
  7. <img style="width: 36px; height: 36px;" class="mr5" src="@/assets/images/pdf_icon.png" alt="" />
  8. <div>
  9. <div class="item-text">{{ file.fileName }}</div>
  10. <div v-if="file.fileSize" class="item-text">{{ changeByte(file.fileSize) }}</div>
  11. </div>
  12. </el-link>
  13. <a class="delete-item" @click="download(file.url, {}, file.fileName)" :underline="false">
  14. <div class="d-flex a-c j-c flex-cln">
  15. <el-icon size="16"><Download /></el-icon>
  16. <div style="padding-top: 6px;">下载</div>
  17. </div>
  18. </a>
  19. </div>
  20. </el-col>
  21. </el-row>
  22. <div v-if="!fileList.length">-</div>
  23. </transition-group>
  24. </template>
  25. <script setup lang="ts">
  26. import { download } from '@/utils/request';
  27. import { propTypes } from '@/utils/propTypes';
  28. import { changeByte } from '@/utils/ruoyi';
  29. const props = defineProps({
  30. modelValue: [String, Object, Array],
  31. value: [String, Object, Array],
  32. span: propTypes.number.def(18),
  33. isObject: propTypes.bool.def(true)
  34. });
  35. const fileList = ref<any>([]);
  36. watch(
  37. () => props.modelValue,
  38. async (val) => {
  39. if (val) {
  40. let list = [];
  41. if (Array.isArray(val)) {
  42. list = val;
  43. } else if (props.isObject) {
  44. list = [val];
  45. }
  46. fileList.value = [...list];
  47. } else {
  48. fileList.value = [];
  49. return [];
  50. }
  51. },
  52. { deep: true, immediate: true }
  53. );
  54. watch(
  55. () => props.value,
  56. async (val) => {
  57. console.log(val);
  58. if (val) {
  59. let list = [];
  60. if (Array.isArray(val)) {
  61. list = val;
  62. } else if (props.isObject) {
  63. list = [val];
  64. }
  65. fileList.value = [...list];
  66. } else {
  67. fileList.value = [];
  68. return [];
  69. }
  70. },
  71. { immediate: true }
  72. );
  73. const handleDownload = () => {};
  74. </script>
  75. <style scoped lang="scss">
  76. .upload-file-uploader {
  77. margin-bottom: 5px;
  78. }
  79. .upload-list-item {
  80. position: relative;
  81. display: flex;
  82. align-items: center;
  83. border: 1px solid #e8e8e8;
  84. border-radius: 2px;
  85. padding-right: 60px;
  86. box-sizing: border-box;
  87. margin-bottom: 12px;
  88. &:hover {
  89. border-color: var(--el-color-primary);
  90. background-color: rgba(#0f8240, 0.06);
  91. .delete-item {
  92. opacity: 1;
  93. }
  94. }
  95. }
  96. .item-text {
  97. line-height: 1.2;
  98. font-size: 14px;
  99. word-break:break-all;
  100. }
  101. .delete-item {
  102. width: 48px;
  103. position: absolute;
  104. top: -1px;
  105. bottom: -1px;
  106. right: 0;
  107. display: flex;
  108. justify-content: center;
  109. font-size: 12px;
  110. align-items: center;
  111. color: #fff;
  112. border: 1px solid var(--el-color-primary);
  113. cursor: pointer;
  114. background-color: var(--el-color-primary);
  115. opacity: 0;
  116. }
  117. .right-item {
  118. padding: 8px 10px;
  119. justify-content: start;
  120. box-sizing: border-box;
  121. }
  122. .upload-file {
  123. width: 100%;
  124. }
  125. </style>