SetGroups.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('cloudenv.clouduser_list_a1') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.clouduser')" :count="params.data.length" :action="$t('cloudenv.clouduser_list_a1')" />
  6. <dialog-table class="mb-2" :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('dictionary.cloudgroup')" :extra="$t('cloudenv.clouduser_text2')">
  11. <list-select
  12. v-decorator="decorators.cloudgroup_ids"
  13. :listProps="cloudgroupListSelectProps"
  14. :formatter="formatterLabel"
  15. :dialog-params="{ mask: false }" />
  16. </a-form-item>
  17. </a-form>
  18. </div>
  19. <div slot="footer">
  20. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  21. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  22. </div>
  23. </base-dialog>
  24. </template>
  25. <script>
  26. import * as R from 'ramda'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. import ListSelect from '@/sections/ListSelect'
  30. import { getNameFilter } from '@/utils/common/tableFilter'
  31. export default {
  32. name: 'ClouduserSetGroupsDialog',
  33. components: {
  34. ListSelect,
  35. },
  36. mixins: [DialogMixin, WindowsMixin],
  37. data () {
  38. return {
  39. loading: false,
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. decorators: {
  44. cloudgroup_ids: [
  45. 'cloudgroup_ids',
  46. {
  47. initialValue: this.params.data[0].cloudgroups && this.params.data[0].cloudgroups.map(item => item.id),
  48. },
  49. ],
  50. },
  51. formItemLayout: {
  52. wrapperCol: {
  53. span: 19,
  54. },
  55. labelCol: {
  56. span: 5,
  57. },
  58. },
  59. cloudgroupListSelectProps: {
  60. list: this.$list.createList(this, {
  61. id: this.id,
  62. resource: 'cloudgroups',
  63. apiVersion: 'v1',
  64. getParams: () => {
  65. return {
  66. scope: this.$store.getters.scope,
  67. manager_id: this.params.data[0].manager_id,
  68. cloudaccount_id: this.params.data[0].cloudaccount_id,
  69. }
  70. },
  71. filterOptions: {
  72. name: getNameFilter(),
  73. },
  74. }),
  75. columns: [
  76. {
  77. field: 'name',
  78. title: this.$t('table.title.name'),
  79. showOverflow: 'title',
  80. sortable: true,
  81. },
  82. {
  83. field: 'description',
  84. title: this.$t('table.title.desc'),
  85. showOverflow: 'title',
  86. },
  87. {
  88. field: 'cloudpolicies',
  89. title: this.$t('cloudenv.text_329'),
  90. slots: {
  91. default: ({ row }) => {
  92. if (R.isNil(row.cloudpolicies) || R.isEmpty(row.cloudpolicies)) return this.$t('cloudenv.text_330')
  93. return [<list-body-cell-popover text={this.$t('cloudenv.text_245', [(row.cloudpolicies && row.cloudpolicies.length) || 0])} min-width="600px">
  94. <vxe-grid
  95. showOverflow={false}
  96. row-config={{ isHover: true }}
  97. column-config={{ resizable: false }}
  98. data={ row.cloudpolicies }
  99. columns={[
  100. {
  101. field: 'name',
  102. title: this.$t('common.name'),
  103. },
  104. {
  105. field: 'description',
  106. title: this.$t('table.title.desc'),
  107. formatter: ({ cellValue }) => cellValue || '-',
  108. },
  109. ]} />
  110. </list-body-cell-popover>]
  111. },
  112. },
  113. },
  114. ],
  115. // expandConfig: {
  116. // lazy: true,
  117. // loadMethod: async ({ row }) => {
  118. // let manager = new this.$Manager('cloudpolicies', 'v1')
  119. // try {
  120. // const response = await manager.list({
  121. // params: {
  122. // cloudgroup_id: row.id,
  123. // scope: this.$store.getters.scope,
  124. // },
  125. // })
  126. // row.feCloudpolicies = response.data.data || []
  127. // return response
  128. // } catch (error) {
  129. // throw error
  130. // } finally {
  131. // manager = null
  132. // }
  133. // },
  134. // // visibleMethod: ({ row }) => {
  135. // // return row.cloudpolicies && row.cloudpolicies.length > 0
  136. // // },
  137. // },
  138. },
  139. }
  140. },
  141. methods: {
  142. formatterLabel (row) {
  143. return row.description ? `${row.name} / ${row.description}` : row.name
  144. },
  145. async handleConfirm () {
  146. this.loading = true
  147. try {
  148. const values = await this.form.fc.validateFields()
  149. await this.params.onManager('performAction', {
  150. id: this.params.data[0].id,
  151. steadyStatus: 'available',
  152. managerArgs: {
  153. action: 'set-groups',
  154. data: values,
  155. },
  156. })
  157. if (this.params.success) {
  158. this.params.success()
  159. }
  160. this.cancelDialog()
  161. } finally {
  162. this.loading = false
  163. }
  164. },
  165. },
  166. }
  167. </script>