RuoYi
2021-07-09 5dec58e7f52a937af12918c3e8bde732d51cf483
自定义弹窗拖拽指令
已添加2个文件
已修改2个文件
已删除1个文件
101 ■■■■ 文件已修改
ruoyi-ui/src/directive/dialog/drag.js 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/directive/index.js 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/directive/permission/hasPermi.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/directive/permission/hasRole.js 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/src/directive/permission/index.js 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-ui/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;
      };
    }
  }
};
ruoyi-ui/src/directive/index.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,18 @@
import hasRole from './permission/hasRole'
import hasPermi from './permission/hasPermi'
import dialogDrag from './dialog/drag'
const install = function(Vue) {
  Vue.directive('hasRole', hasRole)
  Vue.directive('hasPermi', hasPermi)
  Vue.directive('dialogDrag', dialogDrag)
}
if (window.Vue) {
  window['hasRole'] = hasRole
  window['hasPermi'] = hasPermi
  window['dialogDrag'] = dialogDrag
  Vue.use(install); // eslint-disable-line
}
export default install
ruoyi-ui/src/directive/permission/hasPermi.js
@@ -1,5 +1,5 @@
 /**
 * æ“ä½œæƒé™å¤„理
 * v-hasPermi æ“ä½œæƒé™å¤„理
 * Copyright (c) 2019 ruoyi
 */
 
ruoyi-ui/src/directive/permission/hasRole.js
@@ -1,5 +1,5 @@
 /**
 * è§’色权限处理
 * v-hasRole è§’色权限处理
 * Copyright (c) 2019 ruoyi
 */
 
ruoyi-ui/src/directive/permission/index.js
ÎļþÒÑɾ³ý