CreateProject.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <a-form :form="form.fc" v-bind="formItemLayout">
  3. <a-form-item :label="$t('system.text_101')">
  4. <a-input :placeholder="$t('system.text_168')" v-decorator="decorators.name" />
  5. </a-form-item>
  6. <a-form-item :label="$t('common.description')">
  7. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  8. </a-form-item>
  9. <a-form-item :label="$t('dictionary.domain')" v-if="$store.getters.isAdminMode && $store.getters.l3PermissionEnable">
  10. <base-select
  11. resource="domains"
  12. v-decorator="decorators.domain_id"
  13. :params="domainParams"
  14. remote
  15. version="v1"
  16. :showSync="true"
  17. :select-props="{ placeholder: $t('system.text_443', [$t('dictionary.domain')])}" />
  18. <div slot="extra">{{$t('system.text_439')}}<help-link :href="domainCreateLink">{{$t('system.text_440')}}</help-link>
  19. </div>
  20. </a-form-item>
  21. </a-form>
  22. </template>
  23. <script>
  24. import { mapGetters } from 'vuex'
  25. export default {
  26. name: 'CreateProject',
  27. data () {
  28. return {
  29. form: {
  30. fc: this.$form.createForm(this, { onValuesChange: this.onValuesChange }),
  31. fd: {
  32. domain: '',
  33. },
  34. },
  35. formItemLayout: {
  36. wrapperCol: {
  37. span: 21,
  38. xxl: {
  39. span: 22,
  40. },
  41. },
  42. labelCol: {
  43. span: 3,
  44. xxl: {
  45. span: 2,
  46. },
  47. },
  48. },
  49. decorators: {
  50. name: [
  51. 'name',
  52. {
  53. validateFirst: true,
  54. rules: [
  55. {
  56. required: true, message: this.$t('system.text_170'),
  57. },
  58. ],
  59. },
  60. ],
  61. description: ['description'],
  62. domain_id: [
  63. 'domain_id',
  64. {
  65. rules: [
  66. { required: true, message: this.$t('rules.domain') },
  67. ],
  68. },
  69. ],
  70. },
  71. domainParams: {
  72. scope: this.$store.getters.scope,
  73. limit: 20,
  74. enabled: true,
  75. },
  76. }
  77. },
  78. computed: {
  79. ...mapGetters(['isAdminMode', 'l3PermissionEnable', 'userInfo']),
  80. tenant () {
  81. return this.$route.query.tenant
  82. },
  83. domain () {
  84. return this.$route.query.domain
  85. },
  86. isClone () {
  87. if (this.$route.query.tenant && this.$route.query.domain) {
  88. return true
  89. }
  90. return false
  91. },
  92. domainCreateLink () {
  93. return this.$router.resolve('/domain/create').href
  94. },
  95. },
  96. created () {
  97. // 如果 query 携带 tenant 和 domain,表示 clone
  98. if (this.isClone) {
  99. // 触发watch获取域quotas,进行上限设置
  100. this.form.fd.domain = this.domain
  101. } else if (!this.isAdminMode || !this.l3PermissionEnable) {
  102. if (!this.l3PermissionEnable) {
  103. this.form.fd.domain = 'default'
  104. } else {
  105. this.form.fd.domain = this.userInfo.projectDomainId
  106. }
  107. }
  108. },
  109. mounted () {
  110. this.form.fc.setFieldsValue({ domain_id: this.form.fd.domain })
  111. },
  112. methods: {
  113. validateForm () {
  114. return this.form.fc.validateFields()
  115. },
  116. onValuesChange (props, values) {
  117. if (values.hasOwnProperty('domain_id')) {
  118. this.form.fd.domain = values.domain_id
  119. }
  120. },
  121. },
  122. }
  123. </script>