33function addReminder ( ) {
44 var table = document . getElementById ( 'reminderTable' ) ;
55 var row = table . insertRow ( table . rows . length - 1 ) ;
6+ // 默认类型为 beforeStart,文本框可编辑
67 row . innerHTML = `
78 <td>
89 <select class="reminder-select">
9- <option value="beforeStart">当距离考试开始时间还有</option>
10+ <option value="beforeStart" selected >当距离考试开始时间还有</option>
1011 <option value="beforeEnd">当距离考试结束时间还有</option>
1112 <option value="afterEnd">当考试结束后</option>
1213 <option value="start">当考试开始时</option>
1314 <option value="end">当考试结束时</option>
1415 </select>
1516 </td>
16- <td><input type="number" class="reminder-time-input" placeholder="分钟" disabled ></td>
17+ <td><input type="number" class="reminder-time-input" placeholder="分钟"></td>
1718 <td>
1819 <select name="audioSelect" class="reminder-select"></select>
1920 </td>
2021 <td><button class="reminder-btn" onclick="removeReminder(this)">移除提醒</button></td>
2122 ` ;
2223 row . cells [ 0 ] . querySelector ( 'select' ) . addEventListener ( 'change' , function ( ) {
23- row . cells [ 1 ] . querySelector ( 'input' ) . disabled = this . value === 'start' || this . value === 'end' ;
24- row . cells [ 1 ] . querySelector ( 'input' ) . placeholder = this . value === 'start' || this . value === 'end' ? '-' : '分钟' ;
24+ var input = row . cells [ 1 ] . querySelector ( 'input' ) ;
25+ if ( this . value === 'start' || this . value === 'end' ) {
26+ input . disabled = true ;
27+ input . placeholder = '-' ;
28+ } else {
29+ input . disabled = false ;
30+ input . placeholder = '分钟' ;
31+ }
2532 } ) ;
2633 audioController . populateAudioSelect ( ) ;
2734}
@@ -33,20 +40,16 @@ function removeReminder(button) {
3340
3441function saveConfig ( ) {
3542 try {
43+ if ( ! validateReminders ( ) ) {
44+ return ;
45+ }
3646 var table = document . getElementById ( 'reminderTable' ) ;
3747 var reminders = [ ] ;
3848 for ( var i = 1 ; i < table . rows . length - 1 ; i ++ ) {
3949 var row = table . rows [ i ] ;
4050 var condition = row . cells [ 0 ] . querySelector ( 'select' ) . value ;
4151 var timeInput = row . cells [ 1 ] . querySelector ( 'input' ) ;
4252 var audioSelect = row . cells [ 2 ] . querySelector ( 'select' ) ;
43- // 校验:只有距离开始/结束/考试后类型时必须填写时间
44- if ( condition === 'beforeStart' || condition === 'beforeEnd' || condition === 'afterEnd' ) {
45- if ( ! timeInput . value || isNaN ( timeInput . value ) || Number ( timeInput . value ) <= 0 ) {
46- errorSystem . show ( '保存失败,请为“距离开始/结束/考试后”类型填写有效的分钟数' ) ;
47- return ;
48- }
49- }
5053 if ( timeInput && audioSelect ) {
5154 reminders . push ( {
5255 condition : condition ,
@@ -141,6 +144,23 @@ function exportConfig() {
141144 }
142145}
143146
147+ // 校验函数,供关闭弹窗和保存时调用
148+ function validateReminders ( ) {
149+ var table = document . getElementById ( 'reminderTable' ) ;
150+ for ( var i = 1 ; i < table . rows . length - 1 ; i ++ ) {
151+ var row = table . rows [ i ] ;
152+ var condition = row . cells [ 0 ] . querySelector ( 'select' ) . value ;
153+ var timeInput = row . cells [ 1 ] . querySelector ( 'input' ) ;
154+ if ( condition === 'beforeStart' || condition === 'beforeEnd' || condition === 'afterEnd' ) {
155+ if ( ! timeInput . value || isNaN ( timeInput . value ) || Number ( timeInput . value ) <= 0 ) {
156+ errorSystem . show ( '请为“距离开始/结束/考试后”类型填写有效的分钟数' ) ;
157+ return false ;
158+ }
159+ }
160+ }
161+ return true ;
162+ }
163+
144164// 页面加载时自动填充提醒表格
145165document . addEventListener ( "DOMContentLoaded" , ( ) => {
146166 // 加载提醒设置
@@ -225,19 +245,13 @@ document.addEventListener("DOMContentLoaded", () => {
225245 const closeBtn = document . getElementById ( 'close-reminder-btn' ) ;
226246 if ( closeBtn ) {
227247 closeBtn . addEventListener ( 'click' , function ( e ) {
228- var table = document . getElementById ( 'reminderTable' ) ;
229- for ( var i = 1 ; i < table . rows . length - 1 ; i ++ ) {
230- var row = table . rows [ i ] ;
231- var condition = row . cells [ 0 ] . querySelector ( 'select' ) . value ;
232- var timeInput = row . cells [ 1 ] . querySelector ( 'input' ) ;
233- if ( condition === 'beforeStart' || condition === 'beforeEnd' || condition === 'afterEnd' ) {
234- if ( ! timeInput . value || isNaN ( timeInput . value ) || Number ( timeInput . value ) <= 0 ) {
235- errorSystem . show ( '请为“距离开始/结束/考试后”类型填写有效的分钟数' ) ;
236- e . preventDefault ( ) ;
237- return ;
238- }
239- }
248+ if ( ! validateReminders ( ) ) {
249+ e . preventDefault ( ) ;
250+ // 阻止关闭弹窗,需配合reminderModal.js
251+ window . __reminderCloseBlocked = true ;
252+ return ;
240253 }
254+ window . __reminderCloseBlocked = false ;
241255 // ...existing code for关闭弹窗...
242256 } ) ;
243257 }
0 commit comments