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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<template>
  <div class="diy-page" id="diy-page"
    @mousedown.stop="onmousedown($event)"
    @mouseup.stop="onmouseup($event)"
    @contextmenu.prevent.stop="del">
    <div class="title"
      :style="{backgroundColor: basicSet.titleColor}">
      <img
      v-if="basicSet.titleImg" :src="basicSet.titleImg" alt="">
    </div>
    <div class="container">
      <img :id="item.id" :src="item.url" alt="" v-for="item in basicSet.bgImg" :key="item.id">
    </div>
    <hotspot :attr="{
      x: item.x,
      y: item.y,
      w: item.w,
      h: item.h,
      type: item.type,
      z: item.z,
      img:getFileUrl(item),
      fixedPosition: item.fixedPosition,
      isShow:item.isDisplayProd !== '1'
    }" v-for="(item) in hotList" :key="item.id"
    :id="item.id"
    >
    </hotspot>
  </div>
</template>
<script>
import hotspot from './components/hotspot.vue'
import create from './components/event/create'
import { mapMutations, mapState } from 'vuex'
export default {
  name: 'diy-page',
  components: {
    hotspot
  },
  data() {
    return {
      createFlag: false
    }
  },
  computed: {
    ...mapState(['diyList', 'mousedown']),
    basicSet() {
      return this.diyList.filter((v) => {
        return v.type === 'basicSet'
      })[0]
    },
    hotList() {
      return this.diyList.filter((v) => {
        return v.type !== 'basicSet'
      })
    }
  },
  methods: {
    ...mapMutations(['updateMousedown', 'delPopDiyList']),
    /**
     * 获取热区上传的图片地址
     */
    getFileUrl(item) {
      let fileUrl = null
      if (item.fileUrl) {
        fileUrl = item.fileUrl
      } else if (item.img) {
        fileUrl = item.img
      } else if (item.banners && item.banners.length) {
        fileUrl = item.banners[0].url
      }
      return fileUrl
    },
    onmousedown($event) {
      if ($event.which !== 1) {
        return
      }
      this.updateMousedown({ startTime: new Date() })
    },
    onmouseup($event) {
      const time = new Date() - this.mousedown.startTime
      document.getElementById('diy-aside').style.overflowY = 'auto'
      document.getElementById('main-container').style.overflowY = 'auto'
      document.onmousemove = null
      if (time > 200) {
        this.createFlag = false
        return false
      }
      if ($event.which === 1) {
        if (this.createFlag) {
          this.createFlag = false
          document.onmousemove = null
        } else {
          this.createFlag = true
          create($event)
        }
      }
    },
    del() {
      if (!this.createFlag) {
        return false
      }
      this.delPopDiyList()
      this.updateMousedown({ activeId: this.diyList[this.diyList.length - 1].id, zIndex: this.mousedown.zIndex - 1 })
      this.createFlag = false
    }
  }
}
</script>
<style scoped lang="scss">
.diy-page {
  width: 375px;
  min-height: 667px;
  -webkit-touch-callout:none;
  -webkit-user-select:none;
  -khtml-user-select:none;
  -moz-user-select:none;
  -ms-user-select:none;
  user-select:none;
  position: relative;
  .title {
    height: 44px;
    display: flex;
    align-items: center;
    // justify-content: center;
    position: fixed;
    width: 375px;
    z-index: 1000;
    img {
      max-height:  100%;
      max-width: 100%;
      margin-left: 20px;
    }
  }
  .container {
    position: relative;
    top: 44px;
    z-index: 1;
    img {
      width: 100%;
      display: block;
    }
  }
}
</style>