delete.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ params.title }}</div>
  4. <div slot="body">
  5. <a-alert v-if="alertProps" v-bind="alertProps" class="mb-2" />
  6. <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="this.params.name" :unit="params.unit" />
  7. <dialog-table v-if="params.columns && params.columns.length" :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <dialog-content :content="params.content" />
  9. </div>
  10. <div slot="footer">
  11. <a-popconfirm
  12. :title="$t('compute.server_recovery_delete_confirm')"
  13. :visible="visible"
  14. :ok-text="$t('dialog.ok')"
  15. :cancel-text="$t('dialog.cancel')"
  16. @visibleChange="handleVisibleChange"
  17. @confirm="handleConfirm"
  18. @cancel="cancelDialog">
  19. <a-button v-bind="okButtonProps">{{ $t("dialog.ok") }}</a-button>
  20. </a-popconfirm>
  21. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  22. </div>
  23. </base-dialog>
  24. </template>
  25. <script>
  26. import * as R from 'ramda'
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. export default {
  30. name: 'ServerRecoveryDeleteDialog',
  31. components: {
  32. DialogContent: {
  33. props: {
  34. content: {
  35. type: Function,
  36. },
  37. },
  38. render () {
  39. if (this.content) {
  40. return this.content()
  41. }
  42. return null
  43. },
  44. },
  45. },
  46. mixins: [DialogMixin, WindowsMixin],
  47. data () {
  48. return {
  49. loading: false,
  50. visible: false,
  51. }
  52. },
  53. computed: {
  54. alertProps () {
  55. const { alert } = this.params
  56. const data = {
  57. String: { message: alert, type: 'warning' },
  58. Object: alert,
  59. }
  60. const t = R.type(alert)
  61. return data[t] || null
  62. },
  63. okButtonProps () {
  64. const defaultProps = {
  65. type: 'primary',
  66. loading: this.loading,
  67. }
  68. const { okButtonProps } = this.params
  69. if (okButtonProps && R.type(okButtonProps) === 'Object') {
  70. return Object.assign(defaultProps, okButtonProps)
  71. }
  72. return defaultProps
  73. },
  74. idKey () {
  75. return this.params.idKey || 'id'
  76. },
  77. },
  78. methods: {
  79. handleVisibleChange (visible) {
  80. if (!visible) {
  81. this.visible = false
  82. return
  83. }
  84. if (this.params.data.some(item => item.status === 'running')) {
  85. this.visible = true
  86. } else {
  87. this.handleConfirm()
  88. }
  89. },
  90. async handleConfirm () {
  91. this.loading = true
  92. try {
  93. const ids = this.params.data.map(item => item[this.idKey])
  94. if (this.params.ok) {
  95. await this.params.ok(ids, this.params.data)
  96. } else {
  97. let params = {}
  98. params = {
  99. ...params,
  100. ...this.params.requestParams,
  101. }
  102. const response = await this.params.onManager('batchDelete', {
  103. id: ids,
  104. managerArgs: { params, data: this.params.requestData },
  105. })
  106. if (this.params.vm && this.params.vm.destroySidePages) {
  107. this.params.vm.destroySidePage(this.params.vm.windowId)
  108. }
  109. if (this.params.success && R.is(Function, this.params.success)) {
  110. this.params.success(response)
  111. }
  112. // this.$message.success(this.$t('common.success'))
  113. }
  114. this.cancelDialog()
  115. } finally {
  116. this.loading = false
  117. }
  118. },
  119. },
  120. }
  121. </script>