attachment.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <el-table v-loading="loading" :data="tableData" :stripe="true">
  3. <el-table-column label="附件名称" align="center" prop="title" />
  4. <el-table-column label="操作" align="center">
  5. <template #default="scope">
  6. <el-link type="primary" download :href="scope.row.url" :underline="false" target="_blank">下载</el-link>
  7. <el-button v-if="showPreview" class="m-l-10px" link type="primary" @click="handlePreview(scope.row.url, row)">预览</el-button>
  8. </template>
  9. </el-table-column>
  10. </el-table>
  11. <Dialog title="附件详情" v-model="openPreview" width="1000" @close="openPreview = false">
  12. <div>
  13. <IFrame style="max-height: 80vh;" :src="fileUrl" />
  14. </div>
  15. </Dialog>
  16. </template>
  17. <script setup>
  18. defineOptions({ name: 'PersonAttachment' })
  19. import { PersonInfoApi } from '@/api/menduner/system/person'
  20. import { Base64 } from 'js-base64'
  21. const props = defineProps({
  22. showPreview: Boolean,
  23. userId: [String, Number]
  24. })
  25. const loading = ref(false)
  26. const tableData = ref([])
  27. const total = ref(0)
  28. const queryParams = reactive({
  29. pageNo: 1,
  30. pageSize: 5,
  31. userId: props.userId
  32. })
  33. const fileUrl = ref('')
  34. const openPreview = ref(false)
  35. const fileName = ref('')
  36. const baseUrl = import.meta.env.VITE_PREVIEW_URL
  37. const handlePreview = (url) => {
  38. if (!url) return message.warning('预览失败!')
  39. openPreview.value = true
  40. fileUrl.value = !url.includes('.pdf') ? `${baseUrl}/onlinePreview?url=${encodeURIComponent(Base64.encode(url))}` : url
  41. }
  42. const getList = async () => {
  43. loading.value = true
  44. try {
  45. const data = await PersonInfoApi.getPersonAttachmentList(queryParams)
  46. tableData.value = data.list
  47. total.value = data.total
  48. } finally {
  49. loading.value = false
  50. }
  51. }
  52. watch(() => props.userId, (newVal) => {
  53. if (newVal) {
  54. queryParams.userId = newVal
  55. getList()
  56. }
  57. }, { immediate: true }, { deep: true })
  58. </script>