List.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-columns2
  5. show-tag-filter
  6. :list="list"
  7. :columns="templateListColumns || columns"
  8. :group-actions="groupActions"
  9. :single-actions="singleActions"
  10. :export-data-options="exportDataOptions"
  11. :showSearchbox="showSearchbox"
  12. :defaultSearchKey="defaultSearchKey"
  13. :showSingleActions="isTemplate ? false : showActions"
  14. :showGroupActions="showActions && showGroupActions"
  15. :show-page="!isTemplate" />
  16. </template>
  17. <script>
  18. import { mapGetters } from 'vuex'
  19. import ListMixin from '@/mixins/list'
  20. import ResTemplateListMixin from '@/mixins/resTemplateList'
  21. import {
  22. getNameFilter,
  23. getStatusFilter,
  24. getBrandFilter,
  25. getAccountFilter,
  26. getTenantFilter,
  27. getDomainFilter,
  28. getDescriptionFilter,
  29. getCreatedAtFilter,
  30. getDistinctFieldFilter,
  31. } from '@/utils/common/tableFilter'
  32. import expectStatus from '@/constants/expectStatus'
  33. import WindowsMixin from '@/mixins/windows'
  34. import GlobalSearchMixin from '@/mixins/globalSearch'
  35. import regexp from '@/utils/regexp'
  36. import SingleActionsMixin from '../mixins/singleActions'
  37. import ColumnsMixin from '../mixins/columns'
  38. import { ASSOCIATE_MAP } from '../constants'
  39. export default {
  40. name: 'EipList',
  41. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  42. props: {
  43. id: String,
  44. cloudEnv: String,
  45. getParams: {
  46. type: Object,
  47. },
  48. cloudEnvOptions: {
  49. type: Array,
  50. },
  51. showCreateAction: {
  52. type: Boolean,
  53. default: true,
  54. },
  55. hiddenColumns: {
  56. type: Array,
  57. default: () => (['created_at']),
  58. },
  59. },
  60. data () {
  61. const filter = {}
  62. if (this.$route.query.hasOwnProperty('is_associated')) {
  63. filter.is_associated = [this.$route.query.is_associated]
  64. }
  65. const createAction = {
  66. label: this.$t('network.text_26'),
  67. permission: 'eips_create',
  68. action: () => {
  69. this.$router.push({
  70. path: `${this.$route.path}/create`,
  71. query: {
  72. type: this.cloudEnv,
  73. },
  74. })
  75. },
  76. meta: () => ({
  77. buttonType: 'primary',
  78. validate: !this.cloudEnvEmpty,
  79. tooltip: this.cloudEnvEmpty ? this.$t('common.no_platform_available') : '',
  80. }),
  81. }
  82. const groupActions = [
  83. {
  84. label: this.$t('network.text_200'),
  85. actions: () => {
  86. return [
  87. {
  88. label: this.$t('network.text_201'),
  89. permission: 'eips_perform_syncstatus',
  90. action: () => {
  91. this.onManager('batchPerformAction', {
  92. steadyStatus: ['running', 'ready'],
  93. managerArgs: {
  94. action: 'syncstatus',
  95. },
  96. })
  97. },
  98. },
  99. {
  100. label: this.$t('compute.perform_change_owner', [this.$t('dictionary.project')]),
  101. permission: 'eips_perform_change_owner',
  102. action: () => {
  103. this.createDialog('ChangeOwenrDialog', {
  104. data: this.list.selectedItems,
  105. columns: this.columns,
  106. name: this.$t('dictionary.eip'),
  107. onManager: this.onManager,
  108. resource: 'eips',
  109. refresh: this.refresh,
  110. })
  111. },
  112. meta: () => {
  113. const ret = {
  114. validate: false,
  115. tooltip: '',
  116. }
  117. if (this.isProjectMode) {
  118. ret.tooltip = this.$t('common_601')
  119. return ret
  120. }
  121. return {
  122. validate: true,
  123. }
  124. },
  125. },
  126. {
  127. label: this.$t('table.action.set_tag'),
  128. permission: 'eips_perform_set_user_metadata',
  129. action: () => {
  130. this.createDialog('SetTagDialog', {
  131. data: this.list.selectedItems,
  132. columns: this.columns,
  133. onManager: this.onManager,
  134. mode: 'add',
  135. params: {
  136. resources: 'eip',
  137. },
  138. tipName: this.$t('dictionary.eip'),
  139. })
  140. },
  141. },
  142. {
  143. label: this.$t('network.text_131'),
  144. permission: 'eips_delete',
  145. action: () => {
  146. this.createDialog('DeleteResDialog', {
  147. vm: this,
  148. data: this.list.selectedItems,
  149. columns: this.columns,
  150. title: this.$t('network.text_131'),
  151. name: this.$t('dictionary.eip'),
  152. onManager: this.onManager,
  153. })
  154. },
  155. meta: () => {
  156. return {
  157. validate: this.list.allowDelete(),
  158. }
  159. },
  160. },
  161. ]
  162. },
  163. meta: () => {
  164. return {
  165. validate: this.list.selected.length,
  166. }
  167. },
  168. },
  169. ]
  170. if (this.showCreateAction) {
  171. groupActions.unshift(createAction)
  172. }
  173. return {
  174. list: this.$list.createList(this, {
  175. ctx: this,
  176. id: this.id,
  177. resource: 'eips',
  178. getParams: this.getParam,
  179. isTemplate: this.isTemplate,
  180. templateLimit: this.templateLimit,
  181. filter,
  182. filterOptions: {
  183. external_id: {
  184. label: this.$t('table.title.external_id'),
  185. },
  186. id: {
  187. label: this.$t('table.title.id'),
  188. },
  189. name: getNameFilter(),
  190. description: getDescriptionFilter(),
  191. brand: getBrandFilter('brands', ['VMware']),
  192. ip_addr: {
  193. label: 'IP',
  194. filter: true,
  195. formatter: val => {
  196. return `ip_addr.contains(${val})`
  197. },
  198. },
  199. status: getStatusFilter('eip'),
  200. is_associated: {
  201. label: this.$t('network.is_associated'),
  202. dropdown: true,
  203. items: [
  204. { label: this.$t('network.associated'), key: 'true' },
  205. { label: this.$t('network.un_associated'), key: 'false' },
  206. ],
  207. },
  208. cloudaccount: getAccountFilter(),
  209. projects: getTenantFilter(),
  210. project_domains: getDomainFilter(),
  211. region: {
  212. label: this.$t('common_282'),
  213. },
  214. associate_type: getDistinctFieldFilter({
  215. label: this.$t('network.associate_resource_type'),
  216. field: 'associate_type',
  217. mapper: (list) => {
  218. return list.filter(item => item.key).map(item => {
  219. return {
  220. key: item.key,
  221. label: ASSOCIATE_MAP[item.key]?.name || item.label,
  222. }
  223. })
  224. },
  225. }),
  226. associate_name: { label: this.$t('network.associate_resource_name') },
  227. associate_id: { label: this.$t('network.associate_resource_id') },
  228. charge_type: {
  229. label: this.$t('network.text_192'),
  230. dropdown: true,
  231. multiple: false,
  232. // distinctField: {
  233. // type: 'extra_field',
  234. // key: 'charge_type',
  235. // },
  236. items: [
  237. { label: this.$t('network.text_193'), key: 'traffic' },
  238. { label: this.$t('network.text_194'), key: 'bandwidth' },
  239. ],
  240. },
  241. mode: {
  242. label: this.$t('network.text_249'),
  243. dropdown: true,
  244. multiple: false,
  245. items: [
  246. { label: this.$t('network.text_221'), key: 'elastic_ip' },
  247. { label: this.$t('network.public_ip'), key: 'public_ip' },
  248. ],
  249. },
  250. created_at: getCreatedAtFilter(),
  251. },
  252. autoHiddenFilterKey: 'eip_hidden_columns',
  253. steadyStatus: Object.values(expectStatus.eip).flat(),
  254. responseData: this.responseData,
  255. hiddenColumns: this.hiddenColumns, // ['metadata', 'account'],
  256. }),
  257. groupActions: groupActions,
  258. }
  259. },
  260. computed: {
  261. ...mapGetters(['isProjectMode']),
  262. exportDataOptions () {
  263. return {
  264. downloadType: 'local',
  265. title: this.$t('network.text_221'),
  266. items: [
  267. { field: 'id', title: 'ID' },
  268. { field: 'external_id', title: this.$t('table.title.external_id') },
  269. ...this.columns,
  270. ],
  271. }
  272. },
  273. showActions () {
  274. return !this.$isScopedPolicyMenuHidden('eip_hidden_columns.perform_action')
  275. },
  276. },
  277. watch: {
  278. cloudEnv (val) {
  279. this.$nextTick(() => {
  280. this.list.fetchData(0)
  281. })
  282. },
  283. },
  284. created () {
  285. this.initSidePageTab('eip-detail')
  286. this.list.fetchData()
  287. },
  288. methods: {
  289. getParam () {
  290. const ret = {
  291. ...this.getParams,
  292. details: true,
  293. show_emulated: true,
  294. }
  295. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  296. return ret
  297. },
  298. handleOpenSidepage (row, tab) {
  299. this.initSidePageTab('eip-detail')
  300. this.sidePageTriggerHandle(this, 'EipSidePage', {
  301. id: row.id,
  302. resource: 'eips',
  303. getParams: this.getParam,
  304. steadyStatus: Object.values(expectStatus.eip).flat(),
  305. }, {
  306. list: this.list,
  307. hiddenColumns: this.hiddenColumns,
  308. tab,
  309. })
  310. },
  311. defaultSearchKey (search) {
  312. if (regexp.isIPv4(search)) {
  313. return 'ip_addr'
  314. }
  315. },
  316. },
  317. }
  318. </script>