终端菜单垂直拖拽
This commit is contained in:
parent
728d4a1500
commit
5f92af684f
8
src/directive/verticalDrag/index.js
Normal file
8
src/directive/verticalDrag/index.js
Normal file
@ -0,0 +1,8 @@
|
||||
import Vue from 'vue';
|
||||
import install from './verticalDrag';
|
||||
|
||||
const verticalDrag = function(Vue) {
|
||||
Vue.directive('verticalDrag', install);
|
||||
};
|
||||
|
||||
Vue.use(verticalDrag);
|
100
src/directive/verticalDrag/verticalDrag.js
Normal file
100
src/directive/verticalDrag/verticalDrag.js
Normal file
@ -0,0 +1,100 @@
|
||||
/* 垂直拖拽 */
|
||||
export default {
|
||||
bind(el) {
|
||||
const dialogHeaderEl = el.querySelector('.verticalDrag__header');
|
||||
const dialogFooterEl = el.querySelector('.verticalDrag__footer');
|
||||
const dragDom = el;
|
||||
dialogHeaderEl.style.cursor = 'move';
|
||||
dialogFooterEl.style.cursor = 'move';
|
||||
|
||||
/** 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);*/
|
||||
const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null);
|
||||
|
||||
dialogHeaderEl.onmousedown = (e) => {
|
||||
e.stopPropagation();
|
||||
/** 鼠标按下,计算当前元素距离可视区的距离*/
|
||||
const disY = e.clientY;
|
||||
const oY = e.offsetY;
|
||||
const bY = dragDom.offsetHeight;
|
||||
|
||||
/** 获取到的值带px 正则匹配替换*/
|
||||
let styT;
|
||||
|
||||
/** 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px*/
|
||||
if (sty.top.includes('%')) {
|
||||
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
|
||||
} else {
|
||||
styT = +sty.top.replace(/\px/g, '');
|
||||
}
|
||||
|
||||
document.onmousemove = function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let cY = e.clientY;
|
||||
if (cY < oY) {
|
||||
cY = oY;
|
||||
}
|
||||
if (cY > document.body.clientHeight - bY) {
|
||||
cY = document.body.clientHeight - bY;
|
||||
}
|
||||
/** 通过事件委托,计算移动的距离*/
|
||||
const t = cY - disY;
|
||||
|
||||
/** 移动当前元素*/
|
||||
dragDom.style.top = `${t + styT}px`;
|
||||
|
||||
/** 将此时的位置传出去*/
|
||||
// binding.value({ x: e.pageX, y: e.pageY });
|
||||
};
|
||||
|
||||
document.onmouseup = function () {
|
||||
e.stopPropagation();
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
};
|
||||
};
|
||||
dialogFooterEl.onmousedown = (e) => {
|
||||
e.stopPropagation();
|
||||
/** 鼠标按下,计算当前元素距离可视区的距离*/
|
||||
const disY = e.clientY;
|
||||
const oY = e.offsetY;
|
||||
const bY = dragDom.offsetHeight;
|
||||
|
||||
/** 获取到的值带px 正则匹配替换*/
|
||||
let styT;
|
||||
|
||||
/** 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px*/
|
||||
if (sty.top.includes('%')) {
|
||||
styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100);
|
||||
} else {
|
||||
styT = +sty.top.replace(/\px/g, '');
|
||||
}
|
||||
|
||||
document.onmousemove = function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
let cY = e.clientY;
|
||||
if (cY < bY) {
|
||||
cY = bY;
|
||||
}
|
||||
if (cY > document.body.clientHeight - oY) {
|
||||
cY = document.body.clientHeight - oY;
|
||||
}
|
||||
/** 通过事件委托,计算移动的距离*/
|
||||
const t = cY - disY;
|
||||
|
||||
/** 移动当前元素*/
|
||||
dragDom.style.top = `${t + styT}px`;
|
||||
|
||||
/** 将此时的位置传出去*/
|
||||
// binding.value({ x: e.pageX, y: e.pageY });
|
||||
};
|
||||
|
||||
document.onmouseup = function () {
|
||||
e.stopPropagation();
|
||||
document.onmousemove = null;
|
||||
document.onmouseup = null;
|
||||
};
|
||||
};
|
||||
}
|
||||
};
|
@ -24,6 +24,7 @@ import '@/directive/dialogLoading/index.js';
|
||||
import '@/directive/drag/index.js';
|
||||
import '@/directive/focus/index.js';
|
||||
import '@/directive/quickMenuDrag/index.js';
|
||||
import '@/directive/verticalDrag/index.js';
|
||||
import '@/directive/waves/index.js';
|
||||
import messages from '@/i18n/index';
|
||||
|
||||
|
@ -204,7 +204,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
height: this.$store.state.app.height - 37,
|
||||
height: this.$store.state.app.height - 38,
|
||||
filterSectionList:[],
|
||||
mapStationDirectionData:[],
|
||||
// filterSectionMap:{},
|
||||
|
@ -1,7 +1,9 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="isShow && terminalList.length" class="terminalList">
|
||||
<div v-if="isShow && terminalList.length" v-verticalDrag class="terminalList">
|
||||
<div class="drag-line verticalDrag__header" />
|
||||
<div v-for="(eachTerminal,index) in terminalList" :key="index" :class="picture==eachTerminal.code?'eachTerminal active':'eachTerminal'" @click="eachTerminal.click(eachTerminal.code)">{{ eachTerminal.name }}</div>
|
||||
<div class="drag-line verticalDrag__footer" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@ -322,6 +324,10 @@ export default {
|
||||
border-radius: 5px 0 0 5px;
|
||||
z-index: 2000;
|
||||
}
|
||||
.drag-line {
|
||||
width: 100%;
|
||||
height: 5px;
|
||||
}
|
||||
.eachTerminal{
|
||||
padding: 8px 0;
|
||||
text-align: center;
|
||||
|
Loading…
Reference in New Issue
Block a user