index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div>
  3. <div class="d-flex" v-for="(item) in labelList" :key="item.key">
  4. <a-form-item :wrapperCol="{ span: 24 }">
  5. <a-input-group compact v-if="keyBaseSelectProps">
  6. <div class="d-flex">
  7. <a-input class="oc-addonBefore ant-input-group-addon" style="width: 80px;" :defaultValue="keyLabel" readonly />
  8. <base-select v-decorator="decorators.key(item.key)" v-bind="keyBaseSelectProps" />
  9. </div>
  10. </a-input-group>
  11. <a-input v-else :addonBefore="keyLabel" v-decorator="decorators.key(item.key)" :placeholder="keyPlaceholder" />
  12. </a-form-item>
  13. <div class="mx-3"> = </div>
  14. <a-form-item :wrapperCol="{ span: 24 }">
  15. <a-input :addonBefore="valueLabel" v-decorator="decorators.value(item.key)" :placeholder="valuePlaceholder" />
  16. </a-form-item>
  17. <a-button v-if="firstCanDelete || labelList.length > 1" type="danger" shape="circle" icon="delete" @click="del(item)" class="mt-1 ml-3" />
  18. </div>
  19. <a-button type="primary" icon="plus" @click="add">{{$t('k8s.text_81', [ title ])}}</a-button>
  20. </div>
  21. </template>
  22. <script>
  23. import * as R from 'ramda'
  24. import { uuid } from '@/utils/utils'
  25. import i18n from '@/locales'
  26. export default {
  27. name: 'K8SLables',
  28. props: {
  29. title: {
  30. type: String,
  31. default: i18n.t('k8s.text_82'),
  32. },
  33. keyLabel: {
  34. type: String,
  35. default: i18n.t('k8s.text_83'),
  36. },
  37. valueLabel: {
  38. type: String,
  39. default: i18n.t('k8s.text_84'),
  40. },
  41. decorators: {
  42. type: Object,
  43. validator: val => R.is(Function, val.key) && R.is(Function, val.value),
  44. },
  45. keyPlaceholder: {
  46. type: String,
  47. default: i18n.t('k8s.text_85'),
  48. },
  49. valuePlaceholder: {
  50. type: String,
  51. default: i18n.t('k8s.text_85'),
  52. },
  53. keyBaseSelectProps: {
  54. type: Object,
  55. },
  56. firstCanDelete: {
  57. type: Boolean,
  58. default: true,
  59. },
  60. },
  61. data () {
  62. return {
  63. labelList: [],
  64. }
  65. },
  66. methods: {
  67. add () {
  68. this.labelList.push({ key: uuid() })
  69. },
  70. del (item) {
  71. const index = this.labelList.findIndex(val => val.key === item.key)
  72. this.labelList.splice(index, 1)
  73. },
  74. },
  75. }
  76. </script>