Update.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.text_406')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('cloudenv.text_14')" :count="params.data.length" :action="$t('cloudenv.text_406')" />
  6. <dialog-table class="mb-2" :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <common-form-items />
  11. </a-form>
  12. </div>
  13. <div slot="footer">
  14. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  15. <test-button
  16. :disabled="!form.fc.getFieldValue('http_proxy') && !form.fc.getFieldValue('https_proxy')"
  17. :post="testPost"
  18. :isSuccessAlert="false" />
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import * as R from 'ramda'
  25. import { formItemLayout } from '../constants'
  26. import CommonFormItems from '../components/CommonFormItems'
  27. import TestButton from '@/sections/TestButton'
  28. import DialogMixin from '@/mixins/dialog'
  29. import WindowsMixin from '@/mixins/windows'
  30. export default {
  31. name: 'ProxysettingUpdateDialog',
  32. components: { CommonFormItems, TestButton },
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. formItemLayout,
  37. loading: false,
  38. form: {
  39. fc: this.$form.createForm(this),
  40. },
  41. }
  42. },
  43. created () {
  44. this._backfill()
  45. },
  46. methods: {
  47. async _backfill () {
  48. await this.$nextTick()
  49. const { setFieldsValue } = this.form.fc
  50. const [row] = this.params.data
  51. setFieldsValue({
  52. https_proxy: row.https_proxy,
  53. http_proxy: row.http_proxy,
  54. no_proxy: row.no_proxy,
  55. })
  56. },
  57. async testPost () {
  58. const manager = new this.$Manager('proxysettings')
  59. try {
  60. const keys = ['http_proxy', 'https_proxy']
  61. const values = await this.form.fc.validateFields(['http_proxy', 'https_proxy'])
  62. const { data } = await manager.performClassAction({
  63. action: 'test',
  64. data: {
  65. http_proxy: values.http_proxy,
  66. https_proxy: values.https_proxy,
  67. },
  68. })
  69. keys.forEach(k => {
  70. if (!data[k] || !values[k] || R.type(data[k]) !== 'Object') return false
  71. const { ok, reason } = data[k]
  72. if (ok) {
  73. this.$notification.success({
  74. message: this.$t('cloudenv.text_407', [this.$t('proxysettings')[k]]),
  75. description: this.$t('cloudenv.text_408'),
  76. })
  77. } else {
  78. this.$notification.error({
  79. message: this.$t('cloudenv.text_409', this.$t('proxysettings')[k]),
  80. description: reason,
  81. })
  82. }
  83. })
  84. } catch (err) {
  85. throw err
  86. }
  87. },
  88. async handleConfirm () {
  89. this.loading = true
  90. try {
  91. const values = await this.form.fc.validateFields()
  92. const ids = this.params.data.map(item => item.id)
  93. await this.params.onManager('update', {
  94. id: ids[0],
  95. managerArgs: {
  96. data: values,
  97. },
  98. })
  99. this.cancelDialog()
  100. } catch (err) {
  101. throw err
  102. } finally {
  103. this.loading = false
  104. }
  105. },
  106. },
  107. }
  108. </script>