fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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>
  <div class="diy-hotspot" :style="{
      width: attr.w + 'px',
      height: attr.h + 'px',
      left: left,
      top: top,
      position: attr.fixedPosition ? 'fixed' : 'absolute',
      'z-index': attr.z,
      backgroundImage:`url(${attr.img})`
    }" ref="diy-hotspot" v-drag>
    <span :style="{'z-index': attr.z+99}">{{attr.z - 99}}</span>
    <div class="resize-icon" v-show="attr.isShow" v-resize></div>
  </div>
</template>
<script>
import resize from './event/resize'
import drag from './event/drag'
export default {
  name: 'diy-hotspot',
  props: {
    attr: {
      required: true,
      type: Object
    }
  },
  computed: {
    left () {
      // 获取左边菜单的宽度
      const menuW = document.getElementById('menu-aside').clientWidth
      const leftW = menuW + 21
      return this.attr.fixedPosition ? this.attr.x + leftW + 'px' : this.attr.x + 'px'
    },
    top () {
      if (this.attr.fixedPosition) {
        return this.attr.y + 148 + 'px'
      } else {
        return this.attr.y + 'px'
      }
    }
  },
  directives: {
    resize,
    drag
  }
}
</script>
<style scoped lang="scss">
.diy-hotspot {
  background: rgb(64, 21, 219);
  opacity: .5;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 40px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  .resize-icon {
    position: absolute;
    width: 10px;
    height: 10px;
    left: calc(100% - 5px);
    top: calc(100% - 5px);
    background: yellow;
    cursor: se-resize;
  }
}
</style>