Create.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('samluser.create_title') }}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc"
  7. v-bind="formItemLayout">
  8. <a-form-item :label="$t('cloudenv.clouduser_list_t4')" :extra="$t('common_625')">
  9. <user-select
  10. v-decorator="decorators.owner_id"
  11. :cloudaccount-id="params.cloudaccount.id"
  12. :user.sync="form.fi.user"
  13. :project.sync="form.fi.project"
  14. :cloudprovider-id="form.fi.cloudprovider.id"
  15. :defaultDomainId="params.defaultDomainId"
  16. :defaultProjectId="params.defaultProjectId"
  17. :defaultUserId="params.userId" />
  18. </a-form-item>
  19. <template>
  20. <a-form-item :label="$t('dictionary.cloudprovider')">
  21. <base-select
  22. v-decorator="decorators.cloudprovider_id"
  23. resource="cloudproviders"
  24. filterable
  25. isDefaultSelect
  26. :params="cloudproviderParams"
  27. :item.sync="form.fi.cloudprovider"
  28. @change="cloudproviderChange" />
  29. </a-form-item>
  30. </template>
  31. <a-form-item :label="$t('dictionary.cloudusergroup')" :extra="$t('samluser.create_cloudgroup_extra')">
  32. <list-select
  33. v-decorator="decorators.cloudgroup_id"
  34. :listProps="cloudgroupListSelectProps"
  35. :formatter="formatterLabel"
  36. :dialog-params="{ mask: false }"
  37. :multiple="false" />
  38. </a-form-item>
  39. </a-form>
  40. </div>
  41. <div slot="footer">
  42. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  43. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  44. </div>
  45. </base-dialog>
  46. </template>
  47. <script>
  48. import * as R from 'ramda'
  49. import DialogMixin from '@/mixins/dialog'
  50. import WindowsMixin from '@/mixins/windows'
  51. import { getNameFilter } from '@/utils/common/tableFilter'
  52. import ListSelect from '@/sections/ListSelect'
  53. import UserSelect from '../components/UserSelect'
  54. export default {
  55. name: 'SamluserCreateDialog',
  56. components: {
  57. UserSelect,
  58. ListSelect,
  59. },
  60. mixins: [DialogMixin, WindowsMixin],
  61. props: {
  62. params: {
  63. type: Object,
  64. default: () => {},
  65. },
  66. },
  67. data () {
  68. return {
  69. loading: false,
  70. form: {
  71. fc: this.$form.createForm(this),
  72. fi: {
  73. user: {},
  74. cloudprovider: {},
  75. project: {},
  76. },
  77. },
  78. decorators: {
  79. owner_id: [
  80. 'owner_id',
  81. {
  82. rules: [
  83. { required: true, message: this.$t('common.select') },
  84. ],
  85. },
  86. ],
  87. cloudprovider_id: [
  88. 'cloudprovider_id',
  89. {
  90. rules: [
  91. { required: true, message: this.$t('common.select') },
  92. ],
  93. },
  94. ],
  95. cloudgroup_id: [
  96. 'cloudgroup_id',
  97. {
  98. rules: [
  99. { required: true, message: this.$t('common.select') },
  100. // { required: this.params.cloudaccount.brand === 'Google', message: this.$t('common.select') },
  101. ],
  102. },
  103. ],
  104. },
  105. cloudgroupListSelectProps: {
  106. list: this.$list.createList(this, {
  107. id: this.id,
  108. resource: 'cloudgroups',
  109. apiVersion: 'v1',
  110. getParams: () => {
  111. const params = {
  112. manager_id: this.form.fi.cloudprovider.id,
  113. }
  114. if (this.$store.getters.isAdminMode) {
  115. params.domain_id = this.params.cloudaccount.domain_id
  116. } else {
  117. params.scope = this.$store.getters.scope
  118. }
  119. return params
  120. },
  121. filterOptions: {
  122. name: getNameFilter(),
  123. },
  124. }),
  125. columns: [
  126. {
  127. field: 'name',
  128. title: this.$t('table.title.name'),
  129. showOverflow: 'title',
  130. },
  131. {
  132. field: 'description',
  133. title: this.$t('cloudenv.text_327'),
  134. showOverflow: 'title',
  135. },
  136. {
  137. field: 'cloudpolicies',
  138. title: this.$t('cloudenv.text_329'),
  139. slots: {
  140. default: ({ row }) => {
  141. if (R.isNil(row.cloudpolicies) || R.isEmpty(row.cloudpolicies)) return this.$t('cloudenv.text_330')
  142. return [<list-body-cell-popover text={this.$t('cloudenv.text_245', [(row.cloudpolicies && row.cloudpolicies.length) || 0])} min-width="600px">
  143. <vxe-grid
  144. showOverflow={false}
  145. row-config={{ isHover: true }}
  146. column-config={{ resizable: false }}
  147. data={ row.cloudpolicies }
  148. columns={[
  149. {
  150. field: 'name',
  151. title: this.$t('common.name'),
  152. },
  153. {
  154. field: 'description',
  155. title: this.$t('table.title.desc'),
  156. formatter: ({ cellValue }) => cellValue || '-',
  157. },
  158. ]} />
  159. </list-body-cell-popover>]
  160. },
  161. },
  162. },
  163. ],
  164. },
  165. formItemLayout: {
  166. wrapperCol: {
  167. span: 20,
  168. },
  169. labelCol: {
  170. span: 4,
  171. },
  172. },
  173. }
  174. },
  175. computed: {
  176. cloudproviderParams () {
  177. return {
  178. scope: this.$store.getters.scope,
  179. cloudaccount_id: this.params.cloudaccount.id,
  180. }
  181. },
  182. isGoogle () {
  183. return this.params.cloudaccount.brand === 'Google'
  184. },
  185. namePlaceholder () {
  186. if (this.form.fi.user && this.form.fi.user.name) {
  187. if (this.isGoogle) {
  188. return this.$t('cloudenv.text_377')
  189. }
  190. return this.form.fi.user.name
  191. }
  192. return ''
  193. },
  194. nameRepeatParams () {
  195. if (this.isGoogle) {
  196. return { cloudprovider_id: this.form.fi.cloudprovider.id }
  197. }
  198. return { cloudaccount_id: this.params.cloudaccount.id }
  199. },
  200. nameExtra () {
  201. if (this.isGoogle) return null
  202. return this.$t('cloudenv.clouduser_text1')
  203. },
  204. },
  205. methods: {
  206. cloudproviderChange () {
  207. this.form.fc.setFieldsValue({
  208. cloudgroup_id: null,
  209. })
  210. },
  211. async handleConfirm () {
  212. this.loading = true
  213. try {
  214. const { ...values } = await this.form.fc.validateFields()
  215. if (!this.isGoogle) {
  216. values.cloudaccount_id = this.params.cloudaccount.id
  217. }
  218. values.project_id = this.form.fi.project.id
  219. values.project_domain = this.form.fi.project.project_domain
  220. await this.params.onManager('create', {
  221. managerArgs: {
  222. data: values,
  223. },
  224. })
  225. this.cancelDialog()
  226. } finally {
  227. this.loading = false
  228. }
  229. },
  230. formatterLabel (row) {
  231. return row.description ? `${row.name} / ${row.description}` : row.name
  232. },
  233. },
  234. }
  235. </script>