he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
  <div class="right-menu" :style="containerStyle" v-show="visible">
    <div class="right-menu-content" @click.stop="handleWrapperClick">
      <slot></slot>
    </div>
  </div>
</template>
 
<script>
export default {
  name: "RightMenu",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    x: {
      type: Number,
      default: 0,
    },
    y: {
      type: Number,
      default: 0,
    },
    autoClose: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {};
  },
  computed: {
    containerStyle() {
      return {
        top: this.y + "px",
        left: this.x + "px",
      };
    },
  },
  methods: {
    handleWrapperClick() {
      if (this.autoClose) {
        this.handleClose();
      }
    },
    handleClose() {
      this.hide();
    },
    hide() {
      this.$emit("update:visible", false);
    },
  },
  mounted() {
    // 添加点击事件
    document.body.addEventListener(
      "click",
      (event) => {
        this.handleClose();
        event.stopPropagation();
      },
      false
    );
  },
};
</script>
 
<style scoped>
.right-menu {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
}
.right-menu-list {
  font-size: 12px;
  background-color: #ffffff;
}
.right-menu-list a {
  display: block;
  color: #000000;
  padding: 4px;
}
.right-menu-list a:hover {
  background-color: #cccccc;
}
</style>