ProxySetting.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <a-form-item :label="$t('cloudenv.text_14')" v-if="isPermission">
  3. <a-switch
  4. :checkedChildren="$t('cloudenv.text_84')"
  5. :unCheckedChildren="$t('cloudenv.text_85')"
  6. v-model="isOpenProxy" />
  7. <div v-if="isOpenProxy" class="d-flex align-items-center w-50">
  8. <a-select class="base-select" :loading="loading" showSearch :filterOption="filterOption" v-decorator="decorator">
  9. <a-select-option v-for="item of proxyOpts" :key="item.id" :value="item.id">
  10. {{item.name}} {{item.id === 'DIRECT' ? $t('cloudenv.text_110') : null}}
  11. </a-select-option>
  12. </a-select>
  13. <a @click="fetchQueryProxy"><a-icon :spin="loading" type="sync" class="ml-2" /></a>
  14. </div>
  15. <div slot="extra">
  16. <div v-if="!isOpenProxy">{{$t('cloudenv.text_111')}}</div>
  17. <div v-else>{{$t('cloudenv.text_112')}}<span class="link-color oc-pointer" @click="createProxySetting">{{$t('cloudenv.text_104')}}</span></div>
  18. </div>
  19. </a-form-item>
  20. </template>
  21. <script>
  22. import { mapGetters } from 'vuex'
  23. import { hasPermission } from '@/utils/auth'
  24. import WindowsMixin from '@/mixins/windows'
  25. export default {
  26. name: 'ProxySetting',
  27. mixins: [WindowsMixin],
  28. props: {
  29. account: {
  30. type: Object,
  31. },
  32. fc: {
  33. type: Object,
  34. },
  35. fd: {
  36. type: Object,
  37. },
  38. cloneData: {
  39. type: Object,
  40. default: () => ({}),
  41. },
  42. },
  43. data () {
  44. const { proxy_setting_id } = this.cloneData
  45. return {
  46. proxyOpts: [],
  47. loading: false,
  48. isOpenProxy: proxy_setting_id && proxy_setting_id !== 'DIRECT',
  49. }
  50. },
  51. computed: {
  52. ...mapGetters(['isAdminMode', 'userInfo', 'l3PermissionEnable']),
  53. decorator () {
  54. const { proxy_setting_id } = this.cloneData
  55. return [
  56. 'proxy_setting',
  57. {
  58. initialValue: (!proxy_setting_id || proxy_setting_id === 'DIRECT') ? '' : proxy_setting_id,
  59. rules: [{ required: true, message: this.$t('common.tips.select', [this.$t('cloudenv.text_14')]) }],
  60. },
  61. ]
  62. },
  63. isPermission () {
  64. return hasPermission({ key: 'proxysettings_list' })
  65. },
  66. },
  67. created () {
  68. if (this.isPermission) {
  69. this.fetchQueryProxy()
  70. }
  71. },
  72. methods: {
  73. filterOption (input, option) {
  74. return (
  75. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  76. )
  77. },
  78. async fetchQueryProxy () {
  79. const manager = new this.$Manager('proxysettings')
  80. if (this.loading) {
  81. return false
  82. }
  83. const params = {
  84. limit: 0,
  85. }
  86. if (this.account) {
  87. params.project_domain = this.account.domain_id
  88. } else if (this.l3PermissionEnable && this.isAdminMode) {
  89. params.project_domain = this.fc.getFieldValue('domain').key
  90. } else {
  91. params.project_domain = this.userInfo.projectDomainId
  92. }
  93. this.loading = true
  94. try {
  95. const { data } = await manager.list({ params })
  96. this.proxyOpts = data.data
  97. if (this.proxyOpts && this.proxyOpts.length > 0 && this.account) {
  98. this.fc.setFieldsValue({
  99. proxy_setting: this.account.proxy_setting_id,
  100. })
  101. } else {
  102. this.fc.setFieldsValue({
  103. proxy_setting: 'DIRECT',
  104. })
  105. }
  106. } catch (err) {
  107. throw err
  108. } finally {
  109. this.loading = false
  110. }
  111. },
  112. createProxySetting () {
  113. this.createDialog('ProxysettingCreateDialog', {
  114. domain: this.account ? this.account.domain_id : this.fd.domain || {},
  115. success: async () => {
  116. await this.fetchQueryProxy()
  117. if (this.proxyOpts && this.proxyOpts.length > 0) {
  118. this.fc.setFieldsValue({ proxy_setting: this.proxyOpts[0].id })
  119. }
  120. },
  121. })
  122. },
  123. },
  124. }
  125. </script>