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
<template>
  <div class="swiper-box">
    <swiper ref="sceneSwiper" v-if="sceneData.length>=1" :options="swiperOption" class="swiper-box-container">
      <!-- <span class="task-tip" v-show="Camera.rules.length == 0 ">暂无场景,请开始创建</span> -->
      <swiper-slide v-for="item in sceneData" :key="item.id+'s'">
        <div class="wrap-box" >
          <div class="inner">
            <div class="scenario-icon">
              <div class="single" v-if="item.rules.length==1">
                <div class="svg-wrap">
                  <!-- <svg class="icon" aria-hidden="true" style="font-size:4rem;">
                    <use :xlink:href="`#${item.rules[0].icon}`" />
                  </svg> -->
                  <img class="baseImg" :src="`data:image/png;base64,${item.rules[0].icon_blob}`" alt="">
                </div>
              </div>
              <div class="double" v-else-if="item.rules.length==2">
                <div class="svg-wrap" v-for="(rule,index) in item.rules" :key="index">
                  <!-- <svg class="icon" aria-hidden="true" style="font-size:2rem;">
                    <use :xlink:href="`#${rule.icon}`" />
                  </svg> -->
                  <img class="baseImg" :src="`data:image/png;base64,${rule.icon_blob}`" alt="">
                </div>
              </div>
              <div class="third" v-else-if="item.rules.length==3">
                <div class="svg-wrap" v-for="(rule,index) in item.rules" :key="'t'+index">
                  <!-- <svg class="icon" aria-hidden="true" style="font-size:2rem;">
                    <use :xlink:href="`#${rule.icon}`" />
                  </svg> -->
                  <img class="baseImg" :src="`data:image/png;base64,${rule.icon_blob}`" alt="">
                </div>
              </div>
              <div class="four" v-else-if="item.rules.length==4">
                <div class="svg-wrap" v-for="(rule,index) in item.rules" :key="'f'+index">
                  <!-- <svg class="icon" aria-hidden="true" style="font-size:2rem;">
                    <use :xlink:href="`#${rule.icon}`" />
                  </svg> -->
                  <img class="baseImg" :src="`data:image/png;base64,${rule.icon_blob}`" alt="">
                </div>
              </div>
            </div>
            <div class="scenario-name">{{item.scene_name}}</div>
          </div>
        </div>
      </swiper-slide>
    </swiper>
    <div class="swiper-pre-border" v-show="sceneData.length > 4 ">
      <div class="icon-btn" slot="button-prev">
        <i class="iconfont iconzuo"></i>
      </div>
    </div>
    <div class="swiper-next-border" v-show="sceneData.length > 4 ">
      <div class="icon-btn" slot="button-next">
        <i class="iconfont iconyou1"></i>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  props:[
    // 'swiperOption',
    'sceneData'
  ],
  
  data() {
    return {
      // mockSceneData: [
      //   { scenename: "name1", id:1, icon: ["iconrenlianjiance", "icongetijingzhi"] },
      //   { scenename: "name2", id:2, icon: ["iconchouyan-copy"] },
      //   {
      //     scenename: "name3",
      //     id:3,
      //     icon: [
      //       "iconrenshukouzhao",
      //       "iconchouyan-copy",
      //       "iconrenlianjiance",
      //       "icongetijingzhi"
      //     ]
      //   },
      //   {
      //     scenename: "name4",
      //     id:4,
      //     icon: ["iconchouyan-copy", "iconrenlianjiance", "icongetijingzhi"]
      //   },
      //   { scenename: "name5", id:5, icon: ["icongetijingzhi"] },
      //   { scenename: "name6", id:6, icon: ["iconrenshukouzhao", "icongetijingzhi"] },
      //   { scenename: "name7", id:7, icon: ["iconrenlianjiance"] }
      // ],
      swiperOption: {
        slidesPerView: 4,
        spaceBetween: 0,
        pagination: {
          el: ".swiper-pagination",
          clickable: true
        },
        navigation: {
          nextEl: ".swiper-next-border",
          prevEl: ".swiper-pre-border"
        },
        observer:true,//修改swiper自己或子元素时,自动初始化swiper
        observeParents:true,//修改swiper的父元素时,自动初始化swiper
      },
      mySwiper: {}
    }
  },
  mounted(){
    // this.mySwiper = this.$refs.sceneSwiper.swiper;
   
  },
  methods:{
    //拆分二维数组
    chunk(arr,size = 1){
      if(arr.length == 0) return;
      const tempContainer = [];
      let innerArr = [];
      arr.forEach(item => {
        if(innerArr.length == 0){
          tempContainer.push(innerArr);
        }
        innerArr.push(item);
        if(innerArr.length == size){
          innerArr = [];
        }
      });
      return tempContainer;
    }
  },
  computed: {
    slides() {
      return this.chunk(this.mockSceneData,5);
    }
  }
};
</script>
 
<style lang="scss">
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
.wrap-box {
  width: 100%;
  display: inline-block;
  .inner {
    width: 90%;
    box-sizing: border-box;
    position: relative;
    font-size: 14px;
    padding: 7px 0 48px;
    transition: all 1s;
    background: #ffffff;
    border: 1px solid #e2e2e2;
    box-shadow: 0 5px 12px 0 rgba(0, 0, 0, 0.07);
    border-radius: 4px;
    margin: auto;
    &:hover {
      .mask {
        display: block;
      }
    }
    .mask {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.65);
      backdrop-filter: blur(1px) brightness(100%);
      text-align: center;
      z-index: 1;
      border-radius: 3px;
      display: none;
      .tool {
        position: absolute;
        top: 49%;
        left: 50%;
        transform: translate(-50%, -50%);
        i {
          font-size: 50px;
        }
        i:nth-of-type(1) {
          margin-right: 30px;
        }
        i:nth-of-type(2) {
          color: red;
        }
      }
    }
    .scenario-icon {
      display: flex;
      width: 85%;
      height: 85%;
      margin: auto;
      justify-content: center;
      align-content: center;
      align-items: center;
      .single,
      .double,
      .third,
      .four {
        width: 80%;
        padding-top: 80%;
        position: relative;
        margin: auto;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        .svg-wrap {
          width: 47%;
          position: absolute;
          height: 0;
          padding-top: 47%;
          text-align: center;
          box-shadow: 0 0 3px 2px rgb(247, 247, 247) inset;
          img {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 96%;
          }
        }
      }
      .single {
        margin: auto;
        .svg-wrap {
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          box-shadow: none;
          width: 100%
        }
      }
      .double {
        .svg-wrap:nth-of-type(1) {
          top: 50%;
          transform: translateY(-50%);
          left: 0;
        }
        .svg-wrap:nth-of-type(2) {
          top: 50%;
          transform: translateY(-50%);
          right: 0;
        }
      }
      .third {
        .svg-wrap:nth-of-type(1) {
          top: 0;
          left: 0;
        }
        .svg-wrap:nth-of-type(2) {
          top: 0;
          right: 0;
        }
        .svg-wrap:nth-of-type(3) {
          top: 50%;
          left: 50%;
          transform: translateX(-50%);
        }
      }
      .four {
        .svg-wrap:nth-of-type(1) {
          top: 0;
          left: 0;
        }
        .svg-wrap:nth-of-type(2) {
          top: 0;
          right: 0;
        }
        .svg-wrap:nth-of-type(3) {
          top: 50%;
          left: 0;
        }
        .svg-wrap:nth-of-type(4) {
          top: 50%;
          right: 0;
        }
      }
    }
    .scenario-name {
      width: 100%;
      height: 30px;
      box-sizing: border-box;
      padding: 0 4px;
      text-align: center;
      position: absolute;
      bottom: 10px;
      left: 0;
    }
  }
}
</style>