NetSelect.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div class="d-flex align-items-center">
  3. <base-select
  4. class="w-100"
  5. resource="networks"
  6. v-model="networkId"
  7. :item.sync="network"
  8. :params="networkParams"
  9. :select-props="{ placeholder: $t('compute.text_195') }"
  10. @change="handleChange" />
  11. <a-input
  12. class="ml-2"
  13. v-if="ipShow"
  14. :placeholder="$t('compute.text_197')"
  15. v-model="ip"
  16. @change="handleChange" />
  17. <a-button v-if="ipShow" type="link" @click="handleHiddenIp" class="pl-0 pr-0 ml-2">{{$t('common_115')}}</a-button>
  18. <a-button v-else type="link" @click="handleShowIp" class="pl-0 pr-0 ml-2">{{$t('compute.text_198')}}</a-button>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'NetSelect',
  24. props: {
  25. projectDomain: String,
  26. },
  27. inject: ['form'],
  28. data () {
  29. return {
  30. ipShow: false,
  31. networkId: undefined,
  32. network: {},
  33. ip: '',
  34. }
  35. },
  36. computed: {
  37. networkParams () {
  38. const ret = {
  39. is_on_premise: true,
  40. usable: true,
  41. vpc: 'default',
  42. }
  43. if (this.projectDomain) ret.project_domain = this.projectDomain
  44. if (this.$store.getters.isDomainMode) ret.scope = this.$store.getters.scope
  45. return ret
  46. },
  47. },
  48. methods: {
  49. handleShowIp () {
  50. this.ipShow = true
  51. },
  52. handleHiddenIp () {
  53. this.ipShow = false
  54. },
  55. handleChange () {
  56. this.$nextTick(() => {
  57. this.$emit('change', {
  58. access_net: this.network,
  59. access_ip: this.ip,
  60. })
  61. })
  62. },
  63. },
  64. }
  65. </script>