SetPolicy.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('cloudenv.cloudgroup_single_action2') }}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.cloudgroup')" :count="params.data.length" :action="$t('cloudenv.cloudgroup_single_action2')" />
  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.policy')">
  11. <list-select
  12. v-decorator="decorators.cloudpolicy_ids"
  13. :listProps="policySelectProps"
  14. :formatter="row => `${row.name} / ${row.description || ''}`"
  15. :dialog-params="{ mask: false, width: 900, title: $t('rules.policy') }" />
  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 get from 'lodash/get'
  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: 'CloudgroupSetPolicyDialog',
  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. fi: {
  43. generate_name: '',
  44. },
  45. },
  46. decorators: {
  47. cloudpolicy_ids: [
  48. 'cloudpolicy_ids',
  49. {
  50. validateFirst: true,
  51. initialValue: get(this.params.data[0], 'cloudpolicies', []).map(item => item.id),
  52. },
  53. ],
  54. },
  55. policySelectProps: {
  56. list: this.$list.createList(this, {
  57. id: this.id,
  58. resource: 'cloudpolicies',
  59. apiVersion: 'v1',
  60. getParams: () => {
  61. return {
  62. scope: this.$store.getters.scope,
  63. manager_id: this.params.data[0].manager_id,
  64. cloudaccount_id: this.params.data[0].cloudaccount_id,
  65. }
  66. },
  67. filterOptions: {
  68. name: getNameFilter(),
  69. },
  70. }),
  71. columns: [
  72. {
  73. field: 'name',
  74. title: this.$t('table.title.name'),
  75. showOverflow: 'title',
  76. },
  77. {
  78. field: 'description',
  79. title: this.$t('table.title.desc'),
  80. showOverflow: 'title',
  81. },
  82. ],
  83. },
  84. formItemLayout: {
  85. wrapperCol: {
  86. span: 21,
  87. },
  88. labelCol: {
  89. span: 3,
  90. },
  91. },
  92. }
  93. },
  94. methods: {
  95. async handleConfirm () {
  96. this.loading = true
  97. try {
  98. const values = await this.form.fc.validateFields()
  99. await this.params.onManager('performAction', {
  100. steadyStatus: ['available'],
  101. id: this.params.data[0].id,
  102. managerArgs: {
  103. action: 'set-policies',
  104. data: {
  105. ...values,
  106. provider: this.params.data[0].provider,
  107. },
  108. },
  109. })
  110. if (this.params.success) {
  111. this.params.success()
  112. }
  113. this.cancelDialog()
  114. } finally {
  115. this.loading = false
  116. }
  117. },
  118. },
  119. }
  120. </script>