index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div>
  3. <a-tabs hideAdd v-model="active" type="editable-card" @edit="onEdit" @change="handleTabChange" class="spec-container-tabs">
  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('compute.container', [i+1])}}</span>
  8. </a-badge>
  9. </template>
  10. <spec-container-form :decorators="getDecorators(pane.key)" :cluster="cluster" :namespace="namespace" :form="form" :paneKey="pane.key" />
  11. </a-tab-pane>
  12. <a-tab-pane key="add-tab" class="add-container-tab" :closable="false">
  13. <template v-slot:tab>
  14. <a-button type="dashed" size="small" @click.stop="add" icon="plus">{{$t('compute.add_container')}}</a-button>
  15. </template>
  16. </a-tab-pane>
  17. </a-tabs>
  18. </div>
  19. </template>
  20. <script>
  21. import * as R from 'ramda'
  22. import { uuid } from '@/utils/utils'
  23. import SpecContainerForm from './Form'
  24. export default {
  25. name: 'SpecContainers',
  26. components: {
  27. SpecContainerForm,
  28. },
  29. props: {
  30. decorators: {
  31. type: Object,
  32. required: true,
  33. },
  34. cluster: String,
  35. namespace: String,
  36. form: {
  37. type: Object,
  38. validator: v => v.fc,
  39. },
  40. errPanes: {
  41. type: Array,
  42. default: () => [],
  43. },
  44. },
  45. data () {
  46. const key = uuid()
  47. return {
  48. active: key,
  49. panes: [
  50. { key },
  51. ],
  52. }
  53. },
  54. created () {
  55. this.syncPanes()
  56. },
  57. methods: {
  58. syncPanes () {
  59. this.$emit('update:panes', this.panes)
  60. },
  61. showBadge (pane) {
  62. return this.errPanes.includes(pane.key)
  63. },
  64. add () {
  65. const key = uuid()
  66. this.panes.push({
  67. key,
  68. })
  69. this.active = key
  70. this.syncPanes()
  71. },
  72. onEdit (targetKey, action) {
  73. if (action === 'remove') {
  74. const index = this.panes.findIndex(val => val.key === targetKey)
  75. this.panes.splice(index, 1)
  76. if (this.active === targetKey) {
  77. this.active = this.panes[0].key
  78. }
  79. this.syncPanes()
  80. }
  81. },
  82. handleTabChange (key) {
  83. if (key === 'add-tab') {
  84. this.add()
  85. }
  86. },
  87. getDecorators (k) {
  88. const ret = {}
  89. R.forEachObjIndexed((item, key) => {
  90. if (R.is(Function, item)) {
  91. ret[key] = item(k)
  92. }
  93. }, this.decorators)
  94. return ret
  95. },
  96. },
  97. }
  98. </script>
  99. <style lang="less" scoped>
  100. .spec-container-tabs :deep(.ant-tabs-tab:last-child) {
  101. background: transparent !important;
  102. border: none !important;
  103. }
  104. .spec-container-tabs :deep(.ant-tabs-tab:last-child:hover) {
  105. background: transparent !important;
  106. }
  107. .spec-container-tabs :deep(.ant-tabs-tab:last-child.ant-tabs-tab-active) {
  108. background: transparent !important;
  109. border: none !important;
  110. }
  111. </style>