|
|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<transition name="message-fade">
|
|
|
- <div v-if="localVisible" class="message-overlay" @click.self="handleOverlayClick">
|
|
|
- <div class="message-box" :style="zIndexStyle">
|
|
|
+ <div v-if="localVisible" class="message-overlay" :class="{ 'no-backdrop': noBackdrop }" :style="zIndexStyle" @click.self="handleOverlayClick">
|
|
|
+ <div class="message-box">
|
|
|
|
|
|
<div class="message-header">
|
|
|
<span class="message-title">{{ title }}</span>
|
|
|
@@ -14,6 +14,7 @@
|
|
|
|
|
|
<div class="message-footer" v-if="showConfirm">
|
|
|
<div class="message-btn-group">
|
|
|
+ <button v-if="showCancel" class="message-btn message-btn-cancel" @click="cancel">{{ cancelText }}</button>
|
|
|
<button class="message-btn" @click="confirm">{{ confirmText }}</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -38,16 +39,20 @@ export default {
|
|
|
showConfirm: { type: Boolean, default: true },
|
|
|
confirmText: { type: String, default: "确认" },
|
|
|
closeOnClickModal: { type: Boolean, default: false },
|
|
|
-
|
|
|
+ showCancel: { type: Boolean, default: false },
|
|
|
+ cancelText: { type: String, default: "取消" },
|
|
|
+ noBackdrop: { type: Boolean, default: false },
|
|
|
+
|
|
|
// 如果依然保留函数回调方式(主要用于命令式调用)
|
|
|
onClose: { type: Function, default: null },
|
|
|
- onConfirm: { type: Function, default: null }
|
|
|
+ onConfirm: { type: Function, default: null },
|
|
|
+ onCancel: { type: Function, default: null }
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
// 内部变量,避免直接修改 prop(visible) 报错
|
|
|
- localVisible: this.visible,
|
|
|
- zIndex: 2000,
|
|
|
+ localVisible: this.visible,
|
|
|
+ zIndex: 9000,
|
|
|
timer: null
|
|
|
};
|
|
|
},
|
|
|
@@ -78,7 +83,7 @@ export default {
|
|
|
this.startTimer();
|
|
|
}
|
|
|
// 实例化时增加全局 zIndex,解决堆叠问题
|
|
|
- Vue.prototype.$msgZIndex = (Vue.prototype.$msgZIndex || 2000) + 1;
|
|
|
+ Vue.prototype.$msgZIndex = (Vue.prototype.$msgZIndex || 9000) + 1;
|
|
|
this.zIndex = Vue.prototype.$msgZIndex;
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -108,6 +113,13 @@ export default {
|
|
|
this.$emit("confirm");
|
|
|
this.close();
|
|
|
},
|
|
|
+ cancel() {
|
|
|
+ if (typeof this.onCancel === "function") {
|
|
|
+ this.onCancel();
|
|
|
+ }
|
|
|
+ this.$emit("cancel");
|
|
|
+ this.close();
|
|
|
+ },
|
|
|
handleOverlayClick() {
|
|
|
if (this.closeOnClickModal) {
|
|
|
this.close();
|
|
|
@@ -225,7 +237,9 @@ export default {
|
|
|
top: 0;
|
|
|
}
|
|
|
.message-btn-group {
|
|
|
- padding: 16px 16px 16px 16px;
|
|
|
+ padding: 16px;
|
|
|
+ display: flex;
|
|
|
+ gap: 10px;
|
|
|
}
|
|
|
|
|
|
.message-btn {
|
|
|
@@ -245,6 +259,26 @@ export default {
|
|
|
box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
|
|
|
}
|
|
|
|
|
|
+.message-btn-cancel {
|
|
|
+ background: transparent;
|
|
|
+ border: 1px solid rgba(130, 150, 190, 0.4);
|
|
|
+}
|
|
|
+.message-btn-cancel:hover {
|
|
|
+ background: rgba(255, 255, 255, 0.05);
|
|
|
+ border-color: rgba(130, 150, 190, 0.8);
|
|
|
+ box-shadow: none;
|
|
|
+}
|
|
|
+
|
|
|
+.message-overlay.no-backdrop {
|
|
|
+ background: none;
|
|
|
+ backdrop-filter: none;
|
|
|
+ -webkit-backdrop-filter: none;
|
|
|
+ pointer-events: none;
|
|
|
+}
|
|
|
+.no-backdrop .message-box {
|
|
|
+ pointer-events: auto;
|
|
|
+}
|
|
|
+
|
|
|
.message-fade-enter-active, .message-fade-leave-active {
|
|
|
transition: opacity 0.3s, transform 0.3s;
|
|
|
}
|