preview.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div>
  3. <div @click="detail">
  4. <slot name="title">
  5. <el-button type="primary" text>查看</el-button>
  6. </slot>
  7. </div>
  8. <el-image-viewer
  9. v-if="showImage"
  10. :url-list="preList"
  11. @close="showImage = false"
  12. />
  13. <el-drawer v-model="show" :size="1200">
  14. <template #title>
  15. <h4
  16. class="ml-20 black flex flex-center flex-justify-start full-width font-16 bold"
  17. >
  18. {{ data ? data.title : '' }}
  19. </h4>
  20. </template>
  21. <div>
  22. <div v-if="data">
  23. <div v-if="data.imgs.length === 0" class="flex flex-center">
  24. <div v-html="data.content" class="preview"></div>
  25. </div>
  26. <div v-else v-for="item in data.imgs" :key="item.id">
  27. <img :src="item.filePath" style="width: 1100px" />
  28. </div>
  29. </div>
  30. <div
  31. class="bottom flex flex-center flex-justify-center"
  32. v-if="isAccess === 2 || showAction"
  33. >
  34. <el-button type="primary" icon="Download" @click="downloadClick"
  35. >下 载
  36. </el-button>
  37. <share
  38. class="ml-20"
  39. :project-id="projectId"
  40. :ids="id"
  41. v-if="isAccess === 2"
  42. />
  43. </div>
  44. </div>
  45. </el-drawer>
  46. </div>
  47. </template>
  48. <script>
  49. import api from '@/api/index.js'
  50. import share from '@/views/resource/component/share.vue'
  51. export default {
  52. components: {
  53. share
  54. },
  55. props: {
  56. title: {
  57. type: String,
  58. default: () => {
  59. return ''
  60. }
  61. },
  62. isAccess: {
  63. type: Number,
  64. default: 3
  65. },
  66. showAction: {
  67. type: Boolean,
  68. default: false
  69. },
  70. projectId: {
  71. type: String,
  72. default: ''
  73. },
  74. id: {
  75. type: String,
  76. default: null
  77. }
  78. },
  79. data() {
  80. return {
  81. show: false,
  82. data: null,
  83. preList: [],
  84. showImage: false,
  85. watermarkOptions: {
  86. content: 'watermark',
  87. gap: [20, 20],
  88. offset: [10, 10],
  89. zIndex: 5,
  90. rotate: -20
  91. }
  92. }
  93. },
  94. methods: {
  95. detail() {
  96. if (Number(this.id, 10).toString() === 'NaN') {
  97. console.log('yyyy')
  98. // 如果id 不是数字开头,即mongo 62开头的id,查看文章详情
  99. this.$api.resource.fileDetail(this.id).then(res => {
  100. if (res.code === 200) {
  101. this.data = res.data
  102. this.show = true
  103. }
  104. })
  105. } else {
  106. this.$api.resource.fileInfo({ id: this.id }).then(res => {
  107. if (res.code === 200) {
  108. const tmp = res.data
  109. if (api.offices.includes(tmp.suffix)) {
  110. this.openByFile()
  111. } else {
  112. this.preList.length = 0
  113. this.preList.push(tmp.filePath)
  114. this.showImage = true
  115. }
  116. }
  117. })
  118. }
  119. },
  120. openByFile() {
  121. this.$api.resource.fileDetailByFile(this.id).then(res => {
  122. if (res.code === 200) {
  123. this.data = res.data
  124. this.show = true
  125. }
  126. })
  127. },
  128. async downloadClick() {
  129. const link = document.createElement('a')
  130. link.href = this.data.url
  131. link.download = this.data.title
  132. link.click()
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. .preview {
  139. width: 960px;
  140. padding: 20px;
  141. }
  142. .bottom {
  143. position: fixed;
  144. bottom: 0;
  145. box-shadow: -2px 0px 2px rgba(0, 0, 0, 0.1);
  146. background-color: white;
  147. height: 30px;
  148. padding: 10px;
  149. width: 1200px;
  150. border: #e6e8ed solid 1px;
  151. }
  152. :deep(.el-drawer__body) {
  153. padding: 0;
  154. }
  155. </style>