终端菜单垂直拖拽

This commit is contained in:
dong 2023-01-30 17:52:26 +08:00
parent 728d4a1500
commit 5f92af684f
5 changed files with 117 additions and 2 deletions

View File

@ -0,0 +1,8 @@
import Vue from 'vue';
import install from './verticalDrag';
const verticalDrag = function(Vue) {
Vue.directive('verticalDrag', install);
};
Vue.use(verticalDrag);

View 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;
};
};
}
};

View File

@ -24,6 +24,7 @@ import '@/directive/dialogLoading/index.js';
import '@/directive/drag/index.js'; import '@/directive/drag/index.js';
import '@/directive/focus/index.js'; import '@/directive/focus/index.js';
import '@/directive/quickMenuDrag/index.js'; import '@/directive/quickMenuDrag/index.js';
import '@/directive/verticalDrag/index.js';
import '@/directive/waves/index.js'; import '@/directive/waves/index.js';
import messages from '@/i18n/index'; import messages from '@/i18n/index';

View File

@ -204,7 +204,7 @@ export default {
}, },
data() { data() {
return { return {
height: this.$store.state.app.height - 37, height: this.$store.state.app.height - 38,
filterSectionList:[], filterSectionList:[],
mapStationDirectionData:[], mapStationDirectionData:[],
// filterSectionMap:{}, // filterSectionMap:{},

View File

@ -1,7 +1,9 @@
<template> <template>
<div> <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 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>
</div> </div>
</template> </template>
@ -322,6 +324,10 @@ export default {
border-radius: 5px 0 0 5px; border-radius: 5px 0 0 5px;
z-index: 2000; z-index: 2000;
} }
.drag-line {
width: 100%;
height: 5px;
}
.eachTerminal{ .eachTerminal{
padding: 8px 0; padding: 8px 0;
text-align: center; text-align: center;