LbListCell.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div>
  3. <a-icon type="loading" v-if="loading" />
  4. <div v-else-if="content && content.length">
  5. <div v-for="(obj, i) in content" :key="i">
  6. <a-tag class="mb-1 d-block text-truncate" type="info" size="mini" :title="obj">{{ obj }}</a-tag>
  7. </div>
  8. </div>
  9. <div v-else-if="showUnused">
  10. <a-icon type="bulb" theme="twoTone" twoToneColor="#f5222d" class="mr-1" />
  11. <span>{{$t('network.text_245')}}</span>
  12. </div>
  13. <div class="error-color" v-else-if="errorText">
  14. <span>{{ errorText }}</span>
  15. <a-icon type="sync" :spin="loading" @click="fetchData" :style="{ color: '#1890ff' }" />
  16. </div>
  17. <div v-else>-</div>
  18. </div>
  19. </template>
  20. <script>
  21. import * as R from 'ramda'
  22. import { uuid } from '@/utils/utils'
  23. export default {
  24. name: 'LbListCell',
  25. props: {
  26. params: {
  27. type: Object,
  28. required: true,
  29. },
  30. manager: {
  31. type: Object,
  32. required: true,
  33. },
  34. format: {
  35. type: Function,
  36. required: true,
  37. },
  38. status: {
  39. type: String,
  40. },
  41. type: {
  42. type: String,
  43. validator: val => !val || ['lb', 'lbBackendGroup'].includes(val),
  44. },
  45. },
  46. data () {
  47. return {
  48. loading: false,
  49. content: [],
  50. showUnused: false,
  51. }
  52. },
  53. watch: {
  54. params () {
  55. this.fetchData()
  56. },
  57. },
  58. created () {
  59. this.fetchData()
  60. },
  61. methods: {
  62. async fetchData () {
  63. const values = Object.values(this.params).filter(val => !!val)
  64. if (R.isNil(values) || R.isEmpty(values)) return
  65. if (this.status === 'deleting' || this.status === 'deleted') return
  66. this.loading = true
  67. this.showUnused = false
  68. const params = { ...this.params, $t: uuid() }
  69. const { data: { data = [] } } = await this.manager.list({ params })
  70. try {
  71. if (!data.length && this.type === 'lb') {
  72. this.showUnused = true
  73. }
  74. const content = data.map(item => this.format(item)).filter(v => !!v)
  75. this.loading = false
  76. this.errorText = ''
  77. this.content = content
  78. } catch (error) {
  79. this.showUnused = false
  80. if (error.response.status === 404) {
  81. this.errorText = this.$t('network.text_246')
  82. } else {
  83. this.errorText = this.$t('network.text_247')
  84. }
  85. this.loading = false
  86. }
  87. },
  88. },
  89. }
  90. </script>