Files
learning-system-portal/src/components/CustomErrorMessage.vue
2025-11-18 19:00:51 +08:00

113 lines
1.9 KiB
Vue

<template>
<transition name="fade">
<div v-if="visible" class="custom-info-message" @click="handleClose">
<div class="message-content">
<div class="icon-wrapper">
<span class="icon-text">X</span>
</div>
<div class="message-text">{{ message }}</div>
</div>
</div>
</transition>
</template>
<script>
export default {
name: "CustomErrorMessage",
data() {
return {
visible: false,
message: "",
timer: null,
};
},
methods: {
show(msg, duration = 3000) {
this.message = msg;
this.visible = true;
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
this.hide();
}, duration);
},
hide() {
this.visible = false;
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
},
handleClose() {
this.hide();
},
},
beforeDestroy() {
if (this.timer) {
clearTimeout(this.timer);
}
},
};
</script>
<style scoped>
.custom-info-message {
position: fixed;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 3000;
cursor: pointer;
}
.message-content {
display: flex;
align-items: center;
background: rgba(255, 241, 240, 1);
border-radius: 8px;
padding: 8px 16px;
border: 1px solid rgba(255, 204, 199, 1);
}
.icon-wrapper {
width: 16px;
height: 16px;
border-radius: 50%;
background: rgba(230, 31, 31, 1);
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
flex-shrink: 0;
}
.icon-wrapper .icon-text {
color: #fff;
font-size: 12px;
font-weight: 400;
font-style: normal;
line-height: 1;
}
.message-text {
color: rgba(0, 0, 0, 0.88);
font-size: 14px;
font-weight: 400;
line-height: 1.5;
flex: 1;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
</style>