IngressRule.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div>
  3. <a-card v-for="item in ruleList" class="mb-3" :key="item.key">
  4. <a-form-item>
  5. <a-input v-decorator="decorators.host(item.key)" :placeholder="$t('k8s.text_205')" />
  6. </a-form-item>
  7. <a-card class="mb-2" v-for="(val, i) in item.routes" :key="val.k">
  8. <a-row :gutter="1">
  9. <a-col :span="16">
  10. <a-form-item>
  11. <base-select
  12. v-decorator="decorators.services(item.key).serviceName(val.k)"
  13. resource="k8s_services"
  14. version="v1"
  15. :need-params="true"
  16. filterable
  17. :params="serviceParams"
  18. id-key="name"
  19. :item.sync="val.service"
  20. :select-props="{ placeholder: $t('k8s.text_206') }" />
  21. </a-form-item>
  22. </a-col>
  23. <a-col :span="8">
  24. <a-form-item>
  25. <!-- <base-select
  26. :options="genPortOpts(val.service)"
  27. idKey="port"
  28. nameKey="port"
  29. v-decorator="decorators.services(item.key).servicePort(val.k)"
  30. :select-props="{ placeholder: $t('k8s.text_207') }" /> -->
  31. <a-select v-decorator="decorators.services(item.key).servicePort(val.k)" :placeholder="$t('k8s.text_207')">
  32. <a-select-option v-for="v in genPortOpts(val.service)" :key="v.port" :value="v.port">{{ v.port }}</a-select-option>
  33. </a-select>
  34. </a-form-item>
  35. </a-col>
  36. </a-row>
  37. <a-form-item>
  38. <a-input v-decorator="decorators.services(item.key).servicePath(val.k)" :placeholder="$t('k8s.text_208')" />
  39. </a-form-item>
  40. <a class="ml-2 error-color" @click="remvoeRoute(item.routes, i)" v-if="item.routes.length > 1">{{$t('k8s.text_201')}}</a>
  41. </a-card>
  42. <a-button class="mt-2" type="primary" icon="plus" @click="addRoute(item)">{{$t('k8s.text_209')}}</a-button>
  43. <a-button class="ml-2" type="danger" @click="removeRule(item)" v-if="ruleList.length > 1">{{$t('k8s.text_201')}}</a-button>
  44. </a-card>
  45. <a-button type="primary" icon="plus" @click="addRule">{{$t('k8s.text_210')}}</a-button>
  46. </div>
  47. </template>
  48. <script>
  49. import { uuid } from '@/utils/utils'
  50. export default {
  51. name: 'IngressCreateRouterRules',
  52. props: {
  53. decorators: {
  54. type: Object,
  55. required: true,
  56. },
  57. cluster: {
  58. type: String,
  59. },
  60. namespace: {
  61. type: String,
  62. },
  63. },
  64. data () {
  65. const key = uuid()
  66. return {
  67. ruleList: [{
  68. key,
  69. routes: [
  70. { k: uuid(), service: {} },
  71. ],
  72. }],
  73. }
  74. },
  75. computed: {
  76. serviceParams () {
  77. if (this.namespace && this.cluster) {
  78. return {
  79. namespace: this.namespace,
  80. cluster: this.cluster,
  81. scope: this.$store.getters.scope,
  82. limit: 0,
  83. details: true,
  84. admin: this.$store.getters.isAdminMode,
  85. }
  86. }
  87. return {}
  88. },
  89. },
  90. methods: {
  91. addRule () {
  92. const key = uuid()
  93. this.ruleList.push({
  94. key,
  95. routes: [
  96. { k: uuid(), ports: [] },
  97. ],
  98. })
  99. },
  100. removeRule (item) {
  101. const index = this.ruleList.findIndex(val => val.key === item.key)
  102. this.ruleList.splice(index, 1)
  103. },
  104. addRoute (item) {
  105. item.routes.push({ k: uuid(), ports: [] })
  106. },
  107. remvoeRoute (item, i) {
  108. item.splice(i, 1)
  109. },
  110. genPortOpts (service) {
  111. if (service && service.internalEndpoint && service.internalEndpoint.ports) {
  112. return service.internalEndpoint.ports.filter(val => val.protocol && val.protocol.toLowerCase() === 'tcp') // 仅支持tcp协议,不知udp协议(没有http/https)
  113. }
  114. return []
  115. },
  116. },
  117. }
  118. </script>