feat: 修订了调试功能
这个提交包含在:
@ -56,6 +56,18 @@ const debugMenuItems = ref<DebugMenuItem[]>([])
|
||||
const debugMenuLoading = ref(false)
|
||||
const debugMenuError = ref('')
|
||||
const debugActionLoading = ref<string | null>(null)
|
||||
const debugFieldId = ref('')
|
||||
const queryAnswerLoading = ref(false)
|
||||
const undoLoading = ref(false)
|
||||
|
||||
type GuardedFieldInfo = {
|
||||
field_id: string
|
||||
source: string | null
|
||||
tolerance: number | null
|
||||
placeholder: string | null
|
||||
unit: string | null
|
||||
}
|
||||
const guardedFields = ref<GuardedFieldInfo[]>([])
|
||||
|
||||
const currentExperiment = computed((): string => {
|
||||
const hash = window.location.hash
|
||||
@ -125,6 +137,20 @@ const loadDebugMenu = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const loadGuardedFields = async () => {
|
||||
try {
|
||||
const url = `${backendUrl.value}/debug/guarded-fields?experiment=${encodeURIComponent(currentExperiment.value)}`
|
||||
const resp = await fetch(url)
|
||||
if (resp.ok) {
|
||||
const data = await resp.json()
|
||||
guardedFields.value = (data?.fields || []) as GuardedFieldInfo[]
|
||||
if (guardedFields.value.length > 0 && !debugFieldId.value) {
|
||||
debugFieldId.value = guardedFields.value[0]!.field_id
|
||||
}
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
const executeDebugAction = async (item: DebugMenuItem) => {
|
||||
debugActionLoading.value = item.action
|
||||
const resultId = ++resultIdCounter
|
||||
@ -163,6 +189,58 @@ const executeDebugAction = async (item: DebugMenuItem) => {
|
||||
debugActionLoading.value = null
|
||||
}
|
||||
|
||||
const queryAnswer = async () => {
|
||||
const fid = debugFieldId.value.trim()
|
||||
if (!fid) return
|
||||
queryAnswerLoading.value = true
|
||||
const resultId = ++resultIdCounter
|
||||
const entry: DebugResult = {
|
||||
id: resultId, timestamp: Date.now(),
|
||||
label: `答案查询: ${fid}`,
|
||||
endpoint: `GET ${backendUrl.value}/debug/answer?field_id=${fid}`,
|
||||
method: 'GET', success: false, body: null, error: '',
|
||||
}
|
||||
try {
|
||||
const url = `${backendUrl.value}/debug/answer?field_id=${encodeURIComponent(fid)}&experiment=${encodeURIComponent(currentExperiment.value)}`
|
||||
const resp = await fetch(url)
|
||||
const body = (await resp.json().catch(() => resp.text())) as unknown
|
||||
entry.success = resp.ok
|
||||
entry.body = body
|
||||
} catch (e: any) {
|
||||
entry.error = e.message || String(e)
|
||||
}
|
||||
debugResults.value.unshift(entry)
|
||||
if (debugResults.value.length > 50) debugResults.value.length = 50
|
||||
expandedResult.value = resultId
|
||||
queryAnswerLoading.value = false
|
||||
}
|
||||
|
||||
const undoLastReading = async () => {
|
||||
const fid = debugFieldId.value.trim()
|
||||
if (!fid) return
|
||||
undoLoading.value = true
|
||||
const resultId = ++resultIdCounter
|
||||
const entry: DebugResult = {
|
||||
id: resultId, timestamp: Date.now(),
|
||||
label: `回退: ${fid}`,
|
||||
endpoint: `POST ${backendUrl.value}/value/undo?field_id=${fid}`,
|
||||
method: 'POST', success: false, body: null, error: '',
|
||||
}
|
||||
try {
|
||||
const url = `${backendUrl.value}/value/undo?field_id=${encodeURIComponent(fid)}&experiment=${encodeURIComponent(currentExperiment.value)}`
|
||||
const resp = await fetch(url, { method: 'POST' })
|
||||
const body = (await resp.json().catch(() => resp.text())) as unknown
|
||||
entry.success = resp.ok
|
||||
entry.body = body
|
||||
} catch (e: any) {
|
||||
entry.error = e.message || String(e)
|
||||
}
|
||||
debugResults.value.unshift(entry)
|
||||
if (debugResults.value.length > 50) debugResults.value.length = 50
|
||||
expandedResult.value = resultId
|
||||
undoLoading.value = false
|
||||
}
|
||||
|
||||
const togglePanel = () => {
|
||||
if (!isVisible.value) {
|
||||
loadExperiences()
|
||||
@ -211,6 +289,7 @@ onMounted(() => {
|
||||
if (debugEnabled.value) {
|
||||
loadExperiences()
|
||||
loadDebugMenu()
|
||||
loadGuardedFields()
|
||||
}
|
||||
})
|
||||
|
||||
@ -336,6 +415,39 @@ const navToExperience = (id: string) => {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="debug-field" style="margin-top:0.5rem">
|
||||
<label>fieldId 选择器</label>
|
||||
<div class="debug-input-row">
|
||||
<select
|
||||
v-model="debugFieldId"
|
||||
class="debug-input debug-select"
|
||||
>
|
||||
<option v-if="guardedFields.length === 0" value="">加载中...</option>
|
||||
<option
|
||||
v-for="gf in guardedFields"
|
||||
:key="gf.field_id"
|
||||
:value="gf.field_id"
|
||||
>
|
||||
{{ gf.field_id }} ({{ gf.source || 'manual' }} ±{{ gf.tolerance }})
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
class="debug-btn debug-btn-sm"
|
||||
:disabled="queryAnswerLoading || !debugFieldId"
|
||||
@click="queryAnswer"
|
||||
>
|
||||
{{ queryAnswerLoading ? '...' : '查答案' }}
|
||||
</button>
|
||||
<button
|
||||
class="debug-btn debug-btn-sm debug-btn-danger"
|
||||
:disabled="undoLoading || !debugFieldId"
|
||||
@click="undoLastReading"
|
||||
>
|
||||
{{ undoLoading ? '...' : '回退' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="debugResults.length > 0" class="debug-results">
|
||||
<div class="debug-logs-header">
|
||||
<span>操作结果({{ debugResults.length }})</span>
|
||||
@ -531,6 +643,11 @@ const navToExperience = (id: string) => {
|
||||
border-color: #007bff;
|
||||
}
|
||||
|
||||
.debug-select {
|
||||
flex: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.debug-btn {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
@ -550,6 +667,14 @@ const navToExperience = (id: string) => {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.debug-btn-danger {
|
||||
background: #dc3545;
|
||||
}
|
||||
|
||||
.debug-btn-danger:hover {
|
||||
background: #c82333;
|
||||
}
|
||||
|
||||
.debug-btn-sm {
|
||||
padding: 0.35rem 0.6rem;
|
||||
font-size: 0.8rem;
|
||||
|
||||
@ -31,6 +31,12 @@ const fieldData = computed(() => experimentStore.data)
|
||||
const areaResults = computed(() => experimentStore.areaResults)
|
||||
const allFieldsValidated = computed(() => experimentStore.allFieldsValidated)
|
||||
const dataVersion = computed(() => experimentStore.dataVersion)
|
||||
const pendingField = computed(() => experimentStore.pendingField)
|
||||
const controlStatus = computed(() => experimentStore.controlStatus)
|
||||
const backendBaseUrl = computed(() => {
|
||||
if (!props.validationUrl) return ''
|
||||
return props.validationUrl.replace(/\/value\/?$/, '')
|
||||
})
|
||||
|
||||
const configSummary = computed<ConfigSummary>(() => {
|
||||
const fields: ConfigSummary['fields'] = []
|
||||
@ -185,6 +191,9 @@ watch(allFieldsValidated, (newValue) => {
|
||||
:area-results="areaResults"
|
||||
:on-field-update="handleFieldUpdate"
|
||||
:on-field-validate="handleFieldValidate"
|
||||
:pending-field="pendingField"
|
||||
:backend-base-url="backendBaseUrl"
|
||||
:control-status="controlStatus"
|
||||
:cell-inspect-mode="cellInspectMode"
|
||||
:on-cell-inspect="(info: any) => emit('cell-inspect', info)"
|
||||
/>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject } from 'vue'
|
||||
import { computed, inject, ref } from 'vue'
|
||||
import type { GridSheet, GridCell, GridInputCell } from '@/types/experiment'
|
||||
import ExperimentGridCell from './ExperimentGridCell.vue'
|
||||
import { AIEvalContextKey } from '@/utils/aiEvalContext'
|
||||
@ -7,10 +7,13 @@ import { renderTextWithLatex } from '@/utils/latex'
|
||||
|
||||
const props = defineProps<{
|
||||
sheet: GridSheet
|
||||
fieldData: Record<string, { value: any; validated: boolean; validationResult?: { accept: boolean; message: string } }>
|
||||
fieldData: Record<string, { value: any; validated: boolean; validationResult?: { accept: boolean; message: string; severity?: string } }>
|
||||
areaResults: Record<string, { value: any; formatted: string; error?: string }>
|
||||
onFieldUpdate: (fieldId: string, value: any) => void
|
||||
onFieldValidate: (fieldId: string) => void
|
||||
pendingField?: string | null
|
||||
backendBaseUrl?: string
|
||||
controlStatus?: string | null
|
||||
cellInspectMode?: boolean
|
||||
onCellInspect?: (info: { sheetTitle?: string; cellType: string; label: string; value: any; unit?: string; validation?: any }) => void
|
||||
}>()
|
||||
@ -40,6 +43,31 @@ function getCellValidationResult(cell: GridCell) {
|
||||
return props.fieldData[cell.fieldId]?.validationResult
|
||||
}
|
||||
|
||||
function isCellPending(cell: GridCell): boolean {
|
||||
if (!props.pendingField || !cell || cell.type !== 'input') return false
|
||||
return (cell as GridInputCell).fieldId === props.pendingField
|
||||
}
|
||||
|
||||
function isCellLocked(cell: GridCell): boolean {
|
||||
if (!cell || cell.type !== 'input') return false
|
||||
const inp = cell as GridInputCell
|
||||
if (!inp.readingGuard?.enabled) return false
|
||||
if (!props.pendingField) return inp.fieldId !== findFirstGuardedField()
|
||||
return inp.fieldId !== props.pendingField
|
||||
}
|
||||
|
||||
function findFirstGuardedField(): string {
|
||||
if (!props.sheet.cells) return ''
|
||||
for (const row of props.sheet.cells) {
|
||||
for (const cell of row) {
|
||||
if (cell && cell.type === 'input' && (cell as GridInputCell).readingGuard?.enabled) {
|
||||
return (cell as GridInputCell).fieldId
|
||||
}
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
function getCellAreaResult(cell: GridCell) {
|
||||
if (!cell || cell.type !== 'computed') return undefined
|
||||
return props.areaResults[cell.areaId]
|
||||
@ -50,6 +78,8 @@ function onCellInput(fieldId: string, value: any) {
|
||||
}
|
||||
|
||||
function onCellBlur(fieldId: string) {
|
||||
const val = props.fieldData[fieldId]?.value
|
||||
if (val === null || val === undefined || val === '') return
|
||||
props.onFieldValidate(fieldId)
|
||||
}
|
||||
|
||||
@ -87,6 +117,25 @@ function handleCellInspect(cell: GridCell) {
|
||||
const isFirstRowHeader = computed(() => {
|
||||
return props.sheet.columnHeaders && props.sheet.columnHeaders.length > 0
|
||||
})
|
||||
|
||||
const controlBar = computed(() => props.sheet.controlBar?.items || [])
|
||||
|
||||
const displayStatus = computed(() => {
|
||||
if (!props.controlStatus) return ''
|
||||
if (localStorage.getItem('DEBUG') === 'true') return props.controlStatus
|
||||
const s = props.controlStatus
|
||||
if (s.startsWith('空闲')) return '就绪'
|
||||
if (s.startsWith('上升中')) return '监控中'
|
||||
if (s.startsWith('峰值已检测')) return '峰值就绪,请读数'
|
||||
if (s.startsWith('冷却中')) return '监控中'
|
||||
return props.controlStatus
|
||||
})
|
||||
|
||||
function handleControlAction(item: { id: string; method?: string; endpoint?: string }) {
|
||||
if (!item.endpoint || !props.backendBaseUrl) return
|
||||
const url = props.backendBaseUrl + item.endpoint
|
||||
fetch(url, { method: item.method || 'GET' }).catch(() => {})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -107,6 +156,24 @@ const isFirstRowHeader = computed(() => {
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<thead v-if="controlBar.length > 0" class="grid-control-bar">
|
||||
<tr>
|
||||
<td :colspan="sheet.columns" class="control-bar-cell">
|
||||
<div class="control-bar-row">
|
||||
<template v-for="item in controlBar" :key="item.id">
|
||||
<button
|
||||
v-if="item.type === 'action'"
|
||||
class="control-btn"
|
||||
@click="handleControlAction(item)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</button>
|
||||
</template>
|
||||
<span v-if="controlStatus" class="control-status">{{ displayStatus }}</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, ri) in effectiveRows.rows" :key="ri" class="grid-row">
|
||||
<td
|
||||
@ -126,6 +193,8 @@ const isFirstRowHeader = computed(() => {
|
||||
:validated="getCellValidated(cell)"
|
||||
:validation-result="getCellValidationResult(cell)"
|
||||
:area-result="getCellAreaResult(cell)"
|
||||
:is-pending="isCellPending(cell)"
|
||||
:is-locked="isCellLocked(cell)"
|
||||
:inspect-mode="cellInspectMode"
|
||||
@input="(val: any) => onCellInput((cell as GridInputCell).fieldId, val)"
|
||||
@blur="() => onCellBlur((cell as GridInputCell).fieldId)"
|
||||
@ -196,4 +265,42 @@ const isFirstRowHeader = computed(() => {
|
||||
.grid-cell-wrapper:first-child {
|
||||
min-width: 70px;
|
||||
}
|
||||
|
||||
.grid-control-bar {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.control-bar-cell {
|
||||
padding: 6px 10px;
|
||||
background: #f0f4f8;
|
||||
border-bottom: 2px solid #d0d4da;
|
||||
}
|
||||
|
||||
.control-bar-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.control-status {
|
||||
font-size: 0.85rem;
|
||||
color: #333;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
background: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 0.35rem 0.6rem;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.control-btn:hover {
|
||||
background: #0056b3;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -9,9 +9,11 @@ const props = defineProps<{
|
||||
cell: GridCell
|
||||
value?: any
|
||||
validated?: boolean
|
||||
validationResult?: { accept: boolean; message: string }
|
||||
validationResult?: { accept: boolean; message: string; severity?: string }
|
||||
areaResult?: { value: any; formatted: string; error?: string }
|
||||
inspectMode?: boolean
|
||||
isPending?: boolean
|
||||
isLocked?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@ -53,14 +55,15 @@ const bgColor = computed(() => {
|
||||
|
||||
if (isFocused.value) return '#e8f0fe'
|
||||
|
||||
if (props.validated && props.validationResult?.accept) {
|
||||
return '#d4edda'
|
||||
}
|
||||
if (props.validated && props.validationResult && !props.validationResult.accept) {
|
||||
if (props.validationResult && !props.validationResult.accept) {
|
||||
return '#f8d7da'
|
||||
}
|
||||
if (props.value !== null && props.value !== undefined && props.value !== '') {
|
||||
return '#fff3cd'
|
||||
if (props.validated && props.validationResult?.accept) {
|
||||
if (props.validationResult.severity === 'warning') return '#fff3cd'
|
||||
return '#d4edda'
|
||||
}
|
||||
if (hasValue.value) {
|
||||
return '#e8f0fe'
|
||||
}
|
||||
return '#ffffff'
|
||||
})
|
||||
@ -174,6 +177,8 @@ onBeforeUnmount(() => {
|
||||
'cell-focused': isFocused,
|
||||
'cell-inspect-mode': inspectMode,
|
||||
'cell-inspect-hover': inspectMode && isHovering,
|
||||
'cell-pending': isInput && isPending && !isFocused,
|
||||
'cell-locked': isInput && isLocked,
|
||||
}"
|
||||
:style="{
|
||||
backgroundColor: isLabel ? labelBgColor : isInput ? bgColor : isComputed ? (areaResult?.error ? '#f8d7da' : '#f0fff4') : 'transparent',
|
||||
@ -191,6 +196,7 @@ onBeforeUnmount(() => {
|
||||
class="cell-input-field"
|
||||
:value="internalValue"
|
||||
:placeholder="inputCell?.placeholder || ''"
|
||||
:disabled="isLocked"
|
||||
@input="handleInput"
|
||||
@blur="handleBlur"
|
||||
@focus="handleFocus"
|
||||
@ -254,6 +260,23 @@ onBeforeUnmount(() => {
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
.cell-pending {
|
||||
outline: 3px solid #ff6b35;
|
||||
outline-offset: -2px;
|
||||
animation: pending-pulse 1.5s ease-in-out infinite;
|
||||
box-shadow: 0 0 6px rgba(255, 107, 53, 0.35);
|
||||
}
|
||||
|
||||
.cell-locked {
|
||||
cursor: not-allowed;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@keyframes pending-pulse {
|
||||
0%, 100% { box-shadow: 0 0 4px rgba(255, 107, 53, 0.3); }
|
||||
50% { box-shadow: 0 0 12px rgba(255, 107, 53, 0.6); }
|
||||
}
|
||||
|
||||
.cell-inspect-mode {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户