src/directive/dialog/drag.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/directive/dialog/dragHeight.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/directive/dialog/dragWidth.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/directive/index.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/directive/dialog/drag.js
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,64 @@ /** * v-dialogDrag å¼¹çªææ½ * Copyright (c) 2019 ruoyi */ export default { bind(el, binding, vnode, oldVnode) { const value = binding.value if (value == false) return // è·åææ½å å®¹å¤´é¨ const dialogHeaderEl = el.querySelector('.el-dialog__header'); const dragDom = el.querySelector('.el-dialog'); dialogHeaderEl.style.cursor = 'move'; // è·ååæå±æ§ ie domå ç´ .currentStyle ç«çè°·æ window.getComputedStyle(domå ç´ , null); const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null); dragDom.style.position = 'absolute'; dragDom.style.marginTop = 0; let width = dragDom.style.width; if (width.includes('%')) { width = +document.body.clientWidth * (+width.replace(/\%/g, '') / 100); } else { width = +width.replace(/\px/g, ''); } dragDom.style.left = `${(document.body.clientWidth - width) / 2}px`; // é¼ æ æä¸äºä»¶ 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; let finallyL = l + styL let finallyT = t + styT // ç§»å¨å½åå ç´ dragDom.style.left = `${finallyL}px`; dragDom.style.top = `${finallyT}px`; }; document.onmouseup = function (e) { document.onmousemove = null; document.onmouseup = null; }; } } }; src/directive/dialog/dragHeight.js
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,38 @@ /** * v-dialogDragWidth 坿å¨å¼¹çªé«åº¦ï¼å³ä¸è§ï¼ * Copyright (c) 2019 ruoyi */ export default { bind(el) { const dragDom = el.querySelector(".el-dialog"); const lineEl = document.createElement("div"); lineEl.style = "width: 6px; background: inherit; height: 10px; position: absolute; right: 0; bottom: 0; margin: auto; z-index: 1; cursor: nwse-resize;"; lineEl.addEventListener( "mousedown", function (e) { // é¼ æ æä¸ï¼è®¡ç®å½åå ç´ è·ç¦»å¯è§åºçè·ç¦» const disX = e.clientX - el.offsetLeft; const disY = e.clientY - el.offsetTop; // å½å宽度 é«åº¦ const curWidth = dragDom.offsetWidth; const curHeight = dragDom.offsetHeight; document.onmousemove = function (e) { e.preventDefault(); // ç§»å¨æ¶ç¦ç¨é»è®¤äºä»¶ // éè¿äºä»¶å§æï¼è®¡ç®ç§»å¨çè·ç¦» const xl = e.clientX - disX; const yl = e.clientY - disY; dragDom.style.width = `${curWidth + xl}px`; dragDom.style.height = `${curHeight + yl}px`; }; document.onmouseup = function (e) { document.onmousemove = null; document.onmouseup = null; }; }, false ); dragDom.appendChild(lineEl); }, }; src/directive/dialog/dragWidth.js
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,34 @@ /** * v-dialogDragWidth 坿å¨å¼¹çªå®½åº¦ï¼å³ä¾§è¾¹ï¼ * Copyright (c) 2019 ruoyi */ export default { bind(el) { const dragDom = el.querySelector(".el-dialog"); const lineEl = document.createElement("div"); lineEl.style = "width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;"; lineEl.addEventListener( "mousedown", function (e) { // é¼ æ æä¸ï¼è®¡ç®å½åå ç´ è·ç¦»å¯è§åºçè·ç¦» const disX = e.clientX - el.offsetLeft; // å½å宽度 const curWidth = dragDom.offsetWidth; document.onmousemove = function (e) { e.preventDefault(); // ç§»å¨æ¶ç¦ç¨é»è®¤äºä»¶ // éè¿äºä»¶å§æï¼è®¡ç®ç§»å¨çè·ç¦» const l = e.clientX - disX; dragDom.style.width = `${curWidth + l}px`; }; document.onmouseup = function (e) { document.onmousemove = null; document.onmouseup = null; }; }, false ); dragDom.appendChild(lineEl); }, }; src/directive/index.js
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,12 @@ import dialogDrag from './dialog/drag' import dialogDragWidth from './dialog/dragWidth' import dialogDragHeight from './dialog/dragHeight' const install = function(Vue) { Vue.directive('dialogDrag', dialogDrag) Vue.directive('dialogDragWidth', dialogDragWidth) Vue.directive('dialogDragHeight', dialogDragHeight) } export default install src/main.js
@@ -18,9 +18,10 @@ import 'animate.css'; import VueParticles from 'vue-particles' import dataV from '@jiaminghi/data-view' import directive from '@/directive/index.js' // directive Vue.use(directive) Vue.use(dataV) Vue.use(VueParticles) Vue.prototype.$echarts = echarts; import * as echarts from 'echarts';