| :close-on-press-escape="closeOnPressEscape" |
| 9 | :append-to-body="appendToBody" |
| 10 | :top="dialogTop" |
| 11 | :fullscreen="isMobile" |
| 12 | class="base-dialog" |
| 13 | :class="{ 'mobile-dialog': isMobile }" |
| 14 | > |
| 15 | <slot /> |
| 16 | <template v-if="$slots.footer" #footer> |
| 17 | <slot name="footer" /> |
| 18 | </template> |
| 19 | </el-dialog> |
| 20 | </template> |
| 21 |
| 22 | <script setup lang="ts"> |
| 23 | import { computed } from 'vue' |
| 24 |
| 25 | const props = withDefaults( |
| 26 | defineProps<{ |
| 27 | modelValue: boolean |
| 28 | title: string |
| 29 | width?: string |
| 30 | destroyOnClose?: boolean |
| 31 | closeOnClickModal?: boolean |
| 32 | closeOnPressEscape?: boolean |
| 33 | appendToBody?: boolean |
| 34 | top?: string |
| 35 | isMobile?: boolean |
| 36 | }>(), |
| 37 | { |
| 38 | width: '480px', |
| 39 | destroyOnClose: true, |
| 40 | closeOnClickModal: true, |
| 41 | closeOnPressEscape: true, |
| 42 | appendToBody: false, |
| 43 | top: '15vh', |
| 44 | isMobile: false, |
| 45 | }, |
| 46 | ) |
| 47 |
| 48 | const emit = defineEmits<{ |
| 49 | (e: 'update:modelValue', value: boolean): void |
| 50 | }>() |
| 51 |
| 52 | const visible = computed({ |
| 53 | get: () => props.modelValue, |
| 54 | set: (value) => emit('update:modelValue', value), |
| 55 | }) |
| 56 |
| 57 | const dialogWidth = computed(() => { |
| 58 | if (props.isMobile) return '100%' |
| 59 | return props.width |
| 60 | }) |
| 61 |
| 62 | const dialogTop = computed(() => { |
| 63 | if (props.isMobile) return '0' |
| 64 | return props.top |
| 65 | }) |
| 66 | </script> |
| 67 |
| 68 | <style lang="scss"> |
| 69 | .base-dialog.el-dialog { |
| 70 | border-radius: 16px; |
| 71 |
| 72 | .el-dialog__header { |
| 73 | display: flex; |
| 74 | align-items: center; |
| 75 | justify-content: space-between; |
| 76 | padding: 0 8px; |
| 77 | min-height: 42px; |
| 78 | margin: 0; |
| 79 | position: relative; |
| 80 |
| 81 | &::after { |
| 82 | content: ""; |
| 83 | position: absolute; |
| 84 | bottom: 0; |
| 85 | left: 8px; |
| 86 | right: 8px; |
| 87 | height: 1px; |
| 88 | background: $color-border-lighter; |
| 89 | } |
| 90 | } |
| 91 |
| 92 | .el-dialog__title { |
| 93 | font-size: $font-size-lg; |
| 94 | font-weight: $font-weight-semibold; |
| 95 | } |
| 96 |
| 97 | .el-dialog__body { |
| 98 | padding: 16px 8px; |
| 99 | } |
| 100 |
| 101 | .el-dialog__headerbtn { |
| 102 | position: static; |
| 103 | width: 32px; |
| 104 | height: 32px; |
| 105 | @include flex-center; |
| 106 | border-radius: $radius-sm; |
| 107 | transition: background $transition-fast; |
| 108 |
| 109 | &:hover { |
| 110 | background: $color-bg-hover; |
| 111 | } |
| 112 | } |
| 113 |
| 114 | .el-dialog__footer { |
| 115 | padding: 8px; |
| 116 | display: flex; |
| 117 | justify-content: flex-end; |
| 118 | gap: 8px; |
| 119 | } |
| 120 |
| 121 | &.mobile-dialog { |
| 122 | border-radius: 0; |
| 123 | margin: 0; |
| 124 | height: 100%; |
| 125 | max-height: 100dvh; |
| 126 | display: flex; |
| 127 | flex-direction: column; |
| 128 |
| 129 | .el-dialog__body { |
| 130 | flex: 1; |
| 131 | overflow-y: auto; |
| 132 | padding: 16px 12px; |
| 133 | } |
| 134 |
| 135 | .el-dialog__footer { |
| 136 | padding: 8px 12px; |
| 137 | padding-bottom: calc(8px + env(safe-area-inset-bottom)); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | </style> |