Przeglądaj źródła

feat: 上传弹窗的学校下拉改为可选已登记学校(含内置),保留自动/运营数据学校/手动输入

liangzhao 2 tygodni temu
rodzic
commit
5204186043
1 zmienionych plików z 31 dodań i 5 usunięć
  1. 31 5
      public/ops.js

+ 31 - 5
public/ops.js

@@ -395,13 +395,39 @@
 
   // ---------- 上传 ----------
 
-  function fillSchoolOptions() {
+  async function refreshSchoolOptions() {
     const select = $('opsSchool');
     if (!select) return;
-    const known = (state.summary && state.summary.schools) || [];
+    // 已登记学校(校区地图里的学校注册表,含内置)
+    const registered = [];
+    try {
+      const { res, body } = await api('/api/schools');
+      if (res.ok) {
+        for (const school of (body && body.schools) || []) {
+          if (!school || !school.name) continue;
+          registered.push({
+            name: school.name,
+            hint: [school.province, school.city].filter(Boolean).join(' · '),
+          });
+        }
+      }
+    } catch { /* 注册表取不到时回落到运营数据里的学校 */ }
+
+    // 运营数据中出现过、但还没登记的学校
+    const registeredNames = new Set(registered.map((x) => x.name));
+    const fromOps = ((state.summary && state.summary.schools) || [])
+      .map((x) => x.name)
+      .filter((name) => name && !registeredNames.has(name));
+
     select.innerHTML = '<option value="">自动(读取表格里的「学校名称」列)</option>'
-      + known.map((s) => `<option value="${esc(s.name)}">${esc(s.name)}</option>`).join('')
+      + (registered.length
+        ? `<optgroup label="已登记学校">${registered.map((x) => `<option value="${esc(x.name)}">${esc(x.name)}${x.hint ? '(' + esc(x.hint) + ')' : ''}</option>`).join('')}</optgroup>`
+        : '')
+      + (fromOps.length
+        ? `<optgroup label="运营数据中的学校">${fromOps.map((name) => `<option value="${esc(name)}">${esc(name)}</option>`).join('')}</optgroup>`
+        : '')
       + '<option value="__custom">手动输入…</option>';
+
     select.value = '';
     const custom = $('opsSchoolCustom');
     if (custom) {
@@ -461,14 +487,14 @@
     });
   }
 
-  function openUpload() {
+  async function openUpload() {
     const modal = $('opsUploadModal');
     if (!modal) return;
     state.upload.files = [];
     renderFileList();
     $('opsUploadResult').innerHTML = '';
     $('opsYear').value = String(new Date().getFullYear());
-    fillSchoolOptions();
+    await refreshSchoolOptions();
     if ($('opsForce')) $('opsForce').checked = false;
     $('opsUploadStart').disabled = false;
     modal.hidden = false;