index.vue 2.6 KB

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