wraper.vue 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<template>
    <div class="tw-flex tw-flex-col tw-h-full">
        <div class="tw-overflow-y-hidden tw-flex-1">
            <div class="tw-overflow-y-auto tw-h-full">
                <slot />
            </div>
        </div>
        <template>
            <a-divider />
            <a-space class="tw-justify-end">
                <a-button @click="cancel">取消</a-button>
12
                <slot name="footer" v-if="!noFooter">
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
                    <a-button type="primary" @click="ok" :loading="loading">确认</a-button>
                </slot>
            </a-space>
        </template>
    </div>
</template>

<script>
import { EMPTY_FUN } from '@/utils';

export default {
    props: {
        onOk: {
            type: Function,
            default: EMPTY_FUN,
        },
        onCancel: Function,
        hidden: {
            type: Function,
            default: EMPTY_FUN,
        },
水落(YangLei)'s avatar
水落(YangLei) committed
34 35 36 37
        refresh: {
            type: Function,
            default: EMPTY_FUN,
        },
38 39 40 41
        noFooter: {
            type: Boolean,
            default: false,
        },
42 43 44 45 46 47 48 49 50 51 52 53
    },
    data: () => ({
        loading: false,
    }),
    methods: {
        cancel() {
            if (this.onCancel) this.onCancel();
            this.hidden();
        },

        async ok() {
            this.loading = true;
水落(YangLei)'s avatar
水落(YangLei) committed
54 55 56 57 58 59 60
            try {
                await this.onOk();
                this.hidden();
                this.refresh();
            } catch (error) {
                // todo
            }
61 62 63 64 65
            this.loading = false;
        },
    },
};
</script>