notification.ejs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <style>
  2. .notification {
  3. position: fixed;
  4. top: 50%;
  5. left: 50%;
  6. transform: translate(-50%, -50%) scale(0.9);
  7. max-width: 400px;
  8. width: 90%;
  9. background-color: white;
  10. border-radius: 10px;
  11. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  12. padding: 20px 25px;
  13. display: flex;
  14. align-items: center;
  15. opacity: 0;
  16. visibility: hidden;
  17. transition: all 0.3s ease;
  18. z-index: 1000;
  19. }
  20. .notification.active {
  21. opacity: 1;
  22. visibility: visible;
  23. transform: translate(-50%, -50%) scale(1);
  24. }
  25. .notification-content {
  26. display: flex;
  27. align-items: center;
  28. width: 100%;
  29. }
  30. .notification-icon {
  31. width: 40px;
  32. height: 40px;
  33. background-color: var(--secondary-color);
  34. color: white;
  35. border-radius: 50%;
  36. display: flex;
  37. align-items: center;
  38. justify-content: center;
  39. margin-right: 15px;
  40. flex-shrink: 0;
  41. }
  42. .notification-message {
  43. flex-grow: 1;
  44. font-size: 1rem;
  45. line-height: 1.4;
  46. }
  47. .notification-close {
  48. background: none;
  49. border: none;
  50. cursor: pointer;
  51. margin-left: 15px;
  52. color: var(--light-text);
  53. transition: color 0.3s ease;
  54. flex-shrink: 0;
  55. }
  56. .notification-close:hover {
  57. color: var(--primary-color);
  58. }
  59. /* 添加遮罩层 */
  60. .notification-overlay {
  61. position: fixed;
  62. top: 0;
  63. left: 0;
  64. width: 100%;
  65. height: 100%;
  66. background-color: rgba(0, 0, 0, 0.1);
  67. opacity: 0;
  68. visibility: hidden;
  69. transition: all 0.3s ease;
  70. z-index: 999;
  71. }
  72. .notification-overlay.active {
  73. opacity: 1;
  74. visibility: visible;
  75. }
  76. </style>
  77. <!-- 提示消息组件 -->
  78. <div id="notification" class="notification">
  79. <div class="notification-content">
  80. <div class="notification-icon">
  81. <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  82. <path d="M9 21L15 21" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
  83. <path d="M12 17C14.2091 17 16 15.2091 16 13C16 10.7909 14.2091 9 12 9C9.79086 9 8 10.7909 8 13C8 15.2091 9.79086 17 12 17Z" stroke="currentColor" stroke-width="2"/>
  84. <path d="M12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11C11.4477 11 11 11.4477 11 12C11 12.5523 11.4477 13 12 13Z" fill="currentColor"/>
  85. <circle cx="12" cy="5" r="3" fill="currentColor"/>
  86. </svg>
  87. </div>
  88. <div class="notification-message" id="notification-message"></div>
  89. <button class="notification-close" id="notification-close">
  90. <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  91. <path d="M18 6L6 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
  92. <path d="M6 6L18 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
  93. </svg>
  94. </button>
  95. </div>
  96. </div>
  97. <script>
  98. // 创建遮罩层
  99. const notificationOverlay = document.createElement('div');
  100. notificationOverlay.className = 'notification-overlay';
  101. document.body.appendChild(notificationOverlay);
  102. // 通知组件
  103. const notification = document.getElementById('notification');
  104. const notificationMessage = document.getElementById('notification-message');
  105. const notificationClose = document.getElementById('notification-close');
  106. function showNotification(message, duration = 4000) {
  107. notificationMessage.textContent = message;
  108. // 显示通知和遮罩层
  109. notification.classList.add('active');
  110. notificationOverlay.classList.add('active');
  111. // 设置定时器自动关闭
  112. const timeoutId = setTimeout(() => {
  113. hideNotification();
  114. }, duration);
  115. // 点击关闭按钮或遮罩层
  116. notificationClose.addEventListener('click', closeNotification);
  117. notificationOverlay.addEventListener('click', closeNotification);
  118. function closeNotification() {
  119. clearTimeout(timeoutId);
  120. hideNotification();
  121. notificationClose.removeEventListener('click', closeNotification);
  122. notificationOverlay.removeEventListener('click', closeNotification);
  123. }
  124. }
  125. function hideNotification() {
  126. notification.classList.remove('active');
  127. notificationOverlay.classList.remove('active');
  128. }
  129. </script>