Dialog.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. const dialogVisible = ref(false)
  4. interface DialogProps {
  5. width?: string
  6. }
  7. withDefaults(defineProps<DialogProps>(), {
  8. width: '50%'
  9. })
  10. defineEmits<{ (e: 'on-close', value: boolean): void }>()
  11. const DialogOpen = () => {
  12. dialogVisible.value = true
  13. }
  14. const DialogClose = () => {
  15. dialogVisible.value = false
  16. }
  17. // 导出方法
  18. defineExpose({
  19. DialogOpen,
  20. DialogClose
  21. })
  22. </script>
  23. <template>
  24. <el-dialog v-model="dialogVisible" @close="DialogClose" @closed="DialogClose" :width="width" class="bottomD">
  25. <!-- 默认插槽 -->
  26. <slot></slot>
  27. <!-- 弹框头部 -->
  28. <template #header>
  29. <slot name="header"></slot>
  30. </template>
  31. <!-- 弹框页脚 -->
  32. <template #footer>
  33. <slot name="footer"></slot>
  34. </template>
  35. </el-dialog>
  36. </template>
  37. <style scoped>
  38. :deep(.el-dialog) {
  39. animation: anim-open 1s linear !important;
  40. }
  41. .el-dialog__wrapper {
  42. transition-duration: 0.1s;
  43. }
  44. .el-dialog__wrapper.dialog-fade-enter-active,
  45. .el-dialog__wrapper.dialog-fade-leave-active {
  46. animation: none !important;
  47. }
  48. .bottomD {
  49. animation: anim-open 1s linear !important;
  50. }
  51. @keyframes anim-open {
  52. 0% {
  53. transform: translate3d(100%, 0, 0);
  54. opacity: 0;
  55. }
  56. 25% {
  57. transform: translate3d(60%, 0, 0);
  58. opacity: 0.5;
  59. }
  60. 50% {
  61. transform: translate3d(15%, 0, 0);
  62. opacity: 0.9;
  63. }
  64. 75% {
  65. transform: translate3d(5%, 0, 0);
  66. opacity: 0.95;
  67. }
  68. 100% {
  69. transform: translate3d(0, 0, 0);
  70. opacity: 1;
  71. }
  72. }
  73. </style>