BackupStorageUpdate.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('compute.backup_storage')" :count="params.data.length" :action="action" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('storage.text_38')">
  9. {{ this.getStorageType }}
  10. </a-form-item>
  11. <a-form-item label="NFS Host" v-if="isNfs">
  12. <a-input :placeholder="$t('storage.host.input.place_holder')" v-decorator="decorators.nfs_host" />
  13. </a-form-item>
  14. <a-form-item label="NFS Shared Dir" v-if="isNfs">
  15. <a-input :placeholder="$t('storage.path.input.place_holder')" v-decorator="decorators.nfs_shared_dir" />
  16. </a-form-item>
  17. <a-form-item label="Bucket URL" v-if="isObjectStorage">
  18. <a-input :placeholder="$t('storage.url.input.place_holder')" v-decorator="decorators.object_bucket_url" />
  19. </a-form-item>
  20. <a-form-item label="Access Key" v-if="isObjectStorage">
  21. <a-input :placeholder="$t('storage.access_key.input.place_holder')" v-decorator="decorators.object_access_key" />
  22. </a-form-item>
  23. <a-form-item label="Secret" v-if="isObjectStorage">
  24. <a-input-password :placeholder="$t('storage.access_secret.input.place_holder')" v-decorator="decorators.object_secret" />
  25. </a-form-item>
  26. <a-form-item label="Signing Version" v-if="isObjectStorage">
  27. <a-radio-group v-decorator="decorators.object_sign_ver">
  28. <a-radio-button value="">{{ $t('common_712') }}</a-radio-button>
  29. <a-radio-button value="v2">V2</a-radio-button>
  30. <a-radio-button value="v4">V4</a-radio-button>
  31. </a-radio-group>
  32. </a-form-item>
  33. <a-form-item :label="$t('storage.capacity')" v-show="false">
  34. <a-input-number :min="0" v-decorator="decorators.capacity_mb" /> GB
  35. </a-form-item>
  36. <a-form-item label="Public Bucket URL" v-if="isObjectStorage">
  37. <a-input :placeholder="$t('storage.url.input.place_holder')" v-decorator="decorators.object_bucket_url_ext" />
  38. </a-form-item>
  39. </a-form>
  40. </div>
  41. <div slot="footer">
  42. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  43. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  44. </div>
  45. </base-dialog>
  46. </template>
  47. <script>
  48. import { mapGetters } from 'vuex'
  49. import DialogMixin from '@/mixins/dialog'
  50. import WindowsMixin from '@/mixins/windows'
  51. export default {
  52. name: 'BackupStorageUpdateDialog',
  53. mixins: [WindowsMixin, DialogMixin],
  54. data () {
  55. return {
  56. loading: false,
  57. form: {
  58. fc: this.$form.createForm(this),
  59. },
  60. formItemLayout: {
  61. wrapperCol: {
  62. span: 20,
  63. },
  64. labelCol: {
  65. span: 4,
  66. },
  67. },
  68. }
  69. },
  70. computed: {
  71. ...mapGetters(['isAdminMode', 'userInfo', 'l3PermissionEnable']),
  72. decorators () {
  73. const hostCheckValid = (rule, value, _callback) => {
  74. const pattern = /^(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))$/
  75. const ips = value.split(',')
  76. if (!value || value === '') {
  77. return _callback(new Error(this.$t('storage.nfs_host_check_reqiure')))
  78. }
  79. ips.forEach((item) => {
  80. const [ip, dir] = item.split(':')
  81. if (!pattern.test(ip)) {
  82. return _callback(new Error(this.$t('storage.nfs_host_check_valid')))
  83. } else {
  84. if (dir) {
  85. const reg = /^\/.+/
  86. if (!reg.test(dir)) {
  87. return _callback(new Error(this.$t('storage.nfs_host_check_valid')))
  88. }
  89. }
  90. }
  91. })
  92. _callback()
  93. }
  94. return {
  95. nfs_host: [
  96. 'nfs_host',
  97. {
  98. initialValue: this.params.data[0].nfs_host,
  99. validateFirst: true,
  100. rules: [
  101. { required: true, message: this.$t('storage.nfs_host.validate.prompt'), trigger: 'blur' },
  102. { validator: hostCheckValid, trigger: 'blur' },
  103. ],
  104. },
  105. ],
  106. nfs_shared_dir: [
  107. 'nfs_shared_dir',
  108. {
  109. initialValue: this.params.data[0].nfs_shared_dir,
  110. rules: [
  111. { required: true, message: this.$t('storage.nfs_shared_dir.validate.prompt'), trigger: 'blur' },
  112. ],
  113. },
  114. ],
  115. object_bucket_url: [
  116. 'object_bucket_url',
  117. {
  118. initialValue: this.params.data[0].object_bucket_url,
  119. validateFirst: true,
  120. rules: [
  121. { required: false, message: this.$t('storage.object_bucket_url.validate.prompt'), trigger: 'blur' },
  122. ],
  123. },
  124. ],
  125. object_access_key: [
  126. 'object_access_key',
  127. {
  128. initialValue: this.params.data[0].object_access_key,
  129. rules: [
  130. { required: false, message: this.$t('storage.object_access_key.validate.prompt'), trigger: 'blur' },
  131. ],
  132. },
  133. ],
  134. object_secret: [
  135. 'object_secret',
  136. {
  137. initialValue: this.params.data[0].object_secret,
  138. rules: [
  139. { required: false, message: this.$t('storage.object_secret.validate.prompt'), trigger: 'blur' },
  140. ],
  141. },
  142. ],
  143. object_sign_ver: [
  144. 'object_sign_ver',
  145. {
  146. initialValue: this.params.data[0].object_sign_ver ? this.params.data[0].object_sign_ver : '',
  147. },
  148. ],
  149. object_bucket_url_ext: [
  150. 'object_bucket_url_ext',
  151. {
  152. initialValue: this.params.data[0].object_bucket_url_ext,
  153. validateFirst: true,
  154. rules: [
  155. { required: false, message: this.$t('storage.object_bucket_url_ext.validate.prompt'), trigger: 'blur' },
  156. ],
  157. },
  158. ],
  159. }
  160. },
  161. columns () {
  162. const showFields = ['name', 'status', 'storage_type']
  163. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  164. },
  165. isNfs () {
  166. return this.params.data[0].storage_type === 'nfs'
  167. },
  168. isObjectStorage () {
  169. return this.params.data[0].storage_type === 'object'
  170. },
  171. getStorageType () {
  172. if (this.isNfs) {
  173. return 'NFS'
  174. } else {
  175. return this.$t('storage.object_storage')
  176. }
  177. },
  178. },
  179. methods: {
  180. async handleConfirm () {
  181. const manager = new this.$Manager('backupstorages')
  182. try {
  183. const values = await this.form.fc.validateFields(Object.keys(this.decorators))
  184. await manager.update({ id: this.params.data[0].id, data: { ...values } })
  185. this.cancelDialog()
  186. this.params.refresh && this.params.refresh()
  187. } catch (error) {
  188. throw error
  189. }
  190. },
  191. },
  192. }
  193. </script>