index.vue
3.51 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
<template>
<div class="side-menu-container" ref="fixMenuRef">
<ul class="clearfix fixed-menu-container">
<li
class="menu-item"
:class="{
active: activeMenu === item.value
}"
v-for="item in list"
:key="item.value"
:data-key="item.value"
>
<span class="item-text" :data-key="item.value">{{ item.label }}</span>
</li>
</ul>
<div
ref="popperWrapper"
class="test"
:style="{
opacity: visible ? 1 : 0,
top: currItemPostion.y,
left: currItemPostion.x
}"
>
<el-input
ref="searchRef"
class="menu-child-search"
suffix-icon="el-icon-search"
v-model="input"
placeholder="请输入"
/>
<p class="clearfix menu-child-item">
<span>南京吾悦广场</span>
</p>
<p class="clearfix menu-child-item">
<span>南京吾悦广场</span>
</p>
<p class="clearfix menu-child-item">
<span>南京吾悦广场</span>
</p>
<p class="clearfix menu-child-item">
<span>南京吾悦广场</span>
</p>
</div>
</div>
</template>
<script>
export default {
name: 'FixedMenu',
data() {
return {
list: [
{ label: '集团', value: 'account' },
{ label: '商场', value: 'mall' },
{ label: '楼层', value: 'floor' },
{ label: '店铺', value: 'zone' }
],
activeMenu: 'account',
currItemPostion: { x: 0, y: 0 },
input: '',
visible: true
}
},
mounted() {
document.addEventListener('click', this.onMenuClick, false)
},
beforeDestroy() {
document.removeEventListener('click', this.onMenuClick, false)
},
methods: {
onMenuClick(ev) {
ev.stopPropagation()
try {
const panels = this.$refs.fixMenuRef
const key = ev.target.dataset.key
if (key === 'account') {
this.visible = false
return
}
if (!panels.contains(ev.target)) {
this.visible = false
} else {
this.$refs.searchRef.focus()
this.visible = true
}
// 计算点位 固定选择特殊属性值的元素
const el = document.querySelector(`.menu-item[data-key="${key}"]`)
if (el && this.$refs.popperWrapper) {
const popperWrapperRect = this.$refs.popperWrapper.getBoundingClientRect()
const { x, y } = el.getBoundingClientRect()
this.currItemPostion = {
x: x - popperWrapperRect.width - 3 + 'px',
y: y + 'px'
}
}
} catch (error) {
this.visible = false
console.log(error)
}
}
}
}
</script>
<style lang="scss" scoped>
.fixed-menu-container {
position: fixed;
width: 50px;
right: 5.6vw;
top: 30vh;
box-shadow: 0 0 3px 0 rgba(0, 0, 0, 0.5);
}
.menu-item {
background: #fff;
padding: 12px 0;
color: #444;
text-align: center;
font-size: 14px;
box-sizing: border-box;
cursor: pointer;
&.active {
color: #fff;
background: #06f;
}
&:hover {
color: #fff;
background: #06f;
}
}
.test {
position: fixed;
padding: 5px 9px;
box-sizing: border-box;
background: #fff;
box-shadow: 0 0 1px -4px #333;
}
.menu-child-search {
margin-bottom: 5px;
}
.menu-child-item {
text-align: left;
font-size: 13px;
color: #888;
padding-left: 6px;
padding-right: 6px;
margin-bottom: 4px;
box-sizing: border-box;
cursor: pointer;
&:hover {
background: #0069ff;
color: #fff;
}
}
</style>