<template>
<div></div>
</template>
<script setup>
import { h } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { onMounted, onUnmounted, ref, watchEffect } from "vue";
const timer = ref(null);
const countdown = ref(null);
const showPopup = ref(false);
onMounted(() => {
timer.value = setInterval(() => {
const now = new Date();
console.log(now,'now')
if (
now.getHours() === 14 &&
now.getMinutes() === 12 &&
now.getSeconds() === 0
) {
clearInterval(timer.value);
showPopup.value = true;
countdown.value = setTimeout(() => {
console.log('60秒后退出')
// this.$emit('exit'); 60000
}, 3000);
}
}, 1000);
});
watchEffect(() => {
if (showPopup.value) {
ElMessageBox({
title: "标题",
message: h("p", null, [
h("span", null, "内容 "),
]),
showCancelButton: true,
confirmButtonText: "OK",
cancelButtonText: "Cancel",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
clearTimeout(countdown.value);
console.log('点击了退出')
// this.$emit('exit');
done();
} else {
done();
}
},
}).then((action) => {
ElMessage({
type: "info",
message: `action: ${action}`,
});
});
}
});
onUnmounted(() => {
clearInterval(timer.value);
clearTimeout(countdown.value);
});
</script>
<style scoped></style>