|
@@ -1,21 +1,21 @@
|
|
-import { onMounted, onUnmounted, ref, watchEffect } from "vue";
|
|
|
|
|
|
+import { onMounted, onUnmounted, watchEffect } from "vue";
|
|
|
|
|
|
export function dragSplitPane() {
|
|
export function dragSplitPane() {
|
|
let pos = { y: 0 };
|
|
let pos = { y: 0 };
|
|
- const dragSpliter = ref(null as unknown as HTMLDivElement);
|
|
|
|
- let topPercent = ref(40);
|
|
|
|
|
|
+ let dragSpliter = $ref(null as unknown as HTMLDivElement);
|
|
|
|
+ let topPercent = $ref(40);
|
|
|
|
|
|
const mouseDownHandler = function (e: MouseEvent) {
|
|
const mouseDownHandler = function (e: MouseEvent) {
|
|
// console.log(e);
|
|
// console.log(e);
|
|
- if (e.target !== dragSpliter.value) return;
|
|
|
|
|
|
+ if (e.target !== dragSpliter) return;
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
pos = {
|
|
pos = {
|
|
// Get the current mouse position
|
|
// Get the current mouse position
|
|
y: e.clientY,
|
|
y: e.clientY,
|
|
};
|
|
};
|
|
- // topPercent.value = 100 * e.offsetTop / e.target.parentElement.style.height;
|
|
|
|
- if (dragSpliter.value) {
|
|
|
|
- // dragSpliter.value.style.cursor = "row-resize";
|
|
|
|
|
|
+ // topPercent = 100 * e.offsetTop / e.target.parentElement.style.height;
|
|
|
|
+ if (dragSpliter) {
|
|
|
|
+ // dragSpliter.style.cursor = "row-resize";
|
|
// console.log("add");
|
|
// console.log("add");
|
|
|
|
|
|
document.addEventListener("mousemove", mouseMoveHandler);
|
|
document.addEventListener("mousemove", mouseMoveHandler);
|
|
@@ -29,10 +29,10 @@ export function dragSplitPane() {
|
|
const dy = e.clientY - pos.y;
|
|
const dy = e.clientY - pos.y;
|
|
|
|
|
|
// // Scroll the element
|
|
// // Scroll the element
|
|
- // // dragSpliter.value.style.marginTop =
|
|
|
|
- // // (parseFloat(dragSpliter.value.style.marginTop) || 0) + dy + "px";
|
|
|
|
- dragSpliter.value.style.marginTop = dy + "px";
|
|
|
|
- // console.log(dragSpliter.value.style.marginTop);
|
|
|
|
|
|
+ // // 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 target = e.target as HTMLElement;
|
|
const parent = target.parentElement;
|
|
const parent = target.parentElement;
|
|
// console.log(getComputedStyle(e.target.parentElement).height);
|
|
// console.log(getComputedStyle(e.target.parentElement).height);
|
|
@@ -42,9 +42,9 @@ export function dragSplitPane() {
|
|
// movementY: e.movementY,
|
|
// movementY: e.movementY,
|
|
// });
|
|
// });
|
|
// if (parent)
|
|
// if (parent)
|
|
- // topPercent.value =
|
|
|
|
|
|
+ // topPercent =
|
|
// (100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
// (100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
- // console.log("topPercent", topPercent.value);
|
|
|
|
|
|
+ // console.log("topPercent", topPercent);
|
|
return false;
|
|
return false;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -52,20 +52,20 @@ export function dragSplitPane() {
|
|
const dy = e.clientY - pos.y;
|
|
const dy = e.clientY - pos.y;
|
|
|
|
|
|
// Scroll the element
|
|
// Scroll the element
|
|
- // dragSpliter.value.style.marginTop =
|
|
|
|
- // (parseFloat(dragSpliter.value.style.marginTop) || 0) + dy + "px";
|
|
|
|
- // dragSpliter.value.style.marginTop = dy + "px";
|
|
|
|
- // console.log(dragSpliter.value.style.marginTop);
|
|
|
|
|
|
+ // 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 target = e.target as HTMLElement;
|
|
const parent = target.parentElement;
|
|
const parent = target.parentElement;
|
|
// console.log(getComputedStyle(e.target.parentElement).height);
|
|
// console.log(getComputedStyle(e.target.parentElement).height);
|
|
// console.log("offsetTop", target.offsetTop);
|
|
// console.log("offsetTop", target.offsetTop);
|
|
// TODO: 暂时不知道为啥有 140
|
|
// TODO: 暂时不知道为啥有 140
|
|
if (parent)
|
|
if (parent)
|
|
- topPercent.value =
|
|
|
|
|
|
+ topPercent =
|
|
(100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
(100 * target.offsetTop) / parseFloat(getComputedStyle(parent).height);
|
|
// console.log({
|
|
// console.log({
|
|
- // topPercent: topPercent.value,
|
|
|
|
|
|
+ // topPercent: topPercent,
|
|
// "parseFloat(getComputedStyle(parent).height)": parseFloat(
|
|
// "parseFloat(getComputedStyle(parent).height)": parseFloat(
|
|
// getComputedStyle(parent).height
|
|
// getComputedStyle(parent).height
|
|
// ),
|
|
// ),
|
|
@@ -73,24 +73,24 @@ export function dragSplitPane() {
|
|
// });
|
|
// });
|
|
|
|
|
|
// console.log("removed");
|
|
// console.log("removed");
|
|
- if (dragSpliter.value) {
|
|
|
|
|
|
+ if (dragSpliter) {
|
|
document.removeEventListener("mousemove", mouseMoveHandler);
|
|
document.removeEventListener("mousemove", mouseMoveHandler);
|
|
document.removeEventListener("mouseup", mouseUpHandler);
|
|
document.removeEventListener("mouseup", mouseUpHandler);
|
|
- // dragSpliter.value.style.cursor = "auto";
|
|
|
|
- dragSpliter.value.style.marginTop = "0";
|
|
|
|
|
|
+ // dragSpliter.style.cursor = "auto";
|
|
|
|
+ dragSpliter.style.marginTop = "0";
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
watchEffect(() => {
|
|
watchEffect(() => {
|
|
- if (dragSpliter.value) {
|
|
|
|
|
|
+ if (dragSpliter) {
|
|
// console.log("watchEffect");
|
|
// console.log("watchEffect");
|
|
document.addEventListener("mousedown", mouseDownHandler);
|
|
document.addEventListener("mousedown", mouseDownHandler);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
onUnmounted(() => {
|
|
onUnmounted(() => {
|
|
- if (dragSpliter.value) {
|
|
|
|
|
|
+ if (dragSpliter) {
|
|
document.removeEventListener("mousedown", mouseDownHandler);
|
|
document.removeEventListener("mousedown", mouseDownHandler);
|
|
document.removeEventListener("mousemove", mouseMoveHandler);
|
|
document.removeEventListener("mousemove", mouseMoveHandler);
|
|
document.removeEventListener("mouseup", mouseUpHandler);
|
|
document.removeEventListener("mouseup", mouseUpHandler);
|