任务执行

This commit is contained in:
ywb
2026-05-23 10:02:19 +08:00
parent 35d5c3d70e
commit 6920403035
6 changed files with 883 additions and 420 deletions
+138
View File
@@ -774,3 +774,141 @@ a:hover { text-decoration: underline; }
color: #666;
font-size: 12px;
}
/* ========== 实时日志 ========== */
.log-box {
background: #0a0a0a;
color: #00ff88;
font-family: 'Courier New', 'Menlo', monospace;
font-size: 13px;
line-height: 1.6;
max-height: 320px;
overflow-y: auto;
padding: 12px 16px;
border-radius: 6px;
margin-top: 8px;
border: 1px solid #1a1a1a;
}
.log-line {
padding: 2px 0;
border-bottom: 1px solid #111;
word-break: break-all;
}
.log-empty {
color: #555;
font-style: italic;
padding: 12px 0;
}
/* ========== 弹窗 ========== */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.75);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
}
.modal {
background: #1a1a2e;
padding: 28px 32px;
border-radius: 12px;
min-width: 400px;
max-width: 90%;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.modal h3 {
margin: 0 0 12px 0;
color: #e0e0e0;
}
.modal p {
color: #aaa;
margin: 0 0 16px 0;
}
.modal input[type="text"] {
width: 100%;
padding: 10px 12px;
background: #0a0a0a;
border: 1px solid #333;
border-radius: 6px;
color: #e0e0e0;
font-size: 15px;
outline: none;
box-sizing: border-box;
}
.modal input[type="text"]:focus {
border-color: #409eff;
}
.modal-actions {
display: flex;
gap: 12px;
margin-top: 20px;
}
.modal-actions .btn {
flex: 1;
}
/* ========== 任务清单 ========== */
.task-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
gap: 10px;
margin-top: 10px;
}
.task-cell {
background: #0a0a0a;
border: 1px solid #1a1a1a;
border-radius: 8px;
padding: 12px;
text-align: center;
transition: all 0.3s;
}
.task-cell.task-active {
border-color: #409eff;
background: #0d1b2a;
}
.task-cell.task-completed {
border-color: #4caf50;
opacity: 0.7;
}
.task-cell.task-active .task-step-text {
color: #409eff;
font-weight: bold;
}
.task-pos {
font-size: 16px;
font-weight: bold;
color: #e0e0e0;
margin-bottom: 6px;
}
.task-status-icon {
font-size: 20px;
margin-bottom: 4px;
}
.task-step-text {
font-size: 12px;
color: #888;
margin-bottom: 4px;
}
.task-info {
font-size: 11px;
color: #666;
}
.task-qr {
font-family: monospace;
color: #aaa;
}
.task-photos {
color: #888;
}
.pulse-icon {
animation: taskPulse 1s infinite;
}
@keyframes taskPulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.3; }
}
+77 -27
View File
@@ -7,22 +7,27 @@ createApp({
data() {
return {
missionState: 'idle',
currentPoint: 0,
totalPoints: 0,
progress: 0,
tasks: [],
report: null,
previewUrl: API + '/api/camera/preview',
polling: null
polling: null,
logs: [],
showQrModal: false,
qrValue: '',
}
},
computed: {
missionStateText() {
const map = { idle: '空闲', running: '任务运行中', paused: '已暂停', completed: '已完成' }
const map = {
idle: '空闲',
running: '任务运行中',
paused: '已暂停',
completed: '已完成',
waiting_qr: '等待输入二维码'
}
return map[this.missionState] || '未知'
},
progressPercent() {
if (!this.totalPoints) return 0
return Math.round((this.currentPoint / this.totalPoints) * 100)
}
},
mounted() {
this.poll()
@@ -33,35 +38,55 @@ createApp({
methods: {
poll() {
this.refresh()
this.polling = setInterval(this.refresh, 2000)
this.pollLogs()
this.polling = setInterval(() => {
this.refresh()
this.pollLogs()
}, 2000)
},
async refresh() {
try {
const res = await fetch(API + '/api/mission/state')
const data = await res.json()
this.missionState = data.state || 'idle'
this.missionState = data.status || 'idle'
this.progress = data.progress || 0
if (data.tasks) this.tasks = data.tasks
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
}
// QR 弹窗
if (this.missionState === 'waiting_qr' && !this.showQrModal) {
this.showQrModal = true
this.qrValue = ''
}
// 完成后获取报告
if (this.missionState === 'idle' && this.tasks.length > 0) {
const reportRes = await fetch(API + '/api/mission/report')
const reportData = await reportRes.json()
this.report = reportData.report
}
} catch (e) {}
},
async pollLogs() {
if (this.missionState !== 'running' && this.missionState !== 'waiting_qr') return
try {
const res = await fetch(API + '/api/mission/log')
const data = await res.json()
if (data.log) this.logs = data.log
if (data.progress != null) this.progress = data.progress
if (data.tasks) this.tasks = data.tasks
// 自动滚到底
this.$nextTick(() => {
const box = this.$refs.logBox
if (box) box.scrollTop = box.scrollHeight
})
} catch (e) {}
},
async startMission() {
if (this.missionState !== 'idle') return
this.logs = []
this.progress = 0
this.report = null
this.showQrModal = false
await fetch(API + '/api/mission/start', { method: 'POST' })
this.missionState = 'running'
},
@@ -69,12 +94,37 @@ createApp({
await fetch(API + '/api/mission/pause', { method: 'POST' })
this.missionState = 'paused'
},
async resumeMission() {
await fetch(API + '/api/mission/resume', { method: 'POST' })
this.missionState = 'running'
this.showQrModal = false
},
async stopMission() {
await fetch(API + '/api/mission/stop', { method: 'POST' })
this.missionState = 'idle'
this.showQrModal = false
},
async submitQr() {
const val = this.qrValue.trim()
await fetch(API + '/api/mission/manual-qr', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ qr: val || ' ' })
})
this.showQrModal = false
this.qrValue = ''
},
cancelQr() {
this.showQrModal = false
this.qrValue = ''
fetch(API + '/api/mission/manual-qr', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ qr: 'SKIP' })
})
},
onPreviewError(e) {
e.target.style.display = 'none'
}
}
}).mount('#app')
}).mount('#app')