JoinProject.vue 5.1 KB

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