Commit 5e959d310af6632ae17fc8755bc0f0af28e53833
1 parent
c414e0eb
v3.7.0 自定义可拖动弹窗宽度指令
Showing
3 changed files
with
33 additions
and
2 deletions
yudao-ui-admin/src/directive/dialog/drag.js
yudao-ui-admin/src/directive/dialog/dragWidth.js
0 → 100644
| 1 | +/** | |
| 2 | + * v-dialogDragWidth 可拖动弹窗宽度 | |
| 3 | + * Copyright (c) 2019 ruoyi | |
| 4 | + */ | |
| 5 | + | |
| 6 | +export default { | |
| 7 | + bind(el) { | |
| 8 | + const dragDom = el.querySelector('.el-dialog'); | |
| 9 | + const lineEl = document.createElement('div'); | |
| 10 | + lineEl.style = 'width: 5px; background: inherit; height: 80%; position: absolute; right: 0; top: 0; bottom: 0; margin: auto; z-index: 1; cursor: w-resize;'; | |
| 11 | + lineEl.addEventListener('mousedown', | |
| 12 | + function (e) { | |
| 13 | + // 鼠标按下,计算当前元素距离可视区的距离 | |
| 14 | + const disX = e.clientX - el.offsetLeft; | |
| 15 | + // 当前宽度 | |
| 16 | + const curWidth = dragDom.offsetWidth; | |
| 17 | + document.onmousemove = function (e) { | |
| 18 | + e.preventDefault(); // 移动时禁用默认事件 | |
| 19 | + // 通过事件委托,计算移动的距离 | |
| 20 | + const l = e.clientX - disX; | |
| 21 | + dragDom.style.width = `${curWidth + l}px`; | |
| 22 | + }; | |
| 23 | + document.onmouseup = function (e) { | |
| 24 | + document.onmousemove = null; | |
| 25 | + document.onmouseup = null; | |
| 26 | + }; | |
| 27 | + }, | |
| 28 | + ); | |
| 29 | + dragDom.appendChild(lineEl); | |
| 30 | + } | |
| 31 | +} | ... | ... |
yudao-ui-admin/src/directive/index.js
| 1 | 1 | import hasRole from './permission/hasRole' |
| 2 | 2 | import hasPermi from './permission/hasPermi' |
| 3 | 3 | import dialogDrag from './dialog/drag' |
| 4 | +import dialogDragWidth from './dialog/dragWidth' | |
| 4 | 5 | |
| 5 | 6 | const install = function(Vue) { |
| 6 | 7 | Vue.directive('hasRole', hasRole) |
| 7 | 8 | Vue.directive('hasPermi', hasPermi) |
| 8 | 9 | Vue.directive('dialogDrag', dialogDrag) |
| 10 | + Vue.directive('dialogDragWidth', dialogDragWidth) | |
| 9 | 11 | } |
| 10 | 12 | |
| 11 | 13 | if (window.Vue) { |
| 12 | 14 | window['hasRole'] = hasRole |
| 13 | 15 | window['hasPermi'] = hasPermi |
| 14 | - window['dialogDrag'] = dialogDrag | |
| 15 | 16 | Vue.use(install); // eslint-disable-line |
| 16 | 17 | } |
| 17 | 18 | ... | ... |