index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div>
  3. <a-tabs hideAdd v-model="active" type="editable-card" @edit="onEdit">
  4. <a-tab-pane v-for="(pane, i) in panes" :key="pane.key" :closable="panes.length > 1">
  5. <template v-slot:tab>
  6. <a-badge :dot="showBadge(pane)" :offset="[(panes.length > 1 ? 24 : 10), -5]">
  7. <span>{{$t('k8s.text_114', [i+1])}}</span>
  8. </a-badge>
  9. </template>
  10. <spec-container-form :decorators="getDecorators(pane.key)" :cluster="cluster" :namespace="namespace" :form="form" />
  11. </a-tab-pane>
  12. <template v-slot:tabBarExtraContent>
  13. <a-button type="link" @click="add">{{$t('k8s.text_115')}}</a-button>
  14. </template>
  15. </a-tabs>
  16. </div>
  17. </template>
  18. <script>
  19. import * as R from 'ramda'
  20. import SpecContainerForm from '@K8S/sections/SpecContainer/Form'
  21. import { uuid } from '@/utils/utils'
  22. export default {
  23. name: 'K8SSpecContainers',
  24. components: {
  25. SpecContainerForm,
  26. },
  27. props: {
  28. decorators: {
  29. type: Object,
  30. required: true,
  31. },
  32. cluster: String,
  33. namespace: String,
  34. form: {
  35. type: Object,
  36. validator: v => v.fc,
  37. },
  38. errPanes: {
  39. type: Array,
  40. default: () => [],
  41. },
  42. },
  43. data () {
  44. const key = uuid()
  45. return {
  46. active: key,
  47. panes: [
  48. { key },
  49. ],
  50. }
  51. },
  52. created () {
  53. this.syncPanes()
  54. },
  55. methods: {
  56. syncPanes () {
  57. this.$emit('update:panes', this.panes)
  58. },
  59. showBadge (pane) {
  60. return this.errPanes.includes(pane.key)
  61. },
  62. add () {
  63. const key = uuid()
  64. this.panes.push({
  65. key,
  66. })
  67. this.active = key
  68. this.syncPanes()
  69. },
  70. onEdit (targetKey, action) {
  71. if (action === 'remove') {
  72. const index = this.panes.findIndex(val => val.key === targetKey)
  73. this.panes.splice(index, 1)
  74. if (this.active === targetKey) {
  75. this.active = this.panes[0].key
  76. }
  77. this.syncPanes()
  78. }
  79. },
  80. getDecorators (k) {
  81. const ret = {}
  82. R.forEachObjIndexed((item, key) => {
  83. if (R.is(Function, item)) {
  84. ret[key] = item(k)
  85. }
  86. }, this.decorators)
  87. return ret
  88. },
  89. },
  90. }
  91. </script>