This commit is contained in:
ywb
2026-05-14 21:43:35 +08:00
commit 94c1043f4d
40 changed files with 8602 additions and 0 deletions
+722
View File
@@ -0,0 +1,722 @@
/* ========== 全局样式 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
background: #0f1923;
color: #e8eaed;
font-size: 14px;
min-height: 100vh;
}
a { color: #4fc3f7; text-decoration: none; }
a:hover { text-decoration: underline; }
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px 16px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
/* ========== 顶部栏 ========== */
.topbar {
background: #1a2332;
border-bottom: 1px solid #2a3441;
padding: 0 20px;
display: flex;
align-items: center;
height: 56px;
gap: 32px;
position: sticky;
top: 0;
z-index: 100;
}
.logo { font-size: 18px; font-weight: bold; color: #4fc3f7; }
.nav { display: flex; gap: 4px; }
.nav-link {
padding: 8px 16px;
border-radius: 6px;
color: #9aa0a6;
transition: all 0.2s;
}
.nav-link:hover { background: #2a3441; color: #e8eaed; text-decoration: none; }
.nav-link.active { background: #263238; color: #4fc3f7; }
.status-bar { margin-left: auto; display: flex; gap: 12px; }
.status-item {
padding: 4px 12px;
border-radius: 12px;
font-size: 12px;
font-weight: bold;
}
.status-item.setting { background: #1b3a2f; color: #4caf50; }
.status-item.running { background: #2a2a1b; color: #ffeb3b; }
.status-item.paused { background: #3a2a1a; color: #ff9800; }
.status-item.idle { background: #2a2a2a; color: #9aa0a6; }
/* ========== 卡片 ========== */
.card {
background: #1a2332;
border-radius: 12px;
padding: 20px;
border: 1px solid #2a3441;
}
.card h2 { font-size: 16px; margin-bottom: 16px; color: #4fc3f7; }
/* ========== 状态卡片 ========== */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.status-card {
background: #0f1923;
border-radius: 8px;
padding: 16px;
text-align: center;
border: 1px solid #2a3441;
}
.status-card.ok { border-color: #2e7d32; background: #0d1f14; }
.status-card.error { border-color: #c62828; background: #1f0d0d; }
.status-icon { font-size: 24px; margin-bottom: 8px; }
.status-label { font-size: 12px; color: #9aa0a6; margin-bottom: 4px; }
.status-value { font-size: 14px; font-weight: bold; }
/* ========== 按钮 ========== */
.btn {
padding: 8px 16px;
border-radius: 6px;
border: none;
cursor: pointer;
font-size: 14px;
transition: all 0.2s;
background: #263238;
color: #e8eaed;
font-family: inherit;
}
.btn:hover:not(:disabled) { background: #37474f; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #0277bd; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0288d1; }
.btn-secondary { background: #37474f; }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #f44336; }
.btn-success { background: #2e7d32; color: #fff; }
.btn-success:hover:not(:disabled) { background: #388e3c; }
.btn-warning { background: #e65100; color: #fff; }
.btn-error { background: #c62828; color: #fff; }
.btn-large { padding: 12px 24px; font-size: 16px; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 4px; }
.btn-row { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
/* ========== 表单 ========== */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: #9aa0a6; margin-bottom: 4px; }
.form-group input,
.form-group select {
width: 100%;
padding: 8px 12px;
background: #0f1923;
border: 1px solid #2a3441;
border-radius: 6px;
color: #e8eaed;
font-size: 14px;
font-family: inherit;
}
.form-group input:focus,
.form-group select:focus { outline: none; border-color: #4fc3f7; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* ========== Tabs ========== */
.tabs {
background: #1a2332;
border-bottom: 1px solid #2a3441;
padding: 0 20px;
display: flex;
gap: 4px;
}
.tab {
padding: 12px 20px;
background: none;
border: none;
color: #9aa0a6;
cursor: pointer;
font-size: 14px;
border-bottom: 2px solid transparent;
font-family: inherit;
}
.tab.active { color: #4fc3f7; border-bottom-color: #4fc3f7; }
.tab:hover { color: #e8eaed; }
/* ========== 摄像头预览 ========== */
.camera-preview {
width: 100%;
max-width: 480px;
border-radius: 8px;
overflow: hidden;
margin: 0 auto 16px;
background: #000;
}
.camera-preview img,
.camera-full img {
width: 100%;
display: block;
aspect-ratio: 16/9;
object-fit: cover;
}
.camera-full {
width: 100%;
border-radius: 8px;
overflow: hidden;
background: #000;
}
/* ========== 关节控制 ========== */
.joints-panel { margin-top: 16px; }
.joints-panel h3 { margin-bottom: 12px; font-size: 14px; }
.joint-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.joint-control {
background: #0f1923;
border-radius: 8px;
padding: 12px;
text-align: center;
border: 1px solid #2a3441;
}
.joint-control label { font-size: 12px; color: #4fc3f7; font-weight: bold; }
.joint-value { font-size: 18px; font-weight: bold; color: #fff; margin: 4px 0; }
.joint-buttons { display: flex; align-items: center; gap: 4px; justify-content: center; }
.joint-buttons button {
width: 32px;
height: 32px;
border-radius: 4px;
border: 1px solid #2a3441;
background: #263238;
color: #e8eaed;
cursor: pointer;
font-size: 14px;
}
.joint-buttons input {
width: 60px;
padding: 4px;
text-align: center;
background: #0f1923;
border: 1px solid #2a3441;
border-radius: 4px;
color: #e8eaed;
font-size: 12px;
}
/* ========== 点位列表 ========== */
.point-item {
background: #0f1923;
border: 1px solid #2a3441;
border-radius: 8px;
padding: 12px;
margin-bottom: 12px;
}
.point-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.point-name { font-weight: bold; font-size: 15px; }
.point-coords { font-size: 12px; color: #9aa0a6; margin-bottom: 8px; }
.badge {
padding: 2px 8px;
border-radius: 10px;
font-size: 11px;
background: #263238;
color: #4fc3f7;
}
.pose-list { margin-top: 8px; }
.pose-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 0;
border-bottom: 1px solid #2a3441;
font-size: 13px;
}
.angles { color: #9aa0a6; font-size: 11px; font-family: monospace; }
.pose-add {
display: flex;
gap: 8px;
align-items: center;
margin-top: 8px;
}
.pose-add input { flex: 1; padding: 6px 10px; background: #1a2332; border: 1px solid #2a3441; border-radius: 4px; color: #e8eaed; font-size: 13px; }
.pose-add select { padding: 6px; background: #1a2332; border: 1px solid #2a3441; border-radius: 4px; color: #e8eaed; }
.empty-hint { color: #9aa0a6; text-align: center; padding: 20px; }
.hint { font-size: 12px; color: #9aa0a6; margin-top: 8px; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; }
.alert-error { background: #1f0d0d; border: 1px solid #c62828; color: #ef5350; }
.checkbox-group { display: flex; gap: 16px; }
.checkbox-group label { display: flex; align-items: center; gap: 6px; cursor: pointer; color: #e8eaed; }
/* ========== 运行页面 ========== */
.running-header { display: flex; align-items: center; gap: 20px; margin-bottom: 16px; }
.running-status {
font-size: 18px;
font-weight: bold;
display: flex;
align-items: center;
gap: 8px;
}
.running-status.idle { color: #9aa0a6; }
.running-status.running { color: #4caf50; }
.running-status.paused { color: #ff9800; }
.pulse {
width: 10px;
height: 10px;
border-radius: 50%;
background: currentColor;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0%, 100% { opacity: 1; transform: scale(1); }
50% { opacity: 0.5; transform: scale(0.8); }
}
.running-progress { flex: 1; display: flex; align-items: center; gap: 12px; }
.progress-bar { flex: 1; height: 8px; background: #2a3441; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: #4fc3f7; border-radius: 4px; transition: width 0.3s; }
/* ========== 报告 ========== */
.report-summary { display: flex; gap: 16px; margin-bottom: 16px; }
.stat { padding: 8px 16px; border-radius: 8px; background: #0f1923; border: 1px solid #2a3441; }
.stat.ok { border-color: #2e7d32; color: #4caf50; }
.stat.error { border-color: #c62828; color: #ef5350; }
.report-item { padding: 8px 12px; background: #0f1923; border-radius: 6px; margin-bottom: 8px; border: 1px solid #2a3441; }
.report-point { display: flex; align-items: center; gap: 8px; font-weight: bold; }
.report-status { font-size: 16px; }
.report-pose { font-size: 12px; color: #9aa0a6; padding-left: 24px; margin-top: 4px; }
/* ========== 响应式 ========== */
@media (max-width: 768px) {
.container { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.form-row { grid-template-columns: 1fr; }
.joint-grid { grid-template-columns: repeat(2, 1fr); }
.form-row { grid-template-columns: 1fr; }
}
/* AGV 移动控制面板 */
.agv-status-bar {
display: flex;
gap: 16px;
align-items: center;
padding: 10px 14px;
background: #0f1923;
border-radius: 8px;
margin-bottom: 16px;
font-size: 13px;
color: #9aa0a6;
flex-wrap: wrap;
}
.agv-status-bar strong { color: #e8eaed; }
.agv-control-panel {
display: flex;
flex-direction: column;
align-items: center;
gap: 6px;
max-width: 280px;
margin: 0 auto;
}
.agv-dir-row {
display: grid;
grid-template-columns: 80px 80px 80px;
gap: 6px;
width: 100%;
}
.agv-dir-placeholder { width: 80px; height: 44px; }
.agv-btn {
height: 44px;
border-radius: 8px;
border: 1px solid #2a3441;
background: #263238;
color: #e8eaed;
cursor: pointer;
font-size: 13px;
font-family: inherit;
transition: background 0.15s;
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
user-select: none;
}
.agv-btn:active, .agv-btn:focus { outline: none; }
.agv-btn-up { background: #1b3a2f; border-color: #2e7d32; color: #4caf50; }
.agv-btn-down { background: #3a1b1b; border-color: #7d2e2e; color: #f44336; }
.agv-btn-left { background: #1b2d3a; border-color: #1565c0; color: #42a5f5; }
.agv-btn-right { background: #2d2a1b; border-color: #7d6e2e; color: #ffc107; }
.agv-btn-stop { background: #37474f; border-color: #546e7a; }
.agv-btn-up:active { background: #1e4d38; }
.agv-btn-down:active { background: #4d2020; }
.agv-btn-left:active { background: #1e3a4d; }
.agv-btn-right:active { background: #3d3820; }
.agv-btn-stop:active { background: #455a64; }
.agv-btn-lateral {
background: #2d1b4a;
border-color: #7c4dff;
color: #b388ff;
font-size: 13px;
min-width: 120px;
}
.agv-btn-lateral:active { background: #3d2560; }
.agv-lateral-row {
display: flex;
gap: 12px;
justify-content: center;
margin-top: 8px;
max-width: 280px;
width: 100%;
}
.speed-control {
display: flex;
align-items: center;
gap: 10px;
}
.speed-value {
min-width: 44px;
text-align: right;
font-weight: bold;
color: #4fc3f7;
}
/* 双摄像头预览布局 */
.camera-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
margin-top: 12px;
}
.camera-box {
background: #111;
border-radius: 8px;
overflow: hidden;
}
.camera-label {
padding: 8px 12px;
font-size: 13px;
color: #aaa;
background: #1a1a1a;
border-bottom: 1px solid #333;
}
.camera-img {
width: 100%;
display: block;
aspect-ratio: 4/3;
object-fit: cover;
}
.camera-placeholder {
width: 100%;
aspect-ratio: 4/3;
display: flex;
align-items: center;
justify-content: center;
color: #666;
font-size: 14px;
}
/* ========== 地图标记 ========== */
.map-marker {
position: absolute;
transform: translate(-50%, -100%);
font-size: 20px;
cursor: pointer;
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
z-index: 10;
}
.map-marker:hover {
transform: translate(-50%, -100%) scale(1.2);
}
/* ========== 任务配置 M×N 网格 ========== */
.mission-grid-wrap {
margin-top: 12px;
overflow-x: auto;
}
.mission-grid {
display: grid;
gap: 4px;
grid-template-columns: 80px repeat(var(--cols,4), 90px);
}
.grid-cell {
min-width: 80px;
min-height: 48px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
font-size: 12px;
cursor: pointer;
border: 1px solid #2a3441;
background: #0f1923;
transition: background 0.15s, border-color 0.15s;
}
.grid-cell.active {
background: #1b3a2f;
border-color: #2e7d32;
color: #4caf50;
}
.grid-cell.active:hover {
background: #234;
}
.grid-cell.selected {
border-color: #4fc3f7 !important;
box-shadow: 0 0 0 2px #4fc3f7;
}
.grid-header {
background: transparent;
border-color: transparent;
cursor: default;
font-weight: bold;
color: #9aa0a6;
font-size: 12px;
}
/* 机器配置表单 */
.machine-form {
background: #0f1923;
border: 1px solid #2a3441;
border-radius: 8px;
padding: 16px;
margin-top: 12px;
}
.machine-form h3 {
font-size: 14px;
color: #4fc3f7;
margin-bottom: 10px;
}
.machine-form h4 {
font-size: 13px;
color: #9aa0a6;
margin: 8px 0 6px;
}
/* 姿态列表 */
.pose-list {
margin-top: 8px;
}
.pose-item {
display: flex;
align-items: center;
gap: 8px;
padding: 6px 0;
border-bottom: 1px solid #2a3441;
font-size: 13px;
}
.pose-name {
font-weight: bold;
min-width: 80px;
}
.pose-angles {
color: #9aa0a6;
font-size: 11px;
font-family: monospace;
flex: 1;
}
.pose-add {
display: flex;
gap: 8px;
align-items: center;
margin-top: 8px;
}
.pose-add input {
flex: 1;
padding: 6px 10px;
background: #1a2332;
border: 1px solid #2a3441;
border-radius: 4px;
color: #e8eaed;
font-size: 13px;
}
/* 蛇形序列预览 */
.sequence-preview {
display: flex;
flex-direction: column;
gap: 4px;
max-height: 320px;
overflow-y: auto;
}
.sequence-step {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 12px;
background: #0f1923;
border-radius: 6px;
border: 1px solid #2a3441;
font-size: 13px;
}
.step-index {
background: #263238;
color: #4fc3f7;
border-radius: 10px;
min-width: 28px;
height: 22px;
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
font-weight: bold;
}
.step-info {
flex: 1;
}
.step-side {
padding: 2px 8px;
border-radius: 8px;
font-size: 11px;
font-weight: bold;
}
.step-side:contains('正面') {
background: #1b3a2f;
color: #4caf50;
}
.step-side:contains('背面') {
background: #3a1b2f;
color: #ce93d8;
}
/* 网格单元格点位配置 */
.cell-machine {
font-size: 11px;
font-weight: bold;
color: #2c3e50;
}
.cell-points {
margin-top: 2px;
font-size: 9px;
}
.point-row {
display: flex;
align-items: center;
gap: 2px;
padding: 1px 2px;
background: #f8f9fa;
border-radius: 3px;
cursor: pointer;
margin: 1px 0;
}
.point-row:hover {
background: #e9ecef;
}
.point-label {
color: #666;
min-width: 24px;
}
.point-coords {
color: #0366d6;
font-family: monospace;
font-size: 8px;
flex: 1;
}
.btn-icon-small {
background: none;
border: none;
cursor: pointer;
font-size: 10px;
padding: 1px 3px;
border-radius: 3px;
}
.btn-icon-small:hover {
background: #ddd;
}
/* ========== 任务配置 弹窗 + 网格增强样式 ========== */
/* 弹窗遮罩 */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.65);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal-box {
background: #1a1f2e;
border: 1px solid #2a3a50;
border-radius: 12px;
padding: 20px 24px;
min-width: 380px;
max-width: 500px;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-box h3 { margin: 0 0 8px; color: #e0e6f0; font-size: 16px; }
/* 点位行单元格 */
.point-cell { cursor: pointer; flex-direction: column; gap: 2px; }
.point-cell:hover { border-color: #4fc3f7; background: #162030; }
.point-cell.point-filled { background: #0d2535; border-color: #1565c0; }
.point-coords { font-size: 10px; color: #64b5f6; font-family: monospace; }
.point-empty { font-size: 10px; color: #455a64; }
/* 机器行单元格 */
.machine-cell { cursor: pointer; }
.machine-cell:hover { border-color: #4caf50; background: #1b3a2f; }
.machine-cell.active { background: #1b3a2f; border-color: #2e7d32; color: #4caf50; }
.machine-icon { font-size: 18px; }
.machine-empty { font-size: 16px; color: #455a64; }
/* ========== 任务配置 弹窗 + 网格增强样式 ========== */
/* 弹窗遮罩 */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.65);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal-box {
background: #1a1f2e;
border: 1px solid #2a3a50;
border-radius: 12px;
padding: 20px 24px;
min-width: 380px;
max-width: 500px;
box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal-box h3 { margin: 0 0 8px; color: #e0e6f0; font-size: 16px; }
/* 点位行单元格 */
.point-cell { cursor: pointer; flex-direction: column; gap: 2px; }
.point-cell:hover { border-color: #4fc3f7; background: #162030; }
.point-cell.point-filled { background: #0d2535; border-color: #1565c0; }
.point-coords { font-size: 10px; color: #64b5f6; font-family: monospace; }
.point-empty { font-size: 10px; color: #455a64; }
/* 机器行单元格 */
.machine-cell { cursor: pointer; }
.machine-cell:hover { border-color: #4caf50; background: #1b3a2f; }
.machine-cell.active { background: #1b3a2f; border-color: #2e7d32; color: #4caf50; }
.machine-icon { font-size: 18px; }
.machine-empty { font-size: 16px; color: #455a64; }
/* 点位编辑弹窗 */
.modal-overlay .modal-box { min-width: 420px; }
.modal-overlay .form-row { gap: 8px; }
.modal-overlay .btn-row { gap: 8px; flex-wrap: wrap; }
/* 地图坐标点覆盖层 */
.map-container { position: relative; }
.map-overlay {
position: absolute; top: 0; left: 0; right: 0; bottom: 0;
pointer-events: none; z-index: 10;
}
.map-dot {
position: absolute;
transform: translate(-50%, -50%);
}
.point-dot {
width: 10px; height: 10px;
background: #f39c12;
border-radius: 50%;
border: 2px solid #fff;
box-shadow: 0 0 6px rgba(243,156,18,0.9);
}
+121
View File
@@ -0,0 +1,121 @@
const { createApp } = Vue
const API = ''
createApp({
delimiters: ['[[', ']]'],
data() {
return {
connecting: false,
agvConnected: false,
armConnected: false,
cameraOpened: false,
armCameraOpened: false,
mapLoaded: false,
mapConfig: {},
pointsCount: 0,
currentState: 'idle',
// 摄像头轮询
agvCameraSrc: '/api/camera/refresh?t=' + Date.now(),
armCameraSrc: '/api/camera/arm_refresh?t=' + Date.now(),
agvCameraError: false,
armCameraError: false,
reconnectingDevice: null
}
},
computed: {
allReady() {
return this.agvConnected && this.armConnected && this.cameraOpened && this.mapLoaded
},
statusClass() {
return this.currentState
},
statusText() {
const map = { idle: '空闲', setting: '设置模式', running: '运行中', paused: '已暂停' }
return map[this.currentState] || '未知'
}
},
mounted() {
this.refresh()
setInterval(this.refreshStatus, 3000)
this.refreshCams()
setInterval(() => this.refreshCams(), 2000)
},
methods: {
refreshCams() {
this.agvCameraSrc = '/api/camera/refresh?t=' + Date.now()
this.armCameraSrc = '/api/camera/arm_refresh?t=' + Date.now()
},
async refresh() {
await this.refreshStatus()
await this.loadPoints()
},
async refreshStatus() {
try {
const res = await fetch(API + '/api/status')
const data = await res.json()
this.agvConnected = data.agv_connected
this.armConnected = data.arm_connected
this.cameraOpened = data.camera_opened
this.armCameraOpened = data.arm_camera_opened
this.mapLoaded = data.map_loaded
this.currentState = data.state || 'idle'
if (data.map_loaded && data.map) {
this.mapConfig = data.map
}
} catch (e) {
console.error(e)
}
},
async loadPoints() {
try {
const res = await fetch(API + '/api/points/list')
const data = await res.json()
this.pointsCount = data.points ? data.points.length : 0
} catch (e) {}
},
async connectAll() {
this.connecting = true
try {
const res = await fetch(API + '/api/system/connect', { method: 'POST' })
const data = await res.json()
if (data.errors && data.errors.length) {
alert('部分连接失败:\n' + data.errors.join('\n'))
}
await this.refreshStatus()
} finally {
this.connecting = false
}
},
async disconnectAll() {
await fetch(API + '/api/system/disconnect', { method: 'POST' })
await this.refreshStatus()
},
async connectDevice(device) {
if (this.connecting) return
this.reconnectingDevice = device
try {
const res = await fetch(API + '/api/device/connect', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({device})
})
const data = await res.json()
if (!data.ok && data.error) {
alert(data.device + ' 重连失败: ' + data.error)
}
await this.refreshStatus()
} finally {
this.reconnectingDevice = null
}
},
async goRunning() {
if (!this.allReady) {
alert('请先连接所有设备并加载地图')
} else {
window.location.href = '/running'
}
}
}
}).mount('#app')
+80
View File
@@ -0,0 +1,80 @@
const { createApp } = Vue
const API = ''
createApp({
delimiters: ['[[', ']]'],
data() {
return {
missionState: 'idle',
currentPoint: 0,
totalPoints: 0,
report: null,
previewUrl: API + '/api/camera/preview',
polling: null
}
},
computed: {
missionStateText() {
const map = { idle: '空闲', running: '任务运行中', paused: '已暂停', completed: '已完成' }
return map[this.missionState] || '未知'
},
progressPercent() {
if (!this.totalPoints) return 0
return Math.round((this.currentPoint / this.totalPoints) * 100)
}
},
mounted() {
this.poll()
},
beforeUnmount() {
if (this.polling) clearInterval(this.polling)
},
methods: {
poll() {
this.refresh()
this.polling = setInterval(this.refresh, 2000)
},
async refresh() {
try {
const res = await fetch(API + '/api/mission/state')
const data = await res.json()
this.missionState = data.state || 'idle'
if (this.missionState === 'running') {
const reportRes = await fetch(API + '/api/mission/report')
const reportData = await reportRes.json()
if (reportData.report) {
this.totalPoints = reportData.report.total_points || 0
this.currentPoint = reportData.report.details?.length || 0
this.report = reportData.report
}
} else if (this.missionState === 'idle') {
const reportRes = await fetch(API + '/api/mission/report')
const reportData = await reportRes.json()
if (reportData.report) {
this.report = reportData.report
this.totalPoints = reportData.report.total_points || 0
this.currentPoint = reportData.report.details?.length || 0
}
}
} catch (e) {}
},
async startMission() {
if (this.missionState !== 'idle') return
await fetch(API + '/api/mission/start', { method: 'POST' })
this.missionState = 'running'
},
async pauseMission() {
await fetch(API + '/api/mission/pause', { method: 'POST' })
this.missionState = 'paused'
},
async stopMission() {
await fetch(API + '/api/mission/stop', { method: 'POST' })
this.missionState = 'idle'
},
onPreviewError(e) {
e.target.style.display = 'none'
}
}
}).mount('#app')
+887
View File
@@ -0,0 +1,887 @@
const { createApp } = Vue
const API = ''
const app = createApp({
data() {
return {
tab: 'map',
// 任务配置
missionConfig: { rows: 3, cols: 3, grid: [], machines: [], positions: [] },
// 点位编辑弹窗
editingPoint: null, // 当前编辑的点位 {pointRow, col} — pointRow是点位行号(0~rows)
pointEditor: { x: 0, y: 0, yaw: 0 },
selectedMachine: null,
sequence: [],
poseForm: { name: '', photo_type: 'front', description: '' },
// 地图
mapForm: { map_dir: '/home/elephant/agv_pro_ros2/src/agv_pro_navigation2/map/', map_file: 'map.yaml' },
mapMsg: '',
mapLoaded: false,
mapImageUrl: '',
mapMeta: null,
mapVersion: 0, // 地图点位版本号,用于强制重新渲染
// 点位
points: [],
newPointName: '',
newPointMode: 'front',
newPointSequence: ['front', 'back'],
// 机型(姿态组)
models: [],
selectedModelId: null,
newModelName: '',
newModelDesc: '',
newModelNotes: '',
newPoseForm: {}, // 机型配置:新建姿态的表单
// 机械臂
armConnected: false,
currentAngles: [],
angleInputs: [],
previewUrl: API + '/api/camera/preview',
jogIntervals: {},
// AGV
cameraOpened: false,
agvConnected: false,
agvBattery: null,
agvPosition: null,
agvSpeed: 0.5,
agvMoveInterval: null,
agvCameraUrl: API + '/api/camera/refresh',
agvCameraTimer: null,
}
},
mounted() {
this.refresh()
this.refreshAngles()
},
watch: {
// 监听点位数据变化,自动刷新地图
'missionConfig.positions'() {
this.mapVersion++
},
tab(val) {
if (val === 'agv') {
this.agvCameraTimer = setInterval(() => {
this.agvCameraUrl = API + '/api/camera/refresh?t=' + Date.now()
}, 1000)
} else {
if (this.agvCameraTimer) {
clearInterval(this.agvCameraTimer)
this.agvCameraTimer = null
}
}
}
},
beforeUnmount() {
Object.values(this.jogIntervals).forEach(i => clearInterval(i))
if (this.agvCameraTimer) clearInterval(this.agvCameraTimer)
},
methods: {
async refresh() {
try {
const res = await fetch(API + '/api/status')
const data = await res.json()
this.agvConnected = data.agv_connected
this.armConnected = data.arm_connected
this.cameraOpened = data.camera_opened
this.mapLoaded = data.map_loaded
if (data.map_loaded) {
this.mapImageUrl = API + '/api/map/image?t=' + Date.now()
try {
const metaRes = await fetch(API + '/api/map/meta')
const meta = await metaRes.json()
if (meta.ok) this.mapMeta = meta
} catch (e) {}
}
} catch (e) {}
await this.loadAllPoints()
await this.loadAllModels()
await this.loadAllMachines()
await this.loadMissionConfig()
},
// === 地图 ===
async loadMap() {
const res = await fetch(API + '/api/map/load', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.mapForm)
})
const data = await res.json()
this.mapMsg = data.ok ? '✅ 地图加载成功' : '❌ ' + (data.error || '加载失败')
this.mapLoaded = data.ok
if (data.ok) {
this.mapImageUrl = API + '/api/map/image?t=' + Date.now()
try {
const metaRes = await fetch(API + '/api/map/meta')
const meta = await metaRes.json()
if (meta.ok) this.mapMeta = meta
} catch (e) {}
}
},
onMapError() {
this.mapMsg = '❌ 地图图像加载失败'
},
getMapX(coords) {
if (!coords || !this.mapMeta) {
console.log('[getMapX] mapMeta not loaded, returning default 50');
return 50
}
const [x, y, yaw] = coords
const { resolution, origin, width } = this.mapMeta
const px = (x - origin[0]) / (resolution * width) * 100
const result = Math.max(0, Math.min(100, px));
console.log('[getMapX]', coords, '→ px%:', result);
return result
},
getMapY(coords) {
if (!coords || !this.mapMeta) {
console.log('[getMapY] mapMeta not loaded, returning default 50');
return 50
}
const [x, y, yaw] = coords
const { resolution, origin, height } = this.mapMeta
const py = (y - origin[1]) / (resolution * height) * 100
const result = Math.max(0, Math.min(100, 100 - py));
console.log('[getMapY]', coords, '→ py%:', result);
return result
},
async saveMap() {
await fetch(API + '/api/map/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.mapForm)
})
this.mapMsg = '✅ 地图配置已保存'
},
// === 点位 ===
async loadAllPoints() {
const res = await fetch(API + '/api/points/list')
const data = await res.json()
this.points = data.points || []
},
async addPoint() {
const res = await fetch(API + '/api/points/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: this.newPointName || 'point_' + (this.points.length + 1),
photo_mode: this.newPointMode,
sequence: this.newPointSequence
})
})
const data = await res.json()
if (data.ok) {
await this.loadAllPoints()
this.newPointName = ''
}
},
async deletePoint(id) {
if (!confirm('确定删除该点位?')) return
await fetch(API + '/api/points/delete/' + id, { method: 'DELETE' })
await this.loadAllPoints()
},
async saveAllPoints() {
await fetch(API + '/api/points/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ points: this.points })
})
alert('点位已保存')
},
getPoint(id) {
return this.points.find(p => p.id === id)
},
formatAngles(angles) {
if (!angles) return '—'
return angles.map(a => (a || 0).toFixed(1) + '°').join(' / ')
},
// === 机型管理 ===
async loadAllModels() {
const res = await fetch(API + '/api/models/list')
const data = await res.json()
this.models = data.models || []
this.models.forEach(m => {
if (!this.poseForm[m.id]) {
this.poseForm[m.id] = { name: '', photo_type: 'front', description: '' }
}
})
},
async addModel() {
const res = await fetch(API + '/api/models/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: this.newModelName || '型号_' + (this.models.length + 1),
description: this.newModelDesc || '',
notes: this.newModelNotes || '',
serial_prefix: this.newModelSerial || ''
})
})
const data = await res.json()
if (data.ok) {
await this.loadAllModels()
this.newModelName = ''
this.newModelDesc = ''
this.newModelNotes = ''
this.newModelSerial = ''
}
},
async deleteModel(modelId) {
if (!confirm('确定删除该机型?其下所有姿态将被删除!')) return
await fetch(API + '/api/models/delete/' + modelId, { method: 'DELETE' })
await this.loadAllModels()
},
// === 姿态管理(属于机型)===
async addPose(modelId, photoType, customName) {
const form = this.poseForm[modelId]
const type = photoType || form?.photo_type || 'front'
const name = customName || form?.name || type + '_' + ((this.getModel(modelId)?.poses?.filter(p => p.photo_type === type).length || 0) + 1)
await fetch(API + '/api/models/poses/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model_id: modelId,
name: name,
photo_type: type,
arm_angles: this.currentAngles && this.currentAngles.length === 6 ? this.currentAngles : [0, 0, 0, 0, 0, 0],
speed: 500,
description: form?.description || ''
})
})
await this.loadAllModels()
if (form) {
form.name = ''
form.description = ''
}
},
async deletePose(modelId, poseId) {
if (!confirm('确定删除该姿态?')) return
await fetch(API + '/api/models/' + modelId + '/poses/' + poseId, { method: 'DELETE' })
await this.loadAllModels()
},
async updatePoseAngle(modelId, poseId, jointIndex, event) {
const value = parseFloat(event.target.value)
if (isNaN(value)) return
// Find the pose and update its angle
const model = this.getModel(modelId)
if (!model) return
const pose = model.poses.find(p => p.id === poseId)
if (!pose) return
if (!pose.arm_angles) pose.arm_angles = [0, 0, 0, 0, 0, 0]
pose.arm_angles[jointIndex] = value
// Save to backend
await fetch(API + '/api/models/' + modelId + '/poses/' + poseId, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ arm_angles: pose.arm_angles })
})
},
getModel(id) {
return this.models.find(m => m.id === id)
},
// === 任务配置 ===
async loadMissionConfig() {
try {
const res = await fetch(API + '/api/mission/config')
const data = await res.json()
if (data.ok && data.config) {
this.missionConfig.rows = data.config.rows || 3
this.missionConfig.cols = data.config.cols || 3
this.missionConfig.grid = data.config.grid || []
this.missionConfig.machines = data.machines || []
this.missionConfig.positions = data.config.positions || []
this.mapVersion++
}
} catch (e) { console.error('加载任务配置失败', e) }
},
async generateGrid() {
try {
const res = await fetch(API + '/api/mission/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
rows: this.missionConfig.rows,
cols: this.missionConfig.cols,
grid: []
})
})
const data = await res.json()
if (data.ok) {
this.missionConfig.grid = data.config.grid || []
alert('✅ 网格已生成 (' + this.missionConfig.rows + '×' + this.missionConfig.cols + ')')
} else {
alert('❌ 网格生成失败')
}
} catch (e) { alert('请求失败: ' + e.message) }
},
async saveMissionConfig() {
try {
const res = await fetch(API + '/api/mission/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
rows: this.missionConfig.rows,
cols: this.missionConfig.cols,
grid: this.missionConfig.grid
})
})
const data = await res.json()
if (data.ok) {
alert('✅ 网格配置已保存')
}
} catch (e) { alert('保存失败: ' + e.message) }
},
async loadAllMachines() {
try {
const res = await fetch(API + '/api/mission/machines')
const data = await res.json()
this.missionConfig.machines = data.machines || []
} catch (e) { console.error('加载机器列表失败', e) }
},
// ========== 点位行模型(独立于机器) ==========
/**
* 获取指定点位行的数据
* @param {number} pointRow - 点位行号,范围 0 ~ missionConfig.rows
* - pointRow=0 → 第1台机器的正面拍摄点
* - pointRow=rows → 最后1台机器的背面拍摄点
* - 中间 pointRow=i → 上面机器(i)的背面 + 下面机器(i+1)的正面
* @param {number} col - 列号(0-based
* @returns {object|null} 点位对象 { coords: [x,y,z], ... } 或 null
*/
getPointAt(pointRow, col) {
var positions = this.missionConfig.positions || []
// 在独立 positions 数组中查找 (pointRow, col)
for (var i = 0; i < positions.length; i++) {
var p = positions[i]
if (parseInt(p.row) === pointRow && parseInt(p.col) === col) {
// 优先找 shoot,其次找 front/back
if (p.side === 'shoot') return p
// 再看有没有同一(row,col)的shoot
}
}
// 再找同(row,col)的shoot类型
for (var i = 0; i < positions.length; i++) {
var p = positions[i]
if (parseInt(p.row) === pointRow && parseInt(p.col) === col && p.side === 'shoot') {
return p
}
}
// 兼容旧数据:尝试从机器对象的 front/back 获取
var machineAbove = this.getMachineAt(pointRow - 1, col) // 上面的机器
var machineBelow = this.getMachineAt(pointRow, col) // 下面的机器
if (pointRow === 0 && machineBelow) {
// 第一个点位行 → 下面机器的正面
return machineBelow.front || { coords: [0, 0, 0], poses: [] }
}
if (pointRow === this.missionConfig.rows && machineAbove) {
// 最后一个点位行 → 上面机器的背面
return machineAbove.back || { coords: [0, 0, 0], poses: [] }
}
// 中间点位行:优先返回上面机器的背面
if (machineAbove && machineAbove.back) {
return machineAbove.back
}
if (machineBelow && machineBelow.front) {
return machineBelow.front
}
return null
},
/**
* 获取点位的归属描述(用于弹窗标题)
* @param {number} pointRow - 点位行号
* @param {number} col - 列号
* @returns {string} 如 "第2列 · 机器2背面/机器3正面"
*/
getPointOwnerLabel(pointRow, col) {
var rows = this.missionConfig.rows
var labels = []
if (pointRow === 0) {
// 第一行点位:下面机器的正面
var m = this.getMachineAt(0, col)
if (m) labels.push('机器' + (m.row + 1) + '正面')
} else if (pointRow === rows) {
// 最后行点位:上面机器的背面
var m2 = this.getMachineAt(rows - 1, col)
if (m2) labels.push('机器' + (m2.row + 1) + '背面')
} else {
// 中间点位行:上面机器的背面 + 下面机器的正面
var mAbove = this.getMachineAt(pointRow - 1, col)
var mBelow = this.getMachineAt(pointRow, col)
if (mAbove) labels.push('机器' + (mAbove.row + 1) + '背面')
if (mBelow) labels.push('机器' + (mBelow.row + 1) + '正面')
}
if (labels.length === 0) return '第' + (col + 1) + '列 · 无归属'
return '第' + (col + 1) + '列 · ' + labels.join('/')
},
/**
* 检查点位是否可以清空
* 只有当上下两台机器都不需要这个点位时才能清空
*/
canClearPoint(pointRow, col) {
var rows = this.missionConfig.rows
// 如果上面有机器且机器存在 → 不能清空(上面机器需要此点位拍背面)
if (pointRow > 0 && pointRow <= rows) {
var mAbove = this.getMachineAt(pointRow - 1, col)
if (mAbove) return false
}
// 如果下面有机器且机器存在 → 不能清空(下面机器需要此点位拍正面)
if (pointRow >= 0 && pointRow < rows) {
var mBelow = this.getMachineAt(pointRow, col)
if (mBelow) return false
}
return true
},
getMachineAt(ri, ci) {
if (!this.missionConfig.machines) return null
return this.missionConfig.machines.find(function(m) { return m.row === ri && m.col === ci }) || null
},
// 打开点位编辑弹窗(基于点位行号)
openPointEdit(pointRow, col) {
var existing = this.getPointAt(pointRow, col)
if (existing && existing.coords) {
this.pointEditor.x = existing.coords[0] !== undefined ? existing.coords[0] : 0
this.pointEditor.y = existing.coords[1] !== undefined ? existing.coords[1] : 0
this.pointEditor.yaw = existing.coords[2] !== undefined ? existing.coords[2] : 0
} else {
this.pointEditor.x = 0
this.pointEditor.y = 0
this.pointEditor.yaw = 0
}
this.editingPoint = { pointRow: pointRow, col: col }
},
// 关闭点位编辑弹窗
closePointEdit() {
this.editingPoint = null
},
// 从AGV读取当前坐标到点位编辑器
async loadPointFromAgv() {
if (!this.agvConnected) { alert('请先连接AGV'); return }
try {
const res = await fetch(API + '/api/agv/position')
const pos = await res.json()
if (pos.ok && pos.position && Array.isArray(pos.position)) {
this.pointEditor.x = pos.position[0] ?? 0
this.pointEditor.y = pos.position[1] ?? 0
this.pointEditor.yaw = pos.position[2] ?? 0
alert('✅ 已读取AGV位置: (' + this.pointEditor.x.toFixed(2) + ', ' + this.pointEditor.y.toFixed(2) + ', ' + this.pointEditor.yaw.toFixed(2) + ')')
} else if (pos.ok && (!pos.position || !Array.isArray(pos.position))) {
alert('⚠️ AGV 未发布位置数据,请检查 AGV 传感器是否正常')
} else {
alert('读取AGV位置失败: ' + (pos.error || '未知错误'))
}
} catch (e) { alert('读取AGV位置失败: ' + e.message) }
},
// 保存点位配置到独立 positions 数组
async savePoint() {
if (!this.editingPoint) return
var pointRow = this.editingPoint.pointRow
var col = this.editingPoint.col
var coords = [this.pointEditor.x, this.pointEditor.y, this.pointEditor.yaw]
try {
// 保存到后端独立点位表(使用 point_row 标识点位行)
var saveRes = await fetch(API + '/api/mission/positions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
row: pointRow,
col: col,
side: 'shoot', // 统一用 'shoot' 表示拍摄点位
coords: coords,
poses: []
})
})
var saveData = await saveRes.json()
if (!saveData.ok) {
alert('保存点位失败: ' + (saveData.error || '未知错误'))
return
}
// 同步更新关联机器的坐标(如果有的话)
this.syncPointToMachines(pointRow, col, coords)
await this.loadMissionConfig()
alert('✅ 点位坐标已保存: (' + coords[0].toFixed(2) + ', ' + coords[1].toFixed(2) + ', ' + coords[2].toFixed(2) + ')')
this.closePointEdit()
} catch (e) { alert('保存点位失败: ' + e.message) }
},
// 将点位坐标同步到关联的机器对象
syncPointToMachines(pointRow, col, coords) {
var rows = this.missionConfig.rows
// pointRow=0 → 同步到下面机器(0,col)的front
if (pointRow === 0) {
var m0 = this.getMachineAt(0, col)
if (m0) {
this.updateMachineSide(m0, 'front', coords)
}
return
}
// pointRow=rows → 同步到上面机器(rows-1,col)的back
if (pointRow === rows) {
var mLast = this.getMachineAt(rows - 1, col)
if (mLast) {
this.updateMachineSide(mLast, 'back', coords)
}
return
}
// 中间点位行 → 同步到上面机器的back + 下面机器的front
var mAbove = this.getMachineAt(pointRow - 1, col)
var mBelow = this.getMachineAt(pointRow, col)
if (mAbove) {
this.updateMachineSide(mAbove, 'back', coords)
}
if (mBelow) {
this.updateMachineSide(mBelow, 'front', coords)
}
},
// 更新机器某侧的坐标
async updateMachineSide(machine, side, coords) {
try {
var update = {}
update[side] = {
coords: coords,
poses: (machine[side] && machine[side].poses) ? machine[side].poses : []
}
await fetch(API + '/api/mission/machines/' + machine.id, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(update)
})
} catch (e) { console.error('同步机器坐标失败', e) }
},
// 清空点位(带保护检查)
async clearPoint() {
if (!this.editingPoint) return
var pointRow = this.editingPoint.pointRow
var col = this.editingPoint.col
// 检查是否可以清空
if (!this.canClearPoint(pointRow, col)) {
var ownerLabel = this.getPointOwnerLabel(pointRow, col)
alert('⚠️ 无法清空!此点位服务于: ' + ownerLabel + '\n必须先移除相关机器才能清空此点位。')
return
}
if (!confirm('确定清空此点位坐标?')) return
try {
// 发送清空请求(坐标归零或删除记录)
await fetch(API + '/api/mission/positions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
row: pointRow,
col: col,
side: 'shoot',
coords: [0, 0, 0],
poses: []
})
})
this.pointEditor.x = 0
this.pointEditor.y = 0
this.pointEditor.yaw = 0
await this.loadMissionConfig()
} catch (e) { alert('清空点位失败: ' + e.message) }
},
onCellClick(ri, ci) {
var m = this.getMachineAt(ri, ci)
if (!m) {
// 无机器 → 创建机器记录
this.createMachine(ri, ci).then(function(ok) {
if (ok) {
var created = this.getMachineAt(ri, ci)
if (created) this.selectMachine(created)
}
}.bind(this))
} else {
// 有机器 → 切换为无机器(删除)
this.deleteMachine(m.id)
}
},
async createMachine(ri, ci) {
try {
var machineId = 'm_' + ri + '_' + ci
var res = await fetch(API + '/api/mission/machines/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: machineId,
row: ri,
col: ci,
front: { coords: [0, 0, 0], poses: [] },
back: { coords: [0, 0, 0], poses: [] }
})
})
var data = await res.json()
if (!data.ok && data.error !== '该位置已有机器') {
alert('创建机器失败: ' + (data.error || '未知错误'))
return false
}
await this.loadAllMachines()
return true
} catch (e) { alert('创建机器失败: ' + e.message); return false }
},
selectMachine(machine) {
if (!machine.front) machine.front = { coords: [0, 0, 0], poses: [] }
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]
this.selectedMachine = machine
},
clearSelection() {
this.selectedMachine = null
},
async deleteMachine(machineId) {
if (!confirm('确定删除此机器?\n\n注意:删除后其上方/下方的点位仍可继续使用。')) return
try {
await fetch(API + '/api/mission/machines/' + machineId, { method: 'DELETE' })
this.selectedMachine = null
await this.loadAllMachines()
await this.loadMissionConfig() // 重新加载点位,确保数据同步
} catch (e) { alert('删除失败: ' + e.message) }
},
async saveMachineCoords() {
if (!this.selectedMachine) return
try {
var res = await fetch(API + '/api/mission/machines/' + this.selectedMachine.id, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
front: this.selectedMachine.front,
back: this.selectedMachine.back
})
})
if (res.ok) {
this.mapMsg = '✅ 机器坐标已保存'
setTimeout(function() { this.mapMsg = '' }.bind(this), 2000)
} else {
alert('保存失败: ' + res.status)
}
} catch (e) { alert('保存失败: ' + e.message) }
},
async readPosition(side) {
if (!this.agvConnected) { alert('AGV 未连接'); return }
try {
var res = await fetch(API + '/api/agv/position')
var data = await res.json()
if (data.ok && data.position && Array.isArray(data.position)) {
var x = data.position[0]
var y = data.position[1]
var theta = data.position[2]
if (side === 'front') {
this.selectedMachine.front.coords = [x, y, theta]
} else {
this.selectedMachine.back.coords = [x, y, theta]
}
} else if (data.ok && (!data.position || !Array.isArray(data.position))) {
alert('⚠️ AGV 未发布位置数据,请检查 AGV 传感器是否正常')
} else {
alert('读取位置失败: ' + (data.error || '未知错误'))
}
} catch (e) { alert('读取位置失败: ' + e.message) }
},
async addPoseToMachine(machineId, side) {
var name = this.poseForm.name || '姿态' + (((this.selectedMachine && this.selectedMachine[side] && this.selectedMachine[side].poses) || []).length + 1)
try {
var res = await fetch(API + '/api/mission/poses/' + machineId + '/' + side, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: name,
arm_angles: this.currentAngles.length === 6 ? this.currentAngles : [0, 0, 0, 0, 0, 0],
speed: 500,
description: ''
})
})
var data = await res.json()
if (data.ok) {
this.poseForm.name = ''
await this.loadAllMachines()
var updated = this.getMachineAt(this.selectedMachine.row, this.selectedMachine.col)
if (updated) this.selectMachine(updated)
} else {
alert('添加姿态失败: ' + (data.error || '未知错误'))
}
} catch (e) { alert('添加姿态失败: ' + e.message) }
},
async deletePose(machineId, side, poseId) {
if (!confirm('确定删除此姿态?')) return
try {
await fetch(API + '/api/mission/poses/' + machineId + '/' + side + '/' + poseId, { method: 'DELETE' })
await this.loadAllMachines()
if (this.selectedMachine) {
var updated = this.getMachineAt(this.selectedMachine.row, this.selectedMachine.col)
if (updated) this.selectMachine(updated)
}
} catch (e) { alert('删除姿态失败: ' + e.message) }
},
async capturePosition(ri, ci, side) {
if (!this.agvConnected) { alert('请先连接AGV'); return }
var machine = this.getMachineAt(ri, ci)
if (!machine) {
try {
var machineId = 'm_' + ri + '_' + ci
var res = await fetch(API + '/api/mission/machines/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
id: machineId,
row: ri,
col: ci,
front: { coords: [0, 0, 0], poses: [] },
back: { coords: [0, 0, 0], poses: [] }
})
})
if (!res.ok) throw new Error('创建失败')
await this.loadAllMachines()
machine = this.getMachineAt(ri, ci)
} catch (e) { alert('创建机器失败: ' + e.message); return }
}
try {
var res = await fetch(API + '/api/agv/position')
var pos = await res.json()
var x = 0, y = 0, theta = 0
if (pos.ok && pos.position && Array.isArray(pos.position)) {
x = pos.position[0] || 0
y = pos.position[1] || 0
theta = pos.position[2] || 0
} else if (pos.ok && (!pos.position || !Array.isArray(pos.position))) {
alert('⚠️ AGV 未发布位置数据,请检查 AGV 传感器是否正常')
return
} else {
alert('读取位置失败: ' + (pos.error || '未知错误'))
return
}
if (!machine) { machine = this.getMachineAt(ri, ci) }
if (!machine) { alert('机器记录不存在'); return }
if (side === 'front') { machine.front.coords = [x, y, theta] } else { machine.back.coords = [x, y, theta] }
await fetch(API + '/api/mission/machines/' + machine.id, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(machine)
})
alert((side === 'front' ? '正面' : '背面') + '点位已更新: (' + x.toFixed(2) + ',' + y.toFixed(2) + ',' + theta.toFixed(2) + ')')
} catch (e) { alert('读取位置失败: ' + e.message) }
},
async refreshSequence() {
try {
var res = await fetch(API + '/api/mission/generate_sequence')
var data = await res.json()
if (data.ok) {
this.sequence = data.sequence || []
}
} catch (e) { console.error('刷新序列失败', e) }
},
// === 机械臂 ===
async refreshAngles() {
if (!this.armConnected) return
try {
var res = await fetch(API + '/api/arm/get_angles')
var data = await res.json()
if (data.ok && data.angles) {
this.currentAngles = data.angles
this.angleInputs = [...data.angles]
}
} catch (e) {}
},
async setAngle(idx, val) {
await fetch(API + '/api/arm/set_angle', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ joint: 'J' + (idx + 1), angle: val })
})
},
async applyAngles() {
await fetch(API + '/api/arm/set_angles', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ angles: this.angleInputs, speed: 500 })
})
},
jogStart(idx, dir) {
var joint = 'J' + (idx + 1)
fetch(API + '/api/arm/jog', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ joint, direction: dir })
})
this.jogIntervals[idx] = setInterval(function() { this.refreshAngles() }.bind(this), 200)
},
jogStop(idx) {
clearInterval(this.jogIntervals[idx])
var joint = 'J' + (idx + 1)
fetch(API + '/api/arm/jog', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ joint, direction: 0 })
})
setTimeout(function() { this.refreshAngles() }.bind(this), 300)
},
onPreviewError(e) {
e.target.style.display = 'none'
},
// === AGV 控制 ===
async refreshAgvPosition() {
if (!this.agvConnected) return
try {
var res = await fetch(API + '/api/agv/position')
var data = await res.json()
if (data.ok) {
this.agvPosition = data.position
this.agvBattery = data.battery
}
} catch (e) {}
},
agvMoveStart(dir) {
if (!this.agvConnected) return
fetch(API + '/api/agv/move', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ direction: dir, speed: this.agvSpeed })
})
},
agvMoveStop() {
fetch(API + '/api/agv/move', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ direction: 'stop' })
})
},
async agvStop() {
await fetch(API + '/api/agv/stop', { method: 'POST' })
},
async agvResetCollision() {
if (!this.agvConnected) {
alert('AGV 未连接')
return
}
if (!confirm('确定执行撞物体后复位?')) return
try {
var res = await fetch(API + '/api/agv/reset', { method: 'POST' })
var data = await res.json()
if (data.ok) {
alert('✅ ' + data.message)
await this.refresh()
await this.refreshAgvPosition()
} else {
alert('❌ 复位失败: ' + (data.error || '未知错误'))
}
} catch (e) {
alert('❌ 复位请求失败: ' + e.message)
}
},
}
})
const vm = app.mount('#app')
window.vm = vm // 暴露组件实例
File diff suppressed because one or more lines are too long