index.vue
14.5 KB
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
<!--
* @Date: 2023-07-27 11:04:04
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-08-11 14:14:16
* @FilePath: /map-demo/src/components/Floor/index.vue
* @Description: 文件描述
-->
<template>
<div>
<div class="container">
<div class="main">
<header class="codrops-header">
<h1>3D导航地图</h1>
</header>
<div class="tool-bar">
<div @click="onClose" class="close icon">
<van-icon name="cross" size="1.25rem" />
</div>
<div @click="onSearch" class="search-icon icon">
<van-icon name="search" size="1.25rem" />
</div>
<div v-if="level_show" class="switch-left icon">
<span v-if="level_show < 4" @click="switchFloor('left')">
<van-icon name="arrow-up" size="1.25rem" />
</span>
</div>
<div v-if="level_show" class="close-level icon" @click.native="onCloseLevelAll">
<span>
<van-icon name="points" size="1.25rem" />
</span>
</div>
<div v-if="level_show" class="switch-right icon">
<span v-if="level_show > 1" @click="switchFloor('right')">
<van-icon name="arrow-down" size="1.25rem" />
</span>
</div>
<div class="animate-bar icon">
<div v-if="level_show == 4" class="">
<div v-if="!svg_safe_animate_status" @click="createAnimation(true, level_show - 1, 'safe')" style="font-size: 1.25rem;">
<van-icon name="star-o" />
</div>
<div v-else @click="createAnimation(false, level_show - 1, 'safe')" style="font-size: 1.25rem;">
<van-icon name="star" />
</div>
<div style="height: 0.5rem;"></div>
<div v-if="!svg_toilet_animate_status" @click="createAnimation(true, level_show - 1, 'toilet')" style="font-size: 1.25rem;">
<van-icon name="shop-o" />
</div>
<div v-else @click="createAnimation(false, level_show - 1, 'toilet')" style="font-size: 1.25rem;">
<van-icon name="shop" />
</div>
</div>
<div v-if="level_show == 3">
<div v-if="!svg_door_animate_status" @click="createAnimation(true, level_show - 1, 'door')" style="font-size: 1.25rem;">
<van-icon name="wap-home-o" />
</div>
<div v-else @click="createAnimation(false, level_show - 1, 'door')" style="font-size: 1.25rem;">
<van-icon name="wap-home" />
</div>
</div>
</div>
</div>
<div class="mall">
<!-- <div class="surroundings">
<img class="surroundings__map" src="./surroundings.svg" alt="Surroundings" />
</div> -->
<div class="levels">
<div v-for="(level, index) in level_list" :key="index" @click.capture="onFloorClick(index + 1, $event)"
:class="['level', 'level--' + (index + 1)]">
<div class="level_svg" v-html="level.svg"></div>
<div class="level__pins">
<a @click="clickPin(item, $event)" v-for="(item, index) in level.pin" :key="index" class="pin" :style="item.style"
:data-category="item.category" :data-space="item.space">
<span class="pin__icon">
<svg class="icon icon--pin">
<use xlink:href="#icon-pin"></use>
</svg>
<svg :class="['icon', 'icon--logo', `icon--${item.icon}`]">
<use :xlink:href='"#icon-" + item.icon'></use>
</svg>
</span>
</a>
</div>
<div class="level_after">L{{ index + 1 }}</div>
</div>
</div>
</div>
</div>
</div>
<van-popup v-model:show="show_popup" position="bottom" :overlay="false"
:style="{ height: '50%', background: '#FFF' }">
<div @click="onClosePopup" style="text-align: right; padding: 1rem;">
<van-icon name="cross" size="1.5rem" />
</div>
<div style="margin: 0 1rem">
<div style="font-size: 1.25rem; margin-bottom: 1rem;">{{ popup_title }}</div>
<div> {{ popup_content }} </div>
</div>
</van-popup>
<svg-icon></svg-icon>
<van-popup v-model:show="show_search_popup" position="right" :overlay="true"
:style="{ height: '100%', width: '80%', background: '#FFF' }">
<div style="background-color: #F7f8fa; padding: 1rem;">
<van-field v-model="search_value" @update:model-value="onSearchUpdate" placeholder="请输入搜索关键词" style="border-radius: 5px; padding: 0.5rem 1rem;" />
</div>
<div v-for="(item, index) in search_list" :key="index" v-show="item.show" class="search_box">
<div class="search_box_title">{{ item.title }}</div>
<van-row v-show="x.show" v-for="(x, idx) in item.list" :key="idx" @click="onSearchRow(x.space)"
style="color: #aaa; margin-bottom: 0.5rem;">
<van-col span="20">{{ x.text }}</van-col>
<van-col span="4" style="text-align: right;">{{ x.floor }}</van-col>
</van-row>
</div>
</van-popup>
</div>
</template>
<script>
import './floor.css';
import $ from 'jquery';
import SvgIcon from './svgIcon.vue'
import Data from './pin'
import { wxInfo } from '@/utils/tools'
export default {
data() {
return {
level_show: '',
search_value: '',
show_popup: false,
show_search_popup: false,
level_list: Data,
popup_title: '',
popup_content: '',
search_list: [
{
title: '1-客房',
list: [
{
space: 1.01,
text: '101~110室',
floor: 'L1',
show: true,
},
{
space: 1.02,
text: '111~119室',
floor: 'L1',
show: true,
},
],
show: true
},
{
title: '2-客房',
list: [
{
space: 2.01,
text: '201~210室',
floor: 'L2',
show: true,
},
{
space: 2.02,
text: '211~219室',
floor: 'L2',
show: true,
},
],
show: true
},
],
svg_animate_obj: {
0: [],
1: [],
2: [],
3: [],
},
svg_safe_animate_status: false,
svg_safe_animate: `
<path id="myPath" d="M 689 525 L 889 474 L 670 230 L 473 223 L 462 95" fill="none" stroke="#D49333" stroke-width="5">
</path>
<circle id="myCircle" cx="0" cy="0" r="8" fill="#6584c7">
<animateMotion dur="8s" repeatCount="indefinite">
<mpath href="#myPath" />
</animateMotion>
</circle>
`,
svg_toilet_animate_status: false,
svg_toilet_animate: `
<path id="myPath" d="M 1138.427 213.33 L 486.79 224.966 L 473.061 123.103" fill="none" stroke="#D49333" stroke-width="5">
</path>
<circle id="myCircle" cx="0" cy="0" r="8" fill="#6584c7">
<animateMotion dur="8s" repeatCount="indefinite">
<mpath href="#myPath" />
</animateMotion>
</circle>
`,
svg_door_animate_status: false,
svg_door_animate: `
<path id="myPath" d="M 689 525 L 889 474 L 670 230 L 473 223 L 462 95" fill="none" stroke="#D49333" stroke-width="5">
</path>
<circle id="myCircle" cx="0" cy="0" r="8" fill="#6584c7">
<animateMotion dur="8s" repeatCount="indefinite">
<mpath href="#myPath" />
</animateMotion>
</circle>
`,
}
},
async mounted() {
// if (!wxInfo().isPC) { // 移动端
// $('.level.level--current').css('transform', 'translateZ(1rem) rotate3d(0,0,1,20deg)');
// } else { // PC端
// $('.level.level--current').css('transform', 'translateZ(15vmin) rotate3d(0,0,1,20deg)');
// }
},
methods: {
clearPinShow() {
$('.level__pins').children('.pin').each((index, ele) => {
$(ele).removeClass('pin--active');
});
$('.mall').removeClass('mall--content-open');
},
onFloorClick(level, evt) {
this.level_show = level;
$('.levels').addClass('levels--open').addClass(`levels--selected-${level}`);
$(`.level--${level}`).addClass('level--current');
$(`.level--${level} .level__pins`).addClass('level__pins--active');
// if (!wxInfo().isPC) { // 移动端
// $('.level.level--current').css('transform', 'translateZ(5rem) rotate3d(0,0,1,20deg)');
// } else { // PC端
// $('.level.level--current').css('transform', 'translateZ(20vmin) rotate3d(0,0,1,20deg)');
// }
},
onCloseLevel() {
this.show_popup = false;
let level = this.level_show;
$('.mall').removeClass('mall--content-open');
$('.levels').removeClass('levels--open').removeClass(`levels--selected-${level}`);
// $('.level.level--current').css('transform', '');
$(`.level--${level}`).removeClass('level--current');
$(`.level--${level} .level__pins`).removeClass('level__pins--active');
this.level_show = '';
this.clearPinShow();
},
onCloseLevelAll() {
this.onCloseLevel();
// 清除动画
this.clearAllAnimation();
},
onClose() {
this.onCloseLevelAll();
this.$emit('close');
},
onClickCloseIcon() {
this.clearPinShow();
},
switchFloor(type) { // 切换楼层
let level = this.level_show;
if (type === 'right') {
level = level - 1 < 1 ? 1 : level - 1;
}
if (type === 'left') {
level = level + 1 > 4 ? 4 : level + 1;
}
this.onCloseLevel();
this.onFloorClick(level);
},
onSearch() {
this.show_search_popup = true;
},
onSearchRow(val) {
// 清空图层显示
this.onCloseLevel();
this.show_popup = false;
// 测试锚点
let currentTarget = null;
let category = null;
let space = null;
$('.level__pins').children('.pin').each((index, ele) => {
space = $(ele).data('space'); // 锚点标记
if (space === val) { // 匹配符合的dom节点
category = parseInt(space);// 获取图层标记
currentTarget = ele;
}
$(ele).removeClass('pin--active');
});
// 选择图层
this.onFloorClick(category);
// 选择锚点样式
$(currentTarget).addClass('pin--active');
$('.mall').addClass('mall--content-open');
setTimeout(() => {
// 打开锚点详情
this.show_popup = true;
// 把图层推高
// if (!wxInfo().isPC) { // 移动端
// $('.level.level--current').css('transform', 'translateZ(1rem) rotate3d(0,0,1,20deg)');
// } else { // PC端
// $('.level.level--current').css('transform', 'translateZ(20vmin) rotate3d(0,0,1,20deg)');
// }
this.level_list.forEach(item => {
item.pin.forEach(x => {
if (x.space === val) {
// 打开 pin 详情信息
this.popup_title = x?.affix?.title;
this.popup_content = x?.affix?.content;
}
})
});
}, 500);
// 关闭搜索弹框
this.show_search_popup = false;
},
onClosePopup() {
this.show_popup = false;
this.clearPinShow();
},
clickPin (item, evt) { // 点击pin操作
this.clearPinShow();
$(evt.target).parents('a.pin').addClass('pin--active'); // pin点击效果
//
this.show_popup = true;
// 打开 pin 详情信息
this.popup_title = item?.affix?.title;
this.popup_content = item?.affix?.content;
// 把图层推高
$('.mall').addClass('mall--content-open');
// if (!wxInfo().isPC) { // 移动端
// $('.level.level--current').css('transform', 'translateZ(1rem) rotate3d(0,0,1,20deg)');
// } else { // PC端
// $('.level.level--current').css('transform', 'translateZ(15vmin) rotate3d(0,0,1,20deg)');
// }
},
onSearchUpdate () {
this.search_list.forEach((item) => {
item.list.forEach((x) => {
if (x.text.indexOf(this.search_value) >= 0) {
x.show = true;
} else {
x.show = false;
}
});
// 如果子项里面都为空,隐藏整个项
let show_num = item.list.filter((x) => x.show === true);
if (show_num.length) {
item.show = true;
} else {
item.show = false;
}
});
},
clearAllAnimation () {
// 所有清除动画
for (let key in this.svg_animate_obj) {
if (this.svg_animate_obj[key].length) {
if (this[`svg_${this.svg_animate_obj[key]}_animate_status`]) {
this.createAnimation(false, key, this.svg_animate_obj[key]);
}
}
}
},
createAnimation(flag, level, id) { // 创建动画路径,固定生成动画方法
//
let insertString = '';
if (flag) { // 打开
// 清除动画
this.clearAllAnimation();
this[`svg_${id}_animate_status`] = true;
insertString = this[`svg_${id}_animate`];
let insertIndex = this.level_list[level].svg.indexOf('</svg>');
// 添加相应动画
let modifiedString = this.level_list[level].svg.slice(0, insertIndex) + insertString;
this.level_list[level].svg = modifiedString + '</svg>';
// 新增ID
if (this.svg_animate_obj[level].indexOf(id) < 0) {
this.svg_animate_obj[level].push(id);
}
} else { // 关闭
this[`svg_${id}_animate_status`] = false;
let originalString = this.level_list[level].svg;
let searchTerm = this[`svg_${id}_animate`];
let startIndex = originalString.indexOf(searchTerm);
let endIndex = startIndex + searchTerm.length - 1;
// 删除相应动画
let modifiedString = originalString.substring(0, startIndex) + originalString.substring(endIndex + 1);
this.level_list[level].svg = modifiedString;
// 剔除ID
this.svg_animate_obj[level] = this.svg_animate_obj[level].filter(item => item === id);
}
},
}
}
</script>
<style lang="less" scoped>
.test {
opacity: 0;
}
.search_box {
padding: 1rem;
.search_box_title {
color: #000;
margin-bottom: 1rem;
font-size: 1.15rem;
}
}
.tool-bar {
position: relative;
.icon {
position: absolute;
z-index: 100;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
text-align: center;
}
.close {
top: 1rem;
right: 1rem;
}
.search-icon {
top: 2.75rem;
right: 1rem;
}
.switch-left {
top: 4.5rem;
right: 1rem;
}
.close-level {
top: 6rem;
right: 1rem;
}
.switch-right {
top: 8rem;
right: 1rem;
}
.animate-bar {
top: 12rem;
right: 1rem;
}
}
.level_after {
font-size: 0.75rem;
line-height: 0;
position: absolute;
z-index: 100;
top: -2em;
left: 3.5em;
white-space: nowrap;
color: #7d7d86;
-webkit-transform: rotateZ(45deg) rotateX(-70deg) translateZ(5vmin);
transform: rotateZ(45deg) rotateX(-70deg) translateZ(5vmin);
-webkit-transition: -webkit-transform 1s, color 0.3s;
transition: transform 1s, color 0.3s;
-webkit-transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
}
.level--current {
.level_after {
font-size: 1rem;
-webkit-transform: rotateZ(25deg) rotateX(-60deg) translateZ(15vmin);
transform: rotateZ(25deg) rotateX(-60deg) translateZ(15vmin);
}
}
.level_btn {
font-size: 1rem;
line-height: 0;
position: absolute;
z-index: 100;
top: -2em;
right: 0;
white-space: nowrap;
color: #7d7d86;
-webkit-transform: rotateZ(45deg) rotateX(-70deg) translateZ(5vmin);
transform: rotateZ(45deg) rotateX(-70deg) translateZ(5vmin);
-webkit-transition: -webkit-transform 1s, color 0.3s;
transition: transform 1s, color 0.3s;
-webkit-transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
transition-timing-function: cubic-bezier(0.7, 0, 0.3, 1);
}
</style>