ObjectsUploadFile.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <base-dialog @cancel="handleCancel" :modalProps="{footer: null}">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc" v-bind="formItemLayout">
  6. <a-form-item :label="$t('storage.text_117')">
  7. {{uploadTo}}
  8. </a-form-item>
  9. <a-form-item :label="$t('storage.text_118')" class="upload-file-item pb-3">
  10. <a-upload-dragger
  11. v-decorator="decorators.files"
  12. @change="hanldeFileChange"
  13. v-bind="uploadDraggerConfig">
  14. <div style="padding: 10px; min-width: 600px">
  15. <p class="ant-upload-drag-icon">
  16. <a-icon type="inbox" />
  17. </p>
  18. <p class="ant-upload-text">{{$t('storage.text_119')}}<a>{{$t('storage.text_120')}}</a></p>
  19. </div>
  20. </a-upload-dragger>
  21. </a-form-item>
  22. </a-form>
  23. <div style="text-align: center;margin-top:10px;font-size: 12px;" v-if="statusNums">
  24. <span>{{$t('storage.text_121', [statusNums.uploading])}}</span>
  25. <a-divider type="vertical" />
  26. <span>{{$t('storage.text_122', [statusNums.done])}}</span>
  27. <a-divider type="vertical" />
  28. <span>{{$t('storage.text_123', [statusNums.error])}}</span>
  29. </div>
  30. </div>
  31. </base-dialog>
  32. </template>
  33. <script>
  34. import { formItemLayout } from '@Storage/constants/index.js'
  35. import DialogMixin from '@/mixins/dialog'
  36. import WindowsMixin from '@/mixins/windows'
  37. export default {
  38. name: 'ObjectsUploadFileDialog',
  39. mixins: [DialogMixin, WindowsMixin],
  40. data () {
  41. return {
  42. loading: false,
  43. formItemLayout,
  44. fileList: [],
  45. statusNums: undefined,
  46. modalProps: {
  47. footer: null,
  48. },
  49. form: {
  50. fc: this.$form.createForm(this),
  51. },
  52. decorators: {
  53. files: ['files', {
  54. rules: [
  55. { required: true, message: this.$t('storage.text_124') },
  56. ],
  57. }],
  58. },
  59. }
  60. },
  61. provide () {
  62. return {
  63. form: this.form,
  64. }
  65. },
  66. computed: {
  67. uploadTo () {
  68. const { resItem, prefix } = this.params
  69. return `${resItem.name}/${prefix}`
  70. },
  71. uploadConfig () {
  72. return {
  73. timeout: 0,
  74. url: '/v1/s3uploads',
  75. method: 'post',
  76. processData: false,
  77. }
  78. },
  79. uploadDraggerConfig () {
  80. const { resId, prefix } = this.params
  81. return {
  82. name: 'file',
  83. action: '/api/v1/s3uploads',
  84. multiple: true,
  85. data: (file) => {
  86. const { name, size } = file
  87. return {
  88. bucket_id: resId,
  89. fileName: name,
  90. key: `${prefix}${name}`,
  91. content_length: size,
  92. acl: 'private',
  93. }
  94. },
  95. headers: {
  96. Authorization: `Bearer ${this.$store.getters.auth.auth.session}`,
  97. },
  98. }
  99. },
  100. },
  101. methods: {
  102. async fetchRemoveFile (key) {
  103. try {
  104. const { resId } = this.params
  105. const manager = new this.$Manager('buckets', 'v2')
  106. await manager.performAction({
  107. id: resId,
  108. action: 'delete',
  109. data: {
  110. keys: [key],
  111. },
  112. })
  113. } catch (err) {
  114. throw err
  115. }
  116. },
  117. hanldeFileChange ({ fileList }) {
  118. // if (!fileList || !fileList.length) return false
  119. const _statusNums = {
  120. uploading: 0,
  121. error: 0,
  122. done: 0,
  123. }
  124. if (fileList && Array.isArray(fileList)) {
  125. fileList.forEach((file) => {
  126. const { status, response } = file
  127. if (status === 'error' && response) {
  128. file.response = response.details
  129. }
  130. _statusNums[status] += 1
  131. })
  132. }
  133. this.statusNums = _statusNums
  134. },
  135. handleCancel () {
  136. if (document.getElementsByClassName('ant-upload-list-item-uploading').length) {
  137. this.createDialog('ConfirmDialog', {
  138. title: this.$t('storage.text_125'),
  139. width: '550px',
  140. content: this.$t('storage.text_126'),
  141. onOk: () => {
  142. this.cancelDialog()
  143. this.params.list.fetchData()
  144. },
  145. })
  146. } else {
  147. this.cancelDialog()
  148. this.params.list.fetchData()
  149. }
  150. },
  151. },
  152. }
  153. </script>
  154. <style lang="less">
  155. .upload-file-item .ant-upload-list-item-done .anticon-close {
  156. display: none;
  157. }
  158. .upload-file-item .ant-upload-list-item-done .ant-upload-list-item-card-actions {
  159. display: none;
  160. }
  161. .upload-file-item .ant-upload-list-item .anticon-close {
  162. opacity: 1;
  163. color: rgba(0, 0, 0, 0.7);
  164. z-index: 0;
  165. }
  166. :root .ant-upload-list-item .anticon-close {
  167. font-size: 14px;
  168. }
  169. .upload-file-item .ant-upload-list {
  170. height: 200px;
  171. overflow: auto;
  172. padding-right: 20px;
  173. }
  174. </style>