ObjectsUpdateHttp.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="$t('storage.text_112')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="key" v-for="(val, key) in TYPES" :key="key">
  9. <a-input :placeholder="val" v-decorator="decorators[key]" />
  10. </a-form-item>
  11. </a-form>
  12. </div>
  13. <div slot="footer">
  14. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  15. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  16. </div>
  17. </base-dialog>
  18. </template>
  19. <script>
  20. import DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'ObjectsUpdateHttpDialog',
  24. mixins: [DialogMixin, WindowsMixin],
  25. data () {
  26. const TYPES = {
  27. 'Content-Type': '',
  28. 'Content-Encoding': this.$t('storage.text_113'),
  29. 'Content-Language': this.$t('storage.text_114'),
  30. 'Content-Disposition': this.$t('storage.text_115'),
  31. 'Cache-Control': this.$t('storage.text_116'),
  32. }
  33. const decorators = {}
  34. const { data } = this.params
  35. const meta = data[0].meta
  36. Object.keys(TYPES).forEach(item => {
  37. decorators[item] = [
  38. item,
  39. {
  40. initialValue: meta && meta[item] ? meta[item].toString() : undefined,
  41. },
  42. ]
  43. })
  44. return {
  45. loading: false,
  46. formItemLayout: {
  47. labelCol: { span: 5 },
  48. wrapperCol: { span: 19 },
  49. },
  50. fileList: [],
  51. form: {
  52. fc: this.$form.createForm(this),
  53. },
  54. TYPES,
  55. decorators,
  56. }
  57. },
  58. provide () {
  59. return {
  60. form: this.form,
  61. }
  62. },
  63. methods: {
  64. validateForm () {
  65. return new Promise((resolve, reject) => {
  66. this.form.fc.validateFields((err, values) => {
  67. if (err) return reject(err)
  68. resolve(values)
  69. })
  70. })
  71. },
  72. async handleConfirm () {
  73. this.loading = true
  74. try {
  75. const valies = await this.validateForm()
  76. for (const k in valies) {
  77. if (!valies[k]) {
  78. delete valies[k]
  79. } else {
  80. valies[k] = [valies[k]]
  81. }
  82. }
  83. const { resId, data } = this.params
  84. await new this.$Manager('buckets', 'v2').performAction({
  85. id: resId,
  86. action: 'metadata',
  87. data: {
  88. key: data.map(({ key }) => key),
  89. metadata: valies,
  90. },
  91. })
  92. this.params.refresh()
  93. this.cancelDialog()
  94. } catch (error) {
  95. this.loading = false
  96. throw error
  97. }
  98. },
  99. },
  100. }
  101. </script>