Create.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.create') }}{{ $t('dictionary.clouduser') }}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc"
  7. v-bind="formItemLayout">
  8. <a-form-item :label="$t('cloudenv.text_375')" :extra="nameExtra">
  9. <a-input v-decorator="decorators.generate_name" :placeholder="namePlaceholder" @change="e => { form.fi.generate_name = e.target.value }" />
  10. <template v-slot:extra>
  11. <name-repeated
  12. res="cloudusers"
  13. version="v1"
  14. :name="form.fi.generate_name"
  15. :params="nameRepeatParams" />
  16. </template>
  17. </a-form-item>
  18. <template>
  19. <a-form-item :label="$t('dictionary.cloudprovider')">
  20. <base-select
  21. v-decorator="decorators.manager_id"
  22. resource="cloudproviders"
  23. filterable
  24. isDefaultSelect
  25. :params="cloudproviderParams"
  26. :item.sync="form.fi.cloudprovider" />
  27. </a-form-item>
  28. </template>
  29. <a-form-item :label="$t('cloudenv.clouduser_list_t4')" :extra="$t('common_625')">
  30. <user-select
  31. v-decorator="decorators.owner_id"
  32. :cloudaccount-id="params.cloudaccount.id"
  33. :user.sync="form.fi.user"
  34. :project.sync="form.fi.project"
  35. :cloudprovider-id="form.fi.cloudprovider.id"
  36. :defaultDomainId="params.defaultDomainId"
  37. :defaultProjectId="params.defaultProjectId"
  38. :defaultUserId="params.userId" />
  39. </a-form-item>
  40. <a-form-item :label="$t('system.text_146')" class="mb-0" :extra="isEnableMail ? '' : $t('system.is_config_mail_tips')">
  41. <a-input v-decorator="decorators.email" :disabled="!isEnableMail" :placeholder="$t('system.email_placeholder')" />
  42. </a-form-item>
  43. <a-form-item :wrapperCol="{ offset: 4 }">
  44. <a-checkbox v-decorator="decorators.notify" :disabled="!isCanSendNotify">{{ $t('system.email_checkbox_text') }}</a-checkbox>
  45. </a-form-item>
  46. </a-form>
  47. </div>
  48. <div slot="footer">
  49. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  50. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  51. </div>
  52. </base-dialog>
  53. </template>
  54. <script>
  55. import * as R from 'ramda'
  56. import { mapGetters } from 'vuex'
  57. import DialogMixin from '@/mixins/dialog'
  58. import WindowsMixin from '@/mixins/windows'
  59. import NameRepeated from '@/sections/NameRepeated'
  60. // import ListSelect from '@/sections/ListSelect'
  61. import { getNameFilter } from '@/utils/common/tableFilter'
  62. import UserSelect from '../components/UserSelect'
  63. export default {
  64. name: 'ClouduserCreateDialog',
  65. components: {
  66. NameRepeated,
  67. UserSelect,
  68. // ListSelect,
  69. },
  70. mixins: [DialogMixin, WindowsMixin],
  71. props: {
  72. params: {
  73. type: Object,
  74. defualt: () => { },
  75. },
  76. },
  77. data () {
  78. return {
  79. loading: false,
  80. form: {
  81. fc: this.$form.createForm(this, {
  82. onValuesChange: (props, values) => {
  83. if (values.email && this.isEnableMail) {
  84. this.$nextTick(() => {
  85. const isError = this.form.fc.getFieldError('email')
  86. if (R.isNil(isError) || R.isEmpty(isError)) {
  87. this.isCanSendNotify = true
  88. } else {
  89. this.isCanSendNotify = false
  90. }
  91. })
  92. } else {
  93. this.isCanSendNotify = false
  94. }
  95. },
  96. }),
  97. fi: {
  98. generate_name: '',
  99. user: {},
  100. cloudprovider: {},
  101. project: {},
  102. },
  103. },
  104. decorators: {
  105. generate_name: [
  106. 'generate_name',
  107. {
  108. validateFirst: true,
  109. rules: this.params.cloudaccount.brand === 'Google' ? [
  110. { required: true, message: this.$t('common.text00042') },
  111. { validator: this.$validate('email'), message: this.$t('cloudenv.text_376') },
  112. ] : [],
  113. },
  114. ],
  115. owner_id: [
  116. 'owner_id',
  117. {
  118. rules: [
  119. { required: true, message: this.$t('common.select') },
  120. ],
  121. },
  122. ],
  123. manager_id: [
  124. 'manager_id',
  125. {
  126. rules: [
  127. { required: true, message: this.$t('common.select') },
  128. ],
  129. },
  130. ],
  131. cloudgroup_ids: [
  132. 'cloudgroup_ids',
  133. {
  134. rules: [
  135. { required: this.params.cloudaccount.brand === 'Google', message: this.$t('common.select') },
  136. ],
  137. },
  138. ],
  139. email: [
  140. 'email',
  141. {
  142. rules: [
  143. { validator: this.emailValidator },
  144. ],
  145. },
  146. ],
  147. notify: [
  148. 'notify',
  149. ],
  150. },
  151. cloudgroupListSelectProps: {
  152. list: this.$list.createList(this, {
  153. id: this.id,
  154. resource: 'cloudgroups',
  155. apiVersion: 'v1',
  156. getParams: () => {
  157. const params = {
  158. provider: this.params.cloudaccount.provider,
  159. }
  160. if (this.$store.getters.isAdminMode) {
  161. params.domain_id = this.params.cloudaccount.domain_id
  162. } else {
  163. params.scope = this.$store.getters.scope
  164. }
  165. return params
  166. },
  167. filterOptions: {
  168. name: getNameFilter(),
  169. },
  170. }),
  171. columns: [
  172. {
  173. field: 'name',
  174. title: this.$t('table.title.name'),
  175. showOverflow: 'title',
  176. },
  177. {
  178. field: 'description',
  179. title: this.$t('cloudenv.text_327'),
  180. showOverflow: 'title',
  181. },
  182. {
  183. field: 'cloudpolicies',
  184. title: this.$t('cloudenv.text_329'),
  185. slots: {
  186. default: ({ row }) => {
  187. if (R.isNil(row.cloudpolicies) || R.isEmpty(row.cloudpolicies)) return this.$t('cloudenv.text_330')
  188. return [<list-body-cell-popover text={this.$t('cloudenv.text_245', [(row.cloudpolicies && row.cloudpolicies.length) || 0])} min-width="600px">
  189. <vxe-grid
  190. showOverflow={false}
  191. row-config={{ isHover: true }}
  192. column-config={{ resizable: false }}
  193. data={row.cloudpolicies}
  194. columns={[
  195. {
  196. field: 'name',
  197. title: this.$t('common.name'),
  198. },
  199. {
  200. field: 'description',
  201. title: this.$t('table.title.desc'),
  202. formatter: ({ cellValue }) => cellValue || '-',
  203. },
  204. ]} />
  205. </list-body-cell-popover>]
  206. },
  207. },
  208. },
  209. ],
  210. },
  211. formItemLayout: {
  212. wrapperCol: {
  213. span: 20,
  214. },
  215. labelCol: {
  216. span: 4,
  217. },
  218. },
  219. isCanSendNotify: false,
  220. isEnableMail: false,
  221. }
  222. },
  223. computed: {
  224. ...mapGetters(['userInfo']),
  225. cloudproviderParams () {
  226. return {
  227. scope: this.$store.getters.scope,
  228. cloudaccount_id: this.params.cloudaccount.id,
  229. }
  230. },
  231. isGoogle () {
  232. return this.params.cloudaccount.brand === 'Google'
  233. },
  234. namePlaceholder () {
  235. if (this.form.fi.user && this.form.fi.user.name) {
  236. if (this.isGoogle) {
  237. return this.$t('cloudenv.text_377')
  238. }
  239. return this.form.fi.user.name
  240. }
  241. return ''
  242. },
  243. nameRepeatParams () {
  244. if (this.isGoogle) {
  245. return { manager_id: this.form.fi.cloudprovider.id }
  246. }
  247. return { cloudaccount_id: this.params.cloudaccount.id }
  248. },
  249. nameExtra () {
  250. if (this.isGoogle) return null
  251. return this.$t('cloudenv.clouduser_text1')
  252. },
  253. },
  254. watch: {
  255. 'form.fi.user': {
  256. handler (val, oldVal) {
  257. if (val.id) {
  258. this.isEnableMail && this.fetchEmail(val.id)
  259. }
  260. },
  261. deep: true,
  262. },
  263. },
  264. created () {
  265. this.fetchConfigEmail()
  266. },
  267. methods: {
  268. async fetchEmail (userId) {
  269. const { data } = await new this.$Manager('receivers', 'v1').performClassAction({
  270. action: 'intellij-get',
  271. data: {
  272. scope: this.$store.getters.scope,
  273. user_id: userId,
  274. },
  275. })
  276. this.form.fc.setFieldsValue({ email: data.email || '' })
  277. },
  278. emailValidator (rule, value, callback) {
  279. if (R.isEmpty(value) || R.isNil(value)) {
  280. return callback()
  281. }
  282. return this.$validate('email')(rule, value, callback)
  283. },
  284. async handleConfirm () {
  285. this.loading = true
  286. try {
  287. const { ...values } = await this.form.fc.validateFields()
  288. if (!this.isGoogle) {
  289. values.cloudaccount_id = this.params.cloudaccount.id
  290. }
  291. values.project_id = this.form.fi.project.id
  292. await this.params.onManager('create', {
  293. managerArgs: {
  294. data: values,
  295. },
  296. })
  297. this.cancelDialog()
  298. } finally {
  299. this.loading = false
  300. }
  301. },
  302. formatterLabel (row) {
  303. return row.description ? `${row.name} / ${row.description}` : row.name
  304. },
  305. async fetchConfigEmail () {
  306. this.isEnableMail = false
  307. try {
  308. const res = await new this.$Manager('notifyconfigs/capability', 'v1').list({})
  309. const domainData = res.data.domain || {}
  310. const systemData = res.data.system || []
  311. if (domainData[this.userInfo.projectDomainId] && domainData[this.userInfo.projectDomainId].includes('email')) {
  312. this.isEnableMail = true
  313. return
  314. }
  315. if (systemData.includes('email')) {
  316. this.isEnableMail = true
  317. }
  318. } catch (error) {
  319. throw error
  320. } finally {
  321. this.$emit('update:loading', false)
  322. }
  323. },
  324. },
  325. }
  326. </script>