UnbindResources.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="action" :name="$t('dictionary.snapshotpolicy')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. </div>
  8. <div slot="footer">
  9. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  10. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  11. </div>
  12. </base-dialog>
  13. </template>
  14. <script>
  15. import DialogMixin from '@/mixins/dialog'
  16. import WindowsMixin from '@/mixins/windows'
  17. export default {
  18. name: 'UnbindResourcesDialog',
  19. mixins: [DialogMixin, WindowsMixin],
  20. data () {
  21. return {
  22. loading: false,
  23. action: this.$t('compute.text_723'),
  24. }
  25. },
  26. computed: {
  27. columns () {
  28. return this.params.columns.slice(0, 3)
  29. },
  30. },
  31. methods: {
  32. async doSubmit () {
  33. const ids = this.params.data.map(item => item.id)
  34. const params = {
  35. snapshotpolicy_id: this.params.resId,
  36. }
  37. if (this.params.resourceType === 'disk') {
  38. return this.params.onManager('batchPerformAction', {
  39. id: ids,
  40. steadyStatus: 'ready',
  41. managerArgs: {
  42. action: 'unbind-snapshotpolicy',
  43. data: params,
  44. },
  45. })
  46. } else {
  47. return new this.$Manager('snapshotpolicies').performAction({
  48. id: this.params.resId,
  49. action: 'unbind-resources',
  50. data: {
  51. resources: this.params.data.map(item => { return { id: item.id, type: this.params.resourceType } }),
  52. },
  53. })
  54. }
  55. },
  56. async handleConfirm () {
  57. this.loading = true
  58. try {
  59. await this.doSubmit()
  60. this.$bus.$emit('refresh-snapshotpolicy-list')
  61. this.loading = false
  62. this.params.refresh && this.params.refresh()
  63. this.cancelDialog()
  64. } catch (error) {
  65. this.loading = false
  66. throw error
  67. }
  68. },
  69. },
  70. }
  71. </script>