SetRegionAutoSync.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.text_363')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.region')" :count="params.data.length" :action="$t('cloudenv.text_363')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('cloudenv.text_364')" v-bind="formItemLayout">
  10. <a-switch :checkedChildren="$t('cloudenv.text_84')" :unCheckedChildren="$t('cloudenv.text_85')" v-decorator="decorators.enabled" />
  11. <div slot="extra">{{$t('cloudenv.text_365')}}</div>
  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 DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. import { Manager } from '@/utils/manager'
  25. export default {
  26. name: 'SetRegionAutoSyncDialog',
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. const data = this.params.data[0]
  30. return {
  31. loading: false,
  32. form: {
  33. fc: this.$form.createForm(this),
  34. },
  35. decorators: {
  36. enabled: [
  37. 'enabled',
  38. {
  39. initialValue: data.enabled,
  40. valuePropName: 'checked',
  41. },
  42. ],
  43. },
  44. formItemLayout: {
  45. wrapperCol: {
  46. span: 21,
  47. },
  48. labelCol: {
  49. span: 3,
  50. },
  51. },
  52. }
  53. },
  54. methods: {
  55. validateForm () {
  56. return new Promise((resolve, reject) => {
  57. this.form.fc.validateFields((err, values) => {
  58. if (!err) {
  59. resolve(values)
  60. } else {
  61. reject(err)
  62. }
  63. })
  64. })
  65. },
  66. updateAutoSyncStatus (values, ids) {
  67. const manager = new Manager(`cloudproviders/${this.params.cloudproviderId}/cloudregions`)
  68. if (ids.length > 1) { // 批量操作
  69. return manager.batchUpdate({
  70. ids,
  71. data: {
  72. enabled: values.enabled,
  73. },
  74. })
  75. } else {
  76. return manager.update({
  77. id: ids[0],
  78. data: {
  79. enabled: values.enabled,
  80. },
  81. })
  82. }
  83. },
  84. async handleConfirm () {
  85. this.loading = true
  86. try {
  87. const values = await this.validateForm()
  88. const ids = this.params.data.map(item => item.id)
  89. this.loading = true
  90. await this.updateAutoSyncStatus(values, ids)
  91. this.loading = false
  92. this.cancelDialog()
  93. this.params.refresh()
  94. } catch (error) {
  95. this.loading = false
  96. }
  97. },
  98. },
  99. }
  100. </script>