topo-engine 0.1.4 → 0.1.5

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.
@@ -1216,6 +1216,53 @@
1216
1216
  function getSymbolSpec(cat) {
1217
1217
  return SYMBOL_SPEC[cat] || SYMBOL_SPEC.other;
1218
1218
  }
1219
+ function buildCustomerMap(customerData) {
1220
+ const map = /* @__PURE__ */ new Map();
1221
+ if (!Array.isArray(customerData)) return map;
1222
+ for (const entry of customerData) {
1223
+ if (entry && entry.psrId && Array.isArray(entry.consumerList)) {
1224
+ map.set(String(entry.psrId), entry.consumerList);
1225
+ }
1226
+ }
1227
+ return map;
1228
+ }
1229
+ const METER_CELL_W = 26;
1230
+ const METER_CELL_H = 38;
1231
+ const METER_GAP = 4;
1232
+ const METER_PAD = 6;
1233
+ const MAX_COLS = 5;
1234
+ const SHOW_NAME_LIMIT = 20;
1235
+ function injectCustomers(model, customerMap) {
1236
+ for (const node of model.nodes) {
1237
+ if (node.cat !== "meterBox") continue;
1238
+ const customers = customerMap.get(node.psrId);
1239
+ if (!customers || customers.length === 0) continue;
1240
+ node._customers = customers;
1241
+ if (customers.length === 1) {
1242
+ node._meterBoxMode = "single";
1243
+ node._meterBoxW = 30;
1244
+ node._meterBoxH = 38;
1245
+ } else {
1246
+ const showName = customers.length <= SHOW_NAME_LIMIT;
1247
+ const cols = Math.min(customers.length, MAX_COLS);
1248
+ const rows = Math.ceil(customers.length / cols);
1249
+ const cellW = METER_CELL_W;
1250
+ const cellH = showName ? METER_CELL_H : METER_CELL_W;
1251
+ node._meterBoxMode = "grid";
1252
+ node._meterBoxCols = cols;
1253
+ node._meterBoxRows = rows;
1254
+ node._meterBoxShowName = showName;
1255
+ node._meterBoxW = METER_PAD * 2 + cols * cellW + (cols - 1) * METER_GAP;
1256
+ node._meterBoxH = METER_PAD * 2 + rows * cellH + (rows - 1) * METER_GAP;
1257
+ }
1258
+ }
1259
+ }
1260
+ function getMeterBoxSize(node) {
1261
+ if (node._meterBoxW != null && node._meterBoxH != null) {
1262
+ return { w: node._meterBoxW, h: node._meterBoxH };
1263
+ }
1264
+ return null;
1265
+ }
1219
1266
  function stationPlans(model) {
1220
1267
  const nodesById = new Map(model.nodes.map((n) => [n.id, n]));
1221
1268
  const plans = [];
@@ -1267,6 +1314,10 @@
1267
1314
  const nmap = nodeMap || new Map(model.nodes.map((n) => [n.id, n]));
1268
1315
  const specOf = (id2) => {
1269
1316
  const n = nmap.get(id2);
1317
+ if (n && n.cat === "meterBox") {
1318
+ const dim = getMeterBoxSize(n);
1319
+ if (dim) return dim;
1320
+ }
1270
1321
  const s = getSymbolSpec(n ? n.cat : "other");
1271
1322
  return { w: s.w, h: s.h };
1272
1323
  };
@@ -1924,6 +1975,10 @@
1924
1975
  const sz = (id2) => {
1925
1976
  const n = extNodeMap.get(id2);
1926
1977
  if (n && n._size) return n._size;
1978
+ if (n && n.cat === "meterBox") {
1979
+ const dim = getMeterBoxSize(n);
1980
+ if (dim) return dim;
1981
+ }
1927
1982
  const spec = getSymbolSpec(n ? n.cat : "other");
1928
1983
  return { w: spec.w, h: spec.h };
1929
1984
  };
@@ -2522,22 +2577,30 @@
2522
2577
  const nodes = model.nodes.map((n) => {
2523
2578
  const spec = getSymbolSpec(n.cat);
2524
2579
  const busW = layout.stationBusWidth && layout.stationBusWidth.get(n.id);
2525
- const w = busW || spec.w;
2580
+ const meterBoxDim = n.cat === "meterBox" ? getMeterBoxSize(n) : null;
2581
+ const w = busW || (meterBoxDim ? meterBoxDim.w : spec.w);
2582
+ const h = meterBoxDim ? meterBoxDim.h : spec.h;
2526
2583
  const p = layout.pos.get(n.id) || { x: 0, y: 0 };
2527
2584
  return {
2528
2585
  id: n.id,
2529
- data: { ...n, width: w, height: spec.h },
2586
+ data: { ...n, width: w, height: h },
2530
2587
  style: {
2531
2588
  x: p.x,
2532
2589
  y: p.y,
2533
- size: [w, spec.h],
2590
+ size: [w, h],
2534
2591
  // 自定义字段(进 attributes,供 svg-symbol 节点绘制使用)
2535
2592
  cat: n.cat,
2536
- labelText: n.cat === "bus" || n.cat === "cableTerminal" ? "" : n.shortName || "",
2593
+ labelText: n.cat === "bus" || n.cat === "cableTerminal" || n.cat === "consumer" ? "" : n.shortName || "",
2537
2594
  rotate: layout.stationRotate && layout.stationRotate.get(n.id) || 0,
2538
2595
  highlight: 0,
2539
2596
  cursor: "pointer",
2540
- _nodeId: n.id
2597
+ _nodeId: n.id,
2598
+ // 计量箱客户数据
2599
+ _meterBoxMode: n._meterBoxMode || null,
2600
+ _meterBoxCols: n._meterBoxCols || 0,
2601
+ _meterBoxRows: n._meterBoxRows || 0,
2602
+ _meterBoxShowName: n._meterBoxShowName || false,
2603
+ _customers: n._customers || null
2541
2604
  }
2542
2605
  };
2543
2606
  });
@@ -27789,8 +27852,45 @@
27789
27852
  group.appendChild(new Polygon({ style: { points: [[0, -5], [0, 5], [9, 0]], fill: "none", stroke: C.red, lineWidth: 1.4 } }));
27790
27853
  }
27791
27854
  function drawMeterBox(attributes, group) {
27792
- group.appendChild(new Rect({ style: { x: -9.5, y: -9.5, width: 19, height: 19, fill: C.meterFill, stroke: C.meterText, lineWidth: 0.9 } }));
27793
- text(attributes, group, "JX", 0, 0.5, 7.5, C.meterText);
27855
+ const [w, h] = attributes.size;
27856
+ if (attributes._meterBoxMode === "single") {
27857
+ group.appendChild(new Circle({ style: { cx: 0, cy: -3, r: 11, fill: "none", stroke: C.white, lineWidth: 1.6 } }));
27858
+ group.appendChild(new Line({ style: { x1: 0, y1: -14, x2: 0, y2: -7, stroke: C.white, lineWidth: 1.6 } }));
27859
+ const name = attributes._customers && attributes._customers[0] ? attributes._customers[0].realConsName || attributes._customers[0].consName || "" : "";
27860
+ if (name) {
27861
+ group.appendChild(new Text({ style: { text: name, x: 0, y: 12, fontSize: 8, fill: C.white, fontFamily: FONT, textAlign: "center", textBaseline: "middle" } }));
27862
+ }
27863
+ } else if (attributes._meterBoxMode === "grid" && attributes._customers) {
27864
+ group.appendChild(new Rect({ style: { x: -w / 2, y: -h / 2, width: w, height: h, fill: C.meterFill, stroke: C.meterText, lineWidth: 0.9, radius: 2 } }));
27865
+ const cols = attributes._meterBoxCols || 5;
27866
+ const customers = attributes._customers;
27867
+ const showName = attributes._meterBoxShowName;
27868
+ const cellW = METER_CELL_W;
27869
+ const cellH = showName ? METER_CELL_H : METER_CELL_W;
27870
+ const gridW = cols * cellW + (cols - 1) * METER_GAP;
27871
+ const rows = attributes._meterBoxRows || Math.ceil(customers.length / cols);
27872
+ const gridH = rows * cellH + (rows - 1) * METER_GAP;
27873
+ const startX = -gridW / 2;
27874
+ const startY = -gridH / 2;
27875
+ const meterR = 9;
27876
+ for (let i2 = 0; i2 < customers.length; i2++) {
27877
+ const row2 = Math.floor(i2 / cols);
27878
+ const col = i2 % cols;
27879
+ const cx = startX + col * (cellW + METER_GAP) + cellW / 2;
27880
+ const cy = startY + row2 * (cellH + METER_GAP) + cellW / 2;
27881
+ group.appendChild(new Circle({ style: { cx, cy, r: meterR, fill: "none", stroke: C.meterText, lineWidth: 0.8 } }));
27882
+ group.appendChild(new Line({ style: { x1: cx, y1: cy - meterR, x2: cx, y2: cy - meterR + 4, stroke: C.meterText, lineWidth: 0.8 } }));
27883
+ if (showName) {
27884
+ const name = customers[i2].realConsName || customers[i2].consName || "";
27885
+ if (name) {
27886
+ group.appendChild(new Text({ style: { text: name, x: cx, y: cy + meterR + 6, fontSize: 7, fill: C.meterText, fontFamily: FONT, textAlign: "center", textBaseline: "middle" } }));
27887
+ }
27888
+ }
27889
+ }
27890
+ } else {
27891
+ group.appendChild(new Rect({ style: { x: -9.5, y: -9.5, width: 19, height: 19, fill: C.meterFill, stroke: C.meterText, lineWidth: 0.9 } }));
27892
+ text(attributes, group, "JX", 0, 0.5, 7.5, C.meterText);
27893
+ }
27794
27894
  }
27795
27895
  function drawConsumer(attributes, group) {
27796
27896
  group.appendChild(new Circle({ style: { cx: 0, cy: 0, r: 12.5, fill: "none", stroke: C.white, lineWidth: 1.8 } }));
@@ -27916,8 +28016,10 @@
27916
28016
  props: {
27917
28017
  dataUrl: { type: String, default: "" },
27918
28018
  data: { type: Object, default: null },
28019
+ /** 客户数据(计量箱关联的用户列表),直接传入 JSON 数组 */
28020
+ customerData: { type: Array, default: null },
27919
28021
  /** 主题:'dark'(默认,黑底 SCADA 风)| 'light'(白底);支持 v-model:theme 双向绑定 */
27920
- theme: { type: String, default: "dark" }
28022
+ theme: { type: String, default: "light" }
27921
28023
  },
27922
28024
  emits: ["node-select", "loaded", "top-distances", "update:theme"],
27923
28025
  setup(__props, { expose: __expose, emit: __emit }) {
@@ -28033,6 +28135,10 @@
28033
28135
  lastRaw.value = raw;
28034
28136
  const theme = applyTheme();
28035
28137
  model = parseTopo(raw);
28138
+ if (props.customerData && props.customerData.length) {
28139
+ const customerMap = buildCustomerMap(props.customerData);
28140
+ injectCustomers(model, customerMap);
28141
+ }
28036
28142
  nodeByIdMap = new Map(model.nodes.map((n) => [n.id, n]));
28037
28143
  title.value = String(model.title || "").replace(/\.+$/, "");
28038
28144
  stats.value = model.stats;
@@ -28164,6 +28270,13 @@
28164
28270
  if (lastRaw.value) render(lastRaw.value);
28165
28271
  }
28166
28272
  );
28273
+ vue.watch(
28274
+ () => props.customerData,
28275
+ () => {
28276
+ if (lastRaw.value) render(lastRaw.value);
28277
+ },
28278
+ { deep: true }
28279
+ );
28167
28280
  vue.onBeforeUnmount(() => {
28168
28281
  if (api) {
28169
28282
  api.destroy();
@@ -28223,7 +28336,7 @@
28223
28336
  };
28224
28337
  }
28225
28338
  };
28226
- const TopoGraph = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-562b2247"]]);
28339
+ const TopoGraph = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-c213df91"]]);
28227
28340
  const _hoisted_1$1 = ["data-theme"];
28228
28341
  const _hoisted_2$1 = { class: "panel-head" };
28229
28342
  const _hoisted_3$1 = {
@@ -28533,7 +28646,7 @@
28533
28646
  }
28534
28647
  };
28535
28648
  const DistanceTop10 = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-438b6017"]]);
28536
- const VERSION = "0.1.4";
28649
+ const VERSION = "0.1.5";
28537
28650
  const DESCRIPTION = "配电台区单线图拓扑成图引擎";
28538
28651
  exports2.DESCRIPTION = DESCRIPTION;
28539
28652
  exports2.DistanceTop10 = DistanceTop10;
@@ -28544,11 +28657,14 @@
28544
28657
  exports2.TopoGraph = TopoGraph;
28545
28658
  exports2.VERSION = VERSION;
28546
28659
  exports2.assertOrthogonal = assertOrthogonal;
28660
+ exports2.buildCustomerMap = buildCustomerMap;
28547
28661
  exports2.buildGraphData = buildGraphData;
28548
28662
  exports2.calculateTopDistances = calculateTopDistances;
28549
28663
  exports2.computeOrthogonalLayout = computeOrthogonalLayout;
28550
28664
  exports2.edgeStyle = edgeStyle;
28665
+ exports2.getMeterBoxSize = getMeterBoxSize;
28551
28666
  exports2.getSymbolSpec = getSymbolSpec;
28667
+ exports2.injectCustomers = injectCustomers;
28552
28668
  exports2.parseTopo = parseTopo;
28553
28669
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
28554
28670
  });