💫 动画加上,过渡自然点

This commit is contained in:
BTMuli
2023-08-29 17:09:29 +08:00
parent 6c4a3c7830
commit 5511062d26

View File

@@ -1,8 +1,8 @@
<template> <template>
<transition name="func-confirm-outer"> <transition name="func-confirm-outer">
<div v-show="show" class="confirm-overlay" @click.self.prevent="handleOuter"> <div v-show="show || showOuter" class="confirm-overlay" @click.self.prevent="handleOuter">
<transition name="func-confirm-inner"> <transition name="func-confirm-inner">
<div class="confirm-box"> <div v-show="showInner" class="confirm-box">
<div class="confirm-title"> <div class="confirm-title">
{{ data.title ?? "" }} {{ data.title ?? "" }}
</div> </div>
@@ -56,9 +56,30 @@ const data = reactive({
otcancel: false, otcancel: false,
}); });
const show = ref<boolean>(false); const show = ref<boolean>(false);
const showOuter = ref<boolean>(false);
const showInner = ref<boolean>(false);
const confirmVal = ref<boolean | string>(false); const confirmVal = ref<boolean | string>(false);
const inputVal = ref<string>(""); const inputVal = ref<string>("");
watch(
() => show.value,
() => {
if (show.value) {
showOuter.value = true;
setTimeout(() => {
showInner.value = true;
}, 100);
} else {
setTimeout(() => {
showInner.value = false;
}, 100);
setTimeout(() => {
showOuter.value = false;
}, 300);
}
},
);
onMounted(async () => { onMounted(async () => {
await displayBox(props); await displayBox(props);
}); });
@@ -72,7 +93,10 @@ async function displayBox(props: TGApp.Component.Confirm.Params): Promise<string
// 等待确认框关闭返回关闭后的confirmVal // 等待确认框关闭返回关闭后的confirmVal
return await new Promise<string | boolean>((resolve) => { return await new Promise<string | boolean>((resolve) => {
watch(show, () => { watch(show, () => {
resolve(confirmVal.value); // 等 0.5s 动画
setTimeout(() => {
resolve(confirmVal.value);
}, 500);
}); });
}); });
} }
@@ -107,6 +131,42 @@ defineExpose({
</script> </script>
<style scoped> <style scoped>
.func-confirm-outer-enter-active,
.func-confirm-outer-leave-active,
.func-confirm-inner-enter-active {
transition: all 0.3s;
}
.func-confirm-inner-leave-active {
transition: all 0.5s ease-in-out;
}
.func-confirm-inner-enter-from {
opacity: 0;
transform: scale(1.5);
}
.func-confirm-inner-enter-to,
.func-confirm-inner-leave-from {
opacity: 1;
transform: scale(1);
}
.func-confirm-outer-enter-to,
.func-confirm-outer-leave-from {
opacity: 1;
}
.func-confirm-outer-enter-from,
.func-confirm-outer-leave-to {
opacity: 0;
}
.func-confirm-inner-leave-to {
opacity: 0;
transform: scale(0);
}
.confirm-overlay { .confirm-overlay {
position: fixed; position: fixed;
z-index: 100; z-index: 100;