Merge branch 'sophie' into dev
This commit is contained in:
commit
0875623605
6 files changed
+145
-25
No files matched your search
@@ -13,6 +13,8 @@ interface Props {
|
||||
message?: string;
|
||||
closeOnMask?: boolean;
|
||||
closeOnEsc?: boolean;
|
||||
// 自动关闭时长(毫秒):<= 0 表示不自动关闭。
|
||||
autoCloseMs?: number;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -21,6 +23,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
message: '',
|
||||
closeOnMask: true,
|
||||
closeOnEsc: true,
|
||||
autoCloseMs: 3000,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -69,8 +72,16 @@ const resolvedStyle = computed(() => STYLE_MAP[props.level]);
|
||||
const resolvedIcon = computed(() => ICON_MAP[props.level]);
|
||||
const resolvedTitle = computed(() => props.title || DEFAULT_TITLE_MAP[props.level]);
|
||||
const resolvedMessage = computed(() => props.message || '');
|
||||
let autoCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
const clearAutoCloseTimer = () => {
|
||||
if (!autoCloseTimer) return;
|
||||
clearTimeout(autoCloseTimer);
|
||||
autoCloseTimer = null;
|
||||
};
|
||||
|
||||
const closeDialog = () => {
|
||||
clearAutoCloseTimer();
|
||||
emit('update:modelValue', false);
|
||||
emit('close');
|
||||
};
|
||||
@@ -88,18 +99,28 @@ const handleEscKey = (event: KeyboardEvent) => {
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(visible) => {
|
||||
() => [props.modelValue, props.level, props.title, props.message, props.autoCloseMs],
|
||||
([visible]) => {
|
||||
clearAutoCloseTimer();
|
||||
|
||||
if (!visible) {
|
||||
document.removeEventListener('keydown', handleEscKey);
|
||||
return;
|
||||
}
|
||||
document.addEventListener('keydown', handleEscKey);
|
||||
|
||||
// 关键点:弹框可见时只要内容变化,也会重新计时自动关闭。
|
||||
if (props.autoCloseMs > 0) {
|
||||
autoCloseTimer = setTimeout(() => {
|
||||
closeDialog();
|
||||
}, props.autoCloseMs);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearAutoCloseTimer();
|
||||
document.removeEventListener('keydown', handleEscKey);
|
||||
});
|
||||
</script>
|
||||
@@ -124,7 +145,7 @@ onBeforeUnmount(() => {
|
||||
<X class="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
<div class="flex items-start gap-4 pr-8">
|
||||
<div class="flex items-start gap-4 pr-8 min-h-0">
|
||||
<span
|
||||
class="w-8 h-8 rounded-full border-2 inline-flex items-center justify-center shrink-0 mt-0.5"
|
||||
:class="resolvedStyle.iconWrap"
|
||||
@@ -132,11 +153,11 @@ onBeforeUnmount(() => {
|
||||
<component :is="resolvedIcon" class="w-4 h-4" :class="resolvedStyle.icon" />
|
||||
</span>
|
||||
|
||||
<div class="min-w-0">
|
||||
<div class="min-w-0 w-full">
|
||||
<h3 class="text-[16px] leading-6 font-semibold text-slate-800">
|
||||
{{ resolvedTitle }}
|
||||
</h3>
|
||||
<p class="mt-3 text-[14px] leading-8 text-slate-700 whitespace-pre-line">
|
||||
<p class="level-dialog-message mt-3 text-[14px] leading-8 text-slate-700 whitespace-pre-line break-words">
|
||||
{{ resolvedMessage }}
|
||||
</p>
|
||||
</div>
|
||||
@@ -157,14 +178,31 @@ onBeforeUnmount(() => {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.level-dialog-panel {
|
||||
max-height: min(80vh, 640px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.level-dialog-message {
|
||||
max-height: min(48vh, 320px);
|
||||
overflow: auto;
|
||||
padding-right: 0.25rem;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.level-dialog-panel {
|
||||
max-width: 94vw;
|
||||
max-height: 82vh;
|
||||
padding: 20px 18px;
|
||||
}
|
||||
|
||||
.level-dialog-panel p {
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.level-dialog-message {
|
||||
max-height: 52vh;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user