You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.9 KiB

1 year ago
1 year ago
1 year ago
  1. <script>
  2. import {downLoadObjectFile} from '@/api/eam/eam_object_list.js'
  3. export default {
  4. name: "qcReportFileTable",
  5. props:{
  6. dataList:{
  7. type:Array,
  8. required:true
  9. },
  10. queryLoading:{
  11. type:Boolean,
  12. default:false,
  13. },
  14. columns:{
  15. type:Array,
  16. required: true,
  17. }
  18. },
  19. methods: {
  20. // 预览
  21. previewFile (row) {
  22. const fileName = row.fileName || row.fileType
  23. downLoadObjectFile(row).then(({data}) => {
  24. this.$filePreview.previewFile(data, fileName).then(result => {
  25. if (result.message) {
  26. this.$message.success(result.message)
  27. }
  28. }).catch(error => {
  29. this.$message.error('文件预览失败:' + (error.message || '未知错误'))
  30. })
  31. }).catch(() => {
  32. this.$message.error('文件下载失败,请稍后重试')
  33. })
  34. },
  35. // 文件下载
  36. downloadFile (row) {
  37. downLoadObjectFile(row)
  38. .then(({data}) => {
  39. // 不限制文件下载类型
  40. const blob = new Blob([data], {type: "application/octet-stream"})
  41. // 下载文件名称
  42. const fileName = row.fileName
  43. // a标签下载
  44. const linkNode = document.createElement('a')
  45. // a标签的download属性规定下载文件的名称
  46. linkNode.download = fileName
  47. linkNode.style.display = 'none'
  48. // 生成一个Blob URL
  49. linkNode.href = URL.createObjectURL(blob)
  50. document.body.appendChild(linkNode)
  51. // 模拟在按钮上的一次鼠标单击
  52. linkNode.click()
  53. // 释放URL 对象
  54. URL.revokeObjectURL(linkNode.href)
  55. document.body.removeChild(linkNode)
  56. })
  57. },
  58. }
  59. }
  60. </script>
  61. <template>
  62. <el-table
  63. :height="350"
  64. :data="dataList"
  65. border
  66. v-loading="queryLoading"
  67. element-loading-text="拼命加载中"
  68. style="width: 100%; ">
  69. <el-table-column
  70. v-for="(item,index) in columns" :key="index"
  71. :sortable="item.columnSortable"
  72. :prop="item.columnProp"
  73. :header-align="item.headerAlign"
  74. :show-overflow-tooltip="item.showOverflowTooltip"
  75. :align="item.align"
  76. :fixed="item.fixed===''?false:item.fixed"
  77. :min-width="item.columnWidth"
  78. :label="item.columnLabel">
  79. <template slot-scope="scope">
  80. <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
  81. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
  82. </template>
  83. </el-table-column>
  84. <el-table-column
  85. header-align="center"
  86. align="center"
  87. width="100"
  88. label="操作">
  89. <template slot-scope="scope">
  90. <el-link style="cursor: pointer" @click="previewFile(scope.row)">预览</el-link>
  91. <el-link style="cursor: pointer" @click="downloadFile(scope.row)">下载</el-link>
  92. </template>
  93. </el-table-column>
  94. </el-table>
  95. </template>
  96. <style scoped>
  97. </style>