小草家校通/app.js · 约 2050 字符
1// 小草家校通 · 交互逻辑
2document.addEventListener('click', function (e) {
3 var t = e.target.closest('[data-toast]');
4 if (t) { toast(t.getAttribute('data-toast')); }
5 var st = e.target.closest('.sch-tab');
6 if (st) {
7 var wrap = st.parentElement;
8 [...wrap.children].forEach(function (x) { x.classList.remove('on'); });
9 st.classList.add('on');
10 var day = st.getAttribute('data-day');
11 var rows = document.querySelectorAll('.sch-row[data-row]');
12 rows.forEach(function (r) {
13 var cell = r.querySelector('.sch-cell[data-day="' + day + '"]');
14 [...r.children].forEach(function (c) { c.classList.remove('active'); });
15 if (cell) cell.classList.add('active');
16 });
17 }
18 var opt = e.target.closest('.lr-val .opt');
19 if (opt) {
20 var grp = opt.parentElement;
21 [...grp.children].forEach(function (x) { x.classList.remove('sel'); });
22 opt.classList.add('sel');
23 }
24 var ni = e.target.closest('.ni-btn');
25 if (ni) { ni.textContent = '已确认'; ni.style.opacity = '.6'; toast('已确认收到'); }
26 var hb = e.target.closest('.hw-btn');
27 if (hb && hb.textContent.indexOf('打卡') >= 0) { hb.textContent = '已打卡'; hb.classList.add('done'); toast('打卡成功,老师已收到'); }
28 var ab = e.target.closest('.ac-btn');
29 if (ab && ab.textContent.indexOf('报名') >= 0) { ab.textContent = '已报名'; ab.classList.add('joined'); toast('报名成功'); }
30 var sb = e.target.closest('.submit-btn');
31 if (sb) { toast('提交成功,等待班主任审批'); }
32 var kb = e.target.closest('.kid-switch,.uc-switch');
33 if (kb) { toast('已切换至另一名孩子(演示)'); }
34});
35function toast(msg) {
36 var d = document.createElement('div');
37 d.style.cssText = 'position:fixed;left:50%;bottom:110px;transform:translateX(-50%);background:rgba(12,58,46,.9);color:#fff;padding:10px 20px;border-radius:20px;font-size:13px;z-index:999';
38 d.textContent = msg;
39 document.body.appendChild(d);
40 setTimeout(function () { d.remove(); }, 1800);
41}
42