Sanakey
2024-08-10 28c4845d6fee084d30767a3fec831588d13c88c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template>
  <PageWrapper :class="`${prefixCls}`" dense contentFullHeight fixedHeight>
    <!--    <slot name="left">-->
    <!--      <div class="leftBox">侧边栏</div>-->
    <!--      <div class="centerBox">-->
    <!--        &lt;!&ndash; 此处可以换为其他icon &ndash;&gt;-->
    <!--        <span class="iconBox">66</span>-->
    <!--      </div>-->
    <!--    </slot>-->
    <!--    <slot name="right">-->
    <!--      <div class="rightBox">主栏</div>-->
    <!--    </slot>-->
    <div class="bigBox">
      <div class="leftBox">侧边栏</div>
      <!--拖拽-->
      <div class="centerBox">
        <!-- 此处可以换为其他icon -->
        <span class="iconBox">66</span>
      </div>
      <div class="rightBox">主栏</div>
    </div>
  </PageWrapper>
</template>
 
<script lang="ts" setup>
import {PageWrapper} from '@/components/Page';
import {onMounted} from 'vue';
import {useDesign} from "@/hooks/web/useDesign";
 
onMounted(() => {
  dragControllerLR();
});
const {prefixCls} = useDesign('email');
//拖拽
const dragControllerLR = () => {
  const resize = document.querySelector('.centerBox .iconBox') as any;
  const left = document.querySelector('.leftBox') as any;
  const box = document.querySelector('.bigBox') as any;
  // 鼠标按下事件
  resize.onmousedown = function (e: MouseEvent) {
    //颜色改变提醒
    const startX = e.clientX;
    resize.left = resize.offsetLeft;
    // 鼠标拖动事件
    document.onmousemove = function (e) {
      const endX = e.clientX;
      let moveLen = resize.left + (endX - startX) - box.offsetLeft; // (endx-startx)=移动的距离。resize.left+移动的距离=左边区域最后的宽度
 
      const maxT = box.clientWidth - resize.offsetWidth; // 容器宽度 - 左边区域的宽度 = 右边区域的宽度
 
      if (moveLen < 200) moveLen = 200; // 左边区域的最小宽度为270px
      if (moveLen > maxT - 500) moveLen = maxT - 500; //右边区域最小宽度为500px
 
      resize.style.left = moveLen; // 设置左侧区域的宽度
      left.style.width = moveLen + 'px';
    };
    // 鼠标松开事件
    // eslint-disable-next-line no-unused-vars
    document.onmouseup = function (evt) {
      //颜色恢复
      document.onmousemove = null;
      document.onmouseup = null;
      resize.releaseCapture && resize.releaseCapture(); //当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉
    };
    resize.setCapture && resize.setCapture(); //该函数在属于当前线程的指定窗口里设置鼠标捕获
    return false;
  };
};
</script>
 
<style lang="less" scoped>
@prefix-cls: ~'@{namespace}-email';
.@{prefix-cls} {
  .bigBox {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: row;
 
    .leftBox {
      height: 100%;
      width: 270px;
      border: 1px solid red;
    }
 
    .centerBox {
      width: 8px;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: transparent;
 
      .iconBox {
        transform: rotate(90deg);
        font-size: 16px;
        cursor: w-resize;
 
        &:hover {
          color: red;
        }
      }
    }
 
    .rightBox {
      height: 100%;
      flex: 1;
      border: 1px solid red;
    }
  }
}
</style>