WACATW commited on
Commit
ceddbef
·
verified ·
1 Parent(s): ccc8f57

Update static/js/app.js

Browse files
Files changed (1) hide show
  1. static/js/app.js +17 -8
static/js/app.js CHANGED
@@ -31,21 +31,30 @@ let deleteType = null;
31
 
32
  // Toast function
33
  function showToast(message, type = 'success') {
34
- toastMessage.textContent = message;
35
- toastIcon.className = 'toast-icon fas ';
 
 
 
 
 
 
 
 
 
 
36
 
37
  if (type === 'success') {
38
- toastIcon.classList.add('fa-check-circle', 'success');
39
  } else if (type === 'error') {
40
- toastIcon.classList.add('fa-exclamation-circle', 'error');
41
  } else {
42
- toastIcon.classList.add('fa-info-circle', 'info');
43
  }
44
 
45
- toast.classList.add('show');
46
-
47
  setTimeout(() => {
48
- toast.classList.remove('show');
49
  }, 3000);
50
  }
51
 
 
31
 
32
  // Toast function
33
  function showToast(message, type = 'success') {
34
+ const toastEl = document.getElementById('toast');
35
+ const msgEl = document.getElementById('toastMessage');
36
+ const iconEl = document.getElementById('toastIcon');
37
+
38
+ // 容错处理:如果找不到 Toast 元素,直接在控制台打印,避免阻塞后续代码
39
+ if (!toastEl || !msgEl || !iconEl) {
40
+ console.warn('Toast elements not found. Message:', message);
41
+ return;
42
+ }
43
+
44
+ msgEl.textContent = message;
45
+ iconEl.className = 'toast-icon fas ';
46
 
47
  if (type === 'success') {
48
+ iconEl.classList.add('fa-check-circle', 'success');
49
  } else if (type === 'error') {
50
+ iconEl.classList.add('fa-exclamation-circle', 'error');
51
  } else {
52
+ iconEl.classList.add('fa-info-circle', 'info');
53
  }
54
 
55
+ toastEl.classList.add('show');
 
56
  setTimeout(() => {
57
+ toastEl.classList.remove('show');
58
  }, 3000);
59
  }
60