UploadPreviewPreview.vue 7.3 KB

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