attachmentResume.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <div>
  3. <div class="d-flex attachment-item mb-2 cursor-pointer" v-for="k in attachmentList" :key="k.id">
  4. <v-icon color="primary">mdi-file-account</v-icon>
  5. <div class="file-name ellipsis ml-2">{{ k.title }}</div>
  6. <v-icon color="primary" @click="previewFile(k.url)">mdi-eye-outline</v-icon>
  7. <v-icon class="mx-2" color="primary" @click="handleDownload(k)">mdi-download-box-outline</v-icon>
  8. </div>
  9. </div>
  10. </template>
  11. <script setup>
  12. import { ref } from 'vue'
  13. import { previewFile } from '@/utils'
  14. defineOptions({name: 'enterprise-talentPool-details-attachmentResume'})
  15. const attachmentList = ref([
  16. {
  17. id: "1797473178549903362",
  18. title: "林同学-Java-15875754758.docx",
  19. url: "http://menduner.citupro.com:6868/admin-api/infra/file/24/get/725800ca45aced6c9742e94f576051c8c2527cd49b332c15be2dfbf17daedb92.docx",
  20. createTime: 1717385976000,
  21. updateTime: 1717385976000
  22. },
  23. {
  24. id: "1797484319040229377",
  25. title: "林同学-C++-15875754758.docx",
  26. url: "http://menduner.citupro.com:6868/admin-api/infra/file/24/get/725800ca45aced6c9742e94f576051c8c2527cd49b332c15be2dfbf17daedb92.docx",
  27. createTime: 1717388632000,
  28. updateTime: 1717388632000
  29. },
  30. {
  31. id: "1797511196383563778",
  32. title: "林同学-PHP-15875754758.docx",
  33. url: "http://menduner.citupro.com:6868/admin-api/infra/file/24/get/725800ca45aced6c9742e94f576051c8c2527cd49b332c15be2dfbf17daedb92.docx",
  34. createTime: 1717395040000,
  35. updateTime: 1717395040000
  36. }
  37. ])
  38. const getBlob = (url) => {
  39. return new Promise(resolve => {
  40. const xhr = new XMLHttpRequest()
  41. xhr.open('GET', url, true)
  42. xhr.responseType = 'blob'
  43. xhr.onload = () => {
  44. if (xhr.status === 200) resolve(xhr.response)
  45. }
  46. xhr.send()
  47. })
  48. }
  49. const saveAs = (blob, filename) => {
  50. var link = document.createElement('a')
  51. link.href = window.URL.createObjectURL(blob)
  52. link.download = filename
  53. link.click()
  54. }
  55. // 下载附件
  56. const handleDownload = (k) => {
  57. getBlob(k.url).then(blob => {
  58. saveAs(blob, k.title)
  59. })
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .attachment-item {
  64. color: #555;
  65. font-size: 14px;
  66. .file-name {
  67. width: 230px;
  68. &:hover {
  69. color: var(--v-primary-base);
  70. }
  71. }
  72. }
  73. </style>