DownloadModal.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="640"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <div class="table-operator">
  10. <a-button type="primary" icon="download" @click="downloadAll()">下载全部</a-button>
  11. </div>
  12. <a-table :columns="columns" :dataSource="data">
  13. <span slot="action" slot-scope="record">
  14. <template>
  15. <a @click="handleDownload(record)">下载</a>
  16. </template>
  17. </span>
  18. </a-table>
  19. <template slot="footer">
  20. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">返回</a-button>
  21. </template>
  22. </a-modal>
  23. </template>
  24. <script>
  25. import { queryFile, downloadFile } from '@/api/upms/file'
  26. export default {
  27. name: 'DownLoadModal',
  28. data () {
  29. return {
  30. confirmLoading: false,
  31. modalTitle: null,
  32. visible: false,
  33. data: [],
  34. id: null,
  35. module: null,
  36. allUrl: null,
  37. columns: [
  38. {
  39. title: '名称',
  40. dataIndex: 'name'
  41. },
  42. {
  43. title: '上传时间',
  44. dataIndex: 'createdTime'
  45. },
  46. {
  47. title: '操作',
  48. key: 'action',
  49. width: '200px',
  50. align: 'center',
  51. scopedSlots: { customRender: 'action' }
  52. }
  53. ]
  54. }
  55. },
  56. methods: {
  57. base (id, module, allUrl) {
  58. this.id = id
  59. this.module = module
  60. this.allUrl = allUrl
  61. queryFile({ targetId: id, module: module }).then(res => {
  62. const count = res.data.length
  63. if (count === 0) {
  64. this.$message.error('下载文件不存在')
  65. } else if (count === 1) {
  66. // alert(this.BaseTool.Constant.FILE_URL + res.data[0].url)
  67. window.open(this.BaseTool.Constant.FILE_URL + res.data[0].url)
  68. } else {
  69. this.data = res.data
  70. this.visible = true
  71. }
  72. })
  73. },
  74. handleCancel () {
  75. this.visible = false
  76. this.confirmLoading = false
  77. },
  78. handleDownload (record) {
  79. window.open(this.BaseTool.Constant.FILE_URL + record.url)
  80. },
  81. downloadAll () {
  82. downloadFile(this.allUrl)
  83. // window.open(this.allUrl)
  84. }
  85. }
  86. }
  87. </script>