index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <el-dialog class="show-file" :visible="dialogVisibleShowFile" width="1100px" @close="dialogShowFileClose">
  3. <div slot="title">{{ $t('Key322') }}【{{ fileName }}】</div>
  4. <div v-loading="loading">
  5. <iframe
  6. v-if="fileUrl.length > 0"
  7. id="iframe"
  8. :src="`${$store.state.app.config.doc_preview_service_address}/onlinePreview?url=${fileUrl}`"
  9. width="100%"
  10. height="540px"
  11. />
  12. </div>
  13. <div slot="footer">
  14. <el-button @click="dialogShowFileClose">
  15. {{ $t('Key246') }}
  16. </el-button>
  17. </div>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. import { GetFileStoreInfo } from '@/api/app';
  22. import { encode } from 'js-base64';
  23. export default {
  24. name: 'ShowFile',
  25. props: {
  26. fileName: {
  27. default: '',
  28. type: String
  29. },
  30. fileId: {
  31. default: '',
  32. type: String
  33. }
  34. },
  35. data() {
  36. return {
  37. loading: false,
  38. dialogVisibleShowFile: false,
  39. fileUrl: ''
  40. };
  41. },
  42. watch: {
  43. fileId(newVal) {
  44. if (newVal.length > 0) {
  45. this.getFileStoreInfo();
  46. }
  47. },
  48. dialogVisibleShowFile(newVal) {
  49. if (!newVal) {
  50. this.fileUrl = '';
  51. }
  52. }
  53. },
  54. methods: {
  55. getFileStoreInfo() {
  56. GetFileStoreInfo({ file_id: this.fileId }).then(({ file_url_https }) => {
  57. this.loading = true;
  58. this.fileUrl = encodeURIComponent(encode(file_url_https));
  59. this.$nextTick(() => {
  60. document.getElementById('iframe').onload = () => {
  61. this.loading = false;
  62. };
  63. });
  64. });
  65. },
  66. showDialog() {
  67. this.dialogVisibleShowFile = true;
  68. },
  69. dialogShowFileClose() {
  70. this.dialogVisibleShowFile = false;
  71. this.$emit('dialogShowFileClose');
  72. }
  73. }
  74. };
  75. </script>
  76. <style lang="scss">
  77. @import '~@/styles/mixin';
  78. .show-file {
  79. @include dialog;
  80. .el-dialog__header {
  81. font-weight: bold;
  82. }
  83. %image-parent,
  84. .image-parent {
  85. display: flex;
  86. justify-content: center;
  87. }
  88. .audio-file {
  89. @extend %image-parent;
  90. }
  91. .video-file {
  92. @extend %image-parent;
  93. video {
  94. width: 100%;
  95. }
  96. }
  97. .text-file {
  98. height: 60vh;
  99. .el-textarea,
  100. textarea {
  101. height: 100%;
  102. }
  103. }
  104. }
  105. </style>