FormItems.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!-- 创建和修改属性都需要的 -->
  2. <template>
  3. <div>
  4. <template v-if="storage_type === 'rbd'">
  5. <a-form-item label="Ceph Mon Host" v-if="!edit">
  6. <a-input :placeholder="$t('storage.host.input.place_holder')" v-decorator="decorators.rbd_mon_host" />
  7. </a-form-item>
  8. <a-form-item label="Ceph Pool" v-if="!edit">
  9. <a-input :placeholder="$t('storage.text_21')" v-decorator="decorators.rbd_pool" />
  10. </a-form-item>
  11. <a-form-item label="Ceph Key">
  12. <a-input :placeholder="$t('storage.text_20')" v-decorator="decorators.rbd_key" />
  13. </a-form-item>
  14. </template>
  15. <template v-if="storage_type === 'nfs'">
  16. <a-form-item label="NFS Host">
  17. <a-input :placeholder="$t('storage.host.input.place_holder')" v-decorator="decorators.nfs_host" />
  18. </a-form-item>
  19. <a-form-item label="NFS Shared Dir">
  20. <a-input :placeholder="$t('storage.path.input.place_holder')" v-decorator="decorators.nfs_shared_dir" />
  21. </a-form-item>
  22. </template>
  23. <template v-if="storage_type === 'slvm'">
  24. <a-form-item label="SlvmVgName">
  25. <a-input :placeholder="$t('common.tips.input', ['SlvmVgName'])" v-decorator="decorators.slvm_vg_name" />
  26. </a-form-item>
  27. </template>
  28. </div>
  29. </template>
  30. <script>
  31. import { REGEXP } from '@/utils/validate'
  32. export default {
  33. name: 'BlockStorageFormItems',
  34. props: {
  35. storage_type: {
  36. type: String,
  37. },
  38. edit: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. editData: {
  43. type: Object,
  44. },
  45. },
  46. inject: ['form'],
  47. computed: {
  48. decorators () {
  49. const hostCheckValid = (rule, value, _callback) => {
  50. let isValid = true
  51. if (!value || value === '') isValid = false
  52. const parts = value.split(',')
  53. if (parts.some(part => {
  54. const trimmedPart = part.trim()
  55. return !REGEXP.IPv4.regexp.test(trimmedPart) && !REGEXP.IPv6.regexp.test(trimmedPart)
  56. })) {
  57. isValid = false
  58. }
  59. return isValid ? _callback() : _callback(new Error(this.$t('storage.host.input.place_holder')))
  60. }
  61. const commonCheckValid = (name) => {
  62. return (rule, value, _callback) => {
  63. const pattern = /^[+=./a-zA-Z0-9_-]+$/
  64. if (!value || value === '') {
  65. return _callback(new Error(this.$t('storage.text_25', [name])))
  66. } else if (!pattern.test(value)) {
  67. return _callback(new Error(this.$t('storage.text_25', [name])))
  68. } else {
  69. _callback()
  70. }
  71. }
  72. }
  73. return {
  74. rbd_mon_host: [
  75. 'rbd_mon_host',
  76. {
  77. validateFirst: true,
  78. initialValue: this.editData?.storage_conf?.mon_host || '',
  79. rules: [
  80. { required: true, validator: hostCheckValid, trigger: 'blur' },
  81. ],
  82. },
  83. ],
  84. rbd_key: [
  85. 'rbd_key',
  86. {
  87. initialValue: this.editData?.storage_conf?.key || '',
  88. rules: [
  89. ],
  90. },
  91. ],
  92. rbd_pool: [
  93. 'rbd_pool',
  94. {
  95. validateFirst: true,
  96. initialValue: this.editData?.storage_conf?.pool || '',
  97. rules: [
  98. { required: true, message: this.$t('storage.text_28'), trigger: 'blur' },
  99. { validator: commonCheckValid('Ceph Pool') },
  100. ],
  101. },
  102. ],
  103. nfs_host: [
  104. 'nfs_host',
  105. {
  106. validateFirst: true,
  107. initialValue: this.editData?.storage_conf?.nfs_host || '',
  108. rules: [
  109. { required: true, validator: hostCheckValid, trigger: 'blur' },
  110. ],
  111. },
  112. ],
  113. nfs_shared_dir: [
  114. 'nfs_shared_dir',
  115. {
  116. initialValue: this.editData?.storage_conf?.nfs_shared_dir || '',
  117. rules: [
  118. { required: true, message: this.$t('storage.nfs_shared_dir.validate.prompt'), trigger: 'blur' },
  119. ],
  120. },
  121. ],
  122. slvm_vg_name: [
  123. 'slvm_vg_name',
  124. {
  125. initialValue: this.editData?.storage_conf?.slvm_vg_name || '',
  126. rules: [
  127. { required: true, message: this.$t('common.tips.input', ['SlvmVgName']), trigger: 'blur' },
  128. ],
  129. },
  130. ],
  131. }
  132. },
  133. },
  134. }
  135. </script>