preview.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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="shareId"
  41. v-if="isAccess === 2"
  42. />
  43. <el-button
  44. class="ml-20"
  45. type="primary"
  46. @click="moreDetail"
  47. v-if="liButton"
  48. icon="Folder"
  49. >文件历史
  50. </el-button>
  51. <el-drawer v-model="liShow" :size="600">
  52. <template #title>
  53. <h3
  54. class="ml-5 black flex flex-center flex-justify-start full-width font-14 bold"
  55. >
  56. 文件历史
  57. </h3>
  58. </template>
  59. <div class="ml-10 tips flex flex-align-center">
  60. <el-icon class="mr-5" color="#5acafa" :size="20">
  61. <WarningFilled />
  62. </el-icon>
  63. 点击对应记录,可以查看历史文件
  64. </div>
  65. <div
  66. class="flex ml-20 item"
  67. v-for="(item, index) in fileHistoryList"
  68. :key="item.id"
  69. @click="newDetail(item)"
  70. >
  71. <div class="mt-10 flex flex-center flex-justify-start">
  72. <div class="font-18 bold-500">{{ index + 1 }}、</div>
  73. {{ item.coverUser }}在{{ item.createTime }}上传,编码:{{
  74. item.fileVO.md5
  75. }}
  76. </div>
  77. </div>
  78. </el-drawer>
  79. </div>
  80. </div>
  81. </el-drawer>
  82. </div>
  83. </template>
  84. <script>
  85. import api from '@/api/index.js'
  86. import share from '@/views/resource/component/share.vue'
  87. export default {
  88. components: {
  89. share
  90. },
  91. props: {
  92. title: {
  93. type: String,
  94. default: () => {
  95. return ''
  96. }
  97. },
  98. isAccess: {
  99. type: Number,
  100. default: 3
  101. },
  102. showAction: {
  103. type: Boolean,
  104. default: false
  105. },
  106. projectId: {
  107. type: String,
  108. default: ''
  109. },
  110. id: {
  111. type: String,
  112. default: null
  113. },
  114. shareId: {
  115. type: String,
  116. default: ''
  117. }
  118. },
  119. watch: {
  120. id: {
  121. handler(val) {
  122. if (val != null) {
  123. this.fileId = val
  124. }
  125. },
  126. immediate: true
  127. }
  128. },
  129. data() {
  130. return {
  131. fileId: '',
  132. liButton: false,
  133. liShow: false,
  134. show: false,
  135. data: null,
  136. preList: [],
  137. fileHistoryList: [1, 2, 3],
  138. showImage: false,
  139. watermarkOptions: {
  140. content: 'watermark',
  141. gap: [20, 20],
  142. offset: [10, 10],
  143. zIndex: 5,
  144. rotate: -20
  145. }
  146. }
  147. },
  148. methods: {
  149. newDetail(item) {
  150. this.liShow = false
  151. this.fileId = item.fileVO.id
  152. this.detail()
  153. },
  154. detail() {
  155. // 先判断是否存在历史列表
  156. this.$api.project
  157. .fileHistory({ fileId: this.fileId, current: 1, size: 100 })
  158. .then(res => {
  159. if (res.code === 200) {
  160. if (res.data.total > 0) {
  161. this.liButton = true
  162. this.fileHistoryList = res.data.records
  163. }
  164. }
  165. })
  166. if (Number(this.fileId, 10).toString() === 'NaN') {
  167. console.log('yyyy')
  168. // 如果id 不是数字开头,即mongo 62开头的id,查看文章详情
  169. this.$api.resource.fileDetail(this.fileId).then(res => {
  170. if (res.code === 200) {
  171. this.data = res.data
  172. this.show = true
  173. }
  174. })
  175. } else {
  176. this.$api.resource.fileInfo({ id: this.fileId }).then(res => {
  177. if (res.code === 200) {
  178. const tmp = res.data
  179. if (api.offices.includes(tmp.suffix)) {
  180. this.openByFile()
  181. } else {
  182. this.preList.length = 0
  183. this.preList.push(tmp.filePath)
  184. this.showImage = true
  185. }
  186. }
  187. })
  188. }
  189. },
  190. moreDetail() {
  191. // 显示侧边
  192. this.liShow = true
  193. },
  194. openByFile() {
  195. this.$api.resource.fileDetailByFile(this.fileId).then(res => {
  196. if (res.code === 200) {
  197. this.data = res.data
  198. this.show = true
  199. }
  200. })
  201. },
  202. // 将一个url转化为blob格式的
  203. getBlob(url) {
  204. return new Promise(resolve => {
  205. const xhr = new XMLHttpRequest()
  206. xhr.open('GET', url, true)
  207. xhr.responseType = 'blob'
  208. xhr.onload = () => {
  209. if (xhr.status === 200) {
  210. resolve(xhr.response)
  211. }
  212. }
  213. xhr.send()
  214. })
  215. },
  216. // 最简单a标签那一套
  217. saveAs(blob, fileName) {
  218. const link = document.createElement('a')
  219. link.href = window.URL.createObjectURL(blob)
  220. link.download = fileName
  221. link.click()
  222. },
  223. async downloadClick() {
  224. this.getBlob(this.data.fileAttach.filePath).then(blob => {
  225. this.saveAs(blob, this.data.title)
  226. })
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .preview {
  233. width: 960px;
  234. padding: 20px;
  235. }
  236. .bottom {
  237. position: fixed;
  238. bottom: 0;
  239. box-shadow: -2px 0px 2px rgba(0, 0, 0, 0.1);
  240. background-color: white;
  241. height: 30px;
  242. padding: 10px;
  243. width: 1200px;
  244. border: #e6e8ed solid 1px;
  245. }
  246. .tips {
  247. width: 580px;
  248. padding: 5px 5px;
  249. border-radius: 4px;
  250. background-color: #e2eaf5;
  251. }
  252. .item {
  253. background: #f7f8fa;
  254. border-radius: 4px;
  255. margin: 20px 10px;
  256. padding-bottom: 10px;
  257. padding-left: 5px;
  258. }
  259. .item:hover {
  260. background: #e6e8ed;
  261. border-radius: 4px;
  262. margin: 20px 10px;
  263. padding-bottom: 10px;
  264. padding-left: 5px;
  265. }
  266. :deep(.el-drawer__body) {
  267. padding: 0;
  268. }
  269. </style>