IpSubnets.vue 1.9 KB

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