IngressRule.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 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-card>
  41. <a-button class="mt-2" type="primary" icon="plus" @click="addRoute(item)">{{$t('k8s.text_209')}}</a-button>
  42. </a-card>
  43. <a-button type="primary" icon="plus" @click="addRule">{{$t('k8s.text_210')}}</a-button>
  44. </div>
  45. </template>
  46. <script>
  47. import { uuid } from '@/utils/utils'
  48. export default {
  49. name: 'IngressCreateRouterRules',
  50. props: {
  51. decorators: {
  52. type: Object,
  53. required: true,
  54. },
  55. cluster: {
  56. type: String,
  57. },
  58. namespace: {
  59. type: String,
  60. },
  61. },
  62. data () {
  63. const key = uuid()
  64. return {
  65. ruleList: [{
  66. key,
  67. routes: [
  68. { k: uuid(), service: {} },
  69. ],
  70. }],
  71. }
  72. },
  73. computed: {
  74. serviceParams () {
  75. if (this.namespace && this.cluster) {
  76. return {
  77. namespace: this.namespace,
  78. cluster: this.cluster,
  79. scope: this.$store.getters.scope,
  80. limit: 0,
  81. details: true,
  82. admin: this.$store.getters.isAdminMode,
  83. }
  84. }
  85. return {}
  86. },
  87. },
  88. methods: {
  89. addRule () {
  90. const key = uuid()
  91. this.ruleList.push({
  92. key,
  93. routes: [
  94. { k: uuid(), ports: [] },
  95. ],
  96. })
  97. },
  98. addRoute (item) {
  99. item.routes.push({ k: uuid(), ports: [] })
  100. },
  101. genPortOpts (service) {
  102. if (service && service.internalEndpoint && service.internalEndpoint.ports) {
  103. return service.internalEndpoint.ports.filter(val => val.protocol && val.protocol.toLowerCase() === 'tcp') // 仅支持tcp协议,不知udp协议(没有http/https)
  104. }
  105. return []
  106. },
  107. },
  108. }
  109. </script>