List.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <page-list
  3. ref="EXTERNAL"
  4. show-tag-filter
  5. :list="list"
  6. :columns="columns"
  7. :group-actions="groupActions"
  8. :single-actions="singleActions"
  9. :showSearchbox="showSearchbox"
  10. :showGroupActions="showGroupActions"
  11. :export-data-options="exportDataOptions"
  12. :editConfig="{trigger: 'click', mode: 'row', showIcon: false}"
  13. :extra-export-params="extraExportParams" />
  14. </template>
  15. <script>
  16. import { mapGetters } from 'vuex'
  17. import WindowsMixin from '@/mixins/windows'
  18. import ListMixin from '@/mixins/list'
  19. import {
  20. getNameDescriptionTableColumn,
  21. getTimeTableColumn,
  22. getProjectDomainTableColumn,
  23. getStatusTableColumn,
  24. getTagTableColumn,
  25. } from '@/utils/common/tableColumn'
  26. import { HYPERVISORS_MAP } from '@/constants'
  27. import expectStatus from '@/constants/expectStatus'
  28. import GlobalSearchMixin from '@/mixins/globalSearch'
  29. export default {
  30. name: 'ExternalprojectList',
  31. mixins: [WindowsMixin, ListMixin, GlobalSearchMixin],
  32. props: {
  33. getParams: {
  34. type: [Function, Object],
  35. },
  36. cloudaccount: Object,
  37. id: String,
  38. },
  39. data () {
  40. return {
  41. list: this.$list.createList(this, {
  42. id: this.id,
  43. resource: 'externalprojects',
  44. getParams: this.getParams,
  45. steadyStatus: Object.values(expectStatus.externalproject).flat(),
  46. filterOptions: {
  47. name: {
  48. label: this.$t('cloudenv.text_386'),
  49. filter: true,
  50. formatter: val => {
  51. return `name.contains("${val}")`
  52. },
  53. },
  54. cloudprovider_id: {
  55. label: this.$t('cloudevent.title.manager'),
  56. dropdown: true,
  57. multiple: false,
  58. distinctField: {
  59. type: 'extra_field',
  60. key: 'manager',
  61. },
  62. },
  63. projects: {
  64. label: this.$t('table.title.local_project'),
  65. dropdown: true,
  66. multiple: true,
  67. distinctField: {
  68. type: 'extra_field',
  69. key: 'tenant',
  70. },
  71. },
  72. },
  73. projectOpts: [],
  74. }),
  75. multipleChangeEnable: false,
  76. exportDataOptions: {
  77. items: [
  78. { label: 'ID', key: 'id' },
  79. { label: this.$t('cloudenv.text_386'), key: 'name' },
  80. {
  81. key: 'manager',
  82. label: this.$t('cloudevent.title.manager'),
  83. },
  84. { label: this.$t('cloudenv.text_98'), key: 'status' },
  85. { label: this.$t('cloudenv.priority'), key: 'priority' },
  86. {
  87. label: this.$t('table.title.owner_domain'),
  88. key: 'project_domain',
  89. },
  90. {
  91. label: this.$t('table.title.local_project'),
  92. key: 'tenant',
  93. },
  94. { label: this.$t('cloudenv.text_103'), key: 'created_at' },
  95. ],
  96. },
  97. extraExportParams: {
  98. cloudaccount_id: this.cloudaccount?.id,
  99. },
  100. groupActions: [
  101. {
  102. label: this.$t('cloudenv.text_104'),
  103. permission: 'externalprojects_create',
  104. action: obj => {
  105. this.createDialog('ExternalProjectCreateDialog', {
  106. cloudaccount: this.cloudaccount,
  107. name: this.$t('cloudenv.text_386'),
  108. onManager: this.onManager,
  109. })
  110. },
  111. meta: () => {
  112. return {
  113. buttonType: 'primary',
  114. validate: this.isAllowCreate,
  115. tooltip: this.isAllowCreate ? '' : this.$t('cloudenv.brand_action_deny'),
  116. }
  117. },
  118. },
  119. {
  120. label: this.$t('cloudenv.text_388'),
  121. permission: 'externalprojects_update',
  122. action: obj => {
  123. this.createDialog('ExternalProjectSwitchLocalDialog', {
  124. data: this.list.selectedItems,
  125. cloudaccount: this.cloudaccount,
  126. title: this.$t('cloudenv.text_388'),
  127. name: this.$t('dictionary.project'),
  128. columns: this.columns,
  129. onManager: this.onManager,
  130. })
  131. },
  132. meta: () => {
  133. return {
  134. validate: this.list.selectedItems.length && this.isOwner(),
  135. }
  136. },
  137. },
  138. {
  139. label: this.$t('cloudenv.multiple_modify'),
  140. action: obj => {
  141. this.multipleChangeEnable = true
  142. },
  143. hidden: () => {
  144. return this.multipleChangeEnable
  145. },
  146. meta: () => {
  147. return {
  148. validate: this.isOwner(),
  149. }
  150. },
  151. },
  152. {
  153. label: this.$t('cloudenv.exit_multiple_modify'),
  154. action: obj => {
  155. this.multipleChangeEnable = false
  156. },
  157. hidden: () => {
  158. return !this.multipleChangeEnable
  159. },
  160. },
  161. ],
  162. singleActions: [
  163. {
  164. label: this.$t('cloudenv.text_388'),
  165. permission: 'externalprojects_update',
  166. action: obj => {
  167. this.createDialog('ExternalProjectSwitchLocalDialog', {
  168. data: [obj],
  169. cloudaccount: this.cloudaccount,
  170. title: this.$t('cloudenv.text_388'),
  171. name: this.$t('dictionary.project'),
  172. columns: this.columns,
  173. onManager: this.onManager,
  174. })
  175. },
  176. meta: () => {
  177. return {
  178. validate: this.isOwner(),
  179. }
  180. },
  181. },
  182. {
  183. label: this.$t('cloudenv.set_priority'),
  184. permission: 'externalprojects_update',
  185. action: obj => {
  186. this.createDialog('ExternalProjectSetPriorityDialog', {
  187. data: [obj],
  188. cloudaccount: this.cloudaccount,
  189. title: this.$t('cloudenv.set_priority'),
  190. name: this.$t('cloudenv.text_386'),
  191. columns: this.columns,
  192. onManager: this.onManager,
  193. })
  194. },
  195. },
  196. {
  197. label: this.$t('cloudenv.view_record'),
  198. permission: 'log_list',
  199. action: obj => {
  200. this.createDialog('ExternalProjectLogDialog', {
  201. data: [obj],
  202. })
  203. },
  204. },
  205. ],
  206. projectOpts: [],
  207. }
  208. },
  209. computed: {
  210. ...mapGetters(['isAdminMode', 'userInfo']),
  211. columns () {
  212. const projectColumn = {
  213. field: 'project',
  214. title: this.$t('table.title.local_project'),
  215. }
  216. if (this.multipleChangeEnable) {
  217. projectColumn.editRender = {
  218. name: '$select',
  219. options: this.projectOpts,
  220. events: { change: this.projectChange },
  221. }
  222. projectColumn.slots = {
  223. default: ({ row }) => {
  224. let project = row.project
  225. const filter = this.projectOpts.filter(item => item.value === project)
  226. if (filter[0]) project = filter[0].label
  227. return [<span><span>{project} </span> <i class="vxe-icon--edit-outline"></i></span>]
  228. },
  229. }
  230. }
  231. const ret = [
  232. getNameDescriptionTableColumn({
  233. title: this.$t('cloudenv.text_386'),
  234. onManager: this.onManager,
  235. hideField: true,
  236. showDesc: false,
  237. edit: this.isAllowCreate,
  238. formRules: [
  239. { required: true, message: this.$t('cloudenv.text_190') },
  240. { validator: this.$validate('externalProjectName') },
  241. ],
  242. slotCallback: row => {
  243. return row.name || '-'
  244. },
  245. }),
  246. {
  247. field: 'manager',
  248. title: this.$t('cloudevent.title.manager'),
  249. formatter: ({ row }) => {
  250. return row.manager || '-'
  251. },
  252. },
  253. getStatusTableColumn({
  254. statusModule: 'externalproject',
  255. sortable: false,
  256. helpTool: {
  257. isOpen: true,
  258. title: this.$t('cloudenv.helptool.unavailable.title.tooltip'),
  259. status: ['unavailable'],
  260. },
  261. }),
  262. getTagTableColumn({
  263. onManager: this.onManager,
  264. resource: 'externalprojects',
  265. columns: () => this.columns,
  266. tipName: this.$t('cloudenv.text_386'),
  267. }),
  268. getProjectDomainTableColumn(),
  269. projectColumn,
  270. {
  271. field: 'priority',
  272. title: this.$t('cloudenv.priority'),
  273. sortable: true,
  274. },
  275. getTimeTableColumn({
  276. field: 'created_at',
  277. title: this.$t('cloudenv.text_103'),
  278. }),
  279. ]
  280. return ret
  281. },
  282. isAllowCreate () {
  283. if (this.cloudaccount && [HYPERVISORS_MAP.azure.provider, HYPERVISORS_MAP.qcloud.provider, HYPERVISORS_MAP.aliyun.provider, HYPERVISORS_MAP.huawei.provider, HYPERVISORS_MAP.ksyun.provider].includes(this.cloudaccount.provider)) {
  284. return true
  285. }
  286. return false
  287. },
  288. },
  289. created () {
  290. this.list.fetchData()
  291. this.pm = new this.$Manager('projects', 'v1')
  292. this.fetchProjects()
  293. },
  294. methods: {
  295. isOwner () {
  296. return this.isAdminMode || (this.cloudaccount && this.cloudaccount.domain_id === this.userInfo.projectDomainId)
  297. },
  298. async fetchProjects () {
  299. if (!this.cloudaccount || !this.cloudaccount.domain_id) return
  300. const res = await this.pm.list({
  301. params: {
  302. scope: this.$store.getters.scope,
  303. domain_id: this.cloudaccount.domain_id,
  304. limit: 0,
  305. },
  306. })
  307. const { data: projects = [] } = res.data
  308. this.projectOpts = projects.map(item => {
  309. return {
  310. label: item.name,
  311. value: item.id,
  312. }
  313. })
  314. },
  315. async projectChange (data) {
  316. try {
  317. await this.onManager('performAction', {
  318. id: data.row.id,
  319. steadyStatus: Object.values(expectStatus.externalproject).flat(),
  320. managerArgs: {
  321. action: 'change-project',
  322. data: {
  323. project: data.row.project,
  324. },
  325. },
  326. })
  327. this.$message.success(this.$t('cloudenv.modify_success'))
  328. } catch (error) {
  329. throw error
  330. }
  331. },
  332. },
  333. }
  334. </script>