drawer.vue 1.97 KB
Newer Older
水落(YangLei)'s avatar
水落(YangLei) committed
1 2 3
<template>
    <a-drawer
        placement="right"
陈浩玮's avatar
陈浩玮 committed
4
        :visible="value"
水落(YangLei)'s avatar
水落(YangLei) committed
5 6 7
        :drawerStyle="drawerStyle"
        :bodyStyle="bodyStyle"
        destroyOnClose
陈浩玮's avatar
yonghu  
陈浩玮 committed
8
        :width="width"
水落(YangLei)'s avatar
水落(YangLei) committed
9
        v-bind="$attrs"
陈浩玮's avatar
陈浩玮 committed
10 11
        v-on="$listeners"
        @close="onClose"
水落(YangLei)'s avatar
水落(YangLei) committed
12
    >
陈浩玮's avatar
陈浩玮 committed
13
        <div class="tw-overflow-y-hidden tw-flex-1">
水落(YangLei)'s avatar
水落(YangLei) committed
14 15 16 17 18 19
            <div class="tw-overflow-y-auto tw-h-full">
                <slot />
            </div>
        </div>
        <template>
            <a-divider />
陈浩玮's avatar
陈浩玮 committed
20 21
            <a-space class="tw-justify-end">
                <a-button @click="cancel">取消</a-button>
水落(YangLei)'s avatar
水落(YangLei) committed
22 23 24 25 26 27 28 29 30 31 32 33
                <slot name="footer">
                    <a-button type="primary" @click="ok" :loading="loading">确认</a-button>
                </slot>
            </a-space>
        </template>
    </a-drawer>
</template>

<script>
export default {
    props: {
        oncancel: Function,
陈浩玮's avatar
yonghu  
陈浩玮 committed
34
        onOk: Function,
陈浩玮's avatar
陈浩玮 committed
35
        colesAfter: Function,
陈浩玮's avatar
陈浩玮 committed
36
        value: Boolean,
陈浩玮's avatar
yonghu  
陈浩玮 committed
37
        width: { type: Number, default: 600 },
陈浩玮's avatar
陈浩玮 committed
38 39 40 41
    },
    model: {
        prop: 'value',
        event: 'change',
水落(YangLei)'s avatar
水落(YangLei) committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    },
    data() {
        return {
            loading: false,
            drawerStyle: {
                display: 'flex',
                flexDirection: 'column',
                overflowY: 'hidden',
            },
            bodyStyle: {
                flex: 1,
                overflow: 'hidden',
                display: 'flex',
                flexDirection: 'column',
            },
        };
    },
    methods: {
        cancel() {
            this.oncancel && this.oncancel();
陈浩玮's avatar
陈浩玮 committed
62 63 64 65
            this.$emit('change', false);
        },
        onClose() {
            this.cancel();
水落(YangLei)'s avatar
水落(YangLei) committed
66 67 68
        },
        async ok() {
            this.loading = true;
陈浩玮's avatar
yonghu  
陈浩玮 committed
69 70 71 72 73 74
            try {
                await (this.onOk && this.onOk());
                this.$emit('change', false);
            } catch {
                // TODO
            }
水落(YangLei)'s avatar
水落(YangLei) committed
75
            this.loading = false;
陈浩玮's avatar
陈浩玮 committed
76
            this.colesAfter && this.colesAfter();
水落(YangLei)'s avatar
水落(YangLei) committed
77 78 79 80
        },
    },
};
</script>