SetConfig.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.dbinstances')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. class="mt-3"
  9. :form="form.fc">
  10. <s-k-u ref="SKU" :disableds="disableds" :rdsItem="rdsItem">
  11. <a-radio-group disabled slot="zone" :defaultValue="Object.keys(rdsZone)[0]">
  12. <a-radio-button :key="key" :value="key" v-for="(value, key) in rdsZone">{{value}}</a-radio-button>
  13. </a-radio-group>
  14. </s-k-u>
  15. </a-form>
  16. </div>
  17. <div slot="footer">
  18. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import SKU from '../create/components/SKU'
  25. import DialogMixin from '@/mixins/dialog'
  26. import WindowsMixin from '@/mixins/windows'
  27. export default {
  28. name: 'RSDSetConfig',
  29. components: {
  30. SKU,
  31. },
  32. mixins: [DialogMixin, WindowsMixin],
  33. data () {
  34. return {
  35. loading: false,
  36. formItemLayout: {
  37. wrapperCol: { span: 18 },
  38. labelCol: { span: 6 },
  39. },
  40. rdsZone: {},
  41. }
  42. },
  43. computed: {
  44. form () {
  45. const fc = this.$form.createForm(this, { onValuesChange: this.handleValuesChange })
  46. const { getFieldDecorator, getFieldValue, getFieldsValue, setFieldsValue } = fc
  47. return {
  48. fc,
  49. fd: {
  50. provider: this.params.data[0].provider,
  51. },
  52. getFieldDecorator,
  53. getFieldValue,
  54. getFieldsValue,
  55. setFieldsValue,
  56. }
  57. },
  58. rdsItem () {
  59. const { data } = this.params
  60. return data[0]
  61. },
  62. disableds () {
  63. const _ = {
  64. Huawei: ['engine', 'engine_version', 'zones', 'category', 'storage_type'],
  65. Aliyun: ['engine', 'engine_version', 'zones', 'storage_type'],
  66. Google: ['engine', 'engine_version', 'zones', 'category'],
  67. }
  68. return _[this.rdsItem.brand]
  69. },
  70. scopeParams () {
  71. if (this.$store.getters.isAdminMode) {
  72. return {
  73. project_domain: this.rdsItem.domain_id,
  74. }
  75. } else {
  76. return {
  77. scope: this.$store.getters.scope,
  78. }
  79. }
  80. },
  81. },
  82. provide () {
  83. return {
  84. form: this.form,
  85. formItemLayout: this.formItemLayout,
  86. scopeParams: this.scopeParams,
  87. }
  88. },
  89. async mounted () {
  90. this.form.fc.getFieldDecorator('provider', { preserve: true })
  91. this.form.fc.getFieldDecorator('zones', { preserve: true })
  92. this.form.fc.getFieldDecorator('cloudregion_id', { preserve: true })
  93. this.form.fc.getFieldDecorator('cloudregion', { preserve: true })
  94. const capability = ['engine', 'engine_version', 'category', 'storage_type']
  95. const specs = ['vcpu_count', 'vmem_size_mb', 'zones']
  96. this.keysChange = {
  97. capability,
  98. specs,
  99. }
  100. await this.$nextTick()
  101. this.skuRef = this.$refs.SKU
  102. await this.skuRef.fetchCapability(this.rdsItem.cloudregion_id)
  103. await this.setValues()
  104. },
  105. methods: {
  106. setValues () {
  107. const SKU = this.$refs.SKU
  108. const { engine, provider } = this.rdsItem
  109. const zoneIds = []
  110. const zoneNames = []
  111. let i = 0
  112. for (;;) {
  113. ++i
  114. const id = this.rdsItem[`zone${i}`]
  115. const name = this.rdsItem[`zone${i}_name`]
  116. if (id) {
  117. zoneIds.push(id)
  118. zoneNames.push(name)
  119. } else {
  120. break
  121. }
  122. }
  123. this.rdsZone = {
  124. [zoneIds.join('+')]: zoneNames.join('+'),
  125. }
  126. this.form.setFieldsValue({
  127. provider,
  128. engine,
  129. engine_version: this.rdsItem.engine_version,
  130. category: this.rdsItem.category,
  131. storage_type: this.rdsItem.storage_type,
  132. vcpu_count: this.rdsItem.vcpu_count,
  133. vmem_size_mb: this.rdsItem.vmem_size_mb,
  134. zones: zoneIds.join('+'),
  135. cloudregion_id: this.rdsItem.cloudregion_id,
  136. cloudregion: this.rdsItem.cloudregion_id,
  137. }, SKU.linkageValue)
  138. },
  139. // 获取CPU核数、内存、可用区
  140. capability_change () {
  141. this.skuRef.fetchSpecs()
  142. },
  143. specs_change () {
  144. this.skuRef.fetchSkus()
  145. },
  146. async handleValuesChange (fc, changedFields) {
  147. await this.$nextTick()
  148. Object.keys(changedFields).forEach(field => {
  149. if (changedFields[field] === undefined) return false
  150. let _field = field
  151. for (const k in this.keysChange) {
  152. if (this.keysChange[k].indexOf(_field) > -1) {
  153. _field = k
  154. }
  155. }
  156. const handleChange = this[`${_field}_change`]
  157. if (this[`${_field}_change`]) {
  158. return handleChange()
  159. }
  160. })
  161. },
  162. validateForm () {
  163. return new Promise((resolve, reject) => {
  164. this.form.fc.validateFields((err, values) => {
  165. if (!err) {
  166. if (values.sku) {
  167. values.instance_type = values.sku.name
  168. delete values.sku
  169. }
  170. if (values.zones) {
  171. values.zones.split('+').forEach((zone, index) => {
  172. values[`zone${index + 1}`] = zone
  173. })
  174. delete values.zones
  175. }
  176. resolve(values)
  177. } else {
  178. reject(err)
  179. }
  180. })
  181. })
  182. },
  183. async handleConfirm () {
  184. this.loading = true
  185. try {
  186. const values = await this.validateForm()
  187. await this.params.onManager('performAction', {
  188. id: this.params.data[0].id,
  189. steadyStatus: ['running'],
  190. managerArgs: {
  191. action: 'change-config',
  192. data: values,
  193. },
  194. })
  195. this.cancelDialog()
  196. this.params.refresh()
  197. } finally {
  198. this.loading = false
  199. }
  200. },
  201. },
  202. }
  203. </script>