Skip to content

Commit fb6ef96

Browse files
committed
!453 feat(layer): 新增moveEnd/resizeEnd返回值
* feat(layer): 新增moveEnd/resizeEnd返回值
1 parent 35bae1d commit fb6ef96

File tree

3 files changed

+111
-11
lines changed

3 files changed

+111
-11
lines changed

docs/src/document/zh-CN/components/layer.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,37 @@ const revert = () => {
776776

777777
<template>
778778
<lay-button @click="openCallback" type="primary">打开</lay-button>
779+
<lay-button @click="openMoveEnd" type="primary">moveEnd设置最终位置</lay-button>
780+
<lay-button @click="openResizeEnd" type="primary">resizeEnd设置最终宽高</lay-button>
779781
</template>
780782

781783
<script setup>
782784
import { ref, watch } from "vue";
783785
import { layer } from "@layui/layui-vue"
784786

787+
const openMoveEnd = () => {
788+
layer.open({
789+
title:"移动结束",
790+
content:"移动结束最终位置固定为top50px/left50px",
791+
moveEnd(id, { left, top, isMin, isMax }) {
792+
console.log(left, top, isMin, isMax, "left, top, isMin, isMax");
793+
return ["50px", "50px"];
794+
},
795+
})
796+
}
797+
798+
const openResizeEnd = () => {
799+
layer.open({
800+
title:"缩放结束",
801+
content:"缩放结束最终宽高固定为top500px/left500px",
802+
resize: true,
803+
resizeEnd(id, { width, height }) {
804+
console.log(width, height, "width, height");
805+
return ["500px", "500px"];
806+
},
807+
})
808+
}
809+
785810
const openCallback = () => {
786811
layer.open({
787812
title:"标题",
@@ -959,10 +984,10 @@ const openCallback = () => {
959984
| _yes_ | 点击底部默认按钮(不会主动关闭 `layer` 需要手动关闭,可用于一些逻辑判断) | `function` | `id` | |
960985
| _move-start_ | 弹窗拖动位置开始回调 | `function` | `id` | - |
961986
| _moving_ | 弹窗拖动位置回调 | `function` | `id` | - |
962-
| _move-end_ | 弹窗拖动位置结束回调 | `function` | `id` | - |
987+
| _move-end_ | 弹窗拖动位置结束回调(支持返回最终left/top值) | [MoveEndFn](https://www.layui-vue.com/zh-CN/components/layer#types) | `() => undefined` | - |
963988
| _resize-start_ | 弹窗拉伸位置开始回调 | `function` | `id` | - |
964989
| _resizing_ | 弹窗拉伸位置开始回调 | `function` | `id` | - |
965-
| _resize-end_ | 弹窗拉伸位置开始回调 | `function` | `id` | - |
990+
| _resize-end_ | 弹窗拉伸位置开始回调(支持返回最终width/height值) | [ResizeEndFn](https://www.layui-vue.com/zh-CN/components/layer#types) | `() => undefined` | - |
966991

967992
:::
968993

@@ -1318,4 +1343,29 @@ type ImgListType = {
13181343
};
13191344

13201345
type PropsContentType = VNodeTypes | (() => VNodeTypes);
1346+
1347+
type OperateEndReturn = void | [string, string] | undefined;
1348+
1349+
interface MoveEndFnOptions {
1350+
left: string;
1351+
top: string;
1352+
isMax: boolean;
1353+
isMin: boolean;
1354+
}
1355+
1356+
type MoveEndFn = (
1357+
id: string,
1358+
options: MoveEndFnOptions
1359+
) => OperateEndReturn;
1360+
1361+
interface ResizeEndFnOptions {
1362+
width: string;
1363+
height: string;
1364+
}
1365+
1366+
type ResizeEndFn = (
1367+
id: string,
1368+
options: ResizeEndFnOptions
1369+
) => OperateEndReturn;
1370+
13211371
```

packages/layer/src/component/index.vue

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<script lang="ts" setup>
2-
import type { BtnType, ImgListType, PropsContentType } from "../types";
2+
import type {
3+
BtnType,
4+
ImgListType,
5+
PropsContentType,
6+
MoveEndFn,
7+
ResizeEndFn,
8+
} from "../types";
39
410
import Shade from "./Shade.vue";
511
import Iframe from "./Iframe.vue";
@@ -118,10 +124,10 @@ export interface LayerProps {
118124
revert?: Function;
119125
moveStart?: Function;
120126
moving?: Function;
121-
moveEnd?: Function;
127+
moveEnd?: MoveEndFn;
122128
resizeStart?: Function;
123129
resizing?: Function;
124-
resizeEnd?: Function;
130+
resizeEnd?: ResizeEndFn;
125131
internalDestroy?: Function;
126132
}
127133
@@ -171,10 +177,10 @@ const props = withDefaults(defineProps<LayerProps>(), {
171177
revert: () => {},
172178
moveStart: () => {},
173179
moving: () => {},
174-
moveEnd: () => {},
180+
moveEnd: () => undefined,
175181
resizeStart: () => {},
176182
resizing: () => {},
177-
resizeEnd: () => {},
183+
resizeEnd: () => undefined,
178184
});
179185
180186
const emit = defineEmits(["close", "update:modelValue"]);
@@ -440,14 +446,25 @@ const supportMove = function () {
440446
_l.value = left;
441447
_t.value = top;
442448
}
443-
props.moving(id.value, { top: top, left: left });
449+
props.moving(id.value, { top, left });
444450
},
445451
() => {
446452
// 拖拽结束
447-
props.moveEnd(id.value);
453+
const options = {
454+
left: l.value,
455+
top: t.value,
456+
isMin: min.value,
457+
isMax: max.value,
458+
};
459+
const [left, top] = props.moveEnd(id.value, options) || [];
460+
461+
if (top && left) {
462+
l.value = left;
463+
t.value = top;
464+
}
448465
},
466+
// 拖拽开始
449467
() => {
450-
// 拖拽开始
451468
props.moveStart(id.value);
452469
}
453470
);
@@ -462,8 +479,17 @@ const supportMove = function () {
462479
props.resizing(id.value, { width: width, height: height });
463480
},
464481
() => {
482+
const options = {
483+
width: w.value,
484+
height: h.value,
485+
};
465486
// 拉伸结束
466-
props.resizeEnd(id.value);
487+
const [width, height] = props.resizeEnd(id.value, options) || [];
488+
489+
if (width && height) {
490+
w.value = width;
491+
h.value = height;
492+
}
467493
},
468494
() => {
469495
// 拉伸开始

packages/layer/src/types/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,27 @@ export type ImgListType = {
2020
};
2121

2222
export type PropsContentType = VNodeTypes | (() => VNodeTypes);
23+
24+
type OperateEndReturn = void | [string, string] | undefined;
25+
26+
interface MoveEndFnOptions {
27+
left: string;
28+
top: string;
29+
isMax: boolean;
30+
isMin: boolean;
31+
}
32+
33+
export type MoveEndFn = (
34+
id: string,
35+
options: MoveEndFnOptions
36+
) => OperateEndReturn;
37+
38+
interface ResizeEndFnOptions {
39+
width: string;
40+
height: string;
41+
}
42+
43+
export type ResizeEndFn = (
44+
id: string,
45+
options: ResizeEndFnOptions
46+
) => OperateEndReturn;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy