UploadPreviewPreview.vue 8.2 KB

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