SelectCloudaccount.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="cloudaccount pt-2">
  3. <a-alert type="info" show-icon class="mt-2" v-if="!isCE && !$store.getters.isSysCE && $store.getters.isAdminMode">
  4. <template slot="message">{{$t('cloudenv.text_223')}}<icon type="navbar-more" style="font-size: 15px;" />{{$t('cloudenv.text_224')}}</template>
  5. </a-alert>
  6. <template v-for="(cloudaccounts, env) of types">
  7. <div class="env-item-wrap my-5" v-if="isShowItem(env)" :key="env">
  8. <h2 class="mb-3">{{ envTitle[env] }}</h2>
  9. <div class="items d-flex flex-wrap">
  10. <template v-for="(item, cloudaccount) of cloudaccounts">
  11. <div class="item d-flex p-2 mr-3 align-items-center" v-if="isShowItem(item)" :class="{ active: currentItem.name === item.name }" :key="cloudaccount" @click="selectProvider(item)">
  12. <img :src="item.logo" :style="item.logoStyle" />
  13. <h5 class="flex-fill" v-if="showName(item)">{{ item.name }}</h5>
  14. </div>
  15. </template>
  16. </div>
  17. </div>
  18. </template>
  19. </div>
  20. </template>
  21. <script>
  22. import { isCE } from '@/utils/utils'
  23. import { CLOUDACCOUNT_TYPES, ENV_TITLE } from '@Cloudenv/views/cloudaccount/constants'
  24. import { hasSetupKey, billSupportBrands } from '@/utils/auth'
  25. import setting from '@/config/setting'
  26. export default {
  27. name: 'SelectCloudaccount',
  28. props: {
  29. currentItem: {
  30. type: Object,
  31. required: true,
  32. },
  33. },
  34. data () {
  35. return {
  36. envTitle: ENV_TITLE,
  37. }
  38. },
  39. computed: {
  40. isCE () {
  41. return isCE()
  42. },
  43. globalSettingSetupKeys () {
  44. const { globalSetting } = this.$store.state
  45. if (globalSetting && globalSetting.value) {
  46. return globalSetting.value.setupKeys
  47. }
  48. return undefined
  49. },
  50. types () {
  51. const typesMap = {}
  52. for (const box in CLOUDACCOUNT_TYPES) {
  53. for (const brand in CLOUDACCOUNT_TYPES[box]) {
  54. if (hasSetupKey([brand])) {
  55. if (!typesMap[box]) {
  56. typesMap[box] = {
  57. [brand]: CLOUDACCOUNT_TYPES[box][brand],
  58. }
  59. } else {
  60. typesMap[box][brand] = CLOUDACCOUNT_TYPES[box][brand]
  61. }
  62. if (brand === 'cloudpods') {
  63. const { companyInfo = {} } = this.$store.state.app
  64. const { inner_copyright_en, inner_copyright, inner_logo, inner_logo_format } = companyInfo
  65. CLOUDACCOUNT_TYPES[box][brand].name = setting.language === 'en' ? (inner_copyright_en || CLOUDACCOUNT_TYPES[box][brand].name) : (inner_copyright || CLOUDACCOUNT_TYPES[box][brand].name)
  66. CLOUDACCOUNT_TYPES[box][brand].logo = inner_logo && inner_logo_format ? `data:${inner_logo_format};base64,${inner_logo}` : CLOUDACCOUNT_TYPES[box][brand].logo
  67. }
  68. }
  69. }
  70. }
  71. if (hasSetupKey(['bill']) && !hasSetupKey(['onecloud', 'public', 'private', 'vmware', 'storate'])) {
  72. const setUpKeys = this.globalSettingSetupKeys || []
  73. const billTargetItems = billSupportBrands.filter(key => setUpKeys.includes('bill_' + key))
  74. if (!billTargetItems.length) {
  75. // 旧版本 license只签发bill
  76. if (!hasSetupKey('public')) {
  77. if (!typesMap.public) {
  78. typesMap.public = {}
  79. }
  80. billSupportBrands.map(key => {
  81. typesMap.public[key] = CLOUDACCOUNT_TYPES.public[key]
  82. })
  83. }
  84. } else {
  85. // 新版本 license签发billItem
  86. typesMap.public = typesMap.public || {}
  87. billTargetItems.map(key => {
  88. typesMap.public[key] = CLOUDACCOUNT_TYPES.public[key]
  89. })
  90. }
  91. }
  92. return typesMap
  93. },
  94. },
  95. watch: {
  96. globalSettingSetupKeys: {
  97. handler (value) {
  98. if (value && value.length > 0 && this.defaultItem()) {
  99. this.$emit('update:currentItem', this.defaultItem())
  100. }
  101. },
  102. immediate: true,
  103. },
  104. },
  105. methods: {
  106. defaultItem () {
  107. for (const env in this.types) {
  108. for (const provider in this.types[env]) {
  109. if (this.globalSettingSetupKeys.indexOf(provider.toLowerCase()) > -1) {
  110. return this.types[env][provider]
  111. }
  112. }
  113. }
  114. },
  115. isShowItem (item) {
  116. if (this.globalSettingSetupKeys === undefined) {
  117. return true
  118. }
  119. if (typeof item === 'string') {
  120. if (item === 'private' && this.globalSettingSetupKeys.indexOf('vmware') > -1) return true
  121. return this.globalSettingSetupKeys.indexOf(item) > -1 || (this.globalSettingSetupKeys.indexOf('bill') > -1 && this.isBillEnv(item))
  122. }
  123. // console.log(this.globalSettingSetupKeys, item.provider.toLowerCase(), this.globalSettingSetupKeys.indexOf(item.provider.toLowerCase()) > -1)
  124. return this.globalSettingSetupKeys.indexOf(item.provider.toLowerCase()) > -1 || this.isShowBillItem(item)
  125. },
  126. isBillEnv (env) {
  127. if (env === 'public') {
  128. return true
  129. }
  130. return false
  131. },
  132. isShowBillItem (item) {
  133. if (this.globalSettingSetupKeys.indexOf('bill') === -1) return false
  134. // 开启费用
  135. if (billSupportBrands.indexOf(item.provider.toLowerCase()) > -1) {
  136. // 没有平台但是有费用
  137. if (this.globalSettingSetupKeys.indexOf(`bill_${item.provider.toLowerCase()}`) > -1) {
  138. return true
  139. }
  140. }
  141. return false
  142. },
  143. selectProvider (item) {
  144. this.$emit('update:currentItem', item)
  145. },
  146. showName (item) {
  147. if (item.hiddenName === true) {
  148. return false
  149. } else {
  150. return true
  151. }
  152. },
  153. },
  154. }
  155. </script>
  156. <style lang="less">
  157. .cloudaccount {
  158. h2 {
  159. font-size: 14px;
  160. margin: 0;
  161. }
  162. }
  163. </style>