Skip to content

Commit

Permalink
feat(GuDragResizePlus): add beforeTransform event
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaius-98 committed Jul 26, 2024
1 parent 90dcad5 commit 0425fd8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/components/GuDragResizePlus.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ methods:{
#### events
| 函数名 | 描述 |
| ------------ | ---------------------------------------------------------------- |
| update | 拖拽或设置大小后抛出的事件 包含当前组件的位置及大小信息及nodeKey |
| beforeTransform | 在拖拽更新前抛出的事件 包含当前组件的原始位置、大小信息 |
| update | 更新节点的大小和位置后抛出的事件 包含当前组件的位置及大小信息及nodeKey |
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gaius-utils",
"private": false,
"version": "1.1.6",
"version": "1.1.7",
"author": {
"name": "WangGuoshuai",
"email": "2388838628@qq.com"
Expand Down
22 changes: 20 additions & 2 deletions packages/components/GuDragResizePlus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface DragResizeNodeInfo {
height: number;
left: number;
top: number;
nodeKey?: string | number;
}
const guDragResizePlusRef = ref<HTMLElement | null>(null);
const left = defineModel<number>("left", { required: true });
Expand Down Expand Up @@ -97,13 +98,21 @@ const onResize = (event: MouseEvent, point: ResizePoint) => {
const { top, left, width, height } = getTransformValue(
guDragResizePlusRef.value!
);
onBeforeTransfrom({
width,
top,
left,
height,
nodeKey: nodeKey.value,
});
const move = (event: MouseEvent) => {
const lastInfo = {
width,
top,
left,
height,
};
const diffY = (event.y - startY) / scaleY.value;
const diffX = (event.x - startX) / scaleX.value;
switch (direction) {
Expand Down Expand Up @@ -144,6 +153,13 @@ const onDrag = (event: MouseEvent) => {
const { top, left, width, height } = getTransformValue(
guDragResizePlusRef.value!
);
onBeforeTransfrom({
width,
top,
left,
height,
nodeKey: nodeKey.value,
});
const move = (event: MouseEvent) => {
const lastInfo = {
width,
Expand Down Expand Up @@ -192,7 +208,7 @@ const getTransformValue = (
height: parseFloat(dom.style.height),
};
};
const emit = defineEmits(["update"]);
const emit = defineEmits(["update", "beforeTransform"]);
const isFirst = ref(true);
const onTransformNode = (info: DragResizeNodeInfo) => {
const {
Expand Down Expand Up @@ -267,6 +283,9 @@ const onUpdateNodeTransform = () => {
nodeKey: nodeKey.value,
});
};
const onBeforeTransfrom = (data: DragResizeNodeInfo) => {
emit("beforeTransform", data);
};
watch(
() => [left.value, width.value, height.value, top.value],
() => {
Expand All @@ -279,7 +298,6 @@ watch(
}
);
onMounted(() => {
console.log(width.value, height.value);
onTransformNode({
width: width.value,
height: height.value,
Expand Down

0 comments on commit 0425fd8

Please sign in to comment.