IpSubnets.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <div>
  3. <div class="d-flex" v-for="(item, i) in ipSubnets" :key="item.key">
  4. <ip-subnet
  5. :decorator="genDecorator(item.key)" />
  6. <a-button shape="circle" icon="minus" size="small" v-if="ipSubnets.length > 1" @click="decrease(i)" class="mt-2 ml-2" />
  7. </div>
  8. <div class="d-flex align-items-center" v-if="remain > 0">
  9. <a-button type="primary" shape="circle" icon="plus" size="small" @click="add" />
  10. <a-button type="link" @click="add">{{$t('cloudenv.text_188')}}</a-button>
  11. <span class="count-tips">{{$t('cloudenv.text_251')}}<span class="remain-num">{{ remain }}</span>{{$t('cloudenv.text_24')}}</span>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import * as R from 'ramda'
  17. import IpSubnet from '@/sections/IpSubnet'
  18. import { uuid } from '@/utils/utils'
  19. export default {
  20. name: 'VmNetworkIpSubnets',
  21. components: {
  22. IpSubnet,
  23. },
  24. props: {
  25. decorator: {
  26. type: Object,
  27. required: true,
  28. validator: val => {
  29. const fields = ['startip', 'endip', 'netmask', 'gateway', 'vlan']
  30. return fields.every(f => R.is(Function, val[f]))
  31. },
  32. },
  33. },
  34. data () {
  35. return {
  36. ipSubnets: [{ key: uuid() }],
  37. }
  38. },
  39. computed: {
  40. remain () {
  41. const remain = 6 - this.ipSubnets.length
  42. return Math.max(remain, 0)
  43. },
  44. },
  45. methods: {
  46. genDecorator (uid) {
  47. const ret = {}
  48. R.forEachObjIndexed((value, key) => {
  49. ret[key] = value(uid)
  50. }, this.decorator)
  51. return ret
  52. },
  53. add () {
  54. this.$emit('clear-error')
  55. const key = uuid()
  56. this.ipSubnets.push({
  57. key,
  58. })
  59. },
  60. decrease (index) {
  61. this.ipSubnets.splice(index, 1)
  62. },
  63. },
  64. }
  65. </script>