Create.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{formType === 'update' ? $t('table.action.modify') : $t('network.health_check.create')}}</div>
  4. <div slot="body">
  5. <a-form-model :model="form" :rules="rules" ref="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
  6. <a-form-item :label="$t('dictionary.cloudprovider')" class="mb-0" required>
  7. <div class="d-flex">
  8. <a-form-model-item style="width: 30%" prop="provider">
  9. <base-select
  10. v-model="form.provider"
  11. :options="providerOptions"
  12. isDefaultSelect
  13. :disabled="formType === 'update'"
  14. :select-props="{placeholder: $t('common.tips.select', [$t('network.text_198')])}" />
  15. </a-form-model-item>
  16. <a-form-model-item style="margin-left: 3%; width: 67%" prop="cloudprovider_id">
  17. <base-select
  18. v-model="form.cloudprovider_id"
  19. resource="cloudproviders"
  20. filterable
  21. remote
  22. isDefaultSelect
  23. :disabled="formType === 'update'"
  24. :params="cloudproviderParams"
  25. :select-props="{placeholder: $t('common.tips.select', [$t('dictionary.cloudprovider')])}" />
  26. </a-form-model-item>
  27. </div>
  28. </a-form-item>
  29. <a-form-model-item :label="$t('network.text_199')" prop="cloudregion_id">
  30. <base-select
  31. v-model="form.cloudregion_id"
  32. resource="cloudregions"
  33. filterable
  34. remote
  35. isDefaultSelect
  36. :params="cloudregionParams"
  37. :select-props="{placeholder: $t('common.tips.select', [$t('network.text_199')])}"
  38. :disabled="formType === 'update'" />
  39. </a-form-model-item>
  40. <a-form-model-item :label="$t('table.title.name')" prop="name">
  41. <a-input v-model="form.name" :placeholder="$t('common.tips.input', [$t('table.title.name')])" />
  42. </a-form-model-item>
  43. <a-form-model-item :label="$t('network.text_420')" prop="health_check_type">
  44. <a-select v-model="form.health_check_type" :disabled="formType === 'update'" :placeholder="$t('common.tips.select', [$t('network.text_420')])">
  45. <a-select-option value="HTTP">HTTP</a-select-option>
  46. <a-select-option value="TCP">TCP</a-select-option>
  47. </a-select>
  48. </a-form-model-item>
  49. <a-form-model-item :label="$t('network.waf.rate_limit_rule_type.http.request.uri.path')" prop="health_check_uri">
  50. <a-input v-model="form.health_check_uri" :placeholder="$t('common.tips.input', [$t('network.waf.rate_limit_rule_type.http.request.uri.path')])" />
  51. </a-form-model-item>
  52. <a-form-model-item :label="$t('network.text_165')" prop="health_check_port">
  53. <a-input-number class="w-50" v-model="form.health_check_port" :placeholder="$t('common.tips.input', [$t('network.text_165')])" />
  54. </a-form-model-item>
  55. <!-- <a-form-model-item :label="$t('network.text_156')" prop="health_check_domain">
  56. <a-input v-model="form.health_check_domain" :placeholder="$t('common.tips.input', [$t('network.text_156')])" />
  57. </a-form-model-item> -->
  58. <a-form-model-item :label="$t('network.health_check.method')" prop="health_check_method">
  59. <a-select v-model="form.health_check_method" :placeholder="$t('common.tips.select', [$t('network.health_check.method')])">
  60. <a-select-option value="GET">GET</a-select-option>
  61. <a-select-option value="HEAD">HEAD</a-select-option>
  62. <a-select-option value="POST">POST</a-select-option>
  63. </a-select>
  64. </a-form-model-item>
  65. <a-form-model-item :label="$t('network.health_check.http_code')" prop="health_check_http_code" :extra="$t('network.health_check.http_code_extra')">
  66. <a-input v-model="form.health_check_http_code" :placeholder="$t('common.tips.input', [$t('network.health_check.http_code')])" />
  67. </a-form-model-item>
  68. <a-form-model-item :label="$t('network.health_check.interval')" prop="health_check_interval">
  69. <a-input-number class="w-50" v-model="form.health_check_interval" :placeholder="$t('common.tips.input', [$t('network.health_check.interval')])" />
  70. </a-form-model-item>
  71. <a-form-model-item :label="$t('network.health_check.timeout')" prop="health_check_timeout">
  72. <a-input-number class="w-50" v-model="form.health_check_timeout" :placeholder="$t('common.tips.input', [$t('network.health_check.timeout')])" />
  73. </a-form-model-item>
  74. <a-form-model-item :label="$t('network.health_check.healthy_threshold')" prop="health_check_rise">
  75. <a-input-number class="w-50" v-model="form.health_check_rise" :placeholder="$t('common.tips.input', [$t('network.health_check.healthy_threshold')])" />
  76. </a-form-model-item>
  77. <a-form-model-item :label="$t('network.health_check.unhealthy_threshold')" prop="health_check_fall">
  78. <a-input-number class="w-50" v-model="form.health_check_fall" :placeholder="$t('common.tips.input', [$t('network.health_check.unhealthy_threshold')])" />
  79. </a-form-model-item>
  80. <!-- <a-form-model-item :label="$t('network.health_check.req')" prop="health_check_req">
  81. <a-input v-model="form.health_check_req" :placeholder="$t('common.tips.input', [$t('network.health_check.req')])" />
  82. </a-form-model-item>
  83. <a-form-model-item :label="$t('network.health_check.res')" prop="health_check_res">
  84. <a-input v-model="form.health_check_res" :placeholder="$t('common.tips.input', [$t('network.health_check.res')])" />
  85. </a-form-model-item> -->
  86. </a-form-model>
  87. </div>
  88. <div slot="footer">
  89. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  90. <a-button @click="cancelDialog">{{ $t('network.text_33') }}</a-button>
  91. </div>
  92. </base-dialog>
  93. </template>
  94. <script>
  95. import DialogMixin from '@/mixins/dialog'
  96. import WindowsMixin from '@/mixins/windows'
  97. import { validateModelForm } from '@/utils/validate'
  98. export default {
  99. name: 'HealthCheckCreateDialog',
  100. components: {
  101. },
  102. mixins: [DialogMixin, WindowsMixin],
  103. props: {
  104. parmas: Object,
  105. },
  106. data () {
  107. const providerOptions = [{ id: 'Cloudflare', name: 'Cloudflare' }].filter(item => {
  108. return (this.$store.getters.capability.loadbalancer_engine_brands || []).includes(item.id)
  109. })
  110. const { data = [], type } = this.params
  111. const initForm = data.length > 0 ? data[0] : {}
  112. return {
  113. loading: false,
  114. form: {
  115. provider: initForm.provider || providerOptions[0]?.id,
  116. cloudprovider_id: initForm.cloudprovider_id || undefined,
  117. cloudregion_id: initForm.cloudregion_id || undefined,
  118. name: initForm.name || undefined,
  119. health_check_type: initForm.health_check_type || 'HTTP',
  120. health_check_uri: initForm.health_check_uri || '/',
  121. health_check_port: initForm.health_check_port || 80,
  122. // health_check_domain: initForm.health_check_domain || undefined,
  123. health_check_method: initForm.health_check_method || 'GET',
  124. health_check_http_code: initForm.health_check_http_code || '200',
  125. health_check_interval: initForm.health_check_interval || 60,
  126. health_check_timeout: initForm.health_check_timeout || 5,
  127. health_check_rise: initForm.health_check_rise || 3,
  128. health_check_fall: initForm.health_check_fall || 15,
  129. // health_check_req: undefined,
  130. // health_check_res: undefined,
  131. },
  132. providerOptions,
  133. formType: type,
  134. rules: {
  135. provider: [{ required: true, message: this.$t('common.tips.select', [this.$t('network.text_198')]) }],
  136. cloudprovider_id: [{ required: true, message: this.$t('common.tips.select', [this.$t('dictionary.cloudprovider')]) }],
  137. cloudregion_id: [{ required: true, message: this.$t('common.tips.select', [this.$t('network.text_199')]) }],
  138. name: [{ required: true, validator: this.$validate('resourceName') }],
  139. health_check_type: [{ required: true, message: this.$t('common.tips.select', [this.$t('network.text_420')]) }],
  140. health_check_uri: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.waf.rate_limit_rule_type.http.request.uri.path')]) }],
  141. health_check_port: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.text_165')]) }],
  142. // health_check_domain: [{
  143. // required: true,
  144. // validator: this.$validate('domain'),
  145. // }],
  146. health_check_method: [{ required: true, message: this.$t('common.tips.select', [this.$t('network.health_check.method')]) }],
  147. health_check_http_code: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.http_code')]) }],
  148. health_check_interval: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.interval')]) }],
  149. health_check_timeout: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.timeout')]) }],
  150. health_check_rise: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.healthy_threshold')]) }],
  151. health_check_fall: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.unhealthy_threshold')]) }],
  152. // health_check_req: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.req')]) }],
  153. // health_check_res: [{ required: true, message: this.$t('common.tips.input', [this.$t('network.health_check.res')]) }],
  154. },
  155. }
  156. },
  157. computed: {
  158. cloudregionParams () {
  159. return {
  160. limit: 20,
  161. provider: this.form.provider,
  162. show_emulated: true,
  163. scope: this.$store.getters.scope,
  164. }
  165. },
  166. cloudproviderParams () {
  167. return {
  168. limit: 20,
  169. provider: this.form.provider,
  170. scope: this.$store.getters.scope,
  171. }
  172. },
  173. },
  174. methods: {
  175. genParams () {
  176. const ret = {
  177. ...this.form,
  178. }
  179. return ret
  180. },
  181. async handleConfirm () {
  182. try {
  183. this.loading = true
  184. await validateModelForm(this.$refs.form)
  185. const data = this.genParams()
  186. if (this.formType === 'update') {
  187. await this.params.onManager('update', {
  188. id: this.params.data[0].id,
  189. managerArgs: { data },
  190. })
  191. } else {
  192. await this.params.onManager('create', {
  193. managerArgs: { data },
  194. })
  195. }
  196. this.loading = false
  197. this.cancelDialog()
  198. } catch (e) {
  199. this.loading = false
  200. throw e
  201. }
  202. },
  203. },
  204. }
  205. </script>