preview.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div>
  3. <div @click="detail" class="pointer">
  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" append-to-body>
  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. <el-button
  44. class="ml-20"
  45. type="primary"
  46. @click="moreDetail"
  47. v-if="liButton"
  48. >文件历史
  49. </el-button>
  50. <el-drawer v-model="liShow" :size="600">
  51. <div
  52. class="flex ml-10"
  53. v-for="item in fileHistoryList"
  54. @click="newDetail(item)"
  55. >
  56. <div class="mt-10">{{ item.coverUser }}</div>
  57. <div class="ml-20 mt-10">在{{ item.createTime }}上传,</div>
  58. <div class="ml-20 mt-10">编码{{ item.fileVO.md5 }}</div>
  59. </div>
  60. </el-drawer>
  61. </div>
  62. </div>
  63. </el-drawer>
  64. </div>
  65. </template>
  66. <script>
  67. import api from '@/api/index.js'
  68. import share from '@/views/resource/component/share.vue'
  69. export default {
  70. components: {
  71. share
  72. },
  73. props: {
  74. title: {
  75. type: String,
  76. default: () => {
  77. return ''
  78. }
  79. },
  80. isAccess: {
  81. type: Number,
  82. default: 3
  83. },
  84. showAction: {
  85. type: Boolean,
  86. default: false
  87. },
  88. projectId: {
  89. type: String,
  90. default: ''
  91. },
  92. id: {
  93. type: String,
  94. default: null
  95. }
  96. },
  97. watch: {
  98. id: {
  99. handler(val) {
  100. if (val != null) {
  101. this.fileId = val
  102. }
  103. },
  104. immediate: true
  105. }
  106. },
  107. data() {
  108. return {
  109. fileId: '',
  110. liButton: false,
  111. liShow: false,
  112. show: false,
  113. data: null,
  114. preList: [],
  115. fileHistoryList: [1, 2, 3],
  116. showImage: false,
  117. watermarkOptions: {
  118. content: 'watermark',
  119. gap: [20, 20],
  120. offset: [10, 10],
  121. zIndex: 5,
  122. rotate: -20
  123. }
  124. }
  125. },
  126. methods: {
  127. newDetail(item) {
  128. this.fileId = item.fileVO.id
  129. this.detail()
  130. },
  131. detail() {
  132. //先判断是否存在历史列表
  133. this.$api.project
  134. .fileHistory({ fileId: this.fileId, current: 1, size: 100 })
  135. .then(res => {
  136. if (res.code === 200) {
  137. console.log(res)
  138. if (res.data.total > 0) {
  139. this.liButton = true
  140. this.fileHistoryList = res.data.records
  141. }
  142. }
  143. })
  144. if (Number(this.fileId, 10).toString() === 'NaN') {
  145. console.log('yyyy')
  146. // 如果id 不是数字开头,即mongo 62开头的id,查看文章详情
  147. this.$api.resource.fileDetail(this.fileId).then(res => {
  148. if (res.code === 200) {
  149. this.data = res.data
  150. this.show = true
  151. }
  152. })
  153. } else {
  154. this.$api.resource.fileInfo({ id: this.fileId }).then(res => {
  155. if (res.code === 200) {
  156. const tmp = res.data
  157. if (api.offices.includes(tmp.suffix)) {
  158. this.openByFile()
  159. } else {
  160. this.preList.length = 0
  161. this.preList.push(tmp.filePath)
  162. this.showImage = true
  163. }
  164. }
  165. })
  166. }
  167. },
  168. moreDetail() {
  169. //显示侧边
  170. this.liShow = true
  171. },
  172. openByFile() {
  173. this.$api.resource.fileDetailByFile(this.fileId).then(res => {
  174. if (res.code === 200) {
  175. this.data = res.data
  176. this.show = true
  177. }
  178. })
  179. },
  180. moreClick() {},
  181. async downloadClick() {
  182. const link = document.createElement('a')
  183. link.href = this.data.url
  184. link.download = this.data.title
  185. link.click()
  186. }
  187. }
  188. }
  189. </script>
  190. <style lang="scss" scoped>
  191. .preview {
  192. width: 960px;
  193. padding: 20px;
  194. }
  195. .bottom {
  196. position: fixed;
  197. bottom: 0;
  198. box-shadow: -2px 0px 2px rgba(0, 0, 0, 0.1);
  199. background-color: white;
  200. height: 30px;
  201. padding: 10px;
  202. width: 1200px;
  203. border: #e6e8ed solid 1px;
  204. }
  205. :deep(.el-drawer__body) {
  206. padding: 0;
  207. }
  208. </style>