Ceph.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div>
  3. <page-header :title="$t('k8s.create')" />
  4. <a-form-model
  5. class="mt-3"
  6. ref="formRef"
  7. :model="formData"
  8. :label-col="labelCol"
  9. :wrapper-col="wrapperCol">
  10. <a-card class="mb-2 card" hoverable v-for="(item, i) in formData.config" :key="item.key">
  11. <a-form-model-item
  12. :label="$t('k8s.text_243')"
  13. :prop="'config.' + i + '.clusterId'"
  14. :rules="[
  15. { required: true, message: $t('k8s.text_244'), trigger: 'blur' },
  16. ]">
  17. <a-input v-model="item.clusterId" :placeholder="$t('k8s.text_245')" />
  18. </a-form-model-item>
  19. <a-form-model-item label="Mon Hosts">
  20. <a-form-model-item
  21. v-for="(val, k) in item.monitors"
  22. :key="val.key"
  23. :prop="'config.' + i + '.monitors.' + k + '.monitor'"
  24. :rules="[
  25. { required: true, message: $t('k8s.text_246'), trigger: 'blur' },
  26. ]">
  27. <div class="d-flex align-items-center">
  28. <a-input v-model="val.monitor" :placeholder="$t('k8s.text_247')" />
  29. <a-icon type="minus-circle" style="color: #F56C6C;" class="cursor-pointer ml-2" v-if="item.monitors.length > 1" @click="decreaseMonitor(item, k)" />
  30. <!-- <i style="color: #F56C6C;" class="cursor-pointer ml-2" v-if="item.monitors.length > 1" @click="decreaseMonitor(item, k)" /> -->
  31. </div>
  32. </a-form-model-item>
  33. <a-button type="link" size="small" @click="addMonitor(item)">{{$t('k8s.text_248')}}</a-button>
  34. </a-form-model-item>
  35. <div class="d-flex flex-row-reverse">
  36. <a-button style="color: #F56C6C;" type="link" v-if="formData.config.length > 1" @click="decreaseConfig(item)">{{$t('k8s.text_201')}}</a-button>
  37. </div>
  38. </a-card>
  39. <a-button type="link" size="small" @click="addConfig">{{$t('k8s.text_249')}}</a-button>
  40. <a-form-model-item :wrapper-col="{ span: 20, offset: 3 }">
  41. <a-button class="mr-2" type="primary" @click="handleConfirm('formRef')" :loading="loading">{{$t('common.create')}}</a-button>
  42. <a-button @click="cancel">{{$t('k8s.text_162')}}</a-button>
  43. </a-form-model-item>
  44. </a-form-model>
  45. </div>
  46. </template>
  47. <script>
  48. import * as R from 'ramda'
  49. import { mapGetters } from 'vuex'
  50. import { uuid } from '@/utils/utils'
  51. export default {
  52. name: 'KubeComponentCeph',
  53. props: {
  54. updateData: {
  55. type: Object,
  56. },
  57. },
  58. data () {
  59. let formData = {
  60. config: [
  61. {
  62. key: uuid(),
  63. clusterId: '',
  64. monitors: [{
  65. monitor: '',
  66. key: uuid(),
  67. }],
  68. },
  69. ],
  70. }
  71. if (this.updateData && R.is(Array, this.updateData.config)) {
  72. formData = {
  73. config: this.updateData.config.map(val => {
  74. return {
  75. key: uuid(),
  76. clusterId: val.clusterId,
  77. monitors: val.monitors.map(v => ({
  78. monitor: v,
  79. key: uuid(),
  80. })),
  81. }
  82. }),
  83. }
  84. }
  85. return {
  86. loading: false,
  87. labelCol: { span: 4 },
  88. wrapperCol: { span: 14 },
  89. formData,
  90. }
  91. },
  92. computed: {
  93. ...mapGetters(['userInfo', 'scope', 'isAdminMode']),
  94. },
  95. methods: {
  96. addConfig () {
  97. this.formData.config.push({
  98. key: uuid(),
  99. clusterId: '',
  100. monitors: [{
  101. monitor: '',
  102. k: uuid(),
  103. }],
  104. })
  105. },
  106. decreaseConfig (item) {
  107. const index = this.formData.config.findIndex(val => val.key === item.key)
  108. this.formData.config.splice(index, 1)
  109. },
  110. decreaseMonitor (item, k) {
  111. item.monitors.splice(k, 1)
  112. },
  113. addMonitor (item) {
  114. const index = this.formData.config.findIndex(val => val.key === item.key)
  115. this.formData.config[index].monitors.push({
  116. monitor: '',
  117. k: uuid(),
  118. })
  119. },
  120. cancel () {
  121. this.$router.push('/k8s-kubecomponent')
  122. },
  123. async handleConfirm (formName) {
  124. this.$refs[formName].validate((valid) => {
  125. if (valid) {
  126. const data = this.formData.config.map(val => {
  127. return {
  128. clusterId: val.clusterId,
  129. monitors: val.monitors.map(v => v.monitor),
  130. }
  131. })
  132. this.$emit('submit', { config: data })
  133. }
  134. })
  135. },
  136. },
  137. }
  138. </script>