NetworkIpMacs.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :singleActions="singleActions"
  6. :group-actions="groupActions" />
  7. </template>
  8. <script>
  9. import { mapGetters } from 'vuex'
  10. import WindowsMixin from '@/mixins/windows'
  11. import ListMixin from '@/mixins/list'
  12. import { PROVIDER_MAP } from '@/constants'
  13. export default {
  14. name: 'NetworkIpMacs',
  15. mixins: [WindowsMixin, ListMixin],
  16. props: {
  17. data: {
  18. type: Object,
  19. required: true,
  20. },
  21. },
  22. data () {
  23. return {
  24. list: this.$list.createList(this, {
  25. id: 'NetworkIpMacsForNetworkSidePage',
  26. resource: 'network_ip_macs',
  27. getParams: {
  28. details: true,
  29. network_id: this.data.id,
  30. },
  31. }),
  32. columns: [
  33. {
  34. field: 'ip_addr',
  35. title: 'IP',
  36. },
  37. {
  38. field: 'mac_addr',
  39. title: this.$t('network.text_228'),
  40. },
  41. ],
  42. singleActions: [
  43. {
  44. label: this.$t('common.edit'),
  45. action: (obj) => {
  46. this.createDialog('NetworkIpMacsCreateDialog', {
  47. data: [this.data],
  48. editData: [obj],
  49. name: this.$t('dictionary.network'),
  50. ok: () => {
  51. this.list.fetchData()
  52. },
  53. })
  54. },
  55. meta: (obj) => {
  56. if (!this.isPower(this.data)) {
  57. return {
  58. validate: false,
  59. tooltip: this.$t('network.text_627'),
  60. }
  61. }
  62. return { validate: true }
  63. },
  64. },
  65. {
  66. label: this.$t('common.delete'),
  67. action: (obj) => {
  68. this.createDialog('DeleteResDialog', {
  69. vm: this,
  70. data: [obj],
  71. columns: this.columns,
  72. title: this.$t('common.delete'),
  73. name: this.$t('network.mac_ip.mapping_table'),
  74. onManager: this.onManager,
  75. })
  76. },
  77. meta: (obj) => {
  78. if (!this.isPower(this.data)) {
  79. return {
  80. validate: false,
  81. tooltip: this.$t('network.text_627'),
  82. }
  83. }
  84. if (!this.$getDeleteResult(obj).validate) {
  85. return {
  86. validate: false,
  87. tooltip: this.$getDeleteResult(obj).tooltip,
  88. }
  89. }
  90. return { validate: true }
  91. },
  92. },
  93. ],
  94. groupActions: [
  95. {
  96. label: this.$t('common.create'),
  97. action: () => {
  98. this.createDialog('NetworkIpMacsCreateDialog', {
  99. data: [this.data],
  100. name: this.$t('dictionary.network'),
  101. ok: () => {
  102. this.list.fetchData()
  103. },
  104. })
  105. },
  106. meta: () => {
  107. const isOneCloud = this.data.brand === 'OneCloud'
  108. const provider = this.data.provider
  109. if (!isOneCloud) {
  110. return {
  111. validate: false,
  112. tooltip: !isOneCloud && this.$t('common.not_support_validate_tips', [PROVIDER_MAP[provider].label]),
  113. }
  114. }
  115. if (!this.isPower(this.data)) {
  116. return {
  117. validate: false,
  118. tooltip: this.$t('network.text_627'),
  119. }
  120. }
  121. return {
  122. buttonType: 'primary',
  123. validate: true,
  124. }
  125. },
  126. },
  127. {
  128. label: this.$t('network.mac_ip.import_mapping_table'),
  129. action: () => {
  130. this.createDialog('ImportNetworkIpMacsDialog', {
  131. data: [this.data],
  132. ok: () => {
  133. this.list.fetchData()
  134. },
  135. })
  136. },
  137. meta: () => {
  138. const isOneCloud = this.data.brand === 'OneCloud'
  139. const provider = this.data.provider
  140. if (!isOneCloud) {
  141. return {
  142. validate: false,
  143. tooltip: !isOneCloud && this.$t('common.not_support_validate_tips', [PROVIDER_MAP[provider].label]),
  144. }
  145. }
  146. if (!this.isPower(this.data)) {
  147. return {
  148. validate: false,
  149. tooltip: this.$t('network.text_627'),
  150. }
  151. }
  152. return {
  153. validate: true,
  154. }
  155. },
  156. },
  157. {
  158. label: this.$t('common.delete'),
  159. action: () => {
  160. this.createDialog('DeleteResDialog', {
  161. vm: this,
  162. data: this.list.selectedItems,
  163. columns: this.columns,
  164. title: this.$t('common.delete'),
  165. name: this.$t('network.mac_ip.mapping_table'),
  166. onManager: this.onManager,
  167. })
  168. },
  169. meta: () => {
  170. if (!this.isPower(this.data)) {
  171. return {
  172. validate: false,
  173. tooltip: this.$t('network.text_627'),
  174. }
  175. }
  176. return {
  177. validate: this.list.allowDelete(),
  178. }
  179. },
  180. },
  181. ],
  182. }
  183. },
  184. computed: {
  185. ...mapGetters(['isAdminMode', 'isDomainMode', 'isProjectMode', 'userInfo']),
  186. },
  187. created () {
  188. this.list.fetchData()
  189. },
  190. methods: {
  191. isPower (obj) {
  192. if (this.isAdminMode) return true
  193. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  194. return obj.tenant_id === this.userInfo.projectId
  195. },
  196. },
  197. }
  198. </script>