|
| 1 | +<template> |
| 2 | + <v-dialog v-model="isOpen" max-width="480" persistent> |
| 3 | + <v-card> |
| 4 | + <v-card-title class="dialog-title d-flex align-center justify-space-between"> |
| 5 | + <span>{{ title }}</span> |
| 6 | + <v-btn icon="mdi-close" variant="text" @click="handleClose"></v-btn> |
| 7 | + </v-card-title> |
| 8 | + <v-card-text> |
| 9 | + <div class="message-text">{{ message }}</div> |
| 10 | + <div class="action-hints"> |
| 11 | + <span class="hint-item">{{ confirmHint }}</span> |
| 12 | + <span class="hint-item">{{ cancelHint }}</span> |
| 13 | + <span class="hint-item">{{ closeHint }}</span> |
| 14 | + </div> |
| 15 | + </v-card-text> |
| 16 | + <v-card-actions> |
| 17 | + <v-spacer></v-spacer> |
| 18 | + <v-btn color="gray" @click="handleCancel">{{ t('core.common.dialog.cancelButton') }}</v-btn> |
| 19 | + <v-btn color="red" @click="handleConfirm" class="confirm-button">{{ t('core.common.dialog.confirmButton') }}</v-btn> |
| 20 | + </v-card-actions> |
| 21 | + </v-card> |
| 22 | + </v-dialog> |
| 23 | +</template> |
| 24 | + |
| 25 | +<script setup> |
| 26 | +import { ref } from "vue"; |
| 27 | +import { useI18n } from '@/i18n/composables'; |
| 28 | +
|
| 29 | +const { t } = useI18n(); |
| 30 | +
|
| 31 | +const isOpen = ref(false); |
| 32 | +const title = ref(""); |
| 33 | +const message = ref(""); |
| 34 | +const confirmHint = ref(""); |
| 35 | +const cancelHint = ref(""); |
| 36 | +const closeHint = ref(""); |
| 37 | +let resolvePromise = null; |
| 38 | +
|
| 39 | +const open = (options) => { |
| 40 | + title.value = options.title || t('core.common.dialog.confirmTitle'); |
| 41 | + message.value = options.message || t('core.common.dialog.confirmMessage'); |
| 42 | + confirmHint.value = options.confirmHint || ""; |
| 43 | + cancelHint.value = options.cancelHint || ""; |
| 44 | + closeHint.value = options.closeHint || ""; |
| 45 | + isOpen.value = true; |
| 46 | +
|
| 47 | + return new Promise((resolve) => { |
| 48 | + resolvePromise = resolve; |
| 49 | + }); |
| 50 | +}; |
| 51 | +
|
| 52 | +const handleConfirm = () => { |
| 53 | + isOpen.value = false; |
| 54 | + if (resolvePromise) resolvePromise(true); |
| 55 | +}; |
| 56 | +
|
| 57 | +const handleCancel = () => { |
| 58 | + isOpen.value = false; |
| 59 | + if (resolvePromise) resolvePromise(false); |
| 60 | +}; |
| 61 | +
|
| 62 | +const handleClose = () => { |
| 63 | + isOpen.value = false; |
| 64 | + if (resolvePromise) resolvePromise('close'); |
| 65 | +}; |
| 66 | +
|
| 67 | +defineExpose({ open }); |
| 68 | +</script> |
| 69 | + |
| 70 | + |
| 71 | +<style scoped> |
| 72 | +.message-text { |
| 73 | + margin-bottom: 8px; |
| 74 | + line-height: 1.5; |
| 75 | + font-size: 16px; |
| 76 | + font-weight: 600; |
| 77 | +} |
| 78 | +
|
| 79 | +.action-hints { |
| 80 | + display: flex; |
| 81 | + gap: 15px; |
| 82 | +} |
| 83 | +
|
| 84 | +.hint-item { |
| 85 | + color: var(--v-theme-secondaryText, #666); |
| 86 | + font-size: 12px; |
| 87 | + opacity: 0.7; |
| 88 | +} |
| 89 | +
|
| 90 | +.dialog-title { |
| 91 | + font-size: 20px; |
| 92 | + font-weight: 500; |
| 93 | +} |
| 94 | +
|
| 95 | +.confirm-button { |
| 96 | + color: rgb(239, 68, 68); |
| 97 | +} |
| 98 | +</style> |
0 commit comments