<template>
|
<div class="public-legend-all"
|
ref='publicLegendAll'>
|
<div class="legend-title"
|
@mousedown="move">
|
<i class="el-icon-document"></i>
|
图例
|
<i class="shrink"
|
:class="
|
legendFlag == true
|
? 'el-icon-caret-bottom'
|
: 'el-icon-caret-top'
|
"
|
@click="legendFlag = !legendFlag"></i>
|
</div>
|
<div class="public-legends"
|
v-show="legendFlag">
|
<div v-for="(item, index) in legendsDetail"
|
:key="index">
|
<h3>{{ item.title }}</h3>
|
<ul>
|
<li v-for="(it, ind) in item.content"
|
:key="ind">
|
<span>{{ it.label }}: </span>
|
<img :src="it.src"
|
alt="" />
|
</li>
|
</ul>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
export default {
|
name: 'Legend',
|
props: ['legendsDetail'],
|
data () {
|
return {
|
legendFlag: true
|
}
|
},
|
methods: {
|
move (e) {
|
const odiv = this.$refs.publicLegendAll // 获取目标元素
|
// 算出鼠标相对元素的位置
|
const disX = e.clientX - odiv.offsetLeft
|
const disY = e.clientY - odiv.offsetTop
|
|
const disH = odiv.offsetHeight
|
const disW = odiv.offsetWidth
|
|
document.onmousemove = (e) => {
|
// 鼠标按下并移动的事件
|
// 用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
|
let left = e.clientX - disX
|
let top = e.clientY - disY
|
|
// 绑定元素位置到positionX和positionY上面
|
|
if (left >= window.innerWidth - disW) {
|
left = window.innerWidth - disW
|
}
|
|
if (left <= 0) {
|
left = 0
|
}
|
|
if (top >= window.innerHeight - disH) {
|
top = window.innerHeight - disH
|
}
|
|
if (top <= 60) {
|
top = 60
|
}
|
|
// 移动当前元素
|
odiv.style.left = (left) + 'px'
|
odiv.style.top = (top) + 'px'
|
odiv.style.bottom = 'auto'
|
}
|
document.onmouseup = (e) => {
|
document.onmousemove = null
|
document.onmouseup = null
|
}
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scope>
|
.public-legend-all {
|
position: fixed;
|
right: 10px;
|
top: auto;
|
bottom: 10px;
|
width: 160px;
|
height: auto !important;
|
background: #fff;
|
text-align: center;
|
color: #677788 !important;
|
z-index: 1111 !important;
|
box-shadow: 0px 0px 4px 1px #ccc;
|
.legend-title {
|
position: relative;
|
padding: 0 10px;
|
height: 36px;
|
line-height: 36px;
|
text-align: left;
|
background: #d5e9ff;
|
cursor: move;
|
font-size: 18px;
|
.shrink {
|
position: absolute;
|
top: 10px;
|
right: 10px;
|
cursor: pointer;
|
}
|
}
|
.public-legends {
|
background: #fff;
|
border-radius: 10px;
|
text-align: center;
|
padding: 20px 10px 0 10px;
|
max-height: 320px;
|
overflow-y: auto;
|
& > div {
|
position: relative;
|
padding-bottom: 14px;
|
h3 {
|
position: absolute;
|
top: -22px;
|
left: 20px;
|
background: #fff;
|
color: #4fa9fd;
|
padding: 0 8px;
|
font-size: 13px;
|
border-radius: 10px;
|
}
|
ul {
|
margin: 0;
|
padding: 8px 0 6px 0;
|
border: 1px dashed #4fa9fd;
|
border-radius: 10px;
|
li {
|
padding: 0 10px;
|
display: flex;
|
list-style: none;
|
line-height: 28px;
|
align-items: center;
|
font-size: 16px;
|
span {
|
flex: 1;
|
text-align: left;
|
}
|
img {
|
width: 14px;
|
height: 14px;
|
}
|
}
|
}
|
}
|
}
|
}
|
</style>
|