|
@@ -3,21 +3,35 @@ import { onMounted, onUnmounted, watchEffect } from "vue";
|
|
|
export function dragSplitPane() {
|
|
|
let pos = { y: 0 };
|
|
|
const dragSpliter = $ref<HTMLDivElement>();
|
|
|
- let topPercent = $ref(40);
|
|
|
+ let areaHeight = $ref(0);
|
|
|
+ let initAreaHeight = 0;
|
|
|
+ const minAreaHeight = 74;
|
|
|
+ let maxAreaHeight = null;
|
|
|
|
|
|
const mouseDownHandler = function (e: MouseEvent) {
|
|
|
// console.log(e);
|
|
|
if (e.target !== dragSpliter) return;
|
|
|
e.preventDefault();
|
|
|
pos = {
|
|
|
- // Get the current mouse position
|
|
|
y: e.clientY,
|
|
|
};
|
|
|
- // topPercent = 100 * e.offsetTop / e.target.parentElement.style.height;
|
|
|
- if (dragSpliter) {
|
|
|
- // dragSpliter.style.cursor = "row-resize";
|
|
|
- // console.log("add");
|
|
|
|
|
|
+ const parentDom = dragSpliter.parentElement.parentElement;
|
|
|
+ let sumHeight = 0;
|
|
|
+ for (let i = 0; i < parentDom.childNodes.length; i++) {
|
|
|
+ const dom = parentDom.childNodes[i];
|
|
|
+ if (
|
|
|
+ dom.className &&
|
|
|
+ !dom.className.includes("board-questions") &&
|
|
|
+ !dom.className.includes("board-footer")
|
|
|
+ ) {
|
|
|
+ sumHeight += dom.offsetHeight;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ maxAreaHeight = parentDom.offsetHeight - sumHeight - 16 * 4 - 68;
|
|
|
+ initAreaHeight =
|
|
|
+ dragSpliter.parentElement.previousElementSibling.offsetHeight;
|
|
|
+ if (dragSpliter) {
|
|
|
document.addEventListener("mousemove", mouseMoveHandler);
|
|
|
document.addEventListener("mouseup", mouseUpHandler);
|
|
|
}
|
|
@@ -27,68 +41,22 @@ export function dragSplitPane() {
|
|
|
const mouseMoveHandler = function (e: MouseEvent) {
|
|
|
e.preventDefault();
|
|
|
const dy = e.clientY - pos.y;
|
|
|
+ const curHeight = initAreaHeight + dy;
|
|
|
+ areaHeight = Math.min(maxAreaHeight, Math.max(curHeight, minAreaHeight));
|
|
|
|
|
|
- // // Scroll the element
|
|
|
- // // dragSpliter.style.marginTop =
|
|
|
- // // (parseFloat(dragSpliter.style.marginTop) || 0) + dy + "px";
|
|
|
- dragSpliter.style.marginTop = `${dy}px`;
|
|
|
- // console.log(dragSpliter.style.marginTop);
|
|
|
- // const target = e.target as HTMLElement;
|
|
|
- // const parent = target.parentElement;
|
|
|
- // console.log(getComputedStyle(e.target.parentElement).height);
|
|
|
- // console.log({
|
|
|
- // offsetTop: target.offsetTop,
|
|
|
- // dy: dy,
|
|
|
- // movementY: e.movementY,
|
|
|
- // });
|
|
|
- // if (parent)
|
|
|
- // topPercent =
|
|
|
- // (100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
|
- // console.log("topPercent", topPercent);
|
|
|
return false;
|
|
|
};
|
|
|
|
|
|
- const mouseUpHandler = function (e: MouseEvent) {
|
|
|
- // const dy = e.clientY - pos.y;
|
|
|
-
|
|
|
- // Scroll the element
|
|
|
- // dragSpliter.style.marginTop =
|
|
|
- // (parseFloat(dragSpliter.style.marginTop) || 0) + dy + "px";
|
|
|
- // dragSpliter.style.marginTop = dy + "px";
|
|
|
- // console.log(dragSpliter.style.marginTop);
|
|
|
- const target = e.target as HTMLElement;
|
|
|
- let parent = target.parentElement;
|
|
|
- // console.log(getComputedStyle(e.target.parentElement).height);
|
|
|
- // console.log("offsetTop", target.offsetTop);
|
|
|
- // console.log(target.offsetTop, parent);
|
|
|
- // 鼠标超出了分隔条的parent,则撤销拖动效果
|
|
|
- if (parent !== dragSpliter.parentElement) {
|
|
|
- parent = null;
|
|
|
- }
|
|
|
- if (parent)
|
|
|
- topPercent =
|
|
|
- (100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
|
- // console.log({
|
|
|
- // topPercent: topPercent,
|
|
|
- // "parseFloat(getComputedStyle(parent).height)": parseFloat(
|
|
|
- // getComputedStyle(parent).height
|
|
|
- // ),
|
|
|
- // "target.offsetTop": target.offsetTop,
|
|
|
- // });
|
|
|
-
|
|
|
- // console.log("removed");
|
|
|
+ const mouseUpHandler = function () {
|
|
|
if (dragSpliter) {
|
|
|
document.removeEventListener("mousemove", mouseMoveHandler);
|
|
|
document.removeEventListener("mouseup", mouseUpHandler);
|
|
|
- // dragSpliter.style.cursor = "auto";
|
|
|
- dragSpliter.style.marginTop = "0";
|
|
|
}
|
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
|
watchEffect(() => {
|
|
|
if (dragSpliter) {
|
|
|
- // console.log("watchEffect");
|
|
|
document.addEventListener("mousedown", mouseDownHandler);
|
|
|
}
|
|
|
});
|
|
@@ -101,5 +69,5 @@ export function dragSplitPane() {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- return $$({ dragSpliter, topPercent });
|
|
|
+ return $$({ dragSpliter, areaHeight });
|
|
|
}
|