From 35d5c3d70ed0098ad411ade471ae1f8cef4134e2 Mon Sep 17 00:00:00 2001 From: ywb <347742090@qq.com> Date: Fri, 22 May 2026 09:04:53 +0800 Subject: [PATCH] - --- agv_app/static/js/setting.js | 117 +++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/agv_app/static/js/setting.js b/agv_app/static/js/setting.js index 66315e2..7da9d0d 100644 --- a/agv_app/static/js/setting.js +++ b/agv_app/static/js/setting.js @@ -26,6 +26,9 @@ createApp({ newPointName: '', newPointMode: 'front', newPointSequence: ['front', 'back'], + // 点位编辑器弹窗 + editingPoint: null, + pointEditor: { x: 0, y: 0, yaw: 0 }, // 机型(姿态组) models: [], selectedModelId: null, @@ -254,6 +257,109 @@ createApp({ if (!angles) return '—' return angles.map(a => (a || 0).toFixed(1) + '°').join(' / ') }, + // === 点位编辑器弹窗 === + openPointEdit(ri, ci) { + const point = this.getPointAt(ri, ci) + this.editingPoint = { pointRow: ri, col: ci } + if (point && point.coords && point.coords.length >= 3) { + this.pointEditor = { x: point.coords[0], y: point.coords[1], yaw: point.coords[2] || 0 } + } else { + this.pointEditor = { x: 0, y: 0, yaw: 0 } + } + }, + closePointEdit() { + this.editingPoint = null + }, + getPointOwnerLabel(pointRow, col) { + const rows = this.missionConfig.rows || 0 + if (pointRow === 0) { + return `机器行1·正面` + } else if (pointRow >= rows) { + return `机器行${rows}·背面` + } else { + return `机器行${pointRow}·背面 + 机器行${pointRow+1}·正面` + } + }, + async loadPointFromAgv() { + try { + const res = await fetch(API + '/api/agv/position') + const data = await res.json() + if (data.ok && data.position) { + this.pointEditor.x = data.position.x || 0 + this.pointEditor.y = data.position.y || 0 + this.pointEditor.yaw = data.position.yaw || 0 + } else { + alert('读取AGV位置失败') + } + } catch (e) { alert('读取AGV位置失败: ' + e.message) } + }, + async savePoint() { + if (!this.editingPoint) return + const { pointRow, col } = this.editingPoint + const coords = [this.pointEditor.x, this.pointEditor.y, this.pointEditor.yaw] + const rows = this.missionConfig.rows || 0 + // 根据点位行确定 side + const sides = [] + if (pointRow === 0) { + sides.push('front') + } else if (pointRow >= rows) { + sides.push('back') + } else { + sides.push('back') + sides.push('front') + } + try { + for (const side of sides) { + const res = await fetch(API + '/api/mission/positions', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ row: pointRow, col, side, coords, poses: [] }) + }) + const data = await res.json() + if (!data.ok) { alert(`保存失败(${side}): ` + (data.error || '')); return } + } + alert('点位已保存') + await this.loadMissionConfig() + this.closePointEdit() + } catch (e) { alert('保存失败: ' + e.message) } + }, + async navigateToPoint() { + try { + const res = await fetch(API + '/api/navigate/to', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + x: this.pointEditor.x, + y: this.pointEditor.y, + yaw: this.pointEditor.yaw + }) + }) + const data = await res.json() + if (!data.ok) { alert('导航失败: ' + (data.error || '')) } + } catch (e) { alert('导航失败: ' + e.message) } + }, + async clearPoint() { + if (!this.editingPoint) return + const { pointRow, col } = this.editingPoint + const rows = this.missionConfig.rows || 0 + const sides = pointRow === 0 ? ['front'] : pointRow >= rows ? ['back'] : ['front', 'back'] + try { + for (const side of sides) { + await fetch(API + '/api/mission/positions', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ row: pointRow, col, side, coords: [0, 0, 0], poses: [] }) + }) + } + await this.loadMissionConfig() + this.closePointEdit() + } catch (e) { alert('清空失败: ' + e.message) } + }, + canClearPoint(pointRow, col) { + const point = this.getPointAt(pointRow, col) + if (!point || !point.coords) return true + return point.coords[0] === 0 && point.coords[1] === 0 + }, // === 机型管理 === async loadAllModels() { const res = await fetch(API + '/api/models/list') @@ -382,6 +488,7 @@ createApp({ this.missionConfig.rows = data.config.rows || 3 this.missionConfig.cols = data.config.cols || 3 this.missionConfig.grid = data.config.grid || [] + this.missionConfig.positions = data.config.positions || [] } } catch (e) { console.error('加载任务配置失败', e) } }, @@ -465,6 +572,16 @@ createApp({ this.selectMachine(m) } }, + toggleMachine(ri, ci, event) { + if (event.target.checked) { + // 无机器 → 创建机器 + this.createMachine(ri, ci) + } else { + // 有机器 → 删除机器 + const m = this.getMachineAt(ri, ci) + if (m) this.deleteMachine(m.id) + } + }, async createMachine(ri, ci) { try { const machineId = 'm_' + ri + '_' + ci