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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<template>
  <div class="swiper_3d" v-if="infoData" :style="{
      width: infoData.width,
      height: infoData.height,
      position: infoData.fixedPosition ? 'fixed' : 'absolute',
      top: infoData.codeY,
      left: infoData.codeX,
      zIndex: infoData.z,
    }">
    <div ref="ul" class="box" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend"
         :style="us">
      <div class="item" v-for="(item, $index) in infoData.banners" :key="item.id"
           @click="clickItem(item, $index)" :style="itemStyle($index, item)"
           v-lazy:background-image="{src: item.url}">
        <template v-if="item.checkedData && $index == 1">
          <div v-for="(itemPublic, i) in item.checkedData.slice(0, 2)" :key="itemPublic.publicityId"
               class="swiper_3d_text" :class="i ? 'two' : ''">
            <div class="common-txt-color publicityName font26">
              {{ itemPublic.publicityName }}
            </div>
            <p class="itemArticle text99" :class="i == 0 && iArticle == 0 ? 'b' : ''"
               v-for="(itemArticle, iArticle) in itemPublic.articleArray.slice(0, 4)"
               :key="itemArticle.articleId">
              {{ itemArticle.articleName }}
            </p>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>
<script>
var baseUrl = process.env.VUE_APP_H5_URL
// let startX, startY, endX, endY, moveX, moveY
let startX, endX, moveX
export default {
  name: 'swiper-3d',
  props: {
    infoData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    scrollTop: {
      type: Number
    }
  },
  data () {
    return {
      moveFlag: false,
      rotateX: 0,
      rotateY: 0,
      ulStyle: {
        transform: `rotateX(${this.rotateX}deg)  rotateY(${this.rotateY}deg)`
      }
    }
  },
  computed: {
    us () {
      return Object.assign(this.ulStyle, {
        // "transform-origin": `50% 50% -${this.findHypotenuse(this.infoData.w)}px`,
      })
    },
    itemStyle () {
      return function ($index, item) {
        let t
        // 三棱柱
        switch ($index) {
          case 0:
            t = {
              transform: ` translateZ(${0}px)`
            }
            break
          case 1:
            t = {
              transform: 'rotateY(-240deg)',
              'transform-origin': `50% 0 -${this.findHypotenuse(this.infoData.w) + 11}px`
            }
            break
          case 2:
            t = {
              transform: ' rotateY(240deg)',
              'transform-origin': `50% 0 -${this.findHypotenuse(this.infoData.w) + 11}px`
            }
            break
          case 3:
            t = {
              display: 'none'
            }
            break
        }
        return Object.assign(t, {
          width: this.infoData.width,
          height: this.infoData.height
        })
      }
    }
  },
  methods: {
    findHypotenuse (base, perpendicular) {
      const bSquare = base ** 2
      const hypotenuse = Math.sqrt(bSquare / 3) / 2
      return hypotenuse
    },
    touchstart (e) {
      startX = e.changedTouches[0].clientX
      // startY = e.changedTouches[0].clientY;
    },
    touchmove (e) {
      this.moveFlag = true
      moveX = e.changedTouches[0].clientX
      // moveY = e.changedTouches[0].clientY;
      const x = moveX - startX
      // const y = startY - moveY;
      this.ulStyle = {
        transform: ` rotateY(${this.rotateY + x}deg)`,
        'transform-origin': `50% 50% -${this.findHypotenuse(this.infoData.w) + 10}px`
      }
    },
    touchend (e) {
      endX = e.changedTouches[0].clientX
      const x = endX - startX
      // if (Math.abs(x) % 90 > 45) {
      //  this.rotateY += (x > 0 ? 90 : -90)
      // }
      if (!this.moveFlag) {
        return
      }
      this.rotateY += x > 0 ? 120 : -120
      this.ulStyle = {
        transform: `rotateY(${this.rotateY}deg)`,
        'transform-origin': `50% 50% -${this.findHypotenuse(this.infoData.w) + 10}px`
      }
      this.moveFlag = false
    },
    clickItem (active, index) {
      if (this.$route.query.isPreview) return
      if (active.link && active.link.indexOf('https') > -1) {
        this.openUrl(active)
      } else {
        // 商品详情
        if (active.type === '2') {
          // 1 仅图片 2 商品详情 3活动详情 4文章列表
          const _obj = {
            shopSpuId: active.shopSpuId
          }
          const params = active.shopSkuId ? { ..._obj, ...{ shopSkuId: active.shopSkuId } } : _obj
          console.log(params, '====商品详情传参')
          if (this.$root.isIos) {
            const _strP = `?shopSpuId=${params.shopSpuId}`
            window.webkit.messageHandlers.iosRouter.postMessage(
              `wlyxls://product_detail${params.shopSkuId ? `${_strP}&shopSkuId=${params.shopSkuId}` : _strP}`
            )
          } else {
            window.wlyxls.toCommodityDetailPage(JSON.stringify(params))
          }
        }
        if (active.type === '1' && active.link) {
          this.openUrl(active)
        }
        // 满减满赠
        if (
          (active.type === '3' && active.promotionType == '1') ||
          active.promotionType == '2'
        ) {
          // jumpLink = `/pages/activity/actiiveCuostom?promotionId=${active.promotionId}`;
          const params = {
            promotionId: active.promotionId || ''
          }
          if (this.$root.isIos) {
            window.webkit.messageHandlers.iosRouter.postMessage(
              `wlyxls://category_search_result?promotionId=${params.promotionId}`
            )
          } else {
            window.wlyxls.toActivityCommodityListPage(JSON.stringify(params))
          }
        }
        // 盲盒
        if (active.type === '3' && active.promotionType == '3') {
          const _url = `${baseUrl}/blindBoxNew?promotionId=${active.promotionId}&flag=true`
          console.log(encodeURIComponent(_url), '=====')
          if (window.wlyxls) {
            const params = {
              url: _url,
              isShowTitle: false // 是否显示顶部返回栏,默认显示
            }
            // 打开新的页面
            window.wlyxls.openUrlOnNewPage(JSON.stringify(params))
          } else if (window.webkit) {
            console.log(`wlyxls://browser?url=${encodeURIComponent(_url)}&isShowTitle=false`)
            window.webkit.messageHandlers.iosRouter.postMessage(
              `wlyxls://browser?url=${encodeURIComponent(_url)}&isShowTitle=false`
            )
          } else {
            this.$router.push({
              path: '/blindBoxNew',
              query: { promotionId: active.promotionId, flag: true }
            })
          }
        }
        // 限时抢购
        if (active.type === '3' && active.promotionType == '4') {
          const _url = `${baseUrl}/activity?promotionId=${active.promotionId}&flag=true`
          if (window.wlyxls) {
            const params = {
              url: _url,
              isShowTitle: false // 是否显示顶部返回栏,默认显示
            }
            // 打开新的页面
            window.wlyxls.openUrlOnNewPage(JSON.stringify(params))
          } else if (window.webkit) {
            console.log(`wlyxls://browser?url=${encodeURIComponent(_url)}&isShowTitle=false`)
            window.webkit.messageHandlers.iosRouter.postMessage(
              `wlyxls://browser?url=${encodeURIComponent(_url)}&isShowTitle=false`
            )
          } else {
            this.$router.push({
              path: '/activity',
              query: { promotionId: active.promotionId, flag: true }
            })
          }
        }
        // 优惠卷
        if (active.type === '3' && active.promotionType == '5') {
          if (this.$root.isIos) {
            window.webkit.messageHandlers.iosRouter.postMessage('wlyxls://couponList')
          } else {
            window.wlyxls.toCouponListPage('')
          }
        }
        // 新闻快报
        if (active.type === '4') {
          const params = {
            position: index, // 0-品牌文化  1-新闻快报
            publicityData: JSON.stringify(active)
          }
          if (this.$root.isIos) {
            window.webkit.messageHandlers.toPublicityPage.postMessage(
              JSON.stringify(params)
            )
          } else {
            if (window.wlyxls) {
              window.wlyxls.toPublicityPage(JSON.stringify(params))
            }
          }
        }
        if (active.type === '1' && !active.link) {
          this.$toast('正在研发中,敬请期待')
        }
      }
    },
    // 链接配置
    openUrl (active) {
      let isExit = true
      if (
        active.link.indexOf('/blindBoxNew') != -1 ||
        active.link.indexOf('/activity') != -1
      ) {
        isExit = false
      }
      const params = {
        url: `${active.link}`,
        isShowTitle: isExit // 是否显示顶部返回栏,默认显示
      }
      if (this.$root.isIos) {
        console.log(`wlyxls://browser?url=${encodeURIComponent(active.link)}&isShowTitle=${isExit}`)
        window.webkit.messageHandlers.iosRouter.postMessage(
          `wlyxls://browser?url=${encodeURIComponent(active.link)}&isShowTitle=${isExit}`
        )
      } else {
        if (window.wlyxls) {
          window.wlyxls.openUrlOnNewPage(JSON.stringify(params))
        }
      }
    }
  }
}
</script>
<style scoped lang="scss">
.swiper_3d {
  perspective: 800px;
  perspective-origin: 50% 100px;
  overflow-y: hidden;
  .swiper_3d_text {
    padding: 120px 40px 0 40px;
    box-sizing: border-box;
    color: #000;
    text-align: left;
    box-sizing: border-box;
 
    p {
      font-size: 22px;
      transform-origin: 0 0;
      line-height: 42px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .b {
      color: #666;
      font-size: 26px;
    }
    .publicityName {
      padding: 0 5px;
      display: inline-block;
      margin-bottom: 10px;
      background: #eb0f17;
      color: #fff;
    }
  }
  .two {
    padding-top: 20px;
  }
}
.box {
  position: relative;
  transition: all 0.3s;
  transform-style: preserve-3d;
  transform: perspective(1000);
  .item {
    width: 100%;
    height: 100%;
    text-align: center;
    color: white;
    position: absolute;
    overflow: hidden;
    background-position: center;
    background-size: 100%;
    background-repeat: no-repeat;
  }
}
</style>