| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{ params.title }}</div>
- <div slot="body">
- <a-alert v-if="alertProps" v-bind="alertProps" class="mb-2" />
- <dialog-selected-tips :count="params.data.length" :action="this.params.title" :name="this.params.name" :unit="params.unit" />
- <dialog-table v-if="params.columns && params.columns.length" :data="params.data" :columns="params.columns.slice(0, 3)" />
- <dialog-content :content="params.content" />
- </div>
- <div slot="footer">
- <a-popconfirm
- :title="$t('compute.server_recovery_delete_confirm')"
- :visible="visible"
- :ok-text="$t('dialog.ok')"
- :cancel-text="$t('dialog.cancel')"
- @visibleChange="handleVisibleChange"
- @confirm="handleConfirm"
- @cancel="cancelDialog">
- <a-button v-bind="okButtonProps">{{ $t("dialog.ok") }}</a-button>
- </a-popconfirm>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import * as R from 'ramda'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'ServerRecoveryDeleteDialog',
- components: {
- DialogContent: {
- props: {
- content: {
- type: Function,
- },
- },
- render () {
- if (this.content) {
- return this.content()
- }
- return null
- },
- },
- },
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- visible: false,
- }
- },
- computed: {
- alertProps () {
- const { alert } = this.params
- const data = {
- String: { message: alert, type: 'warning' },
- Object: alert,
- }
- const t = R.type(alert)
- return data[t] || null
- },
- okButtonProps () {
- const defaultProps = {
- type: 'primary',
- loading: this.loading,
- }
- const { okButtonProps } = this.params
- if (okButtonProps && R.type(okButtonProps) === 'Object') {
- return Object.assign(defaultProps, okButtonProps)
- }
- return defaultProps
- },
- idKey () {
- return this.params.idKey || 'id'
- },
- },
- methods: {
- handleVisibleChange (visible) {
- if (!visible) {
- this.visible = false
- return
- }
- if (this.params.data.some(item => item.status === 'running')) {
- this.visible = true
- } else {
- this.handleConfirm()
- }
- },
- async handleConfirm () {
- this.loading = true
- try {
- const ids = this.params.data.map(item => item[this.idKey])
- if (this.params.ok) {
- await this.params.ok(ids, this.params.data)
- } else {
- let params = {}
- params = {
- ...params,
- ...this.params.requestParams,
- }
- const response = await this.params.onManager('batchDelete', {
- id: ids,
- managerArgs: { params, data: this.params.requestData },
- })
- if (this.params.vm && this.params.vm.destroySidePages) {
- this.params.vm.destroySidePage(this.params.vm.windowId)
- }
- if (this.params.success && R.is(Function, this.params.success)) {
- this.params.success(response)
- }
- // this.$message.success(this.$t('common.success'))
- }
- this.cancelDialog()
- } finally {
- this.loading = false
- }
- },
- },
- }
- </script>
|