index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div>
  3. <page-header :title="$t('system.text_167', [$t('dictionary.project')])" />
  4. <steps class="my-3" v-model="step" />
  5. <page-body needMarginBottom>
  6. <component :is="stepComponent" :domainId="projectMsg.domain_id" ref="stepForm" />
  7. </page-body>
  8. <page-footer>
  9. <template v-slot:right>
  10. <a-button type="primary" :loading="loading" @click="handleSubmit">{{ createTxt }}</a-button>
  11. <a-button class="ml-3" @click="handleCancel">{{ stepComponent === 'create-project' ? $t('dialog.cancel') : $t('common.skip') }}</a-button>
  12. </template>
  13. </page-footer>
  14. </div>
  15. </template>
  16. <script>
  17. import step from '@/mixins/step'
  18. import AddUser from './form/AddUser'
  19. import CreateProject from './form/CreateProject'
  20. const R = require('ramda')
  21. export default {
  22. name: 'ProjectCreate',
  23. components: {
  24. AddUser,
  25. CreateProject,
  26. },
  27. mixins: [step],
  28. data () {
  29. return {
  30. loading: false,
  31. projectMsg: {},
  32. step: {
  33. steps: [
  34. { title: this.$t('system.text_444', [this.$t('dictionary.project')]), key: 'create-project' },
  35. { title: this.$t('system.text_445', [this.$t('dictionary.project')]), key: 'add-user' },
  36. ],
  37. currentStep: 0,
  38. },
  39. }
  40. },
  41. computed: {
  42. stepComponent () {
  43. return this.step.steps[this.step.currentStep].key
  44. },
  45. isEnableQuotaCheck () {
  46. return this.$store.getters.userInfo.enable_quota_check
  47. },
  48. createTxt () {
  49. return this.step.currentStep ? this.$t('system.text_498', []) : this.$t('common.create')
  50. },
  51. },
  52. created () {
  53. this.manager = new this.$Manager('projects', 'v1')
  54. },
  55. methods: {
  56. async handleSubmit () {
  57. this.loading = true
  58. try {
  59. const values = await this.$refs.stepForm.validateForm()
  60. if (this.step.currentStep === 0) {
  61. const { data } = await this.createProject(values)
  62. this.projectMsg = data
  63. this.step.currentStep = this.step.currentStep + 1
  64. } else if (this.step.currentStep === 1) {
  65. await this.addUser(values)
  66. this.handleCancel()
  67. }
  68. } catch (error) {
  69. throw error
  70. } finally {
  71. this.loading = false
  72. }
  73. if (this.isEnableQuotaCheck) {
  74. try {
  75. if (R.is(Function, this.$refs.stepForm.doQuotaSet)) {
  76. await this.$refs.stepForm.doQuotaSet({ tenant: this.projectMsg.id })
  77. }
  78. } catch (error) {
  79. this.$message.info(this.$t('system.text_447'))
  80. throw error
  81. }
  82. }
  83. },
  84. async createProject (values) {
  85. try {
  86. const ret = await this.manager.create({
  87. data: values,
  88. })
  89. this.$message.success(this.$t('system.text_448', [this.$t('dictionary.project')]))
  90. return ret
  91. } catch (error) {
  92. throw error
  93. }
  94. },
  95. async addUser (values) {
  96. try {
  97. delete values.domain
  98. await this.manager.performAction({
  99. id: this.projectMsg.id,
  100. action: 'join',
  101. data: values,
  102. })
  103. this.$message.success(this.$t('system.text_449', [this.$t('dictionary.project', this.$t('dictionary.role'))]))
  104. } catch (error) {
  105. throw error
  106. }
  107. },
  108. handleCancel () {
  109. this.$router.push('/project')
  110. },
  111. },
  112. }
  113. </script>