From c0c23b9f3182136badc3ba1c1be1d2718a9f1caa Mon Sep 17 00:00:00 2001 From: "jialong.yu" Date: Tue, 8 Feb 2022 17:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BC=B9=E6=A1=86=E6=8B=96?= =?UTF-8?q?=E6=8B=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/counter/list/index.vue | 10 ++++++- src/plugins/drag/index.js | 51 ++++++++++++++++++++++++++++++++ src/plugins/index.js | 2 ++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/plugins/drag/index.js diff --git a/src/pages/counter/list/index.vue b/src/pages/counter/list/index.vue index 705f4e8..c943551 100644 --- a/src/pages/counter/list/index.vue +++ b/src/pages/counter/list/index.vue @@ -113,7 +113,7 @@ -
+
{{ popText }}
@@ -533,6 +533,14 @@ export default { return this.$store.state.system.fullScreen; }, showPop:function(){/* 展示弹框 */ + const dataDia = this.$refs.dataDia + // 每次显示弹框时重置方位 + if (dataDia) { + dataDia.style.top = '68px' + dataDia.style.left = '50%' + } + + this.$refs.dataDia this.receptionList = [] if(this.$store.state.system.popText == '刷卡器'){ if (this.$store.state.system.id == '62,1'){ diff --git a/src/plugins/drag/index.js b/src/plugins/drag/index.js new file mode 100644 index 0000000..ae6ac6e --- /dev/null +++ b/src/plugins/drag/index.js @@ -0,0 +1,51 @@ +/** + * @description 鉴权指令 + * 当传入的权限当前用户没有时,会移除该组件 + * 用例:text 或者:text + * */ +export default { + bind(el, binding, vnode, oldVnode) { + const dialogHeaderEl = el.querySelector('.dia-header') + const dragDom = el + dialogHeaderEl.style.cursor = 'move' + + // 获取原有属性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null); + const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null) + + dialogHeaderEl.onmousedown = (e) => { + // 鼠标按下,计算当前元素距离可视区的距离 + const disX = e.clientX - dialogHeaderEl.offsetLeft + const disY = e.clientY - dialogHeaderEl.offsetTop + + // 获取到的值带px 正则匹配替换 + let styL, styT + + // 注意在ie中 第一次获取到的值为组件自带50% 移动之后赋值为px + if (sty.left.includes('%')) { + styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100) + styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100) + } else { + styL = +sty.left.replace(/\px/g, '') + styT = +sty.top.replace(/\px/g, '') + } + + document.onmousemove = function(e) { + // 通过事件委托,计算移动的距离 + const l = e.clientX - disX + const t = e.clientY - disY + + // 移动当前元素 + dragDom.style.left = `${l + styL}px` + dragDom.style.top = `${t + styT}px` + + // 将此时的位置传出去 + // binding.value({x:e.pageX,y:e.pageY}) + } + + document.onmouseup = function(e) { + document.onmousemove = null + document.onmouseup = null + } + } + } +} \ No newline at end of file diff --git a/src/plugins/index.js b/src/plugins/index.js index c81b9a1..dd37598 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -4,11 +4,13 @@ import directiveAuth from '@/plugins/auth'; import throttle from '@/plugins/throttle'; +import drag from '@/plugins/drag'; export default { async install (Vue, options) { // 指令 Vue.directive('auth', directiveAuth); Vue.directive('throttle', throttle); + Vue.directive('drag', drag); } } \ No newline at end of file