@huaqiu/dsh-engineering-workbench 0.7.28 → 0.7.29
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.
- package/README.md +3 -2
- package/lib/client.js +265 -23
- package/lib/host.mjs +86 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
打开工程会话后,窗口最右侧的工具栏可直接打开原理图、PCB、板级 3D、结构件、评审和制造。点击「设计」可收起或展开四个设计工具。
|
|
4
4
|
|
|
5
|
-
在华秋 Windows 桌面主菜单「编辑」右侧点击「设计」「评审」或「制造」,直接打开当前会话对应的右侧页面。再次点击会回到该页,保留打开的画布和选中对象。右侧起始页也提供同名入口。「设计」菜单包含「电路设计」和「结构设计」。电路设计页提供原理图、PCB 和板级 3D
|
|
5
|
+
在华秋 Windows 桌面主菜单「编辑」右侧点击「设计」「评审」或「制造」,直接打开当前会话对应的右侧页面。再次点击会回到该页,保留打开的画布和选中对象。右侧起始页也提供同名入口。「设计」菜单包含「电路设计」和「结构设计」。电路设计页提供原理图、PCB 和板级 3D。有多个 KiCad 工程时,默认打开工作区内唯一直接存放在 project 目录下的正式工程(例如 designs/gdspider/project)。可通过「当前工程」切换到候选版本;若存在多个正式工程,则手动选择。结构设计页自动定位工作区各层目录中的 mechanical 或 mechnical;没有可预览模型时优先打开含 STL 的目录,其次为含 OBJ 的目录。多个候选目录可在「已定位目录」中切换,使用下拉框选择 STL 或 OBJ。可输入工作区目录后点击「打开目录」,或点「浏览文件夹」选择本机其他目录。首次打开工程时优先显示原理图;只有板文件时显示 PCB。「结构件」可选择本机的 STL(ASCII 或二进制)或 OBJ 文件预览外壳,拖动旋转,滚轮缩放。单个模型上限为 32 MiB,OBJ 预览显示几何形状。浏览 KiCad 图纸时,输入位号可以查看封装、板上坐标和焊盘网络。「询问助手」把当前对象和文件追加到左侧草稿,由你决定何时发送。
|
|
6
6
|
|
|
7
7
|
评审视图并排显示所选原理图和 PCB,窄栏上下排列。复核标记关联当前组件、文件对及文件版次,在该工程面板打开期间有效。制造页需要在「设置 → 硬件工程」配置 KiCad。三个标签使用当前选择的工程文件。
|
|
8
8
|
|
|
9
9
|
- **BOM** 由已保存的原理图生成,以「器件信息」「采购方案」两层表头对照位号、值、封装、采购型号、供应商、库存和阶梯单价。拖动列边界调宽,拖动列标题换序;列布局会保存在当前桌面,可点「重置列」恢复默认。「查询华秋价格」按生产批量检索华秋目录及供应商库存、起订量和人民币阶梯价。型号不唯一或只有参数匹配时,手动确认采购型号。相同物料合并计量,DNP 不计入采购,缺价行显示在覆盖率中。
|
|
10
|
+
确认采购型号后点击「保存 BOM」,会在原理图旁写入同名的 `.kicad_sch.hq-bom.json` 文件。再次打开可恢复批量、采购选择和上次报价;原理图有变更时仅复用相同物料行。「导出 CSV」导出全部行的采购明细,同一型号的合购金额仅列在首行。
|
|
10
11
|
- **Gerber** 在本机从当前 PCB 导出制造文件,选择图层查看图形,也可打开已有的 Gerber 或钻孔文件。
|
|
11
12
|
- **坐标文件** 显示 KiCad 从板上导出的双面毫米坐标 CSV 原文,也可查看本机 POS、CSV、TSV 或 TXT。
|
|
12
13
|
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
|
|
21
22
|
```powershell
|
|
22
23
|
$cli = Join-Path $env:LOCALAPPDATA 'Programs\Huaqiu Electronic Design Agent Platform\resources\runtime\cli\bin\dsh.cmd'
|
|
23
|
-
& $cli plugin --profile desktop add --offline --ignore-scripts (Resolve-Path '.\huaqiu-dsh-engineering-workbench-0.
|
|
24
|
+
& $cli plugin --profile desktop add --offline --ignore-scripts (Resolve-Path '.\huaqiu-dsh-engineering-workbench-0.6.1.tgz').Path
|
|
24
25
|
```
|
|
25
26
|
|
|
26
27
|
重新启动华秋 DSH 后打开工程会话。例如,向助手说「在右侧打开 control.kicad_pcb 的评审视图,查看 J1」。模型需支持工具调用。插件在构建时复用仓库中的硬件渲染适配器,安装包已包含浏览器端依赖。
|
package/lib/client.js
CHANGED
|
@@ -107439,6 +107439,22 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
107439
107439
|
};
|
|
107440
107440
|
}
|
|
107441
107441
|
const basename = (path) => path.split(/[\\/]/).pop() || path;
|
|
107442
|
+
/** Choose a production project only when the workspace layout identifies one unambiguously. */
|
|
107443
|
+
function defaultCircuitProject(projects, cwd) {
|
|
107444
|
+
if (!cwd) return void 0;
|
|
107445
|
+
const normalize = (path) => {
|
|
107446
|
+
const slashes = path.replaceAll("\\", "/");
|
|
107447
|
+
return /^(?:[a-z]:\/|\/\/)/i.test(slashes) ? slashes.toLowerCase() : slashes;
|
|
107448
|
+
};
|
|
107449
|
+
const root = normalize(cwd).replace(/\/+$/, "") + "/";
|
|
107450
|
+
const candidates = projects.filter((project) => {
|
|
107451
|
+
const path = normalize(project.path);
|
|
107452
|
+
if (!path.startsWith(root) || !/\.kicad_pro$/i.test(path)) return false;
|
|
107453
|
+
const dirs = path.slice(root.length).split("/").slice(0, -1);
|
|
107454
|
+
return dirs.at(-1)?.toLowerCase() === "project" && !dirs.some((dir) => /^\.?candidates?(?:$|[-_.\d])/i.test(dir) || [".history", ".runtime"].includes(dir.toLowerCase()));
|
|
107455
|
+
});
|
|
107456
|
+
return candidates.length === 1 ? candidates[0] : void 0;
|
|
107457
|
+
}
|
|
107442
107458
|
function matches(path, wanted) {
|
|
107443
107459
|
const normal = (s) => s.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
107444
107460
|
let p = normal(path), w = normal(wanted);
|
|
@@ -107617,7 +107633,7 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
107617
107633
|
async function readManufacturingBom(path, cwd, session, signal) {
|
|
107618
107634
|
try {
|
|
107619
107635
|
return {
|
|
107620
|
-
|
|
107636
|
+
...await manufacturingRequest("bom", { path }, signal),
|
|
107621
107637
|
builtIn: false
|
|
107622
107638
|
};
|
|
107623
107639
|
} catch (error) {
|
|
@@ -107628,6 +107644,8 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
107628
107644
|
session,
|
|
107629
107645
|
signal
|
|
107630
107646
|
})).rows,
|
|
107647
|
+
saved: void 0,
|
|
107648
|
+
warning: void 0,
|
|
107631
107649
|
builtIn: true
|
|
107632
107650
|
};
|
|
107633
107651
|
}
|
|
@@ -107750,7 +107768,7 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
107750
107768
|
minimumFractionDigits: 2,
|
|
107751
107769
|
maximumFractionDigits: digits
|
|
107752
107770
|
});
|
|
107753
|
-
function BomGrid({ rows, matches, reference, quantity, busy, summary, select, choose }) {
|
|
107771
|
+
function BomGrid({ rows, matches, reference, quantity, busy, saving, summary, select, choose }) {
|
|
107754
107772
|
const [layout, setLayout] = (0, react.useState)(readLayout);
|
|
107755
107773
|
const [query, setQuery] = (0, react.useState)("");
|
|
107756
107774
|
const [drop, setDrop] = (0, react.useState)();
|
|
@@ -107956,6 +107974,7 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
107956
107974
|
children: status
|
|
107957
107975
|
}),
|
|
107958
107976
|
mpn: !row.dnp && options.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
|
|
107977
|
+
disabled: saving,
|
|
107959
107978
|
"aria-label": key + " 采购型号",
|
|
107960
107979
|
title: [
|
|
107961
107980
|
candidate?.mpn,
|
|
@@ -108142,6 +108161,128 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108142
108161
|
});
|
|
108143
108162
|
}
|
|
108144
108163
|
//#endregion
|
|
108164
|
+
//#region src/bom-snapshot.ts
|
|
108165
|
+
function snapshotLines(rows, matches) {
|
|
108166
|
+
return rows.map((row) => {
|
|
108167
|
+
const match = matches[row.references.join(", ")];
|
|
108168
|
+
if (!match) return { row };
|
|
108169
|
+
return {
|
|
108170
|
+
row,
|
|
108171
|
+
candidates: match.candidates,
|
|
108172
|
+
selection: match.selected ? match.candidates.indexOf(match.selected) : -1,
|
|
108173
|
+
error: match.error
|
|
108174
|
+
};
|
|
108175
|
+
});
|
|
108176
|
+
}
|
|
108177
|
+
function signature(row) {
|
|
108178
|
+
return JSON.stringify([
|
|
108179
|
+
[...row.references].sort(),
|
|
108180
|
+
row.quantity,
|
|
108181
|
+
row.value,
|
|
108182
|
+
row.footprint,
|
|
108183
|
+
row.dnp,
|
|
108184
|
+
Object.entries(row.fields).sort(([a], [b]) => a.localeCompare(b))
|
|
108185
|
+
]);
|
|
108186
|
+
}
|
|
108187
|
+
function restoreMatches(rows, saved) {
|
|
108188
|
+
const previous = new Map(saved.lines.map((line) => [signature(line.row), line]));
|
|
108189
|
+
const matches = {};
|
|
108190
|
+
let unchanged = 0;
|
|
108191
|
+
for (const row of rows) {
|
|
108192
|
+
const line = previous.get(signature(row));
|
|
108193
|
+
if (!line) continue;
|
|
108194
|
+
unchanged++;
|
|
108195
|
+
if (line.candidates) matches[row.references.join(", ")] = {
|
|
108196
|
+
candidates: line.candidates,
|
|
108197
|
+
selected: line.candidates[line.selection ?? -1],
|
|
108198
|
+
error: line.error
|
|
108199
|
+
};
|
|
108200
|
+
}
|
|
108201
|
+
return {
|
|
108202
|
+
matches,
|
|
108203
|
+
changed: unchanged !== rows.length || unchanged !== saved.lines.length
|
|
108204
|
+
};
|
|
108205
|
+
}
|
|
108206
|
+
//#endregion
|
|
108207
|
+
//#region src/bom-export.ts
|
|
108208
|
+
function cell(value) {
|
|
108209
|
+
let text = String(value ?? "");
|
|
108210
|
+
if (typeof value === "string" && (/^\s*[=+@-]/.test(text) || /^[\t\r\n]/.test(text))) text = "'" + text;
|
|
108211
|
+
return "\"" + text.replaceAll("\"", "\"\"") + "\"";
|
|
108212
|
+
}
|
|
108213
|
+
function bomCsv(rows, matches, quantity, queriedAt) {
|
|
108214
|
+
const summary = basket(rows, matches, quantity);
|
|
108215
|
+
const counted = /* @__PURE__ */ new Set();
|
|
108216
|
+
const table = [[
|
|
108217
|
+
"位号",
|
|
108218
|
+
"名称 / 值",
|
|
108219
|
+
"封装",
|
|
108220
|
+
"原厂型号",
|
|
108221
|
+
"数量/板",
|
|
108222
|
+
"生产批量",
|
|
108223
|
+
"需求数量",
|
|
108224
|
+
"采购状态",
|
|
108225
|
+
"采购型号",
|
|
108226
|
+
"制造商",
|
|
108227
|
+
"华秋料号",
|
|
108228
|
+
"供应商",
|
|
108229
|
+
"供应商料号",
|
|
108230
|
+
"库存",
|
|
108231
|
+
"起订量",
|
|
108232
|
+
"单价(元)",
|
|
108233
|
+
"同型号合购数量(仅首行)",
|
|
108234
|
+
"合购金额(元,仅首行)",
|
|
108235
|
+
"待确认候选型号",
|
|
108236
|
+
"询价时间",
|
|
108237
|
+
"查询说明"
|
|
108238
|
+
]];
|
|
108239
|
+
for (const row of rows) {
|
|
108240
|
+
const match = matches[rowKey(row)], part = row.dnp ? void 0 : match?.selected;
|
|
108241
|
+
const price = summary.priceFor(part);
|
|
108242
|
+
const id = part && JSON.stringify([part.manufacturerId, part.mpn]);
|
|
108243
|
+
const first = !!id && !counted.has(id);
|
|
108244
|
+
if (id) counted.add(id);
|
|
108245
|
+
const state = row.dnp ? "不装配" : match?.error ? "查询失败" : part ? price ? "已匹配" : "未报价" : match?.candidates.length ? "待确认" : match ? "无匹配" : "待查询";
|
|
108246
|
+
table.push([
|
|
108247
|
+
rowKey(row),
|
|
108248
|
+
row.value,
|
|
108249
|
+
row.footprint,
|
|
108250
|
+
originalMpn(row),
|
|
108251
|
+
row.quantity,
|
|
108252
|
+
quantity,
|
|
108253
|
+
row.dnp ? 0 : row.quantity * quantity,
|
|
108254
|
+
state,
|
|
108255
|
+
part?.mpn,
|
|
108256
|
+
part?.manufacturer,
|
|
108257
|
+
part?.huaqiuPn,
|
|
108258
|
+
price?.offer.vendor,
|
|
108259
|
+
price?.offer.sku,
|
|
108260
|
+
price?.offer.stock,
|
|
108261
|
+
price && (price.offer.moq || 1),
|
|
108262
|
+
price?.unit,
|
|
108263
|
+
first ? price?.count : "",
|
|
108264
|
+
first && price ? Number(price.cost.toFixed(6)) : "",
|
|
108265
|
+
!part ? match?.candidates.map((c) => c.mpn).join(" / ") : "",
|
|
108266
|
+
queriedAt,
|
|
108267
|
+
match?.error
|
|
108268
|
+
]);
|
|
108269
|
+
}
|
|
108270
|
+
return "" + table.map((r) => r.map(cell).join(",")).join("\r\n") + "\r\n";
|
|
108271
|
+
}
|
|
108272
|
+
function downloadBom(path, csv) {
|
|
108273
|
+
const link = document.createElement("a");
|
|
108274
|
+
const url = URL.createObjectURL(new Blob([csv], { type: "text/csv;charset=utf-8" }));
|
|
108275
|
+
link.href = url;
|
|
108276
|
+
link.download = (path.split(/[\\/]/).pop() || "工程").replace(/\.kicad_sch$/i, "") + "-BOM.csv";
|
|
108277
|
+
document.body.append(link);
|
|
108278
|
+
try {
|
|
108279
|
+
link.click();
|
|
108280
|
+
} finally {
|
|
108281
|
+
link.remove();
|
|
108282
|
+
setTimeout(() => URL.revokeObjectURL(url), 3e4);
|
|
108283
|
+
}
|
|
108284
|
+
}
|
|
108285
|
+
//#endregion
|
|
108145
108286
|
//#region src/Manufacture.tsx
|
|
108146
108287
|
const manufacturingTabs = [
|
|
108147
108288
|
"BOM",
|
|
@@ -108152,8 +108293,9 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108152
108293
|
minimumFractionDigits: 2,
|
|
108153
108294
|
maximumFractionDigits: digits
|
|
108154
108295
|
});
|
|
108155
|
-
function Manufacture({ tab, path, board, cwd, session, reference, location, select, order, ask }) {
|
|
108296
|
+
function Manufacture({ tab, path, board, boardKey = board, cwd, session, reference, location, select, order, ask }) {
|
|
108156
108297
|
const [rows, setRows] = (0, react.useState)([]);
|
|
108298
|
+
const [loading, setLoading] = (0, react.useState)(!!path);
|
|
108157
108299
|
const [message, setMessage] = (0, react.useState)("");
|
|
108158
108300
|
const [quantity, setQuantity] = (0, react.useState)(5);
|
|
108159
108301
|
const [run, setRun] = (0, react.useState)(0);
|
|
@@ -108164,27 +108306,52 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108164
108306
|
pcb: "待查询",
|
|
108165
108307
|
smt: "待查询"
|
|
108166
108308
|
});
|
|
108309
|
+
const [queriedAt, setQueriedAt] = (0, react.useState)("");
|
|
108310
|
+
const [saved, setSaved] = (0, react.useState)();
|
|
108311
|
+
const [saving, setSaving] = (0, react.useState)(false);
|
|
108312
|
+
const [dirty, setDirty] = (0, react.useState)(false);
|
|
108313
|
+
const [saveError, setSaveError] = (0, react.useState)("");
|
|
108167
108314
|
(0, react.useEffect)(() => {
|
|
108168
108315
|
if (!path) {
|
|
108169
108316
|
setMessage("请选择原理图以生成 BOM。");
|
|
108170
108317
|
return;
|
|
108171
108318
|
}
|
|
108172
108319
|
const ctrl = new AbortController();
|
|
108320
|
+
setLoading(true);
|
|
108173
108321
|
setMessage("正在从原理图生成 BOM…");
|
|
108174
108322
|
readManufacturingBom(path, cwd, session, ctrl.signal).then((bom) => {
|
|
108175
|
-
if (
|
|
108176
|
-
|
|
108177
|
-
|
|
108178
|
-
|
|
108323
|
+
if (ctrl.signal.aborted) return;
|
|
108324
|
+
setRows(bom.rows);
|
|
108325
|
+
setBuiltIn(bom.builtIn);
|
|
108326
|
+
let message = bom.warning || (bom.rows.length ? "" : "该原理图没有物料记录。");
|
|
108327
|
+
if (bom.saved) {
|
|
108328
|
+
const previous = bom.saved;
|
|
108329
|
+
const restored = restoreMatches(bom.rows, previous);
|
|
108330
|
+
setSaved({
|
|
108331
|
+
version: previous.version,
|
|
108332
|
+
savedAt: previous.savedAt
|
|
108333
|
+
});
|
|
108334
|
+
setMatches(restored.matches);
|
|
108335
|
+
setQuantity(previous.quantity);
|
|
108336
|
+
setQueriedAt(previous.queriedAt);
|
|
108337
|
+
if (previous.boardKey === boardKey) setQuotes(previous.quotes);
|
|
108338
|
+
if (restored.changed) {
|
|
108339
|
+
message = [message, "原理图物料已变更,仅恢复了未变更行的采购结果。"].filter(Boolean).join(" ");
|
|
108340
|
+
setDirty(true);
|
|
108341
|
+
}
|
|
108179
108342
|
}
|
|
108343
|
+
setMessage(message);
|
|
108180
108344
|
}).catch((e) => {
|
|
108181
108345
|
if (!ctrl.signal.aborted) setMessage(String(e.message));
|
|
108346
|
+
}).finally(() => {
|
|
108347
|
+
if (!ctrl.signal.aborted) setLoading(false);
|
|
108182
108348
|
});
|
|
108183
108349
|
return () => ctrl.abort();
|
|
108184
108350
|
}, [
|
|
108185
108351
|
path,
|
|
108186
108352
|
cwd,
|
|
108187
|
-
session
|
|
108353
|
+
session,
|
|
108354
|
+
boardKey
|
|
108188
108355
|
]);
|
|
108189
108356
|
(0, react.useEffect)(() => {
|
|
108190
108357
|
if (!run) return;
|
|
@@ -108264,7 +108431,32 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108264
108431
|
quantity
|
|
108265
108432
|
]);
|
|
108266
108433
|
const part = rows.find((r) => r.references.some((ref) => ref.toUpperCase() === reference.toUpperCase()));
|
|
108267
|
-
const total = summary.covered ? money(summary.total) + (summary.covered < summary.lines ? "(部分)" : "") :
|
|
108434
|
+
const total = summary.covered ? money(summary.total) + (summary.covered < summary.lines ? "(部分)" : "") : queriedAt ? "暂无已报价项" : "待查询";
|
|
108435
|
+
const querying = busy || quotes.pcb === "查询中…" || quotes.smt === "查询中…";
|
|
108436
|
+
async function save() {
|
|
108437
|
+
setSaving(true);
|
|
108438
|
+
setSaveError("");
|
|
108439
|
+
try {
|
|
108440
|
+
const result = await manufacturingRequest("save-bom", {
|
|
108441
|
+
path,
|
|
108442
|
+
version: saved?.version ?? null,
|
|
108443
|
+
snapshot: {
|
|
108444
|
+
schema: 1,
|
|
108445
|
+
boardKey,
|
|
108446
|
+
quantity,
|
|
108447
|
+
queriedAt,
|
|
108448
|
+
quotes,
|
|
108449
|
+
lines: snapshotLines(rows, matches)
|
|
108450
|
+
}
|
|
108451
|
+
}, new AbortController().signal);
|
|
108452
|
+
setSaved(result);
|
|
108453
|
+
setDirty(false);
|
|
108454
|
+
} catch (e) {
|
|
108455
|
+
setSaveError("保存失败。" + (e instanceof Error ? e.message : String(e)));
|
|
108456
|
+
} finally {
|
|
108457
|
+
setSaving(false);
|
|
108458
|
+
}
|
|
108459
|
+
}
|
|
108268
108460
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
108269
108461
|
className: "ew-manufacture",
|
|
108270
108462
|
"data-manufacturing-tab": tab,
|
|
@@ -108282,14 +108474,26 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108282
108474
|
value: quantity,
|
|
108283
108475
|
onChange: (e) => {
|
|
108284
108476
|
const n = e.target.valueAsNumber;
|
|
108285
|
-
if (Number.isSafeInteger(n) && n >= 1 && n <= 1e5
|
|
108286
|
-
|
|
108477
|
+
if (Number.isSafeInteger(n) && n >= 1 && n <= 1e5 && n !== quantity) {
|
|
108478
|
+
setQuantity(n);
|
|
108479
|
+
setDirty(true);
|
|
108480
|
+
if (!run) setQuotes({
|
|
108481
|
+
pcb: "待查询",
|
|
108482
|
+
smt: "待查询"
|
|
108483
|
+
});
|
|
108484
|
+
}
|
|
108485
|
+
},
|
|
108486
|
+
disabled: saving || loading
|
|
108287
108487
|
}),
|
|
108288
108488
|
" 块"
|
|
108289
108489
|
] }),
|
|
108290
108490
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
108291
|
-
onClick: () =>
|
|
108292
|
-
|
|
108491
|
+
onClick: () => {
|
|
108492
|
+
setRun((n) => n + 1);
|
|
108493
|
+
setQueriedAt((/* @__PURE__ */ new Date()).toISOString());
|
|
108494
|
+
setDirty(true);
|
|
108495
|
+
},
|
|
108496
|
+
disabled: loading || querying || saving || builtIn || !rows.length && !board,
|
|
108293
108497
|
children: busy ? "正在匹配器件…" : "查询华秋价格"
|
|
108294
108498
|
}),
|
|
108295
108499
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
@@ -108310,7 +108514,7 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108310
108514
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
108311
108515
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: "BOM 采购" }),
|
|
108312
108516
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: total }),
|
|
108313
|
-
|
|
108517
|
+
queriedAt && summary.lines > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [
|
|
108314
108518
|
summary.covered,
|
|
108315
108519
|
"/",
|
|
108316
108520
|
summary.lines,
|
|
@@ -108329,6 +108533,25 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108329
108533
|
role: "status",
|
|
108330
108534
|
children: message
|
|
108331
108535
|
}),
|
|
108536
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
108537
|
+
className: "ew-files",
|
|
108538
|
+
children: [
|
|
108539
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
108540
|
+
onClick: save,
|
|
108541
|
+
disabled: !rows.length || querying || saving || builtIn,
|
|
108542
|
+
children: saving ? "保存中…" : "保存 BOM"
|
|
108543
|
+
}),
|
|
108544
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
108545
|
+
disabled: !rows.length || querying,
|
|
108546
|
+
onClick: () => downloadBom(path, bomCsv(rows, matches, quantity, queriedAt)),
|
|
108547
|
+
children: "导出 CSV"
|
|
108548
|
+
}),
|
|
108549
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
108550
|
+
role: "status",
|
|
108551
|
+
children: saveError || (dirty ? "有未保存的更改" : saved ? "已保存 · " + new Date(saved.savedAt).toLocaleString("zh-CN") : "")
|
|
108552
|
+
})
|
|
108553
|
+
]
|
|
108554
|
+
}),
|
|
108332
108555
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BomGrid, {
|
|
108333
108556
|
rows,
|
|
108334
108557
|
matches,
|
|
@@ -108337,13 +108560,17 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108337
108560
|
busy,
|
|
108338
108561
|
summary,
|
|
108339
108562
|
select,
|
|
108340
|
-
|
|
108341
|
-
|
|
108342
|
-
|
|
108343
|
-
|
|
108344
|
-
|
|
108345
|
-
|
|
108346
|
-
|
|
108563
|
+
saving,
|
|
108564
|
+
choose: (key, selected) => {
|
|
108565
|
+
setDirty(true);
|
|
108566
|
+
setMatches((prev) => ({
|
|
108567
|
+
...prev,
|
|
108568
|
+
[key]: {
|
|
108569
|
+
...prev[key],
|
|
108570
|
+
selected
|
|
108571
|
+
}
|
|
108572
|
+
}));
|
|
108573
|
+
}
|
|
108347
108574
|
}),
|
|
108348
108575
|
part && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("footer", { children: [
|
|
108349
108576
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: ["位号 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
@@ -108533,7 +108760,19 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108533
108760
|
let live = true;
|
|
108534
108761
|
setError("");
|
|
108535
108762
|
loadProjects(cwd, void 0, session).then((result) => {
|
|
108536
|
-
if (live)
|
|
108763
|
+
if (!live) return;
|
|
108764
|
+
if (view === "design" && !result.selected) {
|
|
108765
|
+
const preferred = defaultCircuitProject(result.projects ?? [], result.cwd || cwd);
|
|
108766
|
+
if (preferred) {
|
|
108767
|
+
if (!selection.project) selection.project = preferred.path;
|
|
108768
|
+
setData({
|
|
108769
|
+
...result,
|
|
108770
|
+
selected: preferred
|
|
108771
|
+
});
|
|
108772
|
+
return;
|
|
108773
|
+
}
|
|
108774
|
+
}
|
|
108775
|
+
setData(result);
|
|
108537
108776
|
}).catch((e) => {
|
|
108538
108777
|
if (live) {
|
|
108539
108778
|
setData(void 0);
|
|
@@ -108546,7 +108785,9 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108546
108785
|
}, [
|
|
108547
108786
|
cwd,
|
|
108548
108787
|
session,
|
|
108549
|
-
reload
|
|
108788
|
+
reload,
|
|
108789
|
+
view,
|
|
108790
|
+
selection
|
|
108550
108791
|
]);
|
|
108551
108792
|
const projects = data?.projects ?? [];
|
|
108552
108793
|
const active = projects.find((p) => p.path === projectPath) ?? data?.selected ?? (projects.length === 1 ? projects[0] : void 0);
|
|
@@ -108942,6 +109183,7 @@ while (n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3] && n3 === a3[++i3]
|
|
|
108942
109183
|
tab: manufacturingTab,
|
|
108943
109184
|
path: sheet?.path || "",
|
|
108944
109185
|
board: board?.path || "",
|
|
109186
|
+
boardKey,
|
|
108945
109187
|
cwd,
|
|
108946
109188
|
session,
|
|
108947
109189
|
reference,
|
package/lib/host.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { execFile } from "node:child_process";
|
|
3
|
-
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import { lstat, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { tmpdir } from "node:os";
|
|
5
6
|
import { join } from "node:path";
|
|
6
7
|
import { promisify } from "node:util";
|
|
7
8
|
import { createRequire as createRequire$1 } from "module";
|
|
8
|
-
import { randomUUID } from "node:crypto";
|
|
9
9
|
//#region \0rolldown/runtime.js
|
|
10
10
|
var __create = Object.create;
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
@@ -7624,6 +7624,22 @@ function apply$1(ctx) {
|
|
|
7624
7624
|
}), "workbench navigation tool");
|
|
7625
7625
|
}
|
|
7626
7626
|
//#endregion
|
|
7627
|
+
//#region src/bom-snapshot.ts
|
|
7628
|
+
const object = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
7629
|
+
const optionalNumber = (x) => x == null || typeof x === "number" && Number.isFinite(x);
|
|
7630
|
+
const optionalString = (x) => x == null || typeof x === "string";
|
|
7631
|
+
function candidate(x) {
|
|
7632
|
+
return object(x) && typeof x.mpn === "string" && typeof x.manufacturerId === "string" && optionalString(x.manufacturer) && optionalString(x.package) && optionalString(x.huaqiuPn) && Array.isArray(x.offers) && x.offers.every((o) => object(o) && optionalString(o.vendor) && optionalString(o.sku) && optionalNumber(o.stock) && optionalNumber(o.moq) && Array.isArray(o.priceBreaks) && o.priceBreaks.every((t) => object(t) && optionalNumber(t.breakMin) && optionalNumber(t.breakMax) && object(t.prices) && optionalNumber(t.prices.rmb) && optionalNumber(t.prices.cny)));
|
|
7633
|
+
}
|
|
7634
|
+
function validSnapshot(x) {
|
|
7635
|
+
if (!object(x) || x.schema !== 1 || typeof x.quantity !== "number" || !Number.isInteger(x.quantity) || x.quantity < 1 || x.quantity > 1e5 || typeof x.queriedAt !== "string" || typeof x.boardKey !== "string" || !object(x.quotes) || typeof x.quotes.pcb !== "string" || typeof x.quotes.smt !== "string" || !Array.isArray(x.lines)) return false;
|
|
7636
|
+
return x.lines.every((line) => {
|
|
7637
|
+
if (!object(line) || !object(line.row)) return false;
|
|
7638
|
+
const r = line.row;
|
|
7639
|
+
return Array.isArray(r.references) && r.references.every((v) => typeof v === "string") && typeof r.value === "string" && typeof r.footprint === "string" && typeof r.dnp === "boolean" && typeof r.quantity === "number" && Number.isSafeInteger(r.quantity) && object(r.fields) && Object.values(r.fields).every((v) => typeof v === "string") && optionalString(line.error) && (line.candidates === void 0 || Array.isArray(line.candidates) && line.candidates.every(candidate) && typeof line.selection === "number" && Number.isInteger(line.selection) && line.selection >= -1 && line.selection < line.candidates.length);
|
|
7640
|
+
});
|
|
7641
|
+
}
|
|
7642
|
+
//#endregion
|
|
7627
7643
|
//#region src/manufacturing-host.mjs
|
|
7628
7644
|
const run = promisify(execFile);
|
|
7629
7645
|
const route = "/api/v1/engineering-workbench/manufacture";
|
|
@@ -7639,6 +7655,49 @@ const fields = [
|
|
|
7639
7655
|
"Huaqiu PN",
|
|
7640
7656
|
"华秋料号"
|
|
7641
7657
|
];
|
|
7658
|
+
const pendingSaves = /* @__PURE__ */ new Map();
|
|
7659
|
+
async function readSavedBom(file) {
|
|
7660
|
+
let info;
|
|
7661
|
+
try {
|
|
7662
|
+
info = await lstat(file);
|
|
7663
|
+
} catch (e) {
|
|
7664
|
+
if (e.code === "ENOENT") return null;
|
|
7665
|
+
throw e;
|
|
7666
|
+
}
|
|
7667
|
+
if (!info.isFile() || info.size > 25165824) throw new Error("BOM 保存文件无效或过大。");
|
|
7668
|
+
const saved = JSON.parse(await readFile(file, "utf8"));
|
|
7669
|
+
if (!validSnapshot(saved) || typeof saved.version !== "string" || typeof saved.savedAt !== "string") throw new Error("BOM 保存文件格式无效。");
|
|
7670
|
+
return saved;
|
|
7671
|
+
}
|
|
7672
|
+
async function saveBom(file, snapshot, expectedVersion) {
|
|
7673
|
+
if (!validSnapshot(snapshot)) throw new Error("BOM 数据格式无效,请刷新并重试。");
|
|
7674
|
+
const key = process.platform === "win32" ? file.toLowerCase() : file;
|
|
7675
|
+
const write = (pendingSaves.get(key) ?? Promise.resolve()).catch(() => {}).then(async () => {
|
|
7676
|
+
if (((await readSavedBom(file))?.version ?? null) !== expectedVersion) throw new Error("此 BOM 已在其他窗口更新,请重新打开后再保存。");
|
|
7677
|
+
const version = randomUUID(), savedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7678
|
+
const temp = file + "." + version + ".tmp";
|
|
7679
|
+
try {
|
|
7680
|
+
await writeFile(temp, JSON.stringify({
|
|
7681
|
+
...snapshot,
|
|
7682
|
+
version,
|
|
7683
|
+
savedAt
|
|
7684
|
+
}), "utf8");
|
|
7685
|
+
await rename(temp, file);
|
|
7686
|
+
} finally {
|
|
7687
|
+
await rm(temp, { force: true });
|
|
7688
|
+
}
|
|
7689
|
+
return {
|
|
7690
|
+
version,
|
|
7691
|
+
savedAt
|
|
7692
|
+
};
|
|
7693
|
+
});
|
|
7694
|
+
pendingSaves.set(key, write);
|
|
7695
|
+
try {
|
|
7696
|
+
return await write;
|
|
7697
|
+
} finally {
|
|
7698
|
+
if (pendingSaves.get(key) === write) pendingSaves.delete(key);
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7642
7701
|
async function exportText(service, source, kind, signal) {
|
|
7643
7702
|
const cli = service.installations().kicad?.cli;
|
|
7644
7703
|
if (!cli) throw new Error("请在「设置 → 硬件工程」配置 KiCad。");
|
|
@@ -7767,7 +7826,30 @@ async function manufacture(ctx, input, signal) {
|
|
|
7767
7826
|
artifactPath: path,
|
|
7768
7827
|
signal
|
|
7769
7828
|
});
|
|
7770
|
-
if (
|
|
7829
|
+
if (source.kind === "schematic" && (operation === "bom" || operation === "save-bom")) {
|
|
7830
|
+
const file = source.path + ".hq-bom.json";
|
|
7831
|
+
if (operation === "save-bom") return saveBom(file, input.snapshot, input.version);
|
|
7832
|
+
let saved = null, warning = "";
|
|
7833
|
+
try {
|
|
7834
|
+
saved = await readSavedBom(file);
|
|
7835
|
+
} catch (e) {
|
|
7836
|
+
warning = "无法读取已保存的 BOM。" + e.message;
|
|
7837
|
+
}
|
|
7838
|
+
try {
|
|
7839
|
+
return {
|
|
7840
|
+
...await exportText(hardware, source, "bom", signal),
|
|
7841
|
+
saved,
|
|
7842
|
+
warning
|
|
7843
|
+
};
|
|
7844
|
+
} catch (e) {
|
|
7845
|
+
if (!saved || signal.aborted) throw e;
|
|
7846
|
+
return {
|
|
7847
|
+
rows: saved.lines.map((l) => l.row),
|
|
7848
|
+
saved,
|
|
7849
|
+
warning: "无法重新生成原理图 BOM,当前显示上次保存的版本。" + e.message
|
|
7850
|
+
};
|
|
7851
|
+
}
|
|
7852
|
+
}
|
|
7771
7853
|
if (source.kind !== "pcb") throw new Error("请选择 PCB 文件。");
|
|
7772
7854
|
if (operation === "positions") return exportText(hardware, source, "positions", signal);
|
|
7773
7855
|
if (["pcb", "smt"].includes(operation) && Number.isSafeInteger(quantity) && quantity >= 1 && quantity <= 1e5) return quoteBoard(operation, source.text, quantity, signal);
|
|
@@ -7806,4 +7888,4 @@ function apply(ctx) {
|
|
|
7806
7888
|
}), "manufacturing preview and quotes"));
|
|
7807
7889
|
}
|
|
7808
7890
|
//#endregion
|
|
7809
|
-
export { apply, inject, manufacture, name, searchOffers };
|
|
7891
|
+
export { apply, inject, manufacture, name, saveBom, searchOffers };
|