WafInstancesDelete.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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-button v-bind="okButtonProps" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  12. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  13. </div>
  14. </base-dialog>
  15. </template>
  16. <script>
  17. import * as R from 'ramda'
  18. import DialogMixin from '@/mixins/dialog'
  19. import WindowsMixin from '@/mixins/windows'
  20. export default {
  21. name: 'DeleteWafInstancesDialog',
  22. components: {
  23. DialogContent: {
  24. props: {
  25. content: {
  26. type: Function,
  27. },
  28. },
  29. render () {
  30. if (this.content) {
  31. return this.content()
  32. }
  33. return null
  34. },
  35. },
  36. },
  37. mixins: [DialogMixin, WindowsMixin],
  38. data () {
  39. return {
  40. loading: false,
  41. }
  42. },
  43. computed: {
  44. alertProps () {
  45. const { alert } = this.params
  46. const data = {
  47. String: { message: alert, type: 'warning' },
  48. Object: alert,
  49. }
  50. const t = R.type(alert)
  51. return data[t] || null
  52. },
  53. okButtonProps () {
  54. const defaultProps = {
  55. type: 'primary',
  56. loading: this.loading,
  57. }
  58. const { okButtonProps } = this.params
  59. if (okButtonProps && R.type(okButtonProps) === 'Object') {
  60. return Object.assign(defaultProps, okButtonProps)
  61. }
  62. return defaultProps
  63. },
  64. idKey () {
  65. return this.params.idKey || 'id'
  66. },
  67. },
  68. methods: {
  69. async handleConfirm () {
  70. this.loading = true
  71. try {
  72. const ids = this.params.data.map(item => item[this.idKey])
  73. if (this.params.ok) {
  74. await this.params.ok(ids, this.params.data)
  75. } else {
  76. let params = {}
  77. params = {
  78. ...params,
  79. ...this.params.requestParams,
  80. }
  81. const response = await this.params.onManager('batchDelete', {
  82. id: ids,
  83. managerArgs: { params, data: this.params.requestData },
  84. })
  85. if (this.params.vm && this.params.vm.destroySidePages) {
  86. this.params.vm.destroySidePage(this.params.vm.windowId)
  87. }
  88. if (this.params.success && R.is(Function, this.params.success)) {
  89. this.params.success(response)
  90. }
  91. this.$message.success(this.$t('common.success'))
  92. }
  93. this.cancelDialog()
  94. } finally {
  95. this.loading = false
  96. }
  97. },
  98. },
  99. }
  100. </script>