接入测试开始接收控制台
增加原子开始接收接口调用、独立接收状态和运行中接入标记,补充 Ticket08 浏览器接缝测试。
| | |
| | | "test:e2e:ticket04": "playwright test tests/e2e/device-registration.spec.ts", |
| | | "test:e2e:ticket05": "playwright test tests/e2e/shared-fields-and-battery-groups.spec.ts", |
| | | "test:e2e:ticket06": "playwright test tests/e2e/collector-sampling.spec.ts", |
| | | "test:e2e:ticket07": "playwright test tests/e2e/test-required-device-bindings.spec.ts" |
| | | "test:e2e:ticket07": "playwright test tests/e2e/test-required-device-bindings.spec.ts", |
| | | "test:e2e:ticket08": "playwright test tests/e2e/running-start-and-reception-boundaries.spec.ts" |
| | | }, |
| | | "dependencies": { |
| | | "@element-plus/icons-vue": "^2.3.2", |
| | |
| | | fieldType: string |
| | | fieldValue: string | null |
| | | }> |
| | | runtimeAttach?: boolean |
| | | } |
| | | |
| | | export interface TestConfigurationOptions { |
| | |
| | | createTime: string | null |
| | | startedAtUtc: string | null |
| | | endedAtUtc: string | null |
| | | runtimeAttach?: boolean | null |
| | | remark: string | null |
| | | batteryCount: number | null |
| | | } |
| | |
| | | export async function deleteTests(testIds: number[]): Promise<void> { |
| | | await request<ApiResponse>(`/system/test/${testIds.join(',')}`, { method: 'DELETE' }) |
| | | } |
| | | |
| | | /** 原子开始接收;后端确认全部来源后才会改变正式状态。 */ |
| | | export async function startTestReception(testId: number): Promise<TestConfigurationDetail> { |
| | | return (await request<TestDetailResponse>(`/system/test/${testId}/reception/start`, { method: 'POST' })).data |
| | | } |
| | |
| | | <script setup lang="ts"> |
| | | import { computed, onBeforeUnmount, ref } from 'vue' |
| | | import { computed, onBeforeUnmount, onMounted, ref } from 'vue' |
| | | import { ElMessage, ElMessageBox } from 'element-plus' |
| | | import { useRoute, useRouter } from 'vue-router' |
| | | import ConsoleChartPanel from '@/components/ConsoleChartPanel.vue' |
| | | import ConsoleProjectChartPanel from '@/components/ConsoleProjectChartPanel.vue' |
| | | import ConsoleDataListPanel from '@/components/ConsoleDataListPanel.vue' |
| | | import { useTests } from '@/stores/tests' |
| | | import { getTestDetail, startTestReception, type TestConfigurationDetail } from '@/api/tests' |
| | | |
| | | type ConsoleState = '检测中' | '暂停' | '已结束' |
| | | type ConsoleState = '未开始接收' | '检测中' | '暂停' | '已结束' |
| | | type ReceptionState = '未开始接收' | '接收中' | '暂停接收' | '已结束接收' |
| | | type ConsoleTab = 'realtime' | 'step-chart' | 'project-chart' | 'data-list' |
| | | |
| | | const route = useRoute() |
| | | const router = useRouter() |
| | | const { records: testRecords, updateTestStatus } = useTests() |
| | | const testId = computed(() => Number(route.params.id) || 1024) |
| | | const backendDetail = ref<TestConfigurationDetail | null>(null) |
| | | const runtimeAttach = ref(false) |
| | | const receptionState = ref<ReceptionState>('未开始接收') |
| | | const testProfiles: Record<number, { name: string; owner: string; purpose: string; startedAt: string; batteryGroup: string; batteryCount: number; abnormal: boolean }> = { |
| | | 1024: { name: '高温循环性能测试', owner: '张工', purpose: '验证高温环境循环寿命', startedAt: '2026-07-10 14:40:00', batteryGroup: '高温循环 A 组', batteryCount: 8, abnormal: false }, |
| | | 1023: { name: '电芯容量一致性测试', owner: '李工', purpose: '筛查批次容量离散度', startedAt: '2026-07-10 11:30:00', batteryGroup: '容量一致性 A 组', batteryCount: 6, abnormal: true }, |
| | |
| | | } |
| | | }) |
| | | const initialStatus = currentTest.value?.status |
| | | const state = ref<ConsoleState>(initialStatus === '检测完成' || route.query.state === 'ended' ? '已结束' : initialStatus === '暂停' ? '暂停' : '检测中') |
| | | const state = ref<ConsoleState>(initialStatus === '检测完成' || route.query.state === 'ended' ? '已结束' : initialStatus === '暂停' ? '暂停' : initialStatus === '待测试' ? '未开始接收' : '检测中') |
| | | const elapsedSeconds = ref(42 * 60 + 25) |
| | | const stepDialogVisible = ref(false) |
| | | const activeTab = ref<ConsoleTab>(route.query.tab === 'data-list' ? 'data-list' : 'realtime') |
| | |
| | | |
| | | const timer = window.setInterval(() => { if (state.value === '检测中') elapsedSeconds.value += 1 }, 1000) |
| | | onBeforeUnmount(() => window.clearInterval(timer)) |
| | | |
| | | onMounted(async () => { |
| | | try { |
| | | const detail = await getTestDetail(testId.value) |
| | | backendDetail.value = detail |
| | | runtimeAttach.value = detail.runtimeAttach === true |
| | | if (detail.receptionStatus === 'NOT_STARTED') { |
| | | state.value = '未开始接收' |
| | | receptionState.value = '未开始接收' |
| | | } else if (detail.receptionStatus === 'PAUSED') { |
| | | state.value = '暂停' |
| | | receptionState.value = '暂停接收' |
| | | } else if (detail.receptionStatus === 'ENDED') { |
| | | state.value = '已结束' |
| | | receptionState.value = '已结束接收' |
| | | } else { |
| | | state.value = '检测中' |
| | | receptionState.value = '接收中' |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error(error instanceof Error ? error.message : '测试状态加载失败') |
| | | } |
| | | }) |
| | | |
| | | const elapsedText = computed(() => { |
| | | const hours = Math.floor(elapsedSeconds.value / 3600) |
| | |
| | | const channels = computed(() => cells.value.map((cell, index) => ({ no: cell.no, cabinet: cell.cabinet, cabinetState: index === 2 && profile.value.abnormal ? '异常' : '在线', channel: cell.channel, collector: `采集器 COL-${String(Math.floor(index / 4) + 1).padStart(2, '0')}`, collectorState: '在线', temperature: `温度通道 ${index + 1}`, positive: `正电位通道 ${index + 1}`, negative: `负电位通道 ${index + 1}` }))) |
| | | |
| | | function togglePause() { |
| | | if (state.value === '已结束') return |
| | | if (state.value === '已结束' || state.value === '未开始接收') return |
| | | state.value = state.value === '暂停' ? '检测中' : '暂停' |
| | | updateTestStatus(testId.value, state.value === '暂停' ? '暂停' : '检测中') |
| | | ElMessage.success(state.value === '暂停' ? '测试已暂停' : '测试已继续') |
| | | } |
| | | |
| | | async function startReception() { |
| | | if (state.value !== '未开始接收') return |
| | | try { |
| | | backendDetail.value = await startTestReception(testId.value) |
| | | runtimeAttach.value = backendDetail.value.runtimeAttach === true |
| | | state.value = '检测中' |
| | | receptionState.value = '接收中' |
| | | updateTestStatus(testId.value, '检测中') |
| | | ElMessage.success('已开始接收,未向设备发送控制命令') |
| | | } catch (error) { |
| | | ElMessage.error(error instanceof Error ? error.message : '开始接收失败') |
| | | } |
| | | } |
| | | |
| | | async function endTest() { |
| | | if (state.value === '已结束') return |
| | | try { |
| | | await ElMessageBox.confirm('结束测试后将停止设备采集,是否继续?', '确认结束测试', { confirmButtonText: '结束测试', cancelButtonText: '取消', type: 'warning', confirmButtonClass: 'danger-confirm' }) |
| | | await ElMessageBox.confirm('结束接收将关闭本测试的数据接收区间,不会停止设备,是否继续?', '确认结束接收', { confirmButtonText: '结束接收', cancelButtonText: '取消', type: 'warning', confirmButtonClass: 'danger-confirm' }) |
| | | state.value = '已结束' |
| | | updateTestStatus(testId.value, '检测完成') |
| | | ElMessage.success('测试已结束') |
| | |
| | | <div v-show="activeTab === 'realtime'" class="tab-content"> |
| | | <section class="realtime-panel"> |
| | | <header class="realtime-header"> |
| | | <div><strong>实时数据</strong><span class="cell-count">{{ cells.length }} 个电池</span><span class="running-state" :class="state"><i></i>{{ state }}</span></div> |
| | | <div><strong>实时数据</strong><span class="cell-count">{{ cells.length }} 个电池</span><span class="running-state" :class="state"><i></i>{{ state }}</span><span class="reception-state"><i></i>{{ receptionState }}</span><span v-if="runtimeAttach" class="attach-state">运行中接入</span></div> |
| | | <dl><div><dt>测试开始时间</dt><dd>{{ profile.startedAt }}</dd></div><div><dt>测试已进行时间</dt><dd>{{ elapsedText }}</dd></div></dl> |
| | | <div class="test-actions"><button class="primary-button" type="button" :disabled="state === '已结束'" @click="togglePause"><el-icon><VideoPause v-if="state !== '暂停'" /><VideoPlay v-else /></el-icon>{{ state === '暂停' ? '继续测试' : '暂停测试' }}</button><button class="danger-button" type="button" :disabled="state === '已结束'" @click="endTest"><el-icon><CircleCloseFilled /></el-icon>结束测试</button></div> |
| | | <div class="test-actions"><button v-if="state === '未开始接收'" class="primary-button" type="button" @click="startReception"><el-icon><VideoPlay /></el-icon>开始接收</button><button v-else class="primary-button" type="button" :disabled="state === '已结束'" @click="togglePause"><el-icon><VideoPause v-if="state !== '暂停'" /><VideoPlay v-else /></el-icon>{{ state === '暂停' ? '继续接收' : '暂停接收' }}</button><button class="danger-button" type="button" :disabled="state === '已结束' || state === '未开始接收'" @click="endTest"><el-icon><CircleCloseFilled /></el-icon>结束接收</button></div> |
| | | </header> |
| | | <div class="cell-grid"> |
| | | <article v-for="cell in cells" :key="cell.no" class="cell-card"> |
| | |
| | | </template> |
| | | |
| | | <style scoped> |
| | | .console-page{width:100%;padding-bottom:24px}.page-tools{height:34px;display:flex;align-items:center;justify-content:space-between}.page-tools>span{color:#7f8d99;font-size:10px;font-weight:600}.back-button{display:inline-flex;align-items:center;gap:6px;border:0;color:#52606d;background:transparent;font-size:13px;cursor:pointer}.back-button:hover{color:var(--blue)}.primary-button,.secondary-button,.danger-button{height:34px;display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:0 13px;border:1px solid transparent;border-radius:3px;font-size:13px;font-weight:500;cursor:pointer;white-space:nowrap}.primary-button{color:#fff;background:var(--blue);border-color:var(--blue)}.secondary-button{color:#52606d;background:#fff;border-color:var(--line-strong)}.danger-button{color:#fff;background:#ee6666;border-color:#ee6666}.primary-button:disabled,.danger-button:disabled{opacity:.5;cursor:not-allowed}.realtime-panel,.panel,.parameter-panel{border:1px solid #d8e1e9;background:#fff}.realtime-panel{margin-bottom:16px}.realtime-header{min-height:96px;display:grid;grid-template-columns:minmax(190px,1fr) minmax(360px,2fr) auto;align-items:center;gap:24px;padding:16px 20px;border-bottom:1px solid var(--line)}.realtime-header>div:first-child{display:flex;align-items:center;gap:12px}.realtime-header strong{font-size:15px}.cell-count{color:#71808d;font-size:11px}.running-state{display:inline-flex;align-items:center;gap:6px;padding:4px 7px;border:1px solid;font-size:11px}.running-state i{width:5px;height:5px;border-radius:50%;background:currentColor}.running-state.检测中{color:#23865e;background:#edf9f3;border-color:#b8dfcd}.running-state.暂停{color:#b06a18;background:#fff8e9;border-color:#efd59e}.running-state.已结束{color:#7b8794;background:#f2f4f6;border-color:#d8dde2}.realtime-header dl{display:flex;gap:44px}.realtime-header dl>div{display:flex;align-items:center;gap:16px}.realtime-header dt{color:#52606d;font-size:12px}.realtime-header dd{color:#7b8794;font-family:'Cascadia Mono',Consolas,monospace;font-size:12px;font-weight:600}.test-actions{display:flex;gap:10px}.cell-grid{display:grid;grid-template-columns:repeat(4,minmax(190px,1fr));gap:24px;padding:22px 36px}.cell-card{min-width:0;border:1px solid #bec9d3;border-radius:6px;background:#f5f7fa;overflow:hidden}.cell-summary{display:flex;flex-direction:column;gap:7px;padding:16px 18px 12px;border-bottom:1px solid #c8d1d9}.cell-summary strong{color:#1268dc;font-size:13px}.cell-summary span{color:#37688e;font-size:12px;font-weight:600}.cell-summary p,.cell-summary small{color:#71808d;font-size:10px}.metric-list{display:grid;gap:12px;padding:14px 18px 16px}.metric-list>div{display:flex;align-items:center;justify-content:space-between}.metric-list dt{color:#52606d;font-size:10px}.metric-list dd{font-size:17px;font-weight:700}.metric-list .voltage{color:#7f35c5}.metric-list .temperature{color:#bf6100}.metric-list .positive{color:#e99f9f}.metric-list .negative{color:#176ee8}.metric-list .capacity{color:#f59a2a}.metric-list .current{color:#21628c}.console-layout{display:grid;grid-template-columns:minmax(0,2.35fr) minmax(270px,1fr);gap:16px;align-items:start}.console-layout main{display:grid;gap:16px}.panel-heading{height:48px;display:flex;align-items:center;justify-content:space-between;padding:0 16px;border-bottom:1px solid var(--line);background:#fbfdff}.panel-heading>div{display:flex;align-items:center;gap:8px}.panel-heading>div>i{width:3px;height:16px;background:#2b78a3}.panel-heading strong{color:#26333f;font-size:14px}.panel-heading span{color:#81909d;font-size:10px}.compact-button{height:30px;font-size:12px}.project-meta{display:flex;gap:32px;padding:14px 16px 0;color:#71808d;font-size:11px}.project-meta strong{margin-left:8px;color:#31404d}.step-table-wrap,.channel-table-wrap{overflow-x:auto;padding:14px 16px 18px}table{width:100%;border-collapse:collapse;color:#52606d;font-size:12px}th,td{height:38px;padding:0 10px;border:1px solid #d5e0e9;text-align:center;white-space:nowrap}th{color:#52606d;background:#eaf4ff;font-weight:600}.step-table tr.active td{background:#eef7ff}.step-table tr.active td:first-child{border-left:3px solid #2188f5}.step-state{font-size:11px}.step-state.进行中{color:#1677dd}.step-state.已完成{color:#23865e}.step-state.待执行{color:#8795a3}.parameter-panel dl{display:grid;gap:0;padding:12px 18px 18px}.parameter-panel dl>div{display:grid;grid-template-columns:88px minmax(0,1fr);gap:10px;padding:9px 0;border-bottom:1px solid #edf1f5}.parameter-panel dl>div:last-child{border-bottom:0}.parameter-panel dt{color:#71808d;font-size:11px}.parameter-panel dd{min-width:0;color:#52606d;font-size:11px;overflow-wrap:anywhere}.alarm-empty{height:68px;display:flex;align-items:center;gap:8px;margin:14px 16px;padding:0 16px;color:#71808d;background:#f4f7fa;font-size:12px}.alarm-empty .el-icon{color:#23865e;font-size:16px}.alarm-list{display:grid;gap:8px;padding:14px 16px}.alarm-list>div{display:flex;align-items:center;gap:10px;padding:10px 12px;border:1px solid #f0c8a3;background:#fff7ef;color:#b35a25}.alarm-list span,.alarm-list strong,.alarm-list small{display:block}.alarm-list strong{font-size:12px}.alarm-list small{margin-top:3px;color:#8c6849;font-size:10px}.channel-table-wrap table{min-width:1120px}.device-state{display:inline-flex;padding:3px 7px;border:1px solid;font-size:10px}.device-state.在线{color:#23865e;background:#edf9f3;border-color:#b8dfcd}.device-state.异常{color:#b34f4f;background:#fff1f1;border-color:#e9bcbc}.step-dialog-content{display:grid;gap:12px}.step-dialog-content>p{color:#71808d;font-size:12px}.step-dialog-content>strong{color:#26333f}.step-dialog-content dl{display:grid;grid-template-columns:repeat(3,1fr);gap:10px}.step-dialog-content dl>div{padding:12px;border:1px solid #d8e1e9;background:#f8fafc}.step-dialog-content dt{color:#8795a3;font-size:10px}.step-dialog-content dd{margin-top:5px;color:#405261;font-size:12px}@media(max-width:1280px){.cell-grid{gap:16px;padding:20px}.console-layout{grid-template-columns:minmax(0,1fr) 280px}}@media(max-width:1050px){.cell-grid{grid-template-columns:repeat(2,minmax(210px,1fr))}.realtime-header{grid-template-columns:1fr auto}.realtime-header dl{grid-column:1/-1;grid-row:2}.console-layout{grid-template-columns:1fr}.parameter-panel{grid-row:2}}@media(max-width:680px){.realtime-header{grid-template-columns:1fr}.realtime-header dl{grid-column:auto;grid-row:auto;align-items:flex-start;flex-direction:column;gap:10px}.test-actions{justify-content:stretch}.test-actions button{flex:1}.cell-grid{grid-template-columns:1fr;padding:14px}.project-meta{flex-direction:column;gap:8px}.step-dialog-content dl{grid-template-columns:1fr}} |
| | | .console-page{width:100%;padding-bottom:24px}.running-state.未开始接收{color:#7b8794;background:#f2f4f6;border-color:#d8dde2} |
| | | .reception-state{padding:4px 7px;border:1px solid #b9decf;color:#23865e;background:#edf9f3;font-size:11px} |
| | | .attach-state{padding:4px 7px;border:1px solid #bdd8f4;color:#1677dd;background:#edf6ff;font-size:11px} |
| | | /* 双栏收缩边界:宽表只能在所属面板内横向滚动,不能撑开主网格。 */ |
| | | .console-tabs{min-height:52px;display:flex;align-items:center;gap:10px;margin-bottom:14px;padding:0 4px;border-bottom:1px solid #d5e0e9}.console-tabs button{height:30px;min-width:88px;padding:0 16px;border:1px solid transparent;border-radius:16px;color:#52606d;background:#f5f7fa;font-size:12px;cursor:pointer;transition:.16s ease}.console-tabs button:hover{color:var(--blue);background:#edf5fd}.console-tabs button.active{color:#1677dd;background:#dff0ff;border-color:#c4e3ff;font-weight:600}.tab-content{min-width:0}.data-list-panel{min-width:0;border:1px solid #d8e1e9;background:#fff}.data-list-panel .panel-heading>small{color:#8795a3;font-size:10px}.data-table-wrap{width:100%;overflow-x:auto;padding:16px 18px 20px}.data-table-wrap table{min-width:1260px}.data-table-wrap td strong{color:#1268dc}.data-voltage{color:#7f35c5;font-weight:600}.data-temperature{color:#bf6100;font-weight:600} |
| | | .console-layout{grid-template-columns:minmax(0,2.35fr) minmax(300px,1fr);gap:24px;min-width:0} |
| New file |
| | |
| | | import { expect, test, type Page, type Request } from '@playwright/test' |
| | | |
| | | const detail = { |
| | | code: 200, |
| | | msg: '操作成功', |
| | | data: { |
| | | testId: 42, |
| | | testName: 'Ticket08 接收边界测试', |
| | | testStatus: 'WAITING', |
| | | receptionStatus: 'NOT_STARTED', |
| | | batteries: [], |
| | | planSteps: [], |
| | | thresholds: [], |
| | | fieldSnapshots: [], |
| | | runtimeAttach: false, |
| | | }, |
| | | } |
| | | |
| | | async function prepareConsole(page: Page) { |
| | | await page.addInitScript(() => { |
| | | localStorage.setItem('battery_detection_auth_token', 'ticket08-test-token') |
| | | localStorage.setItem('battery_detection_auth_user', JSON.stringify({ |
| | | username: 'operator', displayName: '操作员', role: '操作员', |
| | | })) |
| | | }) |
| | | await page.goto('/test-list/42/console') |
| | | await expect(page.getByRole('button', { name: '开始接收', exact: true })).toBeVisible() |
| | | } |
| | | |
| | | test('在线空闲来源开始接收并切换到接收中', async ({ page }) => { |
| | | let startRequest: Request | undefined |
| | | await page.route('**/system/test/42**', async route => { |
| | | if (route.request().method() === 'POST') { |
| | | startRequest = route.request() |
| | | await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ |
| | | ...detail, |
| | | data: { ...detail.data, testStatus: 'RUNNING', receptionStatus: 'RECEIVING' }, |
| | | }) }) |
| | | return |
| | | } |
| | | await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(detail) }) |
| | | }) |
| | | await prepareConsole(page) |
| | | |
| | | await page.getByRole('button', { name: '开始接收', exact: true }).click() |
| | | await expect.poll(() => startRequest?.method()).toBe('POST') |
| | | await expect(page.getByText('接收中', { exact: true })).toBeVisible() |
| | | await expect(page.getByText('已开始接收,未向设备发送控制命令', { exact: true })).toBeVisible() |
| | | }) |
| | | |
| | | test('运行中接入响应显示边界标记,失败响应保持未开始状态', async ({ page }) => { |
| | | await page.route('**/system/test/42**', async route => { |
| | | if (route.request().method() === 'POST') { |
| | | await route.fulfill({ status: 500, contentType: 'application/json', body: JSON.stringify({ |
| | | code: 500, msg: '检测柜通道 100 当前离线或不可观测', |
| | | }) }) |
| | | return |
| | | } |
| | | await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(detail) }) |
| | | }) |
| | | await prepareConsole(page) |
| | | |
| | | await page.getByRole('button', { name: '开始接收', exact: true }).click() |
| | | await expect(page.getByText('检测柜通道 100 当前离线或不可观测', { exact: true })).toBeVisible() |
| | | await expect(page.getByRole('button', { name: '开始接收', exact: true })).toBeVisible() |
| | | await expect(page.locator('.reception-state')).toHaveText('未开始接收') |
| | | }) |
| | | |
| | | test('后端确认运行中接入时控制台显示运行中接入', async ({ page }) => { |
| | | await page.addInitScript(() => { |
| | | localStorage.setItem('battery_detection_auth_token', 'ticket08-test-token') |
| | | }) |
| | | await page.route('**/system/test/42**', async route => { |
| | | await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ |
| | | ...detail, |
| | | data: { ...detail.data, testStatus: 'RUNNING', receptionStatus: 'RECEIVING', runtimeAttach: true }, |
| | | }) }) |
| | | }) |
| | | await page.goto('/test-list/42/console') |
| | | await expect(page.getByText('运行中接入', { exact: true })).toBeVisible() |
| | | await expect(page.getByText('接收中', { exact: true })).toBeVisible() |
| | | }) |