UploadPemFile.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div>
  3. <a-form-item :label="$t('cloudenv.private_key')">
  4. <a-radio-group @change="handleTypeChange" v-model="type">
  5. <a-radio-button :value="1">{{ $t('cloudenv.private_key.upload_certificate') }}</a-radio-button>
  6. <a-radio-button :value="2">{{ $t('cloudenv.private_key.text_input') }}</a-radio-button>
  7. </a-radio-group>
  8. </a-form-item>
  9. <a-form-item :label="$t('cloudenv.text_116')" v-if="type === 1" class="pem-file-upload">
  10. <a-upload-dragger
  11. v-bind="uploadDraggerConfig"
  12. :beforeUpload="handleBeforeUpload"
  13. :remove="hanldeRemoveFile"
  14. :fileList="fileList">
  15. <div style="padding: 10px;">
  16. <p class="ant-upload-drag-icon">
  17. <a-icon type="inbox" />
  18. </p>
  19. <p class="ant-upload-text">{{ $t('common.drag_file_area') }}</p>
  20. <p class="ant-upload-hint">{{ $t('cloudenv.private_key.upload_pem_file') }}</p>
  21. </div>
  22. </a-upload-dragger>
  23. <a-input v-show="false" v-decorator="decorators.oracle_private_pem" type="text" />
  24. </a-form-item>
  25. <a-form-item :label="$t('cloudenv.text_116')" v-else class="pem-file-upload">
  26. <slot />
  27. </a-form-item>
  28. </div>
  29. </template>
  30. <script>
  31. export default {
  32. name: 'ObjectsUploadPemFileDialog',
  33. props: {
  34. decorators: {
  35. type: Object,
  36. },
  37. fc: {
  38. type: Object,
  39. },
  40. },
  41. data () {
  42. return {
  43. type: 1,
  44. fileList: [],
  45. loading: false,
  46. }
  47. },
  48. computed: {
  49. uploadDraggerConfig () {
  50. return {
  51. name: 'file',
  52. accept: '.pem',
  53. headers: {
  54. Authorization: `Bearer ${this.$store.getters.userInfo.session}`,
  55. },
  56. }
  57. },
  58. },
  59. created () {
  60. this.fileList = []
  61. },
  62. methods: {
  63. handleTypeChange () {
  64. this.fileList = []
  65. },
  66. setValues (val) {
  67. if (!val || val === '') return false
  68. this.fc.setFieldsValue({ oracle_private_pem: val })
  69. },
  70. handleBeforeUpload (file) {
  71. const isPem = file.name.endsWith('.pem')
  72. const isLimit2M = file.size / 1024 / 1024 < 2
  73. if (!isPem) {
  74. this.$message.error(this.$t('cloudenv.private_key.upload_pem_file'))
  75. return false
  76. }
  77. if (!isLimit2M) {
  78. this.$message.error(this.$t('cloudenv.text_121'))
  79. return false
  80. }
  81. file.text().then(val => {
  82. this.setValues(val)
  83. })
  84. this.fileList = [file]
  85. return false
  86. },
  87. hanldeRemoveFile () {
  88. this.fileList = []
  89. this.fc.setFieldsValue({ oracle_private_pem: '' })
  90. return true
  91. },
  92. },
  93. }
  94. </script>
  95. <style>
  96. .pem-file-upload .ant-upload-drag-container {
  97. display: block !important;
  98. }
  99. .pem-file-upload .ant-form-item-label {
  100. visibility: hidden;
  101. }
  102. </style>