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
<template>
  <div class="index_page">
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh" animation-duration="500">
      <!-- 下拉提示,通过 scale 实现一个缩放效果 -->
      <template #pulling="props">
        <span>下拉刷新</span>
      </template>
      <!-- 释放提示 -->
      <template #loosing>
        <span>释放刷新</span>
      </template>
      <!-- 加载提示 -->
      <template #loading>
        <span>正在刷新</span>
      </template>
      <div class="status_bar" :style="{
            height: $setVw(43),
            background: diyInfo[0].titleColor || '#f8f8f8',
          }" v-if="diyInfo.length">
        <div class="top_view" :style="{
              height: $setVw(statusHeight),
              width: '100%',
              background: diyInfo[0].titleColor || '#f7f7f7',
            }" />
      </div>
      <div v-for="item in diyInfo" :key="item.id">
        <component :ref="item.type" :is="currentView(item.type)" :infoData="item"></component>
      </div>
      <div v-if="diyInfo[0] && diyInfo[0].bgImg && diyInfo[0].bgImg.length"
           :style="{minHeight:minHeight}">
        <img v-lazy="item.url" alt="" v-for="item in diyInfo[0].bgImg" :key="item.id" class="bg_img"
             ref="conf0" />
      </div>
    </van-pull-refresh>
  </div>
</template>
 
<script type="javascript">
import { getDiyInfo } from '@/api/oauth/index'
import VideoPlayer from '@/components/video-player/index.vue'
import NewImage from '@/components/image/index.vue'
import NewSwiper from '@/components/swiper/index.vue'
import NewHeader from '@/components/header/index.vue'
import Notice from '@/components/notice/index.vue'
import Search from '@/components/search/index.vue'
import Swiper3D from '@/components/swiper-3d/index.vue'
import BackToTop from '@/components/backToTop/index.vue'
import { closeLoading } from '@/utils/loading.js'
export default {
  components: {
    VideoPlayer,
    NewImage,
    NewSwiper,
    NewHeader,
    Notice,
    Search,
    Swiper3D,
    BackToTop
  },
 
  data () {
    return {
      minHeight: '',
      isLoading: false,
      diyInfo: [],
      statusHeight: 0,
      ws: null,
      token: '',
      showHeader: ''
    }
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      if (window.plus) {
        this.ws = window.plus.webview.currentWebview()
        this.setRefresh(true)
        this.statusHeight = window.plus.navigator.getStatusbarHeight()
      }
      this.getDiy({ status: 2, diyType: '1' })
    },
    plusReady () {
      this.ws = window.plus.webview.currentWebview()
      this.setRefresh(true)
      this.judgeReq()
      this.statusHeight = window.plus.navigator.getStatusbarHeight()
    },
    setRefresh () {
      this.ws.setPullToRefresh(
        {
          style: 'circle',
          support: true,
          height: '50px',
          range: '50px',
          offset: '50px'
        },
        this.onRefresh
      )
    },
    judgeReq () {
      if (window.plus) {
        const url = this.ws.getURL()
        if (url.indexOf('?') > -1) {
          const id = url.split('?')[1].split('=')[1]
          this.getDiy({ id: id })
        } else {
          this.getDiy({ status: 2, diyType: '1' })
        }
      } else {
        this.getDiy({ status: 2, diyType: '1' })
      }
    },
    onRefresh () {
      // this.ws.beginPullToRefresh()
      this.judgeReq()
      if (
        this.$refs &&
        this.$refs.playVideo &&
        this.$refs.playVideo.length &&
        this.$refs.playVideo[0]
      ) {
        if (this.$refs.playVideo[0].video) {
          this.$refs.playVideo[0].video.close()
          this.$refs.playVideo[0].createVideo()
        }
      }
      if (
        this.$refs &&
        this.$refs.carousel &&
        this.$refs.carousel.length &&
        this.$refs.carousel[0]
      ) {
        this.$refs.carousel[0].showSwiper = true
      }
    },
    async getDiy (params) {
      const _this = this
      try {
        this.isLoading = false
        const res = await getDiyInfo(params)
        let maxHeight = 0
        if (_this.ws) _this.ws.endPullToRefresh()
        if (res.data && res.data.length) {
          _this.diyInfo = JSON.parse(res.data[0].styleInfo)
          _this.diyInfo.forEach((v, index) => {
            if (v.w) {
              v.w += 20
            }
            if (v.type == 'search') {
              if (v.x) {
                v.x = v.x + 15
              }
              if (v.w) {
                v.w = v.w - 30
              }
              if (!v.fixedPosition) {
                v.y = v.y - 10
              }
            }
            if (v.y) {
              v.y = (_this.statusHeight + 10) + Math.floor(v.y)
            }
            if (v.x) {
              v.x -= 10
            }
            v.width = v.w ? _this.$setVw(v.w) : 0
            if (v.x) v.codeX = _this.$setVw(v.x)
            if (v.y) v.codeY = _this.$setVw(v.y)
            v.height = v.h ? _this.$setVw(v.h) : 0
            if (v.borderRadius) v.borderRadiu = _this.$setVw(v.borderRadius)
            if (v.strokeSize) v.borderSize = _this.$setVw(v.strokeSize)
            // 判断页面的最小高度  以防止页面背景图高度不够 导致无法滚动查看定位元素
            if ((v.h + v.y) > maxHeight) {
              maxHeight = v.h + v.y - 43 // 减去status_bar的高度
            }
          })
          setTimeout(() => {
            _this.isLoading = false
          }, 500)
        } else {
          _this.diyInfo = []
        }
        this.minHeight = _this.$setVw(maxHeight)
        console.log(_this.diyInfo)
        closeLoading(1)
      } catch (error) {
        closeLoading(1)
        _this.diyInfo = []
        if (this.ws) this.ws.endPullToRefresh()
      }
    },
    currentView (type) {
      let val = ''
      switch (type) {
        case 'basicSet':
          val = 'NewHeader'
          break
        case 'customPage':
        case 'proCategory':
        case 'proDetails':
        case 'actDetails':
        case 'coupon':
          val = 'NewImage'
          break
        case 'search':
          val = 'Search'
          break
        case 'carousel':
          val = 'NewSwiper'
          break
        case 'playVideo':
          val = 'VideoPlayer'
          break
        case 'bulletinBoard':
          val = 'Notice'
          break
        case 'backToTop':
          val = 'BackToTop'
          break
        case 'slide3d':
          val = this.$root.isIos ? 'NewSwiper' : 'Swiper3D'
          break
      }
      return val
    }
  }
}
</script>
 
<style scoped>
* {
  -webkit-touch-callout: none;
}
.bg_img {
  width: 100%;
  height: auto;
  display: block;
  -webkit-touch-callout: none;
}
.top_view {
  height: var(--status-bar-height);
  width: 100%;
  position: fixed;
  background-color: #e0c18f;
  top: 0;
  z-index: 999;
}
</style>