AssociatedCluster.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('network.associated_cluster') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('network.text_20')" :count="params.data.length" :action="$t('network.associated_cluster')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('network.associated_cluster')">
  9. <a-switch
  10. v-decorator="decorators.enable_associated"
  11. :checkedChildren="$t('common.text00062')"
  12. :unCheckedChildren="$t('common.text00063')" />
  13. </a-form-item>
  14. <a-form-item :label="$t('network.text_19')" v-if="form.fd.enable_associated">
  15. <base-select
  16. v-decorator="decorators.cluster_id"
  17. resource="loadbalancerclusters"
  18. :params="clusterParams"
  19. remote
  20. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  21. showSync
  22. :select-props="{ placeholder: $t('network.text_79') }" />
  23. <p slot="extra">
  24. {{$t('network.text_80')}}
  25. <a-button type="link" size="small" @click="createCluster">{{$t('network.text_26')}}</a-button>
  26. </p>
  27. </a-form-item>
  28. </a-form>
  29. </div>
  30. <div slot="footer">
  31. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  32. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  33. </div>
  34. </base-dialog>
  35. </template>
  36. <script>
  37. import DialogMixin from '@/mixins/dialog'
  38. import WindowsMixin from '@/mixins/windows'
  39. export default {
  40. name: 'AssociatedClusterDialog',
  41. mixins: [DialogMixin, WindowsMixin],
  42. data () {
  43. return {
  44. loading: false,
  45. form: {
  46. fc: this.$form.createForm(this, {
  47. onValuesChange: (props, values) => {
  48. Object.keys(values).forEach((key) => {
  49. this.form.fd[key] = values[key]
  50. })
  51. },
  52. }),
  53. fd: {
  54. enable_associated: !!this.params.data[0].cluster_id,
  55. },
  56. },
  57. decorators: {
  58. enable_associated: [
  59. 'enable_associated',
  60. {
  61. valuePropName: 'checked',
  62. initialValue: !!this.params.data[0].cluster_id,
  63. },
  64. ],
  65. cluster_id: [
  66. 'cluster_id',
  67. {
  68. initialValue: this.params.data[0].cluster_id,
  69. rules: [
  70. { required: true, message: this.$t('network.text_79') },
  71. ],
  72. },
  73. ],
  74. },
  75. formItemLayout: {
  76. wrapperCol: {
  77. span: 19,
  78. },
  79. labelCol: {
  80. span: 5,
  81. },
  82. },
  83. }
  84. },
  85. computed: {
  86. clusterParams () {
  87. return {
  88. region: this.params.data[0].region,
  89. }
  90. },
  91. },
  92. methods: {
  93. createCluster () {
  94. this.createDialog('LoadbalancerclusterCreateDialog', {
  95. title: this.$t('network.text_26'),
  96. })
  97. },
  98. doAssociated (id, cluster_id) {
  99. return this.params.onManager('performAction', {
  100. id,
  101. managerArgs: {
  102. action: 'join-cluster',
  103. data: {
  104. cluster_id,
  105. },
  106. },
  107. })
  108. },
  109. doUnAssociated (id, cluster_id) {
  110. return this.params.onManager('performAction', {
  111. id,
  112. managerArgs: {
  113. action: 'leave-cluster',
  114. },
  115. })
  116. },
  117. async handleConfirm () {
  118. this.loading = true
  119. try {
  120. const values = await this.form.fc.validateFields()
  121. const id = this.params.data[0].id
  122. const { enable_associated, cluster_id } = values
  123. if (enable_associated) {
  124. await this.doAssociated(id, cluster_id)
  125. } else {
  126. await this.doUnAssociated(id, cluster_id)
  127. }
  128. this.cancelDialog()
  129. } catch (error) {
  130. throw error
  131. } finally {
  132. this.loading = false
  133. }
  134. },
  135. },
  136. }
  137. </script>