GroupJoin.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_498', [$t('dictionary.group')])}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.user')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :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.group')">
  11. <a-select
  12. :filterOption="filterOption"
  13. :loading="groupLoading"
  14. v-decorator="decorators.groups"
  15. mode="multiple"
  16. :placeholder="$t('rules.group')">
  17. <a-select-option v-for="item in groups" :key="item.id">
  18. {{item.name}}
  19. </a-select-option>
  20. </a-select>
  21. </a-form-item>
  22. <a-form-item v-if="isUserDisabled" :label="$t('iam.enabled_user')" v-bind="formItemLayout" :extra="$t('iam.user_can_enabled')">
  23. <a-switch
  24. :checkedChildren="$t('common_292')"
  25. :unCheckedChildren="$t('common_293')"
  26. v-decorator="decorators.enabled" />
  27. </a-form-item>
  28. </a-form>
  29. </div>
  30. <div slot="footer">
  31. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  32. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  33. </div>
  34. </base-dialog>
  35. </template>
  36. <script>
  37. import DialogMixin from '@/mixins/dialog'
  38. import WindowsMixin from '@/mixins/windows'
  39. export default {
  40. name: 'UserGroupJoinDialog',
  41. mixins: [DialogMixin, WindowsMixin],
  42. data () {
  43. return {
  44. loading: false,
  45. groups: [],
  46. groupLoading: false,
  47. form: {
  48. fc: this.$form.createForm(this),
  49. },
  50. decorators: {
  51. groups: [
  52. 'groups',
  53. {
  54. validateFirst: true,
  55. rules: [
  56. { required: true, message: this.$t('system.text_499') },
  57. ],
  58. },
  59. ],
  60. enabled: [
  61. 'enabled',
  62. {
  63. initialValue: false,
  64. },
  65. ],
  66. },
  67. formItemLayout: {
  68. wrapperCol: {
  69. span: 20,
  70. },
  71. labelCol: {
  72. span: 4,
  73. },
  74. },
  75. }
  76. },
  77. computed: {
  78. isUserDisabled () {
  79. return !this.params.data[0].enabled
  80. },
  81. },
  82. created () {
  83. this.fetchGroups()
  84. },
  85. methods: {
  86. filterOption (input, option) {
  87. return (
  88. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  89. )
  90. },
  91. async fetchGroups (query) {
  92. const manager = new this.$Manager('groups', 'v1')
  93. this.groupLoading = true
  94. try {
  95. const { data } = await manager.list({
  96. params: {
  97. domain_id: this.params.data[0].domain_id,
  98. scope: this.$store.getters.scope,
  99. },
  100. })
  101. this.groups = data.data || []
  102. } catch (err) {
  103. throw err
  104. } finally {
  105. this.groupLoading = false
  106. }
  107. },
  108. async handleConfirm () {
  109. this.loading = true
  110. const { refresh } = this.params
  111. try {
  112. const values = await this.form.fc.validateFields()
  113. const data = {
  114. gids: values.groups,
  115. action: 'join',
  116. }
  117. if (values.enabled) data.enabled = true
  118. await new this.$Manager('users', 'v1').objectRpc({
  119. objId: this.params.resItem.id,
  120. methodname: 'DoJoinGroups',
  121. params: data,
  122. })
  123. if (values.enabled) {
  124. this.$bus.$emit('RefreshUser', this.params.resItem.id)
  125. }
  126. refresh()
  127. this.cancelDialog()
  128. } catch (error) {
  129. this.loading = false
  130. throw error
  131. }
  132. },
  133. },
  134. }
  135. </script>