<template>
    <div class="context-menu" v-show="visible" :style="style">
        <ul class="menu-list">
            <li class="menu-item" @click="handleDelete">
                <i class="el-icon-delete"></i>
                删除
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    name: 'ContextMenu',
    data() {
        return {
            visible: false,
            x: 0,
            y: 0
        }
    },
    computed: {
        style() {
            return {
                left: this.x + 'px',
                top: this.y + 'px'
            }
        }
    },
    methods: {
        show(x, y) {
            this.x = x
            this.y = y
            this.visible = true
            document.addEventListener('click', this.hide)
        },
        hide() {
            this.visible = false
            document.removeEventListener('click', this.hide)
        },
        handleDelete() {
            this.$emit('delete')
            this.hide()
        }
    },
    beforeDestroy() {
        document.removeEventListener('click', this.hide)
    }
}
</script>

<style scoped>
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #e4e7ed;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    z-index: 2000;
}

.menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 14px;
}

.menu-item:hover {
    background-color: #f5f7fa;
}

.menu-item i {
    margin-right: 8px;
}
</style> 