加入二维码设置
This commit is contained in:
+202
-3
@@ -45,13 +45,31 @@ createApp({
|
||||
agvMoveInterval: null,
|
||||
agvCameraUrl: API + '/api/camera/refresh',
|
||||
agvCameraTimer: null,
|
||||
// QR
|
||||
qrScanning: false,
|
||||
qrConfigs: [],
|
||||
qrScanningId: null,
|
||||
armCameraUrl: API + '/api/camera/arm_refresh',
|
||||
newQrName: '',
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.refresh()
|
||||
this.refreshAngles()
|
||||
this.loadQrConfigs()
|
||||
this.nav2Timer = setInterval(this.refreshNavStatus, 3000)
|
||||
},
|
||||
computed: {
|
||||
hasQr() {
|
||||
return !!(this.selectedMachine && this.selectedMachine.qr)
|
||||
},
|
||||
hasQrValue() {
|
||||
return !!(this.selectedMachine && this.selectedMachine.qr && this.selectedMachine.qr.qr_value)
|
||||
},
|
||||
hasQrModelId() {
|
||||
return !!(this.selectedMachine && this.selectedMachine.qr && this.selectedMachine.qr.model_id)
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
tab(val) {
|
||||
if (val === 'agv') {
|
||||
@@ -339,13 +357,22 @@ createApp({
|
||||
try {
|
||||
const res = await fetch(API + '/api/mission/machines')
|
||||
const data = await res.json()
|
||||
this.missionConfig.machines = data.machines || []
|
||||
this.missionConfig.machines = (data.machines || []).map(m => {
|
||||
if (!m.front) m.front = { coords: [0,0,0], poses: [] }
|
||||
if (!m.back) m.back = { coords: [0,0,0], poses: [] }
|
||||
if (!m.qr) m.qr = { coords: [0,0,0], qr_value: '', model_id: '' }
|
||||
return m
|
||||
})
|
||||
} catch (e) { console.error('加载机器列表失败', e) }
|
||||
},
|
||||
getMachineAt(ri, ci) {
|
||||
if (!this.missionConfig.machines) return null
|
||||
return this.missionConfig.machines.find(m => m.row === ri && m.col === ci) || null
|
||||
},
|
||||
getPointAt(ri, ci) {
|
||||
if (!this.missionConfig.positions) return null
|
||||
return this.missionConfig.positions.find(p => p.row === ri && p.col === ci) || null
|
||||
},
|
||||
getPositionAt(ri, ci) {
|
||||
if (!this.missionConfig.machines) return null
|
||||
const machine = this.getMachineAt(ri, ci)
|
||||
@@ -380,7 +407,8 @@ createApp({
|
||||
row: ri,
|
||||
col: ci,
|
||||
front: { coords: [0, 0, 0], poses: [] },
|
||||
back: { coords: [0, 0, 0], poses: [] }
|
||||
back: { coords: [0, 0, 0], poses: [] },
|
||||
qr: { coords: [0, 0, 0], qr_value: '', model_id: '' }
|
||||
})
|
||||
})
|
||||
const data = await res.json()
|
||||
@@ -397,6 +425,8 @@ createApp({
|
||||
else if (!Array.isArray(machine.front.coords)) machine.front.coords = [0, 0, 0]
|
||||
if (!machine.back) machine.back = { coords: [0, 0, 0], poses: [] }
|
||||
else if (!Array.isArray(machine.back.coords)) machine.back.coords = [0, 0, 0]
|
||||
if (!machine.qr) machine.qr = { coords: [0, 0, 0], qr_value: '', model_id: '' }
|
||||
else if (!Array.isArray(machine.qr.coords)) machine.qr.coords = [0, 0, 0]
|
||||
this.selectedMachine = machine
|
||||
},
|
||||
clearSelection() {
|
||||
@@ -418,7 +448,8 @@ createApp({
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
front: this.selectedMachine.front,
|
||||
back: this.selectedMachine.back
|
||||
back: this.selectedMachine.back,
|
||||
qr: this.selectedMachine.qr || { coords: [0, 0, 0], qr_value: '', model_id: '' }
|
||||
})
|
||||
})
|
||||
if (res.ok) {
|
||||
@@ -614,6 +645,174 @@ createApp({
|
||||
async agvStop() {
|
||||
await fetch(API + '/api/agv/stop', { method: 'POST' })
|
||||
},
|
||||
// === QR 安全访问器(避免 v-model 在 v-if 内因 Vue 编译器优化导致 undefined 报错)===
|
||||
machineHasQr(m) {
|
||||
if (!m || !m.qr || !m.qr.coords || m.qr.coords.length < 2) return false
|
||||
return m.qr.coords[0] !== 0 || m.qr.coords[1] !== 0
|
||||
},
|
||||
qrMarkerStyle(m) {
|
||||
if (!this.machineHasQr(m)) return { display: 'none' }
|
||||
return { left: this.getMapX(m.qr.coords) + '%', top: this.getMapY(m.qr.coords) + '%' }
|
||||
},
|
||||
qrMarkerTitle(m) {
|
||||
if (!m || !m.qr) return ''
|
||||
return 'QR: ' + (m.qr.qr_value || '未扫描')
|
||||
},
|
||||
safeQr(key) {
|
||||
if (!this.selectedMachine || !this.selectedMachine.qr) return ''
|
||||
return this.selectedMachine.qr[key] ?? ''
|
||||
},
|
||||
safeQrCoord(idx) {
|
||||
if (!this.selectedMachine || !this.selectedMachine.qr || !this.selectedMachine.qr.coords) return 0
|
||||
return this.selectedMachine.qr.coords[idx] !== undefined ? this.selectedMachine.qr.coords[idx] : 0
|
||||
},
|
||||
setQrCoord(idx, val) {
|
||||
if (this.selectedMachine && this.selectedMachine.qr && this.selectedMachine.qr.coords) {
|
||||
this.selectedMachine.qr.coords[idx] = val
|
||||
}
|
||||
},
|
||||
safeQrModelName() {
|
||||
if (!this.selectedMachine || !this.selectedMachine.qr || !this.selectedMachine.qr.model_id) return ''
|
||||
return this.getModelName(this.selectedMachine.qr.model_id)
|
||||
},
|
||||
// === QR 二维码 ===
|
||||
async readQRPosition() {
|
||||
if (!this.agvConnected) { alert('AGV 未连接'); return }
|
||||
try {
|
||||
const res = await fetch(API + '/api/agv/position')
|
||||
const data = await res.json()
|
||||
if (data.ok && data.position) {
|
||||
const [x, y, theta] = data.position
|
||||
if (!this.selectedMachine.qr) this.selectedMachine.qr = { coords: [0, 0, 0], qr_value: '', model_id: '' }
|
||||
this.selectedMachine.qr.coords = [x, y, theta]
|
||||
} else {
|
||||
alert('读取位置失败: ' + (data.error || '未知错误'))
|
||||
}
|
||||
} catch (e) { alert('读取位置失败: ' + e.message) }
|
||||
},
|
||||
async scanQRCode(machineId) {
|
||||
if (!this.cameraOpened) { alert('AGV 摄像头未打开'); return }
|
||||
this.qrScanning = true
|
||||
try {
|
||||
const res = await fetch(API + '/api/mission/qr_scan/' + machineId, { method: 'POST' })
|
||||
const data = await res.json()
|
||||
if (data.ok) {
|
||||
await this.loadAllMachines()
|
||||
const updated = this.getMachineAt(this.selectedMachine.row, this.selectedMachine.col)
|
||||
if (updated) this.selectMachine(updated)
|
||||
let msg = '✅ 扫描成功: ' + data.qr_value
|
||||
if (data.model_name) msg += ' → 匹配机型: ' + data.model_name
|
||||
else msg += ' → 未匹配到机型'
|
||||
alert(msg)
|
||||
} else {
|
||||
alert('❌ ' + (data.error || '扫描失败'))
|
||||
}
|
||||
} catch (e) { alert('扫描失败: ' + e.message) }
|
||||
this.qrScanning = false
|
||||
},
|
||||
// ========== 二维码配置(独立 Tab)==========
|
||||
async loadQrConfigs() {
|
||||
try {
|
||||
const res = await fetch(API + '/api/qr/configs')
|
||||
const data = await res.json()
|
||||
this.qrConfigs = (data.configs || []).map(c => {
|
||||
// 兼容旧版的 coords → 转为 joint_angles
|
||||
if (!c.joint_angles || !Array.isArray(c.joint_angles)) {
|
||||
c.joint_angles = [0, 0, 0, 0, 0, 0]
|
||||
}
|
||||
return c
|
||||
})
|
||||
} catch (e) { console.error('加载二维码配置失败', e) }
|
||||
},
|
||||
async addQrConfig() {
|
||||
const name = this.newQrName.trim() || ''
|
||||
try {
|
||||
const res = await fetch(API + '/api/qr/configs', {
|
||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ name: name || undefined })
|
||||
})
|
||||
const data = await res.json()
|
||||
if (data.ok) {
|
||||
this.qrConfigs.push(data.entry)
|
||||
this.newQrName = ''
|
||||
}
|
||||
} catch (e) { alert('添加失败: ' + e.message) }
|
||||
},
|
||||
getQrAngle(q, idx) {
|
||||
if (!q || !q.joint_angles || !Array.isArray(q.joint_angles)) return 0
|
||||
return q.joint_angles[idx] !== undefined ? q.joint_angles[idx] : 0
|
||||
},
|
||||
async updateQrAngle(qrId, idx, val) {
|
||||
const q = this.qrConfigs.find(x => x.id === qrId)
|
||||
if (!q) return
|
||||
if (!q.joint_angles || !Array.isArray(q.joint_angles)) q.joint_angles = [0,0,0,0,0,0]
|
||||
q.joint_angles[idx] = parseFloat(val) || 0
|
||||
try {
|
||||
await fetch(API + '/api/qr/configs/' + qrId, {
|
||||
method: 'PUT', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ joint_angles: q.joint_angles })
|
||||
})
|
||||
} catch (e) { console.error('保存角度失败', e) }
|
||||
},
|
||||
async readQrAngles(qrId) {
|
||||
if (!this.armConnected) { alert('机械臂未连接'); return }
|
||||
try {
|
||||
const res = await fetch(API + '/api/qr/configs/' + qrId + '/read-angles', { method: 'POST' })
|
||||
const data = await res.json()
|
||||
if (data.ok) {
|
||||
const q = this.qrConfigs.find(x => x.id === qrId)
|
||||
if (q && data.joint_angles) {
|
||||
q.joint_angles = data.joint_angles
|
||||
}
|
||||
} else {
|
||||
alert('读取角度失败: ' + (data.error || '未知错误'))
|
||||
}
|
||||
} catch (e) { alert('读取角度失败: ' + e.message) }
|
||||
},
|
||||
async saveQrConfig(qrId) {
|
||||
const q = this.qrConfigs.find(x => x.id === qrId)
|
||||
if (!q) return
|
||||
try {
|
||||
const res = await fetch(API + '/api/qr/configs/' + qrId, {
|
||||
method: 'PUT', headers: {'Content-Type':'application/json'},
|
||||
body: JSON.stringify({ name: q.name })
|
||||
})
|
||||
if (!res.ok) alert('保存名称失败')
|
||||
} catch (e) { alert('保存失败: ' + e.message) }
|
||||
},
|
||||
async deleteQrConfig(qrId) {
|
||||
if (!confirm('确定删除此二维码点位?')) return
|
||||
try {
|
||||
await fetch(API + '/api/qr/configs/' + qrId, { method: 'DELETE' })
|
||||
this.qrConfigs = this.qrConfigs.filter(x => x.id !== qrId)
|
||||
} catch (e) { alert('删除失败: ' + e.message) }
|
||||
},
|
||||
getQrModelName(modelId) {
|
||||
const model = this.models.find(m => m.id === modelId)
|
||||
return model ? model.name : ''
|
||||
},
|
||||
getModelName(modelId) {
|
||||
const model = this.models.find(m => m.id === modelId)
|
||||
return model ? model.name : ''
|
||||
},
|
||||
async scanQrEntry(qrId) {
|
||||
this.qrScanningId = qrId
|
||||
try {
|
||||
const res = await fetch(API + '/api/qr/scan/' + qrId, { method: 'POST' })
|
||||
const data = await res.json()
|
||||
if (data.ok) {
|
||||
await this.loadQrConfigs()
|
||||
let msg = '扫描成功: ' + data.qr_value
|
||||
if (data.model_name) msg += ' 匹配机型: ' + data.model_name
|
||||
else msg += ' 未匹配到机型'
|
||||
alert(msg)
|
||||
} else { alert(data.error || '扫描失败') }
|
||||
} catch (e) { alert('扫描失败: ' + e.message) }
|
||||
this.qrScanningId = null
|
||||
},
|
||||
onArmPreviewError() {
|
||||
// 机械臂摄像头预览失败,静默处理
|
||||
},
|
||||
async agvResetCollision() {
|
||||
if (!this.agvConnected) {
|
||||
alert('AGV 未连接')
|
||||
|
||||
Reference in New Issue
Block a user