管道基础大数据平台系统开发-【前端】-新系統界面
TreeWish
2023-03-03 6b30adad53098fe3bd4ba9cc279aa091dc0cdd6d
添加dialog拖拽
已添加4个文件
已修改1个文件
151 ■■■■■ 文件已修改
src/directive/dialog/drag.js 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/directive/dialog/dragHeight.js 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/directive/dialog/dragWidth.js 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/directive/index.js 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main.js 3 ●●●● 补丁 | 查看 | 原始文档 | 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';