Drawer.vue 3.03 KB
Newer Older
wb-ct393452's avatar
wb-ct393452 committed
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
    <div>
        <div :class="['mask', visible ? 'open' : 'close']" @click="close"></div>
        <div :class="['drawer', placement, visible ? 'open' : 'close']">
            <div ref="drawer" class="content beauty-scroll">
                <slot />
            </div>
            <div
                v-if="showHandler"
                :class="['handler-container', placement, visible ? 'open' : 'close']"
                ref="handler"
                @click="toggle"
            >
                <slot v-if="$slots.handler" name="handler" />
                <div v-else class="handler">
                    <a-icon :type="visible ? 'close' : 'bars'" />
                </div>
            </div>
        </div> 
wb-ct393452's avatar
wb-ct393452 committed
20 21 22 23 24
    </div>
</template>

<script>
export default {
25 26 27
    name: 'Drawer',
    data() {
        return {};
wb-ct393452's avatar
wb-ct393452 committed
28
    },
29 30 31
    model: {
        prop: 'visible',
        event: 'change',
wb-ct393452's avatar
wb-ct393452 committed
32
    },
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    props: {
        visible: {
            type: Boolean,
            required: false,
            default: false,
        },
        placement: {
            type: String,
            required: false,
            default: 'left',
        },
        showHandler: {
            type: Boolean,
            required: false,
            default: true,
        },
wb-ct393452's avatar
wb-ct393452 committed
49
    },
50 51 52 53 54 55 56 57 58 59
    methods: {
        open() {
            this.$emit('change', true);
        },
        close() {
            this.$emit('change', false);
        },
        toggle() {
            this.$emit('change', !this.visible);
        },
wb-ct393452's avatar
wb-ct393452 committed
60
    },
61
};
wb-ct393452's avatar
wb-ct393452 committed
62 63 64
</script>

<style lang="less" scoped>
65
.mask {
wb-ct393452's avatar
wb-ct393452 committed
66 67 68 69 70 71 72 73
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    background-color: @shadow-color;
    transition: all 0.5s;
    z-index: 100;
74 75
    &.open {
        display: inline-block;
wb-ct393452's avatar
wb-ct393452 committed
76
    }
77 78
    &.close {
        display: none;
wb-ct393452's avatar
wb-ct393452 committed
79
    }
80 81
}
.drawer {
wb-ct393452's avatar
wb-ct393452 committed
82 83 84 85
    position: fixed;
    transition: all 0.5s;
    height: 100vh;
    z-index: 100;
86 87 88 89 90 91 92 93 94
    &.left {
        left: 0px;
        &.open {
            .content {
                box-shadow: 2px 0 8px @shadow-color;
            }
        }
        &.close {
            transform: translateX(-100%);
wb-ct393452's avatar
wb-ct393452 committed
95 96
        }
    }
97 98 99 100 101 102 103 104 105 106 107 108
    &.right {
        right: 0px;
        .content {
            float: right;
        }
        &.open {
            .content {
                box-shadow: -2px 0 8px @shadow-color;
            }
        }
        &.close {
            transform: translateX(100%);
wb-ct393452's avatar
wb-ct393452 committed
109 110
        }
    }
111 112
}
.content {
wb-ct393452's avatar
wb-ct393452 committed
113 114 115
    display: inline-block;
    height: 100vh;
    overflow-y: auto;
116 117
}
.handler-container {
wb-ct393452's avatar
wb-ct393452 committed
118 119 120 121 122 123 124 125
    position: absolute;
    display: inline-block;
    text-align: center;
    transition: all 0.5s;
    cursor: pointer;
    top: 200px;
    z-index: 100;
    .handler {
126 127 128 129 130 131
        height: 40px;
        width: 40px;
        background-color: @base-bg-color;
        font-size: 26px;
        box-shadow: 0 2px 8px @shadow-color;
        line-height: 40px;
wb-ct393452's avatar
wb-ct393452 committed
132
    }
133 134 135 136 137
    &.left {
        right: -40px;
        .handler {
            border-radius: 0 5px 5px 0;
        }
wb-ct393452's avatar
wb-ct393452 committed
138
    }
139 140 141 142 143
    &.right {
        left: -40px;
        .handler {
            border-radius: 5px 0 0 5px;
        }
wb-ct393452's avatar
wb-ct393452 committed
144
    }
145
}
wb-ct393452's avatar
wb-ct393452 committed
146
</style>