List.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <page-list
  3. show-tag-columns
  4. show-tag-filter
  5. :list="list"
  6. :columns="templateListColumns || columns"
  7. :single-actions="singleActions"
  8. :group-actions="groupActions"
  9. :export-data-options="exportDataOptions"
  10. :showSearchbox="showSearchbox"
  11. :defaultSearchKey="defaultSearchKey"
  12. :showSingleActions="isTemplate ? false : showActions"
  13. :showGroupActions="showActions && showGroupActions"
  14. :show-page="!isTemplate" />
  15. </template>
  16. <script>
  17. import * as R from 'ramda'
  18. import ListMixin from '@/mixins/list'
  19. import ResTemplateListMixin from '@/mixins/resTemplateList'
  20. import expectStatus from '@/constants/expectStatus'
  21. import { getDisabledProvidersActionMeta } from '@/utils/common/hypervisor'
  22. import {
  23. getStatusFilter,
  24. getBrandFilter,
  25. getAccountFilter,
  26. getProjectDomainFilter,
  27. getRegionFilter,
  28. getDescriptionFilter,
  29. getCreatedAtFilter,
  30. } from '@/utils/common/tableFilter'
  31. import WindowsMixin from '@/mixins/windows'
  32. import { getDomainChangeOwnerAction, getSetPublicAction } from '@/utils/common/tableActions'
  33. import regexp from '@/utils/regexp'
  34. import GlobalSearchMixin from '@/mixins/globalSearch'
  35. import SingleActionsMixin from '../mixins/singleActions'
  36. import ColumnsMixin from '../mixins/columns'
  37. export default {
  38. name: 'VPCList',
  39. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin, ColumnsMixin, SingleActionsMixin, ResTemplateListMixin],
  40. props: {
  41. id: String,
  42. getParams: {
  43. type: [Function, Object],
  44. },
  45. cloudEnv: String,
  46. showGroupActions: {
  47. type: Boolean,
  48. default: true,
  49. },
  50. hiddenActions: {
  51. type: Array,
  52. default: () => ([]),
  53. },
  54. hiddenColumns: {
  55. type: Array,
  56. default: () => ([]),
  57. },
  58. hiddenFilterOptions: {
  59. type: Array,
  60. default: () => ([]),
  61. },
  62. cloudEnvOptions: {
  63. type: Array,
  64. },
  65. },
  66. data () {
  67. const filterOptions = {
  68. id: {
  69. label: this.$t('table.title.id'),
  70. },
  71. name: {
  72. label: this.$t('network.text_21'),
  73. filter: true,
  74. formatter: val => {
  75. return `name.contains("${val}")`
  76. },
  77. },
  78. description: getDescriptionFilter(),
  79. status: getStatusFilter('vpc'),
  80. cloudaccount: getAccountFilter(),
  81. brand: getBrandFilter('brands', ['VMware']),
  82. cidr_block: {
  83. label: this.$t('network.vpc.cidr_block.ipv4.label'),
  84. },
  85. project_domains: getProjectDomainFilter(),
  86. region: getRegionFilter(),
  87. created_at: getCreatedAtFilter(),
  88. }
  89. this.hiddenFilterOptions.forEach(key => {
  90. delete filterOptions[key]
  91. })
  92. return {
  93. list: this.$list.createList(this, {
  94. ctx: this,
  95. id: this.id,
  96. resource: 'vpcs',
  97. getParams: this.getParam,
  98. isTemplate: this.isTemplate,
  99. templateLimit: this.templateLimit,
  100. steadyStatus: Object.values(expectStatus.vpc).flat(),
  101. filterOptions,
  102. responseData: this.responseData,
  103. hiddenColumns: ['metadata', 'wire_count', 'created_at'],
  104. autoHiddenFilterKey: 'vpc_hidden_columns',
  105. }),
  106. exportDataOptions: {
  107. items: [
  108. { label: 'ID', key: 'id' },
  109. { label: this.$t('network.text_21'), key: 'name' },
  110. { label: this.$t('network.text_27'), key: 'status' },
  111. { label: this.$t('network.vpc.cidr_block.ipv4.label'), key: 'cidr_block' },
  112. { label: this.$t('network.text_199'), key: 'region' },
  113. { label: this.$t('network.text_198'), key: 'provider' },
  114. { label: this.$t('network.text_196'), key: 'manager' },
  115. { label: this.$t('network.text_571'), key: 'wire_count' },
  116. { label: this.$t('network.text_682'), key: 'network_count' },
  117. {
  118. label: this.$t('common_101'),
  119. key: 'public_scope',
  120. hidden: () => {
  121. return !this.$store.getters.l3PermissionEnable && (this.$store.getters.scopeResource && this.$store.getters.scopeResource.domain.includes('vpcs'))
  122. },
  123. },
  124. { label: this.$t('network.text_233', [this.$t('dictionary.domain')]), key: 'project_domain' },
  125. { label: this.$t('common_715'), key: 'user_tags' },
  126. { label: this.$t('common.createdAt'), key: 'created_at' },
  127. ],
  128. },
  129. groupActions: [
  130. {
  131. label: this.$t('network.text_26'),
  132. permission: 'vpcs_create',
  133. action: () => {
  134. this.$router.push({
  135. path: '/vpc/create',
  136. query: {
  137. type: this.cloudEnv,
  138. },
  139. })
  140. },
  141. meta: () => {
  142. return {
  143. buttonType: 'primary',
  144. validate: !this.cloudEnvEmpty,
  145. tooltip: this.cloudEnvEmpty ? this.$t('common.no_platform_available') : '',
  146. }
  147. },
  148. hidden: () => this.hiddenActions.includes('create'),
  149. },
  150. {
  151. label: this.$t('network.text_200'),
  152. actions: () => {
  153. return [
  154. {
  155. label: this.$t('network.text_201'),
  156. permission: 'vpcs_perform_syncstatus',
  157. action: () => {
  158. this.onManager('batchPerformAction', {
  159. steadyStatus: ['running', 'ready'],
  160. managerArgs: {
  161. action: 'syncstatus',
  162. },
  163. })
  164. },
  165. meta: () => {
  166. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  167. return {
  168. validate: false,
  169. tooltip: this.$t('network.text_627'),
  170. }
  171. }
  172. if (this.list.selectedItems.some(v => v.brand.toLowerCase() === 'onecloud')) {
  173. return {
  174. validate: false,
  175. tooltip: this.$t('network.text_628'),
  176. }
  177. }
  178. return {
  179. validate: true,
  180. }
  181. },
  182. },
  183. getDomainChangeOwnerAction(this, {
  184. name: this.$t('dictionary.vpc'),
  185. resource: 'vpcs',
  186. }, {
  187. permission: 'vpcs_perform_change_owner',
  188. extraMeta: obj => {
  189. return getDisabledProvidersActionMeta({
  190. rows: this.list.selectedItems,
  191. disabledProviders: ['BingoCloud'],
  192. })
  193. },
  194. }),
  195. getSetPublicAction(this, {
  196. name: this.$t('dictionary.vpc'),
  197. scope: 'domain',
  198. resource: 'vpcs',
  199. }, {
  200. permission: 'vpcs_perform_public',
  201. extraMeta: obj => {
  202. return getDisabledProvidersActionMeta({
  203. rows: this.list.selectedItems,
  204. disabledProviders: ['BingoCloud'],
  205. })
  206. },
  207. }),
  208. {
  209. label: this.$t('table.action.set_tag'),
  210. permission: 'vpcs_perform_set_user_metadata',
  211. action: () => {
  212. this.createDialog('SetTagDialog', {
  213. data: this.list.selectedItems,
  214. columns: this.columns,
  215. onManager: this.onManager,
  216. mode: 'add',
  217. params: {
  218. resources: 'vpc',
  219. },
  220. tipName: this.$t('dictionary.vpc'),
  221. })
  222. },
  223. meta: () => {
  224. if (this.list.selectedItems.some(item => !this.isPower(item))) {
  225. return {
  226. validate: false,
  227. tooltip: this.$t('network.text_627'),
  228. }
  229. }
  230. return {
  231. validate: true,
  232. }
  233. },
  234. extraMeta: obj => {
  235. return getDisabledProvidersActionMeta({
  236. rows: this.list.selectedItems,
  237. disabledProviders: ['BingoCloud'],
  238. })
  239. },
  240. },
  241. {
  242. label: this.$t('network.text_131'),
  243. permission: 'vpcs_delete',
  244. action: () => {
  245. let alert = null
  246. if (this.list.selectedItems.some(item => item.provider === 'Aws')) {
  247. alert = this.$t('network.vpc_aws_delete_alert')
  248. }
  249. this.createDialog('DeleteResDialog', {
  250. vm: this,
  251. title: this.$t('network.text_131'),
  252. name: this.$t('dictionary.vpc'),
  253. data: this.list.selectedItems,
  254. columns: this.columns,
  255. onManager: this.onManager,
  256. alert,
  257. })
  258. },
  259. meta: () => {
  260. return {
  261. validate: this.list.allowDelete(),
  262. }
  263. },
  264. extraMeta: obj => {
  265. return getDisabledProvidersActionMeta({
  266. rows: this.list.selectedItems,
  267. disabledProviders: ['BingoCloud', 'SangFor'],
  268. })
  269. },
  270. },
  271. ]
  272. },
  273. meta: () => {
  274. return {
  275. validate: this.list.selected.length,
  276. }
  277. },
  278. },
  279. ],
  280. }
  281. },
  282. computed: {
  283. showActions () {
  284. return !this.$isScopedPolicyMenuHidden('vpc_hidden_columns.perform_action')
  285. },
  286. },
  287. watch: {
  288. cloudEnv (val) {
  289. this.$nextTick(() => {
  290. this.list.fetchData(0)
  291. })
  292. },
  293. },
  294. created () {
  295. this.initSidePageTab('vpc-detail')
  296. this.list.fetchData()
  297. },
  298. methods: {
  299. isPower (obj) {
  300. if (this.isAdminMode) return true
  301. if (this.isDomainMode) return obj.domain_id === this.userInfo.projectDomainId
  302. return obj.tenant_id === this.userInfo.projectId
  303. },
  304. getParam () {
  305. const ret = {
  306. ...(R.is(Function, this.getParams) ? this.getParams() : this.getParams),
  307. }
  308. if (this.cloudEnv) ret.cloud_env = this.cloudEnv
  309. return ret
  310. },
  311. handleOpenSidepage (row, tab) {
  312. this.sidePageTriggerHandle(this, 'VpcSidePage', {
  313. id: row.id,
  314. resource: 'vpcs',
  315. getParams: this.getParam,
  316. }, {
  317. list: this.list,
  318. hiddenActions: this.hiddenActions,
  319. hiddenColumns: this.hiddenColumns,
  320. tab,
  321. })
  322. },
  323. defaultSearchKey (search) {
  324. if (regexp.isPrefixStr(search)) {
  325. return 'cidr_block'
  326. }
  327. },
  328. },
  329. }
  330. </script>