Create.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('cloudenv.text_411')}}</div>
  4. <div slot="body">
  5. <a-form
  6. v-bind="formLayout"
  7. :form="form.fc">
  8. <a-form-item :label="$t('cloudenv.text_410', [$t('dictionary.domain')])" v-bind="formLayout">
  9. <domain-select v-if="isAdminMode && l3PermissionEnable" v-decorator="decorators.project_domain" :params="domainParams" />
  10. <template v-else> {{userInfo.domain.name}} </template>
  11. </a-form-item>
  12. <a-form-item :label="$t('cloudenv.text_95')">
  13. <a-input v-decorator="decorators.name" :placeholder="$t('validator.resourceName')" />
  14. </a-form-item>
  15. <a-form-item :label="$t('common.description')">
  16. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  17. </a-form-item>
  18. <common-form-items />
  19. </a-form>
  20. </div>
  21. <div slot="footer">
  22. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  23. <test-button
  24. :disabled="!form.fc.getFieldValue('http_proxy') && !form.fc.getFieldValue('https_proxy')"
  25. :post="testPost"
  26. :isSuccessAlert="false" />
  27. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  28. </div>
  29. </base-dialog>
  30. </template>
  31. <script>
  32. import * as R from 'ramda'
  33. import { mapGetters } from 'vuex'
  34. import DomainSelect from '@/sections/DomainSelect'
  35. import DialogMixin from '@/mixins/dialog'
  36. import WindowsMixin from '@/mixins/windows'
  37. import TestButton from '@/sections/TestButton'
  38. import CommonFormItems from '../components/CommonFormItems'
  39. export default {
  40. name: 'ProxysettingCreateDialog',
  41. components: {
  42. CommonFormItems,
  43. DomainSelect,
  44. TestButton,
  45. },
  46. mixins: [DialogMixin, WindowsMixin],
  47. data () {
  48. const projectDomainInitialValue = (this.params.domain && this.params.domain.key) || this.$store.getters.userInfo.projectDomainId
  49. return {
  50. loading: false,
  51. form: {
  52. fc: this.$form.createForm(this),
  53. },
  54. decorators: {
  55. name: [
  56. 'name',
  57. {
  58. validateFirst: true,
  59. rules: [
  60. { required: true, message: this.$t('cloudenv.text_190') },
  61. { validator: this.$validate('resourceName') },
  62. ],
  63. },
  64. ],
  65. description: ['description'],
  66. project_domain: [
  67. 'project_domain',
  68. {
  69. initialValue: projectDomainInitialValue,
  70. rules: [
  71. { required: true, message: this.$t('cloudenv.text_284', [this.$t('dictionary.domain')]) },
  72. ],
  73. },
  74. ],
  75. },
  76. formLayout: {
  77. wrapperCol: {
  78. span: 18,
  79. },
  80. labelCol: {
  81. span: 6,
  82. },
  83. },
  84. offsetFormLayout: {
  85. wrapperCol: {
  86. span: 18,
  87. offset: 6,
  88. },
  89. },
  90. domainParams: {
  91. limit: 20,
  92. filter: 'enabled.equals(1)',
  93. },
  94. }
  95. },
  96. computed: mapGetters(['isAdminMode', 'isDomainMode', 'userInfo', 'l3PermissionEnable']),
  97. methods: {
  98. doCreate (data) {
  99. return new this.$Manager('proxysettings').create({ data: data })
  100. },
  101. async testPost () {
  102. const manager = new this.$Manager('proxysettings')
  103. try {
  104. const keys = ['http_proxy', 'https_proxy']
  105. const values = await this.form.fc.validateFields(['http_proxy', 'https_proxy'])
  106. const { data } = await manager.performClassAction({
  107. action: 'test',
  108. data: {
  109. http_proxy: values.http_proxy,
  110. https_proxy: values.https_proxy,
  111. },
  112. })
  113. keys.forEach(k => {
  114. if (!data[k] || !values[k] || R.type(data[k]) !== 'Object') return false
  115. const { ok, reason } = data[k]
  116. if (ok) {
  117. this.$notification.success({
  118. message: this.$t('cloudenv.text_407', [this.$t('proxysettings')[k]]),
  119. description: this.$t('cloudenv.text_408'),
  120. })
  121. } else {
  122. this.$notification.error({
  123. message: this.$t('cloudenv.text_409', [this.$t('proxysettings')[k]]),
  124. description: reason,
  125. })
  126. }
  127. })
  128. } catch (err) {
  129. throw err
  130. }
  131. },
  132. async handleConfirm () {
  133. this.loading = true
  134. try {
  135. const values = await this.form.fc.validateFields()
  136. await this.doCreate(values)
  137. this.cancelDialog()
  138. this.params.refresh && this.params.refresh()
  139. this.params.success && this.params.success()
  140. } catch (error) {
  141. throw error
  142. } finally {
  143. this.loading = false
  144. }
  145. },
  146. },
  147. }
  148. </script>