PreviewModal.vue 2.1 KB

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