DomainProjectSelect.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="cloudprovider-cloudregion-zone-select-wrapper">
  3. <a-row :gutter="8">
  4. <a-col :span="12" v-if="isAdminMode">
  5. <a-form-item>
  6. <base-select
  7. v-decorator="decorators.domain"
  8. resource="domains"
  9. filterable
  10. remote
  11. is-default-select
  12. :select-props="{labelInValue: isAdminMode, labelInValueKeyName: 'key', dropdownClassName: 'oc-select-dropdown', placeholder: $t('rules.domain')}"
  13. :params="domainParams"
  14. @change="domainChange">
  15. <template #optionLabelTemplate="{item}">
  16. <span class="text-color-secondary option-prefix">{{$t('dictionary.domain')}}: </span>{{item.name}}
  17. </template>
  18. </base-select>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :span="isAdminMode?12:24">
  22. <a-form-item :wrapperCol="{ span: 24 }">
  23. <base-select
  24. v-decorator="decorators.projects"
  25. resource="projects"
  26. filterable
  27. remote
  28. :select-props="{labelInValue: labelInValue, labelInValueKeyName: 'key', dropdownClassName: 'oc-select-dropdown', placeholder: $t('rules.project'), mode: 'multiple'}"
  29. :params="projectsParams">
  30. <template #optionLabelTemplate="{item}">
  31. <span class="text-color-secondary option-prefix">{{$t('dictionary.project')}}: </span>{{item.name}}
  32. </template>
  33. </base-select>
  34. </a-form-item>
  35. </a-col>
  36. </a-row>
  37. <div slot="extra">{{$t('system.text_591',[$t('dictionary.project')])}}<help-link :href="projectCreateLink">{{$t('system.text_440')}}</help-link></div>
  38. </div>
  39. </template>
  40. <script>
  41. import * as R from 'ramda'
  42. import { mapGetters } from 'vuex'
  43. export default {
  44. name: 'DomainProjectSelect',
  45. props: {
  46. labelInValue: {
  47. type: Boolean,
  48. default: true,
  49. },
  50. projectDomainId: String,
  51. form: Object,
  52. decorators: {
  53. type: Object,
  54. validator: val => R.is(Array, val.users) && R.is(Array, val.project),
  55. },
  56. },
  57. data () {
  58. return {
  59. domainOpts: [],
  60. projectsOpts: [],
  61. domainLoading: false,
  62. projectsLoading: false,
  63. }
  64. },
  65. computed: {
  66. ...mapGetters(['isAdminMode', 'scope', 'isDomainMode', 'userInfo', 'l3PermissionEnable']),
  67. domainOptions () {
  68. return [{
  69. label: 'Default',
  70. key: 'default',
  71. }]
  72. },
  73. isOpenstack () {
  74. if (this.provider) {
  75. return this.provider.toLowerCase() === 'openstack'
  76. }
  77. return false
  78. },
  79. projectCreateLink () {
  80. return this.$router.resolve('/project/create').href
  81. },
  82. domainParams () {
  83. const ret = {
  84. scope: this.scope,
  85. limit: 20,
  86. enabled: true,
  87. }
  88. if (!this.l3PermissionEnable) {
  89. ret.id = 'default'
  90. } else {
  91. if (!this.isAdminMode) {
  92. ret.id = this.userInfo.projectDomainId
  93. }
  94. }
  95. return ret
  96. },
  97. projectsParams () {
  98. const params = {
  99. scope: this.scope,
  100. limit: 20,
  101. }
  102. if (this.l3PermissionEnable) {
  103. params.project_domain_id = this.projectDomainId || this.userInfo.projectDomainId
  104. } else {
  105. params.project_domain_id = this.projectDomainId
  106. }
  107. if (this.isDomainMode) {
  108. delete params.project_domain_id
  109. }
  110. return params
  111. },
  112. },
  113. mounted () {
  114. },
  115. methods: {
  116. domainChange (domain) {
  117. const domainId = R.is(Object, domain) ? domain.key : domain
  118. if (domainId) {
  119. this.$emit('domainChange', domainId)
  120. }
  121. },
  122. },
  123. }
  124. </script>