SetStaticWebsit.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <div>
  3. <page-header :title="$t('storage.text_183')" />
  4. <page-body needMarginBottom>
  5. <dialog-selected-tips :name="$t('storage.text_18')" :count="1" :action="$t('storage.text_183')" />
  6. <dialog-table class="mb-2" :data="currentItem" :columns="bucketColumns" />
  7. <a-divider />
  8. <a-form :form="form.fc">
  9. <a-form-item :label="$t('storage.text_41')" v-bind="formItemLayout">
  10. <a-switch v-decorator="decorators.status" :checked-children="$t('storage.text_184')" :un-checked-children="$t('storage.text_185')" @change="handleStatusChange" />
  11. </a-form-item>
  12. <template v-if="status">
  13. <div>
  14. <a-form-item :label="$t('storage.text_186')" v-bind="formItemLayout" :extra="$t('storage.text_187')">
  15. <a-input v-decorator="decorators.index" />
  16. </a-form-item>
  17. <a-form-item :label="$t('storage.text_188')" v-bind="formItemLayout" :extra="$t('storage.text_189')">
  18. <a-input v-decorator="decorators.error_document" />
  19. </a-form-item>
  20. </div>
  21. </template>
  22. </a-form>
  23. </page-body>
  24. <page-footer>
  25. <template #right>
  26. <div>
  27. <a-button class="mr-2" type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  28. <a-button @click="handleCancel">{{ $t('dialog.cancel') }}</a-button>
  29. </div>
  30. </template>
  31. </page-footer>
  32. </div>
  33. </template>
  34. <script>
  35. import { getNameDescriptionTableColumn, getStatusTableColumn } from '@/utils/common/tableColumn'
  36. export default {
  37. name: 'SetStaticWebsit',
  38. data () {
  39. return {
  40. loading: false,
  41. status: !!this.$route.query.url,
  42. form: {
  43. fc: this.$form.createForm(this),
  44. },
  45. formItemLayout: {
  46. labelCol: { span: 3 },
  47. wrapperCol: { span: 21 },
  48. },
  49. decorators: {
  50. status: [
  51. 'status',
  52. {
  53. valuePropName: 'checked',
  54. initialValue: !!this.$route.query.url,
  55. },
  56. ],
  57. index: [
  58. 'index',
  59. {
  60. initialValue: this.$route.query.index || '',
  61. rules: [
  62. { required: true, message: this.$t('storage.text_190') },
  63. ],
  64. },
  65. ],
  66. error_document: [
  67. 'error_document',
  68. {
  69. initialValue: this.$route.query.error_document || '',
  70. rules: [
  71. { required: true, message: this.$t('storage.text_190') },
  72. ],
  73. },
  74. ],
  75. },
  76. currentItem: [],
  77. bucketColumns: [
  78. getNameDescriptionTableColumn(),
  79. getStatusTableColumn({ statusModule: 'bucket' }),
  80. {
  81. field: 'storage_class',
  82. title: this.$t('storage.text_38'),
  83. width: 120,
  84. formatter: ({ row }) => {
  85. return row.storage_class || '-'
  86. },
  87. },
  88. ],
  89. }
  90. },
  91. async created () {
  92. const { data: { data } } = await this.fetchBucketData(this.$route.query.id)
  93. this.currentItem = data
  94. },
  95. methods: {
  96. fetchBucketData (id) {
  97. return new this.$Manager('buckets').list({
  98. params: {
  99. id,
  100. batchGet: true,
  101. },
  102. })
  103. },
  104. doSet (data) {
  105. return new this.$Manager('buckets').performAction({
  106. id: this.$route.query.id,
  107. action: 'set-website',
  108. data: {
  109. ...data,
  110. protocol: 'http',
  111. },
  112. })
  113. },
  114. doDelete () {
  115. return new this.$Manager('buckets').performAction({
  116. id: this.$route.query.id,
  117. action: 'delete-website',
  118. })
  119. },
  120. handleStatusChange (val) {
  121. this.status = val
  122. },
  123. handleCancel () {
  124. this.$router.back()
  125. },
  126. async handleConfirm () {
  127. this.loading = true
  128. try {
  129. if (this.status) {
  130. const values = await this.form.fc.validateFields()
  131. await this.doSet(values)
  132. } else {
  133. await this.doDelete()
  134. }
  135. this.loading = false
  136. this.$message.success(this.$t('storage.text_191'))
  137. this.$router.push('/bucket')
  138. } catch (err) {
  139. this.loading = false
  140. }
  141. },
  142. },
  143. }
  144. </script>