Skip to content

Commit

Permalink
fix(popup): 修复 update:visible 事件关闭时重复调用 (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
yang1206 authored Mar 11, 2024
1 parent f342d55 commit 6d69f4d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 40 deletions.
49 changes: 29 additions & 20 deletions src/packages/__VUE/popup/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default create({
emits: ['clickPop', 'clickCloseIcon', 'open', 'close', 'opened', 'closed', 'clickOverlay', 'update:visible'],
setup(props, { emit }) {
let opened: boolean;
const state = reactive({
zIndex: props.zIndex,
showSlot: true,
Expand Down Expand Up @@ -79,25 +80,30 @@ export default create({
});
const open = () => {
if (props.zIndex !== initIndex) {
_zIndex = Number(props.zIndex);
if (!opened) {
opened = true;
if (props.zIndex !== initIndex) {
_zIndex = Number(props.zIndex);
}
emit('update:visible', true);
state.zIndex = ++_zIndex;
if (props.destroyOnClose) {
state.showSlot = true;
}
emit('open');
}
emit('update:visible', true);
state.zIndex = ++_zIndex;
if (props.destroyOnClose) {
state.showSlot = true;
}
emit('open');
};
const close = () => {
// if (!props.visible) return; //避免重复调用
emit('update:visible', false);
emit('close');
if (props.destroyOnClose) {
setTimeout(() => {
state.showSlot = false;
}, +props.duration * 1000);
if (opened) {
opened = false;
emit('update:visible', false);
emit('close');
if (props.destroyOnClose) {
setTimeout(() => {
state.showSlot = false;
}, +props.duration * 1000);
}
}
};
Expand All @@ -108,15 +114,13 @@ export default create({
const onClickCloseIcon = (e: Event) => {
e.stopPropagation();
emit('clickCloseIcon', e);
emit('update:visible', false);
// close();
close();
};
const onClickOverlay = (e: Event) => {
emit('clickOverlay', e);
if (props.closeOnClickOverlay) {
emit('update:visible', false);
// close();
close();
}
};
Expand All @@ -131,7 +135,12 @@ export default create({
watch(
() => props.visible,
() => {
props.visible ? open() : close();
if (props.visible && !opened) {
open();
}
if (!props.visible && opened) {
close();
}
}
);
watchEffect(() => {
Expand Down
49 changes: 29 additions & 20 deletions src/packages/__VUE/popup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default create({
emits: ['clickPop', 'clickCloseIcon', 'open', 'close', 'opened', 'closed', 'clickOverlay', 'update:visible'],
setup(props, { emit }) {
let opened: boolean;
const state = reactive({
zIndex: props.zIndex,
showSlot: true,
Expand Down Expand Up @@ -79,25 +80,30 @@ export default create({
});
const open = () => {
if (props.zIndex !== initIndex) {
_zIndex = Number(props.zIndex);
if (!opened) {
opened = true;
if (props.zIndex !== initIndex) {
_zIndex = Number(props.zIndex);
}
emit('update:visible', true);
state.zIndex = ++_zIndex;
if (props.destroyOnClose) {
state.showSlot = true;
}
emit('open');
}
emit('update:visible', true);
state.zIndex = ++_zIndex;
if (props.destroyOnClose) {
state.showSlot = true;
}
emit('open');
};
const close = () => {
// if (!props.visible) return; //避免重复调用
emit('update:visible', false);
emit('close');
if (props.destroyOnClose) {
setTimeout(() => {
state.showSlot = false;
}, +props.duration * 1000);
if (opened) {
opened = false;
emit('update:visible', false);
emit('close');
if (props.destroyOnClose) {
setTimeout(() => {
state.showSlot = false;
}, +props.duration * 1000);
}
}
};
Expand All @@ -108,15 +114,13 @@ export default create({
const onClickCloseIcon = (e: Event) => {
e.stopPropagation();
emit('clickCloseIcon', e);
emit('update:visible', false);
// close();
close();
};
const onClickOverlay = (e: Event) => {
emit('clickOverlay', e);
if (props.closeOnClickOverlay) {
emit('update:visible', false);
// close();
close();
}
};
Expand All @@ -131,7 +135,12 @@ export default create({
watch(
() => props.visible,
() => {
props.visible ? open() : close();
if (props.visible && !opened) {
open();
}
if (!props.visible && opened) {
close();
}
}
);
watchEffect(() => {
Expand Down

0 comments on commit 6d69f4d

Please sign in to comment.