rollcall-classroom-assets 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dm-app.js +20 -1
  2. package/package.json +1 -1
package/dm-app.js CHANGED
@@ -331,12 +331,31 @@ function rosterDelList() {
331
331
  }
332
332
 
333
333
  // 名单服务端同步:自定义班单名增删(服务端 class_data 权威)
334
+ // ★ 2026-10-14 复核 L2:这条原来是 fire-and-forget(只 .catch(() => {})),而服务端现在有四种
335
+ // 「没写成」:403 没权限 / 409 撞上乐观锁(名单刚被别的老师改了)/ 507 整行超字节 / 网络断。
336
+ // 不回滚就出现最难查的那种问题:老师看见名字已经加上了,刷一次页面它又不见了 ——
337
+ // 界面在说一件服务端并不知道的事。现在失败就把这一次内存改动收回去,
338
+ // 并把服务端那句人话原样显示出来(错误文案单点在 src/index.ts,别在这儿另编一套)。
334
339
  function rosterSync(api, cls, name) {
340
+ const undo = () => {
341
+ const arr = dynRoster[cls] = dynRoster[cls] || [];
342
+ if (api === 'add-student') { const i = arr.indexOf(name); if (i >= 0) arr.splice(i, 1); }
343
+ else if (!arr.includes(name)) arr.push(name);
344
+ try { afterRosterChange(''); } catch (e) { }
345
+ };
335
346
  fetch(`/api/${api}`, {
336
347
  method: 'POST',
337
348
  headers: { 'Content-Type': 'application/json' },
338
349
  body: JSON.stringify({ class: cls, name })
339
- }).catch(() => {});
350
+ }).then(async r => {
351
+ let d = null; try { d = await r.json(); } catch (e) { }
352
+ if (d && d.ok) return;
353
+ undo();
354
+ rosterToast('⚠️ 名单没存上:' + ((d && d.error) || ('HTTP ' + r.status)) + '(刚才那次改动已收回,可重做一次)');
355
+ }).catch(() => {
356
+ undo();
357
+ rosterToast('⚠️ 名单没存上(连不上服务器),刚才那次改动已收回 —— 重做一次或等网络恢复');
358
+ });
340
359
  }
341
360
  // 内置班权威名单全量上传(KV class_data[cls] 就是名单本身,批改页 /api/roster 直接读它)
342
361
  // 串行排队:一次操作可能触发多次上传(批量添加等),排队保证服务端最终状态 = 最后一次全量名单
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollcall-classroom-assets",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Static assets for the classroom workbench (roll-call): app JS, pinyin/xlsx/zxing engines and icons. Published only so they can be served from a China-friendly CDN.",
5
5
  "keywords": [
6
6
  "assets",