UploadPreviewPreview.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="upload-preview" :style="getAreaStyle()">
  3. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  4. <div class="main">
  5. <template v-if="data.file_list.length > 0">
  6. <!-- <template v-if="data.file_list[0].file_name.match(/\.(png|jpg|jpeg)$/i) !== null">
  7. <el-image
  8. style="width: 100%; height: 260px"
  9. :src="data.file_list[0].file_url"
  10. :fit="'contain'"
  11. :preview-src-list="[data.file_list[0].file_url]"
  12. />
  13. </template>
  14. <template v-else-if="data.file_list[0].file_name.indexOf('pdf') !== -1">
  15. <iframe id="ifm" :src="data.file_list[0].newpath" width="100%" height="260px" frameborder="0"></iframe>
  16. </template>
  17. <div v-if="isEnable(data.is_enable_download)" class="uploadBtn" @click="downLoad">
  18. <img style="width: 24px; height: 24px" src="@/assets/download.png" alt="download" />
  19. 下载
  20. </div> -->
  21. <div class="label-box">
  22. <span
  23. v-for="(label, index) in label_list"
  24. :key="index"
  25. :class="[index === active_index ? 'active' : '']"
  26. @click="active_index = index"
  27. >{{ label }}</span
  28. >
  29. </div>
  30. <ul v-if="source_list[active_index].length > 0" class="file-list">
  31. <li v-for="(file, i) in source_list[active_index]" :key="i">
  32. <div class="file-name">
  33. <span>
  34. <SvgIcon :icon-class="icon_list[active_index]" size="16" />
  35. <span>{{ file.file_name ?? file.name }}</span>
  36. </span>
  37. <SvgIcon v-show="file.file_id" icon-class="uploadPreview" size="16" @click="viewDialog(file)" />
  38. <img
  39. v-if="isEnable(data.is_enable_download)"
  40. style="width: 16px; height: 16px"
  41. src="@/assets/download.png"
  42. alt="download"
  43. @click="downLoad(file)"
  44. />
  45. </div>
  46. </li>
  47. </ul>
  48. <p v-else class="label-tips">暂无本类型文件,看看其他类型吧</p>
  49. </template>
  50. </div>
  51. <el-dialog
  52. v-if="visible"
  53. :visible.sync="visible"
  54. :show-close="true"
  55. :close-on-click-modal="true"
  56. :modal-append-to-body="true"
  57. :append-to-body="true"
  58. :lock-scroll="true"
  59. width="80%"
  60. top="0"
  61. >
  62. <iframe v-if="visible" :src="newpath" width="100%" :height="iframeHeight" frameborder="0"></iframe>
  63. </el-dialog>
  64. </div>
  65. </template>
  66. <script>
  67. import PreviewMixin from '../common/PreviewMixin';
  68. import { getConfig, getToken } from '@/utils/auth';
  69. import { GetFileURLMap } from '@/api/app';
  70. const Base64 = require('js-base64').Base64;
  71. import { getUploadPreviewData } from '@/views/book/courseware/data/uploadPreview';
  72. export default {
  73. name: 'UploadPreviewPreview',
  74. mixins: [PreviewMixin],
  75. data() {
  76. return {
  77. data: getUploadPreviewData(),
  78. file_preview_url: getConfig() ? getConfig().doc_preview_service_address : '',
  79. source_list: [[], [], [], []],
  80. label_list: ['音频', '视频', '文档', '压缩包'],
  81. icon_list: ['mp3', 'video', 'file', 'zip'],
  82. active_index: 0,
  83. visible: false,
  84. newpath: '',
  85. iframeHeight: `${window.innerHeight - 100}px`,
  86. };
  87. },
  88. watch: {
  89. 'data.file_list': {
  90. handler(val) {
  91. if (val.length > 0) {
  92. this.handleData();
  93. }
  94. },
  95. immediate: true,
  96. },
  97. },
  98. methods: {
  99. // 处理数据
  100. handleData() {
  101. this.source_list = [[], [], [], []];
  102. this.data.file_list.forEach((item) => {
  103. const suffix = item.file_name.slice(item.file_name.lastIndexOf('.') + 1, item.file_name.length).toLowerCase();
  104. if (suffix === 'mp3' || suffix === 'wma') {
  105. this.source_list[0].push(item);
  106. } else if (suffix === 'mp4' || suffix === 'mov') {
  107. this.source_list[1].push(item);
  108. } else if (suffix === 'zip' || suffix === 'rar') {
  109. this.source_list[3].push(item);
  110. } else {
  111. this.source_list[2].push(item);
  112. }
  113. });
  114. },
  115. // 下载表格
  116. downLoad(file) {
  117. let userInfor = getToken();
  118. let AccessToken = '';
  119. if (userInfor) {
  120. AccessToken = userInfor.access_token;
  121. }
  122. let FileID = file.file_id;
  123. let data = {
  124. AccessToken,
  125. FileID,
  126. };
  127. location.href = `${
  128. process.env.VUE_APP_EEP
  129. }/FileServer/WebFileDownload?AccessToken=${data.AccessToken}&FileID=${data.FileID}`;
  130. },
  131. // 预览
  132. viewDialog(file) {
  133. this.newpath = '';
  134. GetFileURLMap({ file_id_list: [file.file_id] }).then(({ url_map }) => {
  135. // this.$set(
  136. // item,
  137. // 'newpath',
  138. // `${this.file_preview_url}onlinePreview?url=${Base64.encode(url_map[item.file_id])}`,
  139. // );
  140. this.newpath = `${this.file_preview_url}onlinePreview?url=${Base64.encode(url_map[file.file_id])}`;
  141. this.visible = true;
  142. });
  143. },
  144. },
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. @use '@/styles/mixin.scss' as *;
  149. .upload-preview {
  150. @include preview-base;
  151. .uploadBtn {
  152. box-sizing: border-box;
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. width: 96px;
  157. height: 39px;
  158. margin-top: 8px;
  159. font-size: 16px;
  160. line-height: 150%;
  161. color: #000;
  162. cursor: pointer;
  163. background: #fff;
  164. border: 1px solid rgba(0, 0, 0, 10%);
  165. border-radius: 4px;
  166. box-shadow: 0 2px 6px rgba(0, 0, 0, 10%);
  167. img {
  168. margin-right: 13px;
  169. }
  170. }
  171. .label-box {
  172. display: flex;
  173. gap: 10px;
  174. padding: 10px 0;
  175. border-bottom: 1px solid rgba(0, 0, 0, 10%);
  176. span {
  177. padding: 5px 15px;
  178. cursor: pointer;
  179. border-radius: 20px;
  180. &.active {
  181. font-weight: bold;
  182. color: #165dff;
  183. background: #f2f3f5;
  184. }
  185. }
  186. }
  187. .file-list {
  188. display: flex;
  189. flex-direction: column;
  190. row-gap: 5px;
  191. padding: 15px 0;
  192. li {
  193. display: flex;
  194. column-gap: 12px;
  195. align-items: center;
  196. .file-name {
  197. display: flex;
  198. column-gap: 14px;
  199. align-items: center;
  200. justify-content: space-between;
  201. max-width: 500px;
  202. padding: 8px 12px;
  203. font-size: 14px;
  204. color: #1d2129;
  205. background-color: #f7f8fa;
  206. span {
  207. display: flex;
  208. column-gap: 14px;
  209. align-items: center;
  210. }
  211. }
  212. .svg-icon {
  213. cursor: pointer;
  214. }
  215. }
  216. }
  217. .label-tips {
  218. font-size: 14px;
  219. color: #333;
  220. }
  221. :deep .el-dialog {
  222. margin: 0 auto;
  223. }
  224. }
  225. </style>