Ver código fonte

feat: 导入数据后联动刷新校区地图与经营驾驶舱

- 店铺运营上传成功后广播 ops:data-changed 事件
- 经营驾驶舱监听后重拉 summary(筛选选项)与聚合数据,保留图表实例不重建
- 校区地图监听后重拉 /api/schools,更新关联门店数与最近数据日期
- 刷新时清理已不存在的学校/店铺筛选值,避免空结果
liangzhao 2 semanas atrás
pai
commit
9f72a3f263
3 arquivos alterados com 30 adições e 0 exclusões
  1. 23 0
      public/cockpit.js
  2. 2 0
      public/ops.js
  3. 5 0
      public/schools.js

+ 23 - 0
public/cockpit.js

@@ -401,6 +401,25 @@
     }
   }
 
+  /** 数据变更后刷新:重拉筛选选项与聚合数据,不重建图表 */
+  async function refresh() {
+    const { body } = await api('/api/ops/summary');
+    if (!body || !body.enabled) return;
+    // 清理已不存在于新数据的筛选值
+    const schoolNames = new Set((body.schools || []).map((s) => s.name));
+    if (state.schools) {
+      const next = new Set([...state.schools].filter((name) => schoolNames.has(name)));
+      state.schools = next.size ? next : null;
+    }
+    const shopKeys = new Set((body.shops || []).map((s) => String(s.key || s.shopId)));
+    if (state.shops) {
+      const next = new Set([...state.shops].filter((key) => shopKeys.has(key)));
+      state.shops = next.size ? next : null;
+    }
+    mountFilters(body);
+    await loadData();
+  }
+
   async function init() {
     if (state.inited) return;
     state.inited = true;
@@ -423,6 +442,10 @@
     }
   }
 
+  window.addEventListener('ops:data-changed', () => {
+    if (state.inited) refresh();
+  });
+
   window.shanCockpitInit = function () {
     init();
     const refresh = $('btnCockpitRefresh');

+ 2 - 0
public/ops.js

@@ -669,6 +669,8 @@
       state.to = '';
       state.schools = null;
       await init(true);
+      // 通知其它页面(校区地图 / 经营驾驶舱)重新拉取数据
+      window.dispatchEvent(new CustomEvent('ops:data-changed'));
     }
   }
 

+ 5 - 0
public/schools.js

@@ -195,6 +195,11 @@
     }
   }
 
+  // 运营数据变更后,学校的关联门店数/最近日期会变,需要重新拉取
+  window.addEventListener('ops:data-changed', () => {
+    if (inited) load();
+  });
+
   window.shanSchoolsInit = function () {
     if (!inited) {
       inited = true;