List.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions"
  7. :export-data-options="exportDataOptions" />
  8. </template>
  9. <script>
  10. import expectStatus from '@/constants/expectStatus'
  11. import WindowsMixin from '@/mixins/windows'
  12. import ListMixin from '@/mixins/list'
  13. import { getEnabledSwitchActions } from '@/utils/common/tableActions'
  14. import { getStatusFilter, getEnabledFilter, getTenantFilter, getDescriptionFilter } from '@/utils/common/tableFilter'
  15. import SingleActionsMixin from '../mixins/singleActions'
  16. import ColumnsMixin from '../mixins/columns'
  17. export default {
  18. name: 'CloudproviderList',
  19. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  20. props: {
  21. getParams: {
  22. type: [Function, Object],
  23. },
  24. data: {
  25. type: Object,
  26. },
  27. cloudaccountListRefresh: {
  28. type: Function,
  29. },
  30. id: String,
  31. },
  32. data () {
  33. const ownerDomain = list => this.$store.getters.isAdminMode || list.selectedItems.every(obj => obj.domain_id === this.$store.getters.userInfo.projectDomainId)
  34. const isAccountDomain = data => data.share_mode === 'account_domain'
  35. return {
  36. list: this.$list.createList(this, {
  37. id: this.id,
  38. resource: 'cloudproviders',
  39. getParams: this.getParams,
  40. steadyStatus: Object.values(expectStatus.cloudaccount).flat(),
  41. filterOptions: {
  42. external_id: {
  43. label: this.$t('table.title.external_id'),
  44. },
  45. id: {
  46. label: this.$t('table.title.id'),
  47. },
  48. name: {
  49. label: this.$t('cloudenv.text_95'),
  50. filter: true,
  51. formatter: val => {
  52. return `name.contains("${val}")`
  53. },
  54. },
  55. description: getDescriptionFilter(),
  56. status: getStatusFilter('cloudaccount'),
  57. enabled: getEnabledFilter(),
  58. account: {
  59. label: this.$t('cloudenv.text_353'),
  60. filter: true,
  61. filterAny: true,
  62. formatter: val => {
  63. return val.map(id => `account.contains("${id}")`)
  64. },
  65. },
  66. projects: getTenantFilter(),
  67. },
  68. }),
  69. groupActions: [
  70. {
  71. label: this.$t('cloudenv.text_104'),
  72. permission: 'cloudproviders_create',
  73. action: () => {
  74. this.createDialog('cloudproviderCreateDialog', {
  75. data: this.data,
  76. onManager: this.onManager,
  77. refresh: this.refresh,
  78. })
  79. },
  80. meta: () => {
  81. return {
  82. buttonType: 'primary',
  83. validate: this.data.brand === 'Azure' && this.data.access_url === 'AzurePublicCloud',
  84. tooltip: !(this.data.brand === 'Azure' && this.data.access_url === 'AzurePublicCloud') && this.$t('cloudenv.text_333_1'),
  85. }
  86. },
  87. },
  88. {
  89. label: this.$t('common.batchAction'),
  90. actions: obj => {
  91. return [
  92. {
  93. label: this.$t('cloudenv.set_project_mapping'),
  94. permission: 'cloudproviders_perform_project_mapping',
  95. action: () => {
  96. this.createDialog('CloudproviderSetPojectmappingDialog', {
  97. data: this.list.selectedItems,
  98. columns: this.columns,
  99. onManager: this.onManager,
  100. })
  101. },
  102. meta: () => {
  103. return {
  104. validate: !!this.list.selectedItems.length,
  105. }
  106. },
  107. },
  108. ...getEnabledSwitchActions(this, undefined, ['cloudproviders_perform_enable', 'cloudproviders_perform_disable'], {
  109. actions: [
  110. async (obj) => {
  111. const ids = this.list.selectedItems.map(item => item.id)
  112. await this.onManager('batchPerformAction', {
  113. id: ids,
  114. managerArgs: {
  115. action: 'enable',
  116. },
  117. })
  118. this.$bus.$emit('CloudAccountListSingleRefresh', [this.data.id])
  119. },
  120. async (obj) => {
  121. const ids = this.list.selectedItems.map(item => item.id)
  122. await this.onManager('batchPerformAction', {
  123. id: ids,
  124. managerArgs: {
  125. action: 'disable',
  126. },
  127. })
  128. this.$bus.$emit('CloudAccountListSingleRefresh', [this.data.id])
  129. },
  130. ],
  131. metas: [
  132. () => {
  133. const isDisable = !!this.list.selectedItems.find(item => !item.enabled)
  134. return {
  135. validate: this.list.selectedItems.length && ownerDomain && isDisable,
  136. }
  137. },
  138. () => {
  139. const isEnable = !!this.list.selectedItems.find(item => item.enabled)
  140. return {
  141. validate: this.list.selectedItems.length && ownerDomain && isEnable,
  142. }
  143. },
  144. ],
  145. }),
  146. {
  147. label: this.$t('cloudenv.text_294', [this.$t('dictionary.project')]),
  148. permission: 'cloudproviders_perform_change_project',
  149. action: () => {
  150. if (isAccountDomain(this.data)) {
  151. this.createDialog('ChangeProjectDialog', {
  152. name: this.$t('dictionary.cloudprovider'),
  153. data: this.list.selectedItems,
  154. columns: this.columns,
  155. onManager: this.onManager,
  156. alertMessage: this.$t('cloudenv.text_336', [this.$t('dictionary.project'), this.$t('dictionary.domain'), this.$t('dictionary.domain')]),
  157. })
  158. } else {
  159. this.createDialog('ChangeOwenrDialog', {
  160. name: this.$t('dictionary.cloudprovider'),
  161. data: this.list.selectedItems,
  162. columns: this.columns,
  163. onManager: this.onManager,
  164. action: 'change-project',
  165. resource: 'cloudproviders',
  166. alertMessage: this.$t('cloudenv.text_336', [this.$t('dictionary.project'), this.$t('dictionary.domain'), this.$t('dictionary.domain')]),
  167. })
  168. }
  169. },
  170. meta: () => {
  171. return {
  172. validate: this.list.selectedItems.length && this.list.selectedItems.every(val => val.enabled) && ownerDomain(this.list),
  173. }
  174. },
  175. },
  176. {
  177. label: this.$t('cloudenv.text_108'),
  178. permission: 'cloudproviders_delete',
  179. action: () => {
  180. this.createDialog('DeleteResDialog', {
  181. vm: this,
  182. data: this.list.selectedItems,
  183. columns: this.columns,
  184. title: this.$t('cloudenv.text_108'),
  185. onManager: this.onManager,
  186. name: this.$t('cloudenv.text_318'),
  187. alert: this.$t('cloudenv.cloudprovider.delete_tip'),
  188. })
  189. },
  190. meta: () => {
  191. let tooltip
  192. let validate
  193. const isEnabled = this.list.selectedItems.some(val => val.enabled)
  194. const isSyncing = this.list.selectedItems.some(val => val.sync_status === 'syncing')
  195. if (isSyncing) {
  196. tooltip = this.$t('cloudenv.cloudprovider.sync_delete')
  197. validate = false
  198. }
  199. if (isEnabled) {
  200. tooltip = this.$t('network.text_310')
  201. validate = false
  202. }
  203. if (this.data.brand !== 'Azure') {
  204. tooltip = this.$t('cloudenv.text_333')
  205. validate = false
  206. }
  207. if (!this.list.selectedItems.length || !ownerDomain(this.list)) {
  208. tooltip = ''
  209. validate = false
  210. }
  211. return {
  212. tooltip,
  213. validate,
  214. }
  215. },
  216. },
  217. ]
  218. },
  219. meta: () => {
  220. return {
  221. validate: this.list.selectedItems.length,
  222. }
  223. },
  224. },
  225. ],
  226. }
  227. },
  228. computed: {
  229. exportDataOptions () {
  230. return {
  231. downloadType: 'local',
  232. title: this.$t('cloudenv.text_318'),
  233. items: this.columns,
  234. getParams: this.getParams,
  235. hiddenFields: ['resource_tenant'],
  236. fixedItems: [
  237. { key: 'tenant', label: this.$t('cloudenv.text_356', [this.$t('dictionary.project')]) },
  238. { key: 'project_mapping', label: this.$t('cloudenv.text_580') },
  239. ],
  240. }
  241. },
  242. },
  243. created () {
  244. this.initSidePageTab('cloudaccount-detail')
  245. this.list.fetchData()
  246. },
  247. methods: {
  248. handleOpenSidepage (row) {
  249. this.sidePageTriggerHandle(this, 'CloudproviderSidePage', {
  250. id: row.id,
  251. resource: 'cloudproviders',
  252. getParams: this.getParams,
  253. }, {
  254. list: this.list,
  255. })
  256. },
  257. },
  258. }
  259. </script>