From 2f6f04dc89ab0aea2e9f58e695aaad8a7d29c809 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期四, 03 九月 2026 17:28:28 +0800
Subject: [PATCH] 接入测试预警异常页面
---
src/views/Exception.vue | 52 +++++++++++++++++-----------------------------------
1 files changed, 17 insertions(+), 35 deletions(-)
diff --git a/src/views/Exception.vue b/src/views/Exception.vue
index dc08b9a..724fa4d 100644
--- a/src/views/Exception.vue
+++ b/src/views/Exception.vue
@@ -1,7 +1,6 @@
<script setup lang="ts">
-import { computed, reactive, ref } from 'vue'
+import { computed, reactive, ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
-import { getCurrentUser } from '@/utils/auth'
import { useExceptions, type ExceptionRecord, type ExceptionStatus } from '@/stores/exceptions'
interface FilterState {
@@ -12,7 +11,8 @@
processor: string
}
-const { records, handleRecord: saveHandledRecord, removeRecord } = useExceptions()
+const { records, handleServerRecord, loadFromServer } = useExceptions()
+onMounted(async () => { if (!await loadFromServer()) ElMessage.error('异常记录加载失败,请检查后端服务') })
const statuses: ExceptionStatus[] = ['待处理', '已处理']
const processors = ['张工', '李工', '周工', '王工', '赵工', '陈工', 'Admin']
const filters = reactive<FilterState>({ id: '', testName: '', dateRange: null, status: '', processor: '' })
@@ -52,11 +52,6 @@
currentPage.value = 1
}
-function formatDateTime(date = new Date()) {
- const pad = (value: number) => String(value).padStart(2, '0')
- return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`
-}
-
async function handleException(item: ExceptionRecord) {
if (item.status === '已处理') return
@@ -69,27 +64,14 @@
inputValidator: value => value.trim() ? true : '请输入处理说明',
inputErrorMessage: '请输入处理说明',
})
- const processor = getCurrentUser()?.displayName || 'Admin'
- saveHandledRecord(item.id, processor, result.value.trim(), formatDateTime())
- ElMessage.success('异常记录已处理')
- } catch {
- // 用户取消处理。
- }
-}
-
-async function deleteException(item: ExceptionRecord) {
- try {
- await ElMessageBox.confirm(`删除异常记录“#${item.id}”后无法恢复,是否继续?`, '确认删除异常记录', {
- confirmButtonText: '删除',
- cancelButtonText: '取消',
- type: 'warning',
- confirmButtonClass: 'danger-confirm',
- })
- removeRecord(item.id)
- currentPage.value = Math.min(currentPage.value, Math.max(1, Math.ceil(filteredRecords.value.length / pageSize.value)))
- ElMessage.success('异常记录已删除')
- } catch {
- // 用户取消删除。
+ try {
+ await handleServerRecord(item.id, result.value.trim())
+ ElMessage.success('异常记录已处理')
+ } catch {
+ ElMessage.error('异常处理失败,请刷新后重试')
+ }
+ } catch (reason) {
+ if (reason !== 'cancel' && reason !== 'close') ElMessage.error('异常处理窗口打开失败')
}
}
@@ -103,9 +85,9 @@
return
}
- const headers = ['异常记录ID', '测试ID', '测试名称', '测试时间', '异常项', '异常值', '正常值', '异常生成时间', '处理人', '处理时间', '状态', '处理说明']
+ const headers = ['异常记录ID', '测试ID', '测试名称', '测试时间', '来源', '异常项', '异常值', '正常值', '异常生成时间', '处理人', '处理时间', '状态', '处理说明']
const rows = filteredRecords.value.map(item => [
- item.id, item.testId, item.testName, item.testTime, item.exceptionItem, item.abnormalValue,
+ item.id, item.testId, item.testName, item.testTime, item.source, item.exceptionItem, item.abnormalValue,
item.normalValue, item.generatedAt, item.processor || '-', item.handledAt, item.status, item.handleRemark || '-',
])
const csv = `\uFEFF${[headers, ...rows].map(row => row.map(escapeCsv).join(',')).join('\n')}`
@@ -146,13 +128,13 @@
</div>
<div class="table-wrap">
<table>
- <thead><tr><th>异常记录ID</th><th>测试ID</th><th>测试名称</th><th>测试时间</th><th>异常项</th><th>异常值</th><th>正常值</th><th>异常生成时间</th><th>处理人</th><th>处理时间</th><th>状态</th><th class="action-column">操作</th></tr></thead>
+ <thead><tr><th>异常记录ID</th><th>测试ID</th><th>测试名称</th><th>测试时间</th><th>来源</th><th>异常项</th><th>异常值</th><th>正常值</th><th>异常生成时间</th><th>处理人</th><th>处理时间</th><th>状态</th><th class="action-column">操作</th></tr></thead>
<tbody>
<tr v-for="item in pagedRecords" :key="item.id">
<td class="id-cell">#{{ item.id }}</td>
<td class="code-cell">#{{ item.testId }}</td>
<td><strong>{{ item.testName }}</strong></td>
- <td>{{ item.testTime }}</td>
+ <td>{{ item.testTime }}</td><td>{{ item.source }}</td>
<td>{{ item.exceptionItem }}</td>
<td class="abnormal-value">{{ item.abnormalValue }}</td>
<td>{{ item.normalValue }}</td>
@@ -160,9 +142,9 @@
<td>{{ item.processor || '-' }}</td>
<td>{{ item.handledAt }}</td>
<td><span class="status-tag" :class="item.status === '待处理' ? 'pending' : 'handled'"><i></i>{{ item.status }}</span></td>
- <td class="action-column"><div class="row-actions"><button v-if="item.status === '待处理'" type="button" @click="handleException(item)">处理</button><button class="delete-action" type="button" @click="deleteException(item)">删除</button></div></td>
+ <td class="action-column"><div class="row-actions"><button v-if="item.status === '待处理'" type="button" @click="handleException(item)">处理</button></div></td>
</tr>
- <tr v-if="!pagedRecords.length"><td colspan="12" class="empty-cell">暂无符合条件的异常记录</td></tr>
+ <tr v-if="!pagedRecords.length"><td colspan="13" class="empty-cell">暂无符合条件的异常记录</td></tr>
</tbody>
</table>
</div>
--
Gitblit v1.7.1