中国算力平台算力登记系统2.0
yanzhaofeige
2024-09-30 3c4fee1db116c11d4f04727cfe076d7c94daeaf2
commit | author | age
43dc29 1 /**
Y 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       }, false);
28     dragDom.appendChild(lineEl);
29   }
30 }