SetConfig.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.elasticcaches')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc">
  8. <s-k-u :disableds="disableds" ref="REF_SKU" :decorators="decorators" :filterSkuCallback="filterSkuCallback" />
  9. </a-form>
  10. </div>
  11. <div slot="footer">
  12. <a-button :loading="loading" @click="handleConfirm" type="primary">{{ $t('dialog.ok') }}</a-button>
  13. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  14. </div>
  15. </base-dialog>
  16. </template>
  17. <script>
  18. import SKU from '../create/components/SKU'
  19. import changeMinxin from '../create/changeMinxin'
  20. import DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'RedisSetConfigDialog',
  24. components: {
  25. SKU,
  26. },
  27. mixins: [DialogMixin, WindowsMixin, changeMinxin],
  28. data () {
  29. return {
  30. loading: false,
  31. disableds: {
  32. engine: true,
  33. engine_version: true,
  34. local_category: true,
  35. },
  36. }
  37. },
  38. computed: {
  39. redisItem () {
  40. const { data } = this.params
  41. const redisItem = data && data.length > 0 ? data[0] : {}
  42. return redisItem
  43. },
  44. decorators () {
  45. return {
  46. engine: [
  47. 'engine',
  48. {
  49. initialValue: this.redisItem.engine.toLowerCase(),
  50. },
  51. ],
  52. engine_version: [
  53. 'engine_version',
  54. {
  55. initialValue: this.redisItem.engine_version,
  56. },
  57. ],
  58. local_category: [
  59. 'local_category',
  60. {
  61. initialValue: this.redisItem.local_category || this.redisItem.arch_type,
  62. },
  63. ],
  64. }
  65. },
  66. scopeParams () {
  67. if (this.$store.getters.isAdminMode) {
  68. return {
  69. project_domain: this.redisItem.domain_id,
  70. }
  71. } else {
  72. return {
  73. scope: this.$store.getters.scope,
  74. }
  75. }
  76. },
  77. },
  78. async created () {
  79. const redisKeys = ['billing_type', 'provider', 'cloudregion', 'zone']
  80. redisKeys.forEach(k => {
  81. const value = this.redisItem[`${k}_id`] || this.redisItem[k]
  82. this.form.fc.getFieldDecorator(k, { initialValue: value, preserve: true })
  83. })
  84. await this.$nextTick()
  85. this.area_change()
  86. },
  87. methods: {
  88. async handleConfirm () {
  89. this.loading = true
  90. try {
  91. const sku = this.form.fc.getFieldValue('sku') || {}
  92. await this.params.onManager('performAction', {
  93. id: this.params.data[0].id,
  94. steadyStatus: 'running',
  95. managerArgs: {
  96. action: 'change-spec',
  97. data: {
  98. sku: sku.id,
  99. },
  100. },
  101. })
  102. this.params.refresh()
  103. this.cancelDialog()
  104. } catch (error) {
  105. this.loading = false
  106. }
  107. },
  108. filterSkuCallback (row) {
  109. const mdSize = this.redisItem.memory_size_mb || this.redisItem.capacity_mb
  110. if (mdSize < row.memory_size_mb) {
  111. return true
  112. }
  113. return false
  114. },
  115. },
  116. }
  117. </script>