app.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. const parseResponse = async (r) => {
  2. const contentType = r.headers.get('content-type') || '';
  3. if (contentType.includes('application/json')) {
  4. return r.json();
  5. }
  6. const text = await r.text();
  7. return text ? { text } : {};
  8. };
  9. const API = {
  10. get: async (url) => {
  11. const r = await fetch(url);
  12. if (!r.ok) {
  13. const text = await r.text();
  14. throw new Error(`${url}: ${r.status} ${text}`);
  15. }
  16. return parseResponse(r);
  17. },
  18. post: async (url, body = {}) => {
  19. const r = await fetch(url, {
  20. method: 'POST',
  21. headers: { 'Content-Type': 'application/json' },
  22. body: JSON.stringify(body)
  23. });
  24. if (!r.ok) {
  25. const text = await r.text();
  26. throw new Error(`${url}: ${r.status} ${text}`);
  27. }
  28. return parseResponse(r);
  29. },
  30. del: async (url) => {
  31. const r = await fetch(url, { method: 'DELETE' });
  32. if (!r.ok) {
  33. const text = await r.text();
  34. throw new Error(`${url}: ${r.status} ${text}`);
  35. }
  36. return parseResponse(r);
  37. }
  38. };
  39. let currentGroup = null;
  40. let scanPollInterval = null;
  41. let controlsGloballyDisabled = false;
  42. let tempPreview = null;
  43. let selectedSampleEl = null;
  44. function log(msg) {
  45. const panel = document.getElementById('log-panel');
  46. const line = document.createElement('div');
  47. line.textContent = `${new Date().toLocaleTimeString()} ${msg}`;
  48. panel.appendChild(line);
  49. while (panel.children.length > 200) {
  50. panel.removeChild(panel.firstChild);
  51. }
  52. panel.scrollTop = panel.scrollHeight;
  53. }
  54. function setStatus(msg) {
  55. document.getElementById('status').textContent = `状态:${msg}`;
  56. }
  57. function setControlsDisabled(disabled) {
  58. controlsGloballyDisabled = disabled;
  59. ['btn-scan', 'btn-poll-start', 'btn-poll-stop', 'btn-preview', 'btn-add'].forEach(id => {
  60. const el = document.getElementById(id);
  61. if (el) el.disabled = disabled;
  62. });
  63. ['inp-pan', 'inp-tilt', 'inp-zoom', 'inp-dwell'].forEach(id => {
  64. const el = document.getElementById(id);
  65. if (el) el.disabled = disabled;
  66. });
  67. }
  68. async function withDisabled(id, fn) {
  69. const el = document.getElementById(id);
  70. el.disabled = true;
  71. try {
  72. return await fn();
  73. } finally {
  74. if (!controlsGloballyDisabled) {
  75. el.disabled = false;
  76. }
  77. }
  78. }
  79. function parseStrictFloat(value, name) {
  80. const num = Number(value);
  81. if (!Number.isFinite(num)) {
  82. throw new Error(`${name} 必须是有效数字`);
  83. }
  84. return num;
  85. }
  86. function escapeHtml(text) {
  87. const div = document.createElement('div');
  88. div.textContent = text;
  89. return div.innerHTML;
  90. }
  91. function setSelectedPreview(url) {
  92. const img = document.getElementById('selected-preview');
  93. if (url) {
  94. img.src = url;
  95. img.style.display = 'block';
  96. } else {
  97. img.src = '';
  98. img.style.display = 'none';
  99. }
  100. }
  101. function selectSample(sample) {
  102. document.getElementById('inp-pan').value = sample.pan.toFixed(2);
  103. document.getElementById('inp-tilt').value = sample.tilt.toFixed(2);
  104. document.getElementById('inp-zoom').value = sample.zoom;
  105. tempPreview = { path: sample.thumbnail };
  106. setSelectedPreview(`/api/sample-image?path=${encodeURIComponent(sample.thumbnail)}`);
  107. if (sampleCanvas) sampleCanvas.setSelected(sample.pan, sample.tilt);
  108. }
  109. class SampleCanvas {
  110. constructor(canvasId, wrapperId) {
  111. this.canvas = document.getElementById(canvasId);
  112. this.wrapper = document.getElementById(wrapperId);
  113. this.ctx = this.canvas.getContext('2d');
  114. this.samples = [];
  115. this.pans = [];
  116. this.tilts = [];
  117. this.sampleMap = new Map();
  118. this.images = new Map();
  119. this.cellW = 160;
  120. this.cellH = 120;
  121. this.captionH = 20;
  122. this.scale = 1;
  123. this.offsetX = 0;
  124. this.offsetY = 0;
  125. this.selectedPan = null;
  126. this.selectedTilt = null;
  127. this.isDragging = false;
  128. this.dragStart = { x: 0, y: 0, ox: 0, oy: 0 };
  129. this.pendingDraw = false;
  130. this.resize();
  131. window.addEventListener('resize', () => this.resize());
  132. this.setupEvents();
  133. }
  134. resize() {
  135. const rect = this.wrapper.getBoundingClientRect();
  136. this.canvas.width = rect.width;
  137. this.canvas.height = rect.height;
  138. this.draw();
  139. }
  140. setSamples(samples) {
  141. this.samples = samples || [];
  142. this.pans = Array.from(new Set(this.samples.map(s => s.pan))).sort((a, b) => a - b);
  143. this.tilts = Array.from(new Set(this.samples.map(s => s.tilt))).sort((a, b) => b - a);
  144. this.sampleMap = new Map();
  145. this.samples.forEach(s => this.sampleMap.set(`${s.pan},${s.tilt}`, s));
  146. this.images = new Map();
  147. this.samples.forEach(s => {
  148. const img = new Image();
  149. img.crossOrigin = 'anonymous';
  150. img.src = `/api/sample-image?path=${encodeURIComponent(s.thumbnail)}`;
  151. img.onload = () => this.draw();
  152. this.images.set(`${s.pan},${s.tilt}`, img);
  153. });
  154. this.fitToView();
  155. this.draw();
  156. }
  157. contentWidth() {
  158. return this.pans.length * this.cellW;
  159. }
  160. contentHeight() {
  161. return this.tilts.length * (this.cellH + this.captionH);
  162. }
  163. fitToView() {
  164. const pw = this.canvas.width / this.contentWidth();
  165. const ph = this.canvas.height / this.contentHeight();
  166. this.scale = Math.min(pw, ph, 1);
  167. this.offsetX = (this.canvas.width - this.contentWidth() * this.scale) / 2;
  168. this.offsetY = (this.canvas.height - this.contentHeight() * this.scale) / 2;
  169. this.updateZoomLabel();
  170. }
  171. resetView() {
  172. this.fitToView();
  173. this.draw();
  174. }
  175. updateZoomLabel() {
  176. const label = document.getElementById('zoom-level');
  177. if (label) label.textContent = `${Math.round(this.scale * 100)}%`;
  178. }
  179. setupEvents() {
  180. this.canvas.addEventListener('wheel', (e) => {
  181. e.preventDefault();
  182. const rect = this.canvas.getBoundingClientRect();
  183. const mx = e.clientX - rect.left;
  184. const my = e.clientY - rect.top;
  185. const factor = e.deltaY < 0 ? 1.1 : 0.9;
  186. const newScale = Math.max(0.1, Math.min(5.0, this.scale * factor));
  187. this.offsetX = mx - (mx - this.offsetX) * (newScale / this.scale);
  188. this.offsetY = my - (my - this.offsetY) * (newScale / this.scale);
  189. this.scale = newScale;
  190. this.updateZoomLabel();
  191. this.draw();
  192. }, { passive: false });
  193. this.canvas.addEventListener('mousedown', (e) => {
  194. if (e.button !== 0) return;
  195. this.isDragging = true;
  196. this.dragStart = { x: e.clientX, y: e.clientY, ox: this.offsetX, oy: this.offsetY };
  197. this.wrapper.style.cursor = 'grabbing';
  198. });
  199. window.addEventListener('mousemove', (e) => {
  200. if (!this.isDragging) return;
  201. this.offsetX = this.dragStart.ox + (e.clientX - this.dragStart.x);
  202. this.offsetY = this.dragStart.oy + (e.clientY - this.dragStart.y);
  203. this.draw();
  204. });
  205. window.addEventListener('mouseup', () => {
  206. if (this.isDragging) {
  207. this.isDragging = false;
  208. this.wrapper.style.cursor = 'grab';
  209. }
  210. });
  211. this.canvas.addEventListener('click', (e) => {
  212. if (this.isDragging) return;
  213. const rect = this.canvas.getBoundingClientRect();
  214. const mx = e.clientX - rect.left;
  215. const my = e.clientY - rect.top;
  216. const worldX = (mx - this.offsetX) / this.scale;
  217. const worldY = (my - this.offsetY) / this.scale;
  218. const col = Math.floor(worldX / this.cellW);
  219. const row = Math.floor(worldY / (this.cellH + this.captionH));
  220. if (col < 0 || col >= this.pans.length || row < 0 || row >= this.tilts.length) return;
  221. const pan = this.pans[col];
  222. const tilt = this.tilts[row];
  223. const s = this.sampleMap.get(`${pan},${tilt}`);
  224. if (s) selectSample(s);
  225. });
  226. }
  227. setSelected(pan, tilt) {
  228. this.selectedPan = pan;
  229. this.selectedTilt = tilt;
  230. this.draw();
  231. }
  232. draw() {
  233. if (this.pendingDraw) return;
  234. this.pendingDraw = true;
  235. requestAnimationFrame(() => {
  236. this.pendingDraw = false;
  237. this._draw();
  238. });
  239. }
  240. _draw() {
  241. const ctx = this.ctx;
  242. const w = this.canvas.width;
  243. const h = this.canvas.height;
  244. ctx.clearRect(0, 0, w, h);
  245. if (this.samples.length === 0) {
  246. ctx.fillStyle = '#94a3b8';
  247. ctx.font = '14px sans-serif';
  248. ctx.fillText('暂无扫描样本,请先执行 360° 扫描', 20, 30);
  249. return;
  250. }
  251. const rowH = this.cellH + this.captionH;
  252. const startCol = Math.floor((-this.offsetX / this.scale) / this.cellW);
  253. const endCol = Math.ceil((w - this.offsetX) / this.scale / this.cellW);
  254. const startRow = Math.floor((-this.offsetY / this.scale) / rowH);
  255. const endRow = Math.ceil((h - this.offsetY) / this.scale / rowH);
  256. ctx.save();
  257. ctx.translate(this.offsetX, this.offsetY);
  258. ctx.scale(this.scale, this.scale);
  259. for (let r = Math.max(0, startRow); r <= Math.min(this.tilts.length - 1, endRow); r++) {
  260. for (let c = Math.max(0, startCol); c <= Math.min(this.pans.length - 1, endCol); c++) {
  261. const pan = this.pans[c];
  262. const tilt = this.tilts[r];
  263. const x = c * this.cellW;
  264. const y = r * rowH;
  265. const s = this.sampleMap.get(`${pan},${tilt}`);
  266. ctx.fillStyle = '#0f172a';
  267. ctx.fillRect(x, y, this.cellW, rowH);
  268. const img = this.images.get(`${pan},${tilt}`);
  269. if (img && img.complete && img.naturalWidth) {
  270. const sx = 0, sy = 0, sw = img.naturalWidth, sh = img.naturalHeight;
  271. const dw = this.cellW - 4;
  272. const dh = this.cellH - 4;
  273. const scale = Math.min(dw / sw, dh / sh);
  274. const iw = sw * scale;
  275. const ih = sh * scale;
  276. const ix = x + 2 + (dw - iw) / 2;
  277. const iy = y + 2 + (dh - ih) / 2;
  278. ctx.drawImage(img, ix, iy, iw, ih);
  279. } else {
  280. ctx.fillStyle = '#1e293b';
  281. ctx.fillRect(x + 2, y + 2, this.cellW - 4, this.cellH - 4);
  282. }
  283. ctx.fillStyle = '#cbd5e1';
  284. ctx.font = '11px sans-serif';
  285. ctx.textAlign = 'center';
  286. ctx.fillText(`P:${pan.toFixed(0)} T:${tilt.toFixed(0)}`, x + this.cellW / 2, y + this.cellH + 14);
  287. if (this.selectedPan === pan && this.selectedTilt === tilt) {
  288. ctx.strokeStyle = '#22c55e';
  289. ctx.lineWidth = 2;
  290. ctx.strokeRect(x + 1, y + 1, this.cellW - 2, rowH - 2);
  291. }
  292. }
  293. }
  294. ctx.restore();
  295. }
  296. }
  297. let sampleCanvas = null;
  298. async function loadSamples(groupId) {
  299. try {
  300. const data = await API.get(`/api/samples/${groupId}`);
  301. if (!sampleCanvas) {
  302. sampleCanvas = new SampleCanvas('sample-canvas', 'sample-grid-wrapper');
  303. }
  304. sampleCanvas.setSamples(data.samples || []);
  305. } catch (e) {
  306. log(`加载扫描样本失败: ${e.message}`);
  307. }
  308. }
  309. async function loadGroups() {
  310. try {
  311. const status = await API.get('/api/status');
  312. const select = document.getElementById('group-select');
  313. select.innerHTML = '';
  314. const gids = Object.keys(status.groups || {});
  315. gids.forEach(gid => {
  316. const opt = document.createElement('option');
  317. opt.value = gid;
  318. opt.textContent = gid;
  319. select.appendChild(opt);
  320. });
  321. if (gids.length === 0) {
  322. currentGroup = null;
  323. setStatus('未配置摄像头组');
  324. setControlsDisabled(true);
  325. return;
  326. }
  327. setControlsDisabled(false);
  328. if (gids.includes(currentGroup)) {
  329. select.value = currentGroup;
  330. } else {
  331. currentGroup = select.options[0].value;
  332. onGroupChange();
  333. }
  334. } catch (e) {
  335. log(`获取状态失败: ${e.message}`);
  336. }
  337. }
  338. function resetSampleZoom() {
  339. if (sampleCanvas) sampleCanvas.resetView();
  340. }
  341. function onGroupChange() {
  342. currentGroup = document.getElementById('group-select').value;
  343. selectedSampleEl = null;
  344. tempPreview = null;
  345. setSelectedPreview(null);
  346. resetSampleZoom();
  347. loadSamples(currentGroup);
  348. renderVideos(currentGroup);
  349. loadPoints(currentGroup);
  350. }
  351. function renderVideos(groupId) {
  352. const grid = document.getElementById('video-grid');
  353. grid.innerHTML = '';
  354. ['panorama', 'ptz'].forEach(cam => {
  355. const box = document.createElement('div');
  356. box.className = 'video-box';
  357. const title = document.createElement('div');
  358. title.className = 'title';
  359. title.textContent = `${cam} - ${groupId}`;
  360. const img = document.createElement('img');
  361. img.src = `/api/live/${cam}/${groupId}?marked=1&t=${Date.now()}`;
  362. img.alt = cam;
  363. box.appendChild(title);
  364. box.appendChild(img);
  365. grid.appendChild(box);
  366. });
  367. }
  368. async function loadPoints(groupId) {
  369. try {
  370. const data = await API.get(`/api/points/${groupId}`);
  371. const ul = document.getElementById('points');
  372. ul.innerHTML = '';
  373. data.points.forEach(p => {
  374. const li = document.createElement('li');
  375. const span = document.createElement('span');
  376. span.textContent = `P:${p.pan.toFixed(0)} T:${p.tilt.toFixed(0)}`;
  377. const previewBtn = document.createElement('button');
  378. previewBtn.textContent = '预览';
  379. previewBtn.onclick = async () => {
  380. document.getElementById('inp-pan').value = p.pan.toFixed(2);
  381. document.getElementById('inp-tilt').value = p.tilt.toFixed(2);
  382. document.getElementById('inp-zoom').value = p.zoom;
  383. await runPreview(groupId, p.pan, p.tilt, p.zoom, p.id);
  384. };
  385. const delBtn = document.createElement('button');
  386. delBtn.dataset.id = String(p.id);
  387. delBtn.textContent = '删除';
  388. delBtn.onclick = async () => {
  389. if (!currentGroup) {
  390. log('未选择摄像头组');
  391. return;
  392. }
  393. if (!confirm('确定删除该扫描点?')) return;
  394. delBtn.disabled = true;
  395. try {
  396. await API.del(`/api/points/${groupId}/${p.id}`);
  397. loadPoints(groupId);
  398. } catch (e) {
  399. log(`删除失败: ${e.message}`);
  400. delBtn.disabled = false;
  401. }
  402. };
  403. li.appendChild(span);
  404. li.appendChild(previewBtn);
  405. li.appendChild(delBtn);
  406. ul.appendChild(li);
  407. });
  408. } catch (e) {
  409. log(`加载扫描点失败: ${e.message}`);
  410. }
  411. }
  412. async function updateStatus() {
  413. if (!currentGroup) return;
  414. try {
  415. const status = await API.get('/api/status');
  416. const g = status.groups[currentGroup];
  417. if (g) {
  418. setStatus(g.polling_state);
  419. }
  420. } catch (e) {
  421. // ignore
  422. }
  423. }
  424. document.getElementById('group-select').addEventListener('change', onGroupChange);
  425. document.getElementById('btn-scan').addEventListener('click', async () => {
  426. if (!currentGroup) {
  427. log('未选择摄像头组');
  428. return;
  429. }
  430. if (scanPollInterval) return;
  431. const scannedGroup = currentGroup;
  432. const scanBtn = document.getElementById('btn-scan');
  433. scanBtn.disabled = true;
  434. setStatus('扫描中...');
  435. try {
  436. await API.post(`/api/scan/${scannedGroup}`);
  437. log(`开始扫描: ${scannedGroup}`);
  438. scanPollInterval = setInterval(async () => {
  439. try {
  440. const prog = await API.get(`/api/scan/${scannedGroup}/progress`);
  441. const progress = prog.total > 0 ? (prog.current / prog.total) * 100 : 0;
  442. if (prog.state === 'done' || prog.state === 'failed' || progress >= 100) {
  443. clearInterval(scanPollInterval);
  444. scanPollInterval = null;
  445. if (!controlsGloballyDisabled) scanBtn.disabled = false;
  446. if (prog.state === 'done') {
  447. log('扫描完成');
  448. resetSampleZoom();
  449. loadSamples(scannedGroup);
  450. loadPoints(scannedGroup);
  451. } else if (prog.state === 'failed') {
  452. log(`扫描失败: ${prog.error || 'unknown'}`);
  453. }
  454. } else {
  455. setStatus(`扫描中... ${progress.toFixed(0)}%`);
  456. }
  457. } catch (e) {
  458. clearInterval(scanPollInterval);
  459. scanPollInterval = null;
  460. if (!controlsGloballyDisabled) scanBtn.disabled = false;
  461. setStatus('扫描失败');
  462. log(`扫描进度获取失败: ${e.message}`);
  463. }
  464. }, 1000);
  465. } catch (e) {
  466. log(`扫描失败: ${e.message}`);
  467. if (!controlsGloballyDisabled) scanBtn.disabled = false;
  468. setStatus('扫描失败');
  469. }
  470. });
  471. document.getElementById('btn-poll-start').addEventListener('click', async () => {
  472. if (!currentGroup) {
  473. log('未选择摄像头组');
  474. return;
  475. }
  476. await withDisabled('btn-poll-start', async () => {
  477. try {
  478. await API.post(`/api/poll/${currentGroup}/start`);
  479. log(`开始轮询: ${currentGroup}`);
  480. } catch (e) {
  481. log(`轮询启动失败: ${e.message}`);
  482. }
  483. });
  484. });
  485. document.getElementById('btn-poll-stop').addEventListener('click', async () => {
  486. if (!currentGroup) {
  487. log('未选择摄像头组');
  488. return;
  489. }
  490. await withDisabled('btn-poll-stop', async () => {
  491. try {
  492. await API.post(`/api/poll/${currentGroup}/stop`);
  493. log(`停止轮询: ${currentGroup}`);
  494. } catch (e) {
  495. log(`停止失败: ${e.message}`);
  496. }
  497. });
  498. });
  499. async function runPreview(groupId, pan, tilt, zoom, pointId = null) {
  500. const payload = { pan, tilt, zoom };
  501. const result = await API.post(`/api/preview/${groupId}`, payload);
  502. log(`预览位置: P=${pan.toFixed(1)} T=${tilt.toFixed(1)} Z=${zoom}`);
  503. if (result.snapshot_url) {
  504. log(`预览抓拍已保存: ${result.snapshot_path}`);
  505. // 预览抓拍显示在右侧,但不更新保存点图片
  506. setSelectedPreview(result.snapshot_url);
  507. tempPreview = { path: result.snapshot_path };
  508. }
  509. return result;
  510. }
  511. document.getElementById('btn-preview').addEventListener('click', async () => {
  512. if (!currentGroup) {
  513. log('未选择摄像头组');
  514. return;
  515. }
  516. let pan, tilt, zoom;
  517. try {
  518. pan = parseStrictFloat(document.getElementById('inp-pan').value, 'pan');
  519. tilt = parseStrictFloat(document.getElementById('inp-tilt').value, 'tilt');
  520. zoom = Number(document.getElementById('inp-zoom').value);
  521. } catch (e) {
  522. log(`错误:${e.message}`);
  523. return;
  524. }
  525. if (!Number.isInteger(zoom) || zoom < 1) {
  526. log('错误:zoom 必须是大于等于 1 的整数');
  527. return;
  528. }
  529. await withDisabled('btn-preview', async () => {
  530. try {
  531. await runPreview(currentGroup, pan, tilt, zoom);
  532. } catch (e) {
  533. log(`预览失败: ${e.message}`);
  534. }
  535. });
  536. });
  537. document.getElementById('btn-add').addEventListener('click', async () => {
  538. if (!currentGroup) {
  539. log('未选择摄像头组');
  540. return;
  541. }
  542. await withDisabled('btn-add', async () => {
  543. let pan, tilt, zoom, dwellTime;
  544. try {
  545. pan = parseStrictFloat(document.getElementById('inp-pan').value, 'pan');
  546. tilt = parseStrictFloat(document.getElementById('inp-tilt').value, 'tilt');
  547. zoom = Number(document.getElementById('inp-zoom').value);
  548. dwellTime = parseStrictFloat(document.getElementById('inp-dwell').value, '停留时间');
  549. } catch (e) {
  550. log(`错误:${e.message}`);
  551. return;
  552. }
  553. if (pan < 0 || pan > 360) {
  554. log('错误:pan 必须是 0-360 之间的有限数值');
  555. return;
  556. }
  557. if (tilt < -90 || tilt > 90) {
  558. log('错误:tilt 必须是 -90-90 之间的有限数值');
  559. return;
  560. }
  561. if (!Number.isInteger(zoom) || zoom < 1) {
  562. log('错误:zoom 必须是大于等于 1 的整数');
  563. return;
  564. }
  565. if (dwellTime <= 0) {
  566. log('错误:停留时间必须是大于 0 的有限数值');
  567. return;
  568. }
  569. const payload = { pan, tilt, zoom, dwell_time: dwellTime };
  570. if (tempPreview) {
  571. payload.preview_image = tempPreview.path;
  572. }
  573. try {
  574. await API.post(`/api/points/${currentGroup}`, payload);
  575. log('扫描点已保存');
  576. selectedSampleEl = null;
  577. tempPreview = null;
  578. setSelectedPreview(null);
  579. loadPoints(currentGroup);
  580. } catch (e) {
  581. log(`保存失败: ${e.message}`);
  582. }
  583. });
  584. });
  585. document.getElementById('btn-zoom-in').addEventListener('click', () => {
  586. if (sampleCanvas) {
  587. sampleCanvas.scale = Math.min(5.0, sampleCanvas.scale * 1.2);
  588. sampleCanvas.updateZoomLabel();
  589. sampleCanvas.draw();
  590. }
  591. });
  592. document.getElementById('btn-zoom-out').addEventListener('click', () => {
  593. if (sampleCanvas) {
  594. sampleCanvas.scale = Math.max(0.1, sampleCanvas.scale / 1.2);
  595. sampleCanvas.updateZoomLabel();
  596. sampleCanvas.draw();
  597. }
  598. });
  599. document.getElementById('btn-zoom-reset').addEventListener('click', () => {
  600. resetSampleZoom();
  601. });
  602. setControlsDisabled(true);
  603. loadGroups();
  604. setInterval(updateStatus, 2000);