Rollback.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('helm.text_72')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :name="$t('helm.text_73')" :action="$t('helm.text_72')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. v-bind="formItemLayout"
  9. :form="form.fc">
  10. <a-form-item :label="$t('helm.text_74')">
  11. <base-select
  12. v-decorator="decorators.revision"
  13. need-params
  14. :params="releaseParams"
  15. :options="options"
  16. id-key="revision"
  17. name-key="label"
  18. :select-props="{ placeholder: $t('helm.text_30') }" />
  19. </a-form-item>
  20. </a-form>
  21. </div>
  22. <div slot="footer">
  23. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  24. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  25. </div>
  26. </base-dialog>
  27. </template>
  28. <script>
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. export default {
  32. name: 'K8SRollbackDialog',
  33. mixins: [DialogMixin, WindowsMixin],
  34. data () {
  35. return {
  36. loading: false,
  37. options: [],
  38. form: {
  39. fc: this.$form.createForm(this),
  40. fd: {},
  41. },
  42. data: this.params.data[0],
  43. containerImages: [],
  44. decorators: {
  45. revision: [
  46. 'revision',
  47. {
  48. rules: [
  49. { required: true, message: this.$t('helm.text_30') },
  50. ],
  51. },
  52. ],
  53. },
  54. formItemLayout: {
  55. wrapperCol: {
  56. span: 21,
  57. },
  58. labelCol: {
  59. span: 3,
  60. },
  61. },
  62. releaseParams: {
  63. cluster: this.params.cluster,
  64. namespace: this.params.namespace,
  65. },
  66. }
  67. },
  68. created () {
  69. this.fetchData()
  70. },
  71. methods: {
  72. async fetchData () {
  73. const resource = `releases/${this.params.data[0].id}/history`
  74. const { data } = await new this.$Manager(resource, 'v1').list({ params: this.releaseParams })
  75. this.options = this.mapper(data)
  76. },
  77. mapper (data) {
  78. return data.map(val => {
  79. const time = this.$moment(new Date(val.updated))
  80. const date = time.format('YYYY-MM-DD')
  81. const fromNow = time.fromNow()
  82. return {
  83. ...val,
  84. label: `${val.chart}-${val.revision}: ${date}(${fromNow})`,
  85. }
  86. })
  87. },
  88. async doUpdate (values) {
  89. try {
  90. await this.params.onManager('performAction', {
  91. id: this.params.data[0].id,
  92. managerArgs: {
  93. action: 'rollback',
  94. data: {
  95. namespace: this.params.namespace,
  96. cluster: this.params.cluster,
  97. revision: values.revision,
  98. },
  99. },
  100. })
  101. } catch (error) {
  102. throw error
  103. }
  104. },
  105. async handleConfirm () {
  106. this.loading = true
  107. try {
  108. const values = await this.form.fc.validateFields()
  109. await this.doUpdate(values)
  110. this.loading = false
  111. this.cancelDialog()
  112. } catch (error) {
  113. this.loading = false
  114. throw error
  115. }
  116. },
  117. },
  118. }
  119. </script>