index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="rds-create-index pb-5">
  3. <page-header :title="$t('db.text_140')" />
  4. <a-form hideRequiredMark :form="form.fc" class="mt-3" v-bind="formItemLayout">
  5. <a-form-item :label="$t('db.text_139', [$t('dictionary.project')])" v-bind="formItemLayout">
  6. <domain-project :decorators="decorators.projectDomain" :fc="form.fc" :labelInValue="false" />
  7. </a-form-item>
  8. <a-form-item :label="$t('db.text_60')" v-bind="formItemLayout">
  9. <a-input :placeholder="$t('validator.resourceCreateName')" v-decorator="decorators.generate_name" />
  10. <template #extra>
  11. <name-repeated
  12. res="dbinstances"
  13. :name="form.getFieldValue('generate_name')"
  14. :default-text="$t('db.text_142')" />
  15. </template>
  16. </a-form-item>
  17. <a-form-item :label="$t('common.description')" v-bind="formItemLayout">
  18. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  19. </a-form-item>
  20. <!-- 计费方式 -->
  21. <clearing-radios v-bind="formItemLayout" :auto_renew="false" />
  22. <a-form-item :label="$t('db.text_71')" v-if="form.fd.billing_type !== 'prepaid'">
  23. <duration :decorators="decorators.duration" :form="form" />
  24. </a-form-item>
  25. <a-form-item :label="$t('db.text_265')">
  26. <a-input-number v-decorator="decorators.__count__" />
  27. </a-form-item>
  28. <!-- 区域 -->
  29. <item-area
  30. :billingType="form.fd.billing_type"
  31. v-if="form.fd.project"
  32. class="mb-0"
  33. :isRequired="true"
  34. :names="['provider', 'cloudregion']"
  35. filterBrandResource="rds_engine" />
  36. <!-- 套餐信息 -->
  37. <s-k-u ref="SKU" />
  38. <a-form-item v-if="form.fd.provider !== 'Aliyun'" :label="$t('db.text_143')">
  39. <server-password :loginTypes="loginTypes" :decorator="decorators.loginConfig" :form="form" />
  40. </a-form-item>
  41. <!-- 网络 -->
  42. <item-network ref="NETWORK" @vpcListChange="handleVpcListChange" />
  43. <!-- 选择安全组 -->
  44. <a-form-item v-if="showSecgroup(form)" :label="$t('db.text_144')">
  45. <secgroup-config :max="getSecgroupMax(form)" :decorators="decorators.secgroup" :secgroup-params="secgroupParams" />
  46. </a-form-item>
  47. <!-- 标签 -->
  48. <a-form-item :label="$t('table.title.tag')" class="mb-3">
  49. <tag v-decorator="decorators.__meta__" :allowNoValue="false" />
  50. </a-form-item>
  51. <bottom-bar :provider="provider" :values="form.getFieldsValue()" :cloudAccountId="cloudAccountId" @cancel="handleCancel" />
  52. </a-form>
  53. </div>
  54. </template>
  55. <script>
  56. import ServerPassword from '@Compute/sections/ServerPassword'
  57. import SecgroupConfig from '@Compute/sections/SecgroupConfig'
  58. import Duration from '@Compute/sections/Duration'
  59. import ItemArea from '@DB/sections/ItemArea'
  60. import ItemNetwork from '@DB/sections/ItemNetwork'
  61. import NameRepeated from '@/sections/NameRepeated'
  62. import DomainProject from '@/sections/DomainProject'
  63. import Tag from '@/sections/Tag'
  64. import { getInitialValue } from '@/utils/common/ant'
  65. import changeMinxin from './changeMinxin'
  66. import BottomBar from './components/BottomBar'
  67. import SKU from './components/SKU'
  68. import { DECORATORS } from './constants/index'
  69. export default {
  70. name: 'RDSCreate',
  71. components: {
  72. SKU,
  73. DomainProject,
  74. BottomBar,
  75. ServerPassword,
  76. ItemArea,
  77. ItemNetwork,
  78. SecgroupConfig,
  79. NameRepeated,
  80. Duration,
  81. Tag,
  82. },
  83. mixins: [changeMinxin],
  84. data () {
  85. return {
  86. loginTypes: ['random', 'password'],
  87. decorators: DECORATORS,
  88. formItemLayout: {
  89. wrapperCol: {
  90. lg: { span: 18 },
  91. xl: { span: 20 },
  92. xxl: { span: 21 },
  93. },
  94. labelCol: {
  95. lg: { span: 6 },
  96. xl: { span: 4 },
  97. xxl: { span: 3 },
  98. },
  99. },
  100. tailFormItemLayout: {
  101. wrapperCol: {
  102. lg: { span: 18, offset: 6 },
  103. xl: { span: 20, offset: 4 },
  104. xxl: { span: 21, offset: 3 },
  105. },
  106. },
  107. scopeParams: {
  108. scope: this.$store.getters.scope,
  109. project_domain: '',
  110. },
  111. vpcList: [],
  112. vpc: '',
  113. }
  114. },
  115. computed: {
  116. form () {
  117. const fc = this.$form.createForm(this, { onValuesChange: this.handleValuesChange })
  118. const initFd = getInitialValue(DECORATORS)
  119. const { getFieldDecorator, getFieldValue, getFieldsValue, setFieldsValue } = fc
  120. return {
  121. fc,
  122. fd: initFd,
  123. getFieldDecorator,
  124. getFieldValue,
  125. getFieldsValue,
  126. setFieldsValue,
  127. }
  128. },
  129. providers () {
  130. if (this.form.fd.billing_type === 'prepaid') {
  131. return ['Aliyun', 'Huawei']
  132. }
  133. return ['Aliyun', 'Huawei', 'Google', 'Aws']
  134. },
  135. cloudAccountId () {
  136. const values = this.form.getFieldsValue()
  137. const currentVpc = this.vpcList.filter(item => item.id === values.vpc)
  138. if (currentVpc[0]) {
  139. return currentVpc[0].account_id
  140. }
  141. return ''
  142. },
  143. secgroupParams () {
  144. const ret = {}
  145. if (this.vpc) {
  146. ret.vpc_id = this.vpc
  147. }
  148. return ret
  149. },
  150. },
  151. provide () {
  152. return {
  153. form: this.form,
  154. formItemLayout: this.formItemLayout,
  155. scopeParams: this.scopeParams,
  156. tailFormItemLayout: this.tailFormItemLayout,
  157. }
  158. },
  159. methods: {
  160. showSecgroup (form) {
  161. const provider = form.getFieldValue('provider')
  162. if (provider === 'Qcloud') {
  163. return form.getFieldValue('category') !== 'basic'
  164. }
  165. return ['Huawei', 'Aliyun'].includes(provider)
  166. },
  167. getSecgroupMax (form) {
  168. const secgroupMaxMap = {
  169. Huawei: 1,
  170. Qcloud: 5,
  171. Aliyun: 3,
  172. }
  173. return secgroupMaxMap[form.getFieldValue('provider')] || 5
  174. },
  175. handleVpcListChange (list) {
  176. this.vpcList = list
  177. },
  178. handleCancel () {
  179. this.$router.push({ name: 'RDSIndex' })
  180. },
  181. },
  182. }
  183. </script>