index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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="getBindProps(item.key)" />
  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 }" :extra="valueExtra">
  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" shape="circle" icon="minus" size="small" @click="del(item)" class="mt-2 ml-2" />
  18. </div>
  19. <div class="d-flex align-items-center">
  20. <a-tooltip :title="disableConf?.tooltip">
  21. <a-button type="primary" :disabled="disableConf?.disabled" shape="circle" icon="plus" size="small" @click="add" />
  22. <a-button type="link" :disabled="disableConf?.disabled" @click="add">{{$t('compute.repo.add', [ title ])}}</a-button>
  23. </a-tooltip>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import * as R from 'ramda'
  29. import { uuid } from '@/utils/utils'
  30. import i18n from '@/locales'
  31. export default {
  32. name: 'ContainerLables',
  33. props: {
  34. title: {
  35. type: String,
  36. default: i18n.t('compute.repo.label'),
  37. },
  38. keyLabel: {
  39. type: String,
  40. default: i18n.t('compute.repo.key'),
  41. },
  42. valueLabel: {
  43. type: String,
  44. default: i18n.t('compute.repo.value'),
  45. },
  46. decorators: {
  47. type: Object,
  48. validator: val => R.is(Function, val.key) && R.is(Function, val.value),
  49. },
  50. keyPlaceholder: {
  51. type: String,
  52. default: '',
  53. },
  54. valuePlaceholder: {
  55. type: String,
  56. default: '',
  57. },
  58. keyBaseSelectProps: {
  59. type: Object,
  60. },
  61. firstCanDelete: {
  62. type: Boolean,
  63. default: true,
  64. },
  65. checkedValues: {
  66. type: Array,
  67. default: () => [],
  68. },
  69. disableConf: {
  70. type: Object,
  71. default: () => { },
  72. },
  73. },
  74. data () {
  75. return {
  76. labelList: [],
  77. }
  78. },
  79. watch: {
  80. labelList: {
  81. handler (val) {
  82. this.$emit('label-change', val)
  83. },
  84. deep: true,
  85. },
  86. },
  87. methods: {
  88. add () {
  89. this.labelList.push({ key: uuid() })
  90. },
  91. del (item) {
  92. const index = this.labelList.findIndex(val => val.key === item.key)
  93. this.labelList.splice(index, 1)
  94. },
  95. reset () {
  96. this.labelList = []
  97. },
  98. getBindProps (key) {
  99. const { options } = this.keyBaseSelectProps
  100. const bindProps = {
  101. ...this.keyBaseSelectProps,
  102. options: options.filter(v => {
  103. if (this.checkedValues?.length) {
  104. return !this.checkedValues.includes(v.id)
  105. }
  106. return true
  107. }),
  108. }
  109. return bindProps
  110. },
  111. },
  112. }
  113. </script>