
<template>
<el-card body-style="height: calc(100vh - 162px)">
<div class="metamodelBox">
<div class="leftBox" :style="{width:`calc(${defaultLeftWidthRate}% - 2px)`}"></div>
<div class="resize"/>
<div class="rightBox" :style="{width:`calc(100% - ${defaultLeftWidthRate}% - 2px)`}"></div>
</div>
</el-card>
</template>
<script setup lang="ts">
import {onMounted, ref} from "vue";
onMounted(() => {
dragDiv()
})
const defaultLeftWidthRate = ref(20)
const dragDiv = () => {
let resize = document.getElementsByClassName('resize')
let box = document.getElementsByClassName('metamodelBox')
let left = document.getElementsByClassName('leftBox')
for (let i = 0; i < resize.length; i++) {
resize[i].onmousedown = function (e: any) {
let boxWidth = box[i].offsetWidth
let leftWidth = left[i].offsetWidth
let minLeftWidthRate = parseFloat((100 / boxWidth * 100).toFixed(4))
let minRightWidthRate = parseFloat((100 / boxWidth * 100).toFixed(4))
let startX = e.clientX
document.onmousemove = function (e: any) {
let endX = e.clientX
let distX = Math.abs(endX - startX)
if (endX > startX) {
let moveLate = parseFloat(((leftWidth + distX) / boxWidth * 100).toFixed(4));
if ((parseFloat('100') - moveLate) > minRightWidthRate) {
defaultLeftWidthRate.value = moveLate
}
}
if (endX < startX) {
let moveLate = parseFloat(((leftWidth - distX) / boxWidth * 100).toFixed(4));
if (moveLate > minLeftWidthRate) {
defaultLeftWidthRate.value = moveLate
}
}
}
document.onmouseup = function (e: any) {
document.onmousemove = null
document.onmouseup = null
resize[i].releaseCapture && resize[i].releaseCapture()
}
resize[i].setCapture && resize[i].setCapture()
return false
}
}
}
</script>
<style lang="scss">
.metamodelBox {
position: relative;
width: 100%;
height: 100%;
display: flex;
}
.metamodelBox .leftBox {
position: relative;
width: calc(20% - 2px);
height: 100%;
background-color: green;
}
.metamodelBox .resize {
position: relative;
width: 4px;
height: 100%;
color: gray;
background: rgb(214, 214, 214);
cursor: w-resize;
}
.metamodelBox .rightBox {
position: relative;
width: calc(80% - 2px);
height: 100%;
background-color: yellow;
}
</style>```