FileSelect.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template>
  2. <a-form-item :wrapper-col="offsetWrapperCol">
  3. <a-alert type="warning" class="mb-2">
  4. <template v-slot:message>
  5. <div>{{$t('compute.text_814')}}</div>
  6. <div>{{$t('compute.text_815')}}<a-button type="link" @click="handleDownloadTemplate">{{$t('compute.text_816')}}</a-button></div>
  7. <div>{{$t('compute.text_817')}}</div>
  8. </template>
  9. </a-alert>
  10. <a-upload-dragger
  11. v-decorator="decorators.file"
  12. :beforeUpload="beforeUpload"
  13. :fileList="fileList"
  14. :remove="handleRemove">
  15. <div class="pt-3 pb-3">
  16. <p class="ant-upload-drag-icon"><a-icon type="inbox" /></p>
  17. <p class="ant-upload-text">{{$t('compute.text_818')}}</p>
  18. <p class="ant-upload-hint">{{$t('compute.text_819')}}</p>
  19. </div>
  20. </a-upload-dragger>
  21. </a-form-item>
  22. </template>
  23. <script>
  24. import { download } from '@/utils/utils'
  25. export default {
  26. name: 'FileSelect',
  27. props: {
  28. decorators: {
  29. type: Object,
  30. required: true,
  31. },
  32. offsetWrapperCol: {
  33. type: Object,
  34. required: true,
  35. },
  36. downloadUrl: {
  37. type: String,
  38. required: true,
  39. },
  40. },
  41. inject: ['form'],
  42. data () {
  43. return {
  44. fileList: [],
  45. }
  46. },
  47. created () {
  48. this.$bus.$on('PhysicalmachineAddFileSelectClear', this.handleClearFile, this)
  49. },
  50. methods: {
  51. beforeUpload (file) {
  52. this.fileList = [file]
  53. return false
  54. },
  55. handleDownloadTemplate () {
  56. this.$http({
  57. method: 'GET',
  58. url: this.downloadUrl,
  59. responseType: 'blob',
  60. }).then(response => {
  61. download(response.data, 'host_template.xlsx')
  62. })
  63. },
  64. handleClearFile () {
  65. this.fileList = []
  66. this.form.fc.setFieldsValue({
  67. file: undefined,
  68. })
  69. },
  70. handleRemove () {
  71. this.handleClearFile()
  72. },
  73. },
  74. }
  75. </script>