drawer.vue 1.66 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
<template>
    <a-drawer
        placement="right"
        :visible="visible"
        :drawerStyle="drawerStyle"
        :bodyStyle="bodyStyle"
        destroyOnClose
        v-bind="$attrs"
    >
        <div class="tw-overflow-y-hidden">
            <div class="tw-overflow-y-auto tw-h-full">
                <slot />
            </div>
        </div>
        <template>
            <a-divider />
            <a-space>
                <slot name="footer">
                    <a-button @click="cancel">取消</a-button>
                    <a-button type="primary" @click="ok" :loading="loading">确认</a-button>
                </slot>
            </a-space>
        </template>
    </a-drawer>
</template>

<script>
export default {
    props: {
        oncancel: Function,
        onok: Function,
    },
    data() {
        return {
            visiable: false,
            loading: false,
            drawerStyle: {
                display: 'flex',
                flexDirection: 'column',
                overflowY: 'hidden',
            },
            bodyStyle: {
                flex: 1,
                overflow: 'hidden',
                display: 'flex',
                flexDirection: 'column',
            },
        };
    },
    methods: {
        show() {
            this.visiable = true;
        },
        hidden() {
            this.visiable = false;
        },
        cancel() {
            this.oncancel && this.oncancel();
            this.visiable = false;
        },
        async ok() {
            this.loading = true;
            await (this.onok && this.onok());
            this.loading = false;
            this.visiable = false;
        },
    },
};
</script>