This commit is contained in:
ywb
2026-05-22 09:04:53 +08:00
parent 2b627228fb
commit 35d5c3d70e
+117
View File
@@ -26,6 +26,9 @@ createApp({
newPointName: '', newPointName: '',
newPointMode: 'front', newPointMode: 'front',
newPointSequence: ['front', 'back'], newPointSequence: ['front', 'back'],
// 点位编辑器弹窗
editingPoint: null,
pointEditor: { x: 0, y: 0, yaw: 0 },
// 机型(姿态组) // 机型(姿态组)
models: [], models: [],
selectedModelId: null, selectedModelId: null,
@@ -254,6 +257,109 @@ createApp({
if (!angles) return '—' if (!angles) return '—'
return angles.map(a => (a || 0).toFixed(1) + '°').join(' / ') 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() { async loadAllModels() {
const res = await fetch(API + '/api/models/list') const res = await fetch(API + '/api/models/list')
@@ -382,6 +488,7 @@ createApp({
this.missionConfig.rows = data.config.rows || 3 this.missionConfig.rows = data.config.rows || 3
this.missionConfig.cols = data.config.cols || 3 this.missionConfig.cols = data.config.cols || 3
this.missionConfig.grid = data.config.grid || [] this.missionConfig.grid = data.config.grid || []
this.missionConfig.positions = data.config.positions || []
} }
} catch (e) { console.error('加载任务配置失败', e) } } catch (e) { console.error('加载任务配置失败', e) }
}, },
@@ -465,6 +572,16 @@ createApp({
this.selectMachine(m) 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) { async createMachine(ri, ci) {
try { try {
const machineId = 'm_' + ri + '_' + ci const machineId = 'm_' + ri + '_' + ci