index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <a-spin :spinning="loading">
  3. <page-header :title="$t('network.update_cluster')" />
  4. <page-body>
  5. <a-form :form="form.fc" v-bind="formItemLayout">
  6. <a-form-item :label="$t('network.text_21')">
  7. <a-input :disabled="!!lbAgentId" v-decorator="decorators.name" :placeholder="$t('network.text_44')" />
  8. </a-form-item>
  9. <a-form-item :label="$t('common.description')" v-bind="formItemLayout">
  10. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  11. </a-form-item>
  12. <a-form-item :label="$t('network.text_83')" :extra="$t('network.text_84')">
  13. <a-switch :checkedChildren="$t('network.text_85')" :unCheckedChildren="$t('network.text_86')" v-decorator="decorators.preempt" />
  14. </a-form-item>
  15. <a-form-item :label="$t('network.text_87')" :extra="$t('network.text_88')">
  16. <a-input-number v-decorator="decorators.virtual_router_id" :max="255" :min="1" />
  17. </a-form-item>
  18. <a-form-item :label="$t('network.text_92')" :extra="$t('network.text_93')">
  19. <a-input v-decorator="decorators.advert_int" type="number" :addonAfter="$t('network.text_76')" />
  20. </a-form-item>
  21. <a-form-item :label="$t('network.text_95')" :extra="$t('network.text_96')">
  22. <a-input v-decorator="decorators.pass" />
  23. </a-form-item>
  24. <a-form-item v-if="!lbAgentId" :label="$t('common.text00012')" class="mb-0">
  25. <tag v-decorator="decorators.__meta__" />
  26. </a-form-item>
  27. </a-form>
  28. </page-body>
  29. <page-footer>
  30. <template v-slot:right>
  31. <a-button type="primary" :loading="submiting" @click="handleSubmit">{{ $t('common.ok') }}</a-button>
  32. <a-button class="ml-2" @click="handleCancel">{{ $t('dialog.cancel') }}</a-button>
  33. </template>
  34. </page-footer>
  35. </a-spin>
  36. </template>
  37. <script>
  38. import workflowMixin from '@/mixins/workflow'
  39. import WindowsMixin from '@/mixins/windows'
  40. import Tag from '@/sections/Tag'
  41. import validateForm from '@/utils/validate'
  42. export default {
  43. name: 'LBClusterCreate',
  44. components: {
  45. Tag,
  46. },
  47. mixins: [WindowsMixin, workflowMixin],
  48. data () {
  49. return {
  50. loading: false,
  51. submiting: false,
  52. form: {
  53. fc: this.$form.createForm(this),
  54. },
  55. decorators: {
  56. name: [
  57. 'name',
  58. {
  59. validateFirst: true,
  60. rules: [
  61. { required: true, message: this.$t('network.text_116') },
  62. { validator: this.$validate('resourceName') },
  63. ],
  64. },
  65. ],
  66. description: ['description'],
  67. __meta__: [
  68. '__meta__',
  69. {
  70. rules: [
  71. { validator: validateForm('tagName') },
  72. ],
  73. },
  74. ],
  75. virtual_router_id: [
  76. 'virtual_router_id',
  77. {
  78. initialValue: 1,
  79. rules: [
  80. { required: true, message: this.$t('network.text_118') },
  81. ],
  82. },
  83. ],
  84. preempt: [
  85. 'preempt',
  86. {
  87. initialValue: false,
  88. valuePropName: 'checked',
  89. rules: [
  90. { required: true, message: this.$t('network.text_120') },
  91. ],
  92. },
  93. ],
  94. advert_int: [
  95. 'advert_int',
  96. {
  97. initialValue: 1,
  98. normalize: v => Number(v),
  99. rules: [
  100. { required: true, message: this.$t('network.text_121') },
  101. { type: 'integer', min: 1, max: 255, message: this.$t('network.text_122'), trigger: 'blur' },
  102. ],
  103. },
  104. ],
  105. pass: [
  106. 'pass',
  107. ],
  108. },
  109. formItemLayout: {
  110. wrapperCol: {
  111. md: { span: 14 },
  112. xl: { span: 16 },
  113. xxl: { span: 20 },
  114. },
  115. labelCol: {
  116. md: { span: 10 },
  117. xl: { span: 8 },
  118. xxl: { span: 4 },
  119. },
  120. },
  121. }
  122. },
  123. computed: {
  124. clusterId () {
  125. return this.$route.query.id
  126. },
  127. },
  128. created () {
  129. this.manager = new this.$Manager('loadbalancerclusters')
  130. this.getFetchLbCluster()
  131. },
  132. methods: {
  133. setValues (data) {
  134. if (!data || !Object.keys(data).length || !data.params) return false
  135. const params = {
  136. ...data.params,
  137. }
  138. this.form.fc.setFieldsValue({
  139. name: data.name,
  140. description: data.description,
  141. ...params,
  142. })
  143. },
  144. formatValues (values) {
  145. const { name, description, ...params } = values
  146. return {
  147. name,
  148. description,
  149. ...params,
  150. }
  151. },
  152. doUpdate (values) {
  153. return this.manager.performAction({
  154. action: 'params-patch',
  155. id: this.clusterId,
  156. data: this.formatValues(values),
  157. })
  158. },
  159. async getFetchLbCluster () {
  160. const { id } = this.$route.query
  161. try {
  162. const { data = {} } = await this.manager.get(({
  163. id,
  164. }))
  165. this.setValues(data)
  166. } catch (err) {
  167. throw err
  168. }
  169. },
  170. async handleSubmit () {
  171. this.submiting = true
  172. try {
  173. const values = await this.form.fc.validateFields()
  174. await this.doUpdate(values)
  175. this.$store.commit('keepAlive/ADD_DELAY_EVENT', { name: 'ResourceListSingleRefresh', params: this.clusterId })
  176. this.handleCancel()
  177. } catch (error) {
  178. throw error
  179. } finally {
  180. this.submiting = false
  181. }
  182. },
  183. handleCancel () {
  184. this.$router.push('/cluster')
  185. },
  186. },
  187. }
  188. </script>