SetLimit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('k8s.text_68')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :name="$t('k8s.text_64')" :action="$t('k8s.text_68')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. v-bind="formItemLayout"
  9. :form="form.fc">
  10. <a-form-item :label="$t('k8s.text_69')" v-if="!params.hideReplicas">
  11. <a-input v-decorator="decorators.replicas" :min="0" type="number" :placeholder="$t('k8s.text_70')" :addonAfter="$t('k8s.text_71')" @blur="change" />
  12. </a-form-item>
  13. </a-form>
  14. </div>
  15. <div slot="footer">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  17. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </base-dialog>
  20. </template>
  21. <script>
  22. import * as R from 'ramda'
  23. import DialogMixin from '@/mixins/dialog'
  24. import WindowsMixin from '@/mixins/windows'
  25. import expectStatus from '@/constants/expectStatus'
  26. export default {
  27. name: 'K8SSetLimitDialog',
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. return {
  31. loading: false,
  32. form: {
  33. fc: this.$form.createForm(this),
  34. fd: {},
  35. },
  36. data: this.params.data[0],
  37. decorators: {
  38. replicas: [
  39. 'replicas',
  40. {
  41. rules: [
  42. { required: true, message: this.$t('k8s.text_70') },
  43. ],
  44. },
  45. ],
  46. },
  47. formItemLayout: {
  48. wrapperCol: {
  49. span: 19,
  50. },
  51. labelCol: {
  52. span: 5,
  53. },
  54. },
  55. replicas: 3,
  56. }
  57. },
  58. created () {
  59. this.fetchData()
  60. },
  61. methods: {
  62. change (e) {
  63. const val = Number(e.target.value)
  64. if (R.is(Number, val) && !Number.isNaN(val) && val >= 0) {
  65. } else {
  66. this.form.fc.setFieldsValue({
  67. replicas: this.replicas,
  68. })
  69. }
  70. },
  71. async fetchData () {
  72. const { data } = await this.params.onManager('get', {
  73. managerArgs: {
  74. id: this.data.id,
  75. params: {
  76. cluster: this.data.cluster,
  77. namespace: this.data.namespace,
  78. },
  79. },
  80. })
  81. this.replicas = data.replicas || 3
  82. this.$nextTick(() => {
  83. this.form.fc.setFieldsValue({
  84. replicas: this.replicas,
  85. })
  86. })
  87. },
  88. async doUpdate (params) {
  89. const data = {
  90. replicas: params.replicas,
  91. cluster: this.data.cluster,
  92. namespace: this.data.namespace,
  93. }
  94. if (params.hideReplicas) delete data.replicas
  95. try {
  96. await this.params.onManager('update', {
  97. id: this.data.id,
  98. managerArgs: {
  99. data,
  100. },
  101. steadyStatus: Object.values(expectStatus.k8s_resource).flat(),
  102. })
  103. } catch (error) {
  104. throw error
  105. }
  106. },
  107. async handleConfirm () {
  108. this.loading = true
  109. try {
  110. const values = await this.form.fc.validateFields()
  111. await this.doUpdate(values)
  112. this.loading = false
  113. this.cancelDialog()
  114. if (R.is(Function, this.params.success)) this.params.success()
  115. } catch (error) {
  116. this.loading = false
  117. throw error
  118. }
  119. },
  120. },
  121. }
  122. </script>