1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
| <script lang="ts" setup name="XtxDialog"> import { ref, watch } from 'vue' import { onClickOutside } from '@vueuse/core'
const props = defineProps({ title: { type: String, default: '', }, visible: { type: Boolean, default: false, }, }) const emit = defineEmits<{ (e: 'update:visible', visible: boolean): void }>()
const show = ref(false) watch( () => props.visible, (value) => { setTimeout(() => { show.value = value }, 20) }, { immediate: true, } ) const close = () => { emit('update:visible', false) }
const target = ref(null) onClickOutside(target, () => { close() }) </script> <template> <div class="xtx-dialog" v-if="visible" :class="{ fade: show }"> <div class="wrapper" ref="target" :class="{ fade: show }"> <div class="header"> <h3>{{ title }}</h3> <a href="JavaScript:;" class="iconfont icon-close-new" @click="close"></a> </div> <div class="body"> <slot /> </div> <div class="footer"> <slot name="footer" /> </div> </div> </div> </template>
<style scoped lang="less"> .xtx-dialog { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 8887; // background: rgba(0, 0, 0, 0.5); background: rgba(0, 0, 0, 0); &.fade { transition: all 0.4s; background: rgba(0, 0, 0, 0.5); } .wrapper { width: 600px; background: #fff; border-radius: 4px; position: absolute; top: 50%; left: 50%; // transform: translate(-50%, -50%); transform: translate(-50%, -60%); opacity: 0; &.fade { transition: all 0.4s; transform: translate(-50%, -50%); opacity: 1; } .body { padding: 20px 40px; font-size: 16px; .icon-warning { color: @priceColor; margin-right: 3px; font-size: 16px; } } .footer { text-align: center; padding: 10px 0 30px 0; } .header { position: relative; height: 70px; line-height: 70px; padding: 0 20px; border-bottom: 1px solid #f5f5f5; h3 { font-weight: normal; font-size: 18px; } a { position: absolute; right: 25px; top: 25px; font-size: 24px; width: 20px; height: 20px; line-height: 20px; text-align: center; color: #999; &:hover { color: #666; } } } } } </style>
|