ProjectJoin.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <!--a-alert :message="$t('system.text_508', [$t('dictionary.role')])" type="warning" class="mb-2" /-->
  6. <dialog-selected-tips :name="$t('dictionary.user')" :count="params.data.length" :action="action" />
  7. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form
  9. :form="form.fc"
  10. v-bind="formItemLayout">
  11. <a-form-item :label="$t('dictionary.domain')" v-if="isAdminMode">
  12. <a-radio-group v-decorator="decorators.domain" @change="domainChange" v-if="!l3PermissionEnable">
  13. <a-radio-button v-for="item in domainOptions" :value="item.key" :key="item.key">{{ item.label }}</a-radio-button>
  14. </a-radio-group>
  15. <base-select v-else
  16. v-decorator="decorators.domain"
  17. version="v1"
  18. resource="domains"
  19. filterable
  20. :params="domainParams"
  21. :select-props="{ placeholder: $t('rules.project') }"
  22. @change="domainChange" />
  23. </a-form-item>
  24. <a-form-item :label="$t('dictionary.project')">
  25. <base-select
  26. resource="projects"
  27. v-decorator="decorators.projects"
  28. filterable
  29. remote
  30. :select-props="{placeholder: $t('rules.project'), mode: 'multiple'}"
  31. :params="projectParams">
  32. <template #optionLabelTemplate="{item}">
  33. {{item.name}}
  34. </template>
  35. </base-select>
  36. </a-form-item>
  37. <a-form-item :label="$t('dictionary.role')">
  38. <base-select
  39. resource="roles"
  40. v-decorator="decorators.roles"
  41. filterable
  42. remote
  43. :select-props="{placeholder: $t('rules.role'), mode: 'multiple'}"
  44. :params="roleParams">
  45. <template #optionLabelTemplate="{item}">
  46. {{item.name}}
  47. </template>
  48. </base-select>
  49. </a-form-item>
  50. <a-form-item v-if="isUserDisabled" :label="$t('iam.enabled_user')" v-bind="formItemLayout" :extra="$t('iam.user_can_enabled')">
  51. <a-switch
  52. :checkedChildren="$t('common_292')"
  53. :unCheckedChildren="$t('common_293')"
  54. v-decorator="decorators.enabled" />
  55. </a-form-item>
  56. </a-form>
  57. </div>
  58. <div slot="footer">
  59. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  60. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  61. </div>
  62. </base-dialog>
  63. </template>
  64. <script>
  65. // import get from 'lodash/get'
  66. import { mapGetters } from 'vuex'
  67. import DialogMixin from '@/mixins/dialog'
  68. import WindowsMixin from '@/mixins/windows'
  69. export default {
  70. name: 'UserProjectJoinDialog',
  71. mixins: [DialogMixin, WindowsMixin],
  72. data () {
  73. const domainId = this.params.data[0].domain_id
  74. return {
  75. action: this.$t('system.text_195', [this.$t('dictionary.project')]),
  76. loading: false,
  77. projectList: [],
  78. projectLoading: false,
  79. roleList: [],
  80. roleLoading: false,
  81. form: {
  82. fc: this.$form.createForm(this),
  83. },
  84. domainId,
  85. decorators: {
  86. domain: [
  87. 'domain',
  88. {
  89. initialValue: domainId,
  90. },
  91. ],
  92. projects: [
  93. 'projects',
  94. {
  95. rules: [
  96. { required: true, message: this.$t('rules.project') },
  97. ],
  98. },
  99. ],
  100. roles: [
  101. 'roles',
  102. {
  103. rules: [
  104. { required: true, message: this.$t('rules.role') },
  105. ],
  106. },
  107. ],
  108. enabled: [
  109. 'enabled',
  110. {
  111. initialValue: false,
  112. },
  113. ],
  114. },
  115. formItemLayout: {
  116. wrapperCol: {
  117. span: 20,
  118. },
  119. labelCol: {
  120. span: 4,
  121. },
  122. },
  123. }
  124. },
  125. computed: {
  126. ...mapGetters(['isDomainMode', 'isAdminMode', 'l3PermissionEnable', 'scope']),
  127. domainOptions () {
  128. return [{
  129. label: 'Default',
  130. key: 'default',
  131. }]
  132. },
  133. domainParams () {
  134. return {
  135. scope: this.scope,
  136. }
  137. },
  138. projectParams () {
  139. const ret = {
  140. scope: this.scope,
  141. project_domain_id: this.domainId,
  142. limit: 20,
  143. }
  144. return ret
  145. },
  146. roleParams () {
  147. const ret = {
  148. scope: this.scope,
  149. project_domain_id: this.domainId,
  150. limit: 20,
  151. }
  152. return ret
  153. },
  154. isUserDisabled () {
  155. return !this.params.data[0].enabled
  156. },
  157. },
  158. created () {
  159. if (!this.l3PermissionEnable) {
  160. this.domainId = 'default'
  161. }
  162. },
  163. methods: {
  164. async handleConfirm () {
  165. this.loading = true
  166. const manager = new this.$Manager('users', 'v1')
  167. try {
  168. const values = await this.form.fc.validateFields()
  169. await manager.performAction({
  170. id: this.params.data[0].id,
  171. action: 'join',
  172. data: values,
  173. })
  174. this.cancelDialog()
  175. this.$bus.$emit('UserSidepageProjectsListRefresh')
  176. if (values.enabled) {
  177. this.$bus.$emit('RefreshUser', this.params.data[0].id)
  178. }
  179. } catch (error) {
  180. this.loading = false
  181. throw error
  182. }
  183. },
  184. domainChange (val) {
  185. this.domainId = val
  186. },
  187. },
  188. }
  189. </script>