This commit is contained in:
caozehui
2025-01-09 11:13:34 +08:00
parent b94e0323d9
commit 80d1912fd5
2 changed files with 120 additions and 82 deletions

View File

@@ -115,17 +115,19 @@ export namespace CheckData {
ERRORDATA = 4 ERRORDATA = 4
} }
export interface DeviceCheckResult {
deviceId: string,
deviceName: string,
chnResult: ChnCheckResultEnum[] //通道检测结果
}
//用来描述 某个脚本测试项对所有通道的检测结果 //用来描述 某个脚本测试项对所有通道的检测结果
export interface ScriptChnItem { export interface ScriptChnItem {
scriptType: string scriptType: string
scriptName?: string //可以不要该属性,有点多余 scriptName?: string //可以不要该属性,有点多余
// 设备 // 设备
devices: Array<{ devices: Array<DeviceCheckResult>
deviceId: string,
deviceName: string,
chnResult: ChnCheckResultEnum[] //通道检测结果
}>
} }
export enum ButtonColorEnum { export enum ButtonColorEnum {

View File

@@ -187,7 +187,7 @@ const timeDifference = ref(0)
// 真正的检测结果(详细到通道) // 真正的检测结果(详细到通道)
const checkResult = reactive<CheckData.ScriptChnItem[]>([]) const checkResult = reactive<CheckData.ScriptChnItem[]>([])
// 用来存放检测出现失败的测试项id。只要有一个通道检测不合格则该检测项的id会被加入该数组。 // 用来存放检测出现失败的测试项id。只要有一个通道检测不合格则该检测项的id会被加入该数组。
let errorCheckItem: Array<{ scriptType: string, type: 'info' | 'warning' | 'error' }> = [] let errorCheckItem: Array<{ scriptType: string, type: CheckData.ChnCheckResultEnum }> = []
// 用来存放检测日志 // 用来存放检测日志
const testLogList = reactive<CheckData.LogItem[]>([{type: 'info', log: '暂无数据,等待检测开始'}]) const testLogList = reactive<CheckData.LogItem[]>([{type: 'info', log: '暂无数据,等待检测开始'}])
@@ -247,6 +247,12 @@ const checkResultView: ComputedRef<CheckData.ScriptChnViewItem[]> = computed(()
} }
} else { } else {
let tempChnResult: CheckData.ChnCheckResultEnum = device.chnResult[0] let tempChnResult: CheckData.ChnCheckResultEnum = device.chnResult[0]
if (device.chnResult.some(item => item == CheckData.ChnCheckResultEnum.ERRORDATA)) {
tempChnResult = CheckData.ChnCheckResultEnum.ERRORDATA
}
if (device.chnResult.some(item => item == CheckData.ChnCheckResultEnum.TIMEOUT)) {
tempChnResult = CheckData.ChnCheckResultEnum.TIMEOUT
}
if (device.chnResult.some(item => item == CheckData.ChnCheckResultEnum.FAIL)) { if (device.chnResult.some(item => item == CheckData.ChnCheckResultEnum.FAIL)) {
tempChnResult = CheckData.ChnCheckResultEnum.FAIL tempChnResult = CheckData.ChnCheckResultEnum.FAIL
} }
@@ -299,7 +305,7 @@ watch(testStatus, function (newValue, oldValue) {
percentage.value = 0 percentage.value = 0
} }
emit('update:testStatus', 'test_init') emit('update:testStatus', 'test_init')
// startTimer() // todo 可移除 //startTimer() // todo 可移除
testLogList.push({type: 'info', log: `${new Date().toLocaleString()}:初始化开始!`}) testLogList.push({type: 'info', log: `${new Date().toLocaleString()}:初始化开始!`})
} }
}) })
@@ -310,7 +316,7 @@ watch(webMsgSend, function (newValue, oldValue) {
confirmButtonText: '确定', confirmButtonText: '确定',
type: 'error', type: 'error',
}) })
testLogList.push({type: 'error', log: `${new Date().toLocaleString()}${newValue.data}设备通讯中断`}) testLogList.push({type: 'error', log: `${new Date().toLocaleString()}${newValue.data}设备通讯失败`})
emit('update:testStatus', 'test_init_fail') emit('update:testStatus', 'test_init_fail')
} else if (newValue.code == 10551) { } else if (newValue.code == 10551) {
ElMessageBox.alert(`${newValue.data}设备触发报告异常!`, '初始化失败', { ElMessageBox.alert(`${newValue.data}设备触发报告异常!`, '初始化失败', {
@@ -339,10 +345,6 @@ watch(webMsgSend, function (newValue, oldValue) {
confirmButtonText: '确定', confirmButtonText: '确定',
type: 'error', type: 'error',
}) })
testLogList.push({
type: 'warning',
log: `${new Date().toLocaleString()}:连接超时!`
})
emit('update:testStatus', 'connect_timeout') emit('update:testStatus', 'connect_timeout')
break; break;
} }
@@ -395,7 +397,7 @@ watch(webMsgSend, function (newValue, oldValue) {
testLogList.push({type: 'info', log: `${new Date().toLocaleString()}:初始化成功!`}) testLogList.push({type: 'info', log: `${new Date().toLocaleString()}:初始化成功!`})
percentage.value = 3 percentage.value = 3
activeIndex = getNextActiveIndex() + 2 activeIndex = getNextActiveIndex() + 2
// startTimer() //startTimer()
emit('update:testStatus', 'process') emit('update:testStatus', 'process')
} }
@@ -428,7 +430,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('FREQ') activeIndex = getNextActiveIndex('FREQ')
// startTimer() //startTimer()
} }
break; break;
case 'V_Start': case 'V_Start':
@@ -441,7 +443,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('V') activeIndex = getNextActiveIndex('V')
// startTimer() //startTimer()
} }
break; break;
case 'HV_Start': case 'HV_Start':
@@ -454,7 +456,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('HV') activeIndex = getNextActiveIndex('HV')
// startTimer() //startTimer()
} }
break; break;
case 'HI_Start': case 'HI_Start':
@@ -467,7 +469,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('HI') activeIndex = getNextActiveIndex('HI')
// startTimer() //startTimer()
} }
break; break;
case 'HP_Start': case 'HP_Start':
@@ -480,7 +482,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('HP') activeIndex = getNextActiveIndex('HP')
// startTimer() //startTimer()
} }
break; break;
case 'HSV_Start': case 'HSV_Start':
@@ -493,7 +495,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('HSV') activeIndex = getNextActiveIndex('HSV')
// startTimer() //startTimer()
} }
break; break;
case 'HSI_Start': case 'HSI_Start':
@@ -506,7 +508,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('HSI') activeIndex = getNextActiveIndex('HSI')
// startTimer() //startTimer()
} }
break; break;
case 'VOLTAGE_Start': case 'VOLTAGE_Start':
@@ -519,7 +521,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('VOLTAGE') activeIndex = getNextActiveIndex('VOLTAGE')
// startTimer() //startTimer()
} }
break; break;
case 'I_Start': case 'I_Start':
@@ -532,7 +534,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('I') activeIndex = getNextActiveIndex('I')
// startTimer() //startTimer()
} }
break; break;
case 'IMBV_Start': case 'IMBV_Start':
@@ -545,7 +547,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('IMBV') activeIndex = getNextActiveIndex('IMBV')
// startTimer() //startTimer()
} }
break; break;
case 'IMBA_Start': case 'IMBA_Start':
@@ -558,7 +560,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('IMBA') activeIndex = getNextActiveIndex('IMBA')
// startTimer() //startTimer()
} }
break; break;
case 'F_Start': case 'F_Start':
@@ -571,7 +573,7 @@ watch(webMsgSend, function (newValue, oldValue) {
updateLog(false) updateLog(false)
if (testStatus.value != 'paused') { if (testStatus.value != 'paused') {
activeIndex = getNextActiveIndex('F') activeIndex = getNextActiveIndex('F')
// startTimer() //startTimer()
} }
break; break;
case 'Quit': case 'Quit':
@@ -694,15 +696,6 @@ function getRandomInt(max: number): number {
return Math.floor(Math.random() * max) return Math.floor(Math.random() * max)
} }
//判断该检测项(例如 频率准确度检测)是否全部合格(所有设备所有通道所有子检测项目全部合格为合格,否则为不合格)
function getItemCheckResult(scriptType: string): boolean {
let items = errorCheckItem.filter((item) => item.scriptType === scriptType)
if (items.length > 0) {
return true
} else {
return false
}
}
function getTimeDifference(timeDifference: number): string { function getTimeDifference(timeDifference: number): string {
// 将时间差转换为天、小时、分钟、秒 // 将时间差转换为天、小时、分钟、秒
@@ -746,16 +739,32 @@ const updateLog = (isStart: boolean) => {
timeDifferenceItem = endData.value.getTime() - startData.value.getTime(); timeDifferenceItem = endData.value.getTime() - startData.value.getTime();
timeDifference.value += timeDifferenceItem timeDifference.value += timeDifferenceItem
if (getItemCheckResult(scriptData[activeIndex - 1].id)) { let errorItem = getErrorCheckItem(scriptData[activeIndex - 1].id)
testLogList.push({ switch (errorItem?.type) {
type: 'error', case CheckData.ChnCheckResultEnum.SUCCESS:
log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:不符合,用时` + getTimeDifference(timeDifferenceItem),
})
} else {
testLogList.push({ testLogList.push({
type: 'info', type: 'info',
log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:符合,用时` + getTimeDifference(timeDifferenceItem), log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:符合,用时` + getTimeDifference(timeDifferenceItem),
}) })
break
case CheckData.ChnCheckResultEnum.FAIL:
testLogList.push({
type: 'error',
log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:不符合,用时` + getTimeDifference(timeDifferenceItem),
})
break
case CheckData.ChnCheckResultEnum.TIMEOUT:
testLogList.push({
type: 'warning',
log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:连接超时,用时` + getTimeDifference(timeDifferenceItem),
})
break
case CheckData.ChnCheckResultEnum.ERRORDATA:
testLogList.push({
type: 'warning',
log: currentTime.value + ` ${scriptData[activeIndex - 1].scriptName}准确度检测结束:数据异常,用时` + getTimeDifference(timeDifferenceItem),
})
break
} }
if (activeIndex === checkTotal) { if (activeIndex === checkTotal) {
@@ -782,31 +791,58 @@ const updateLog = (isStart: boolean) => {
// } // }
// } // }
const setErrorCheckItem = (scriptType: string, devices: any[]) => { const setErrorCheckItem = (scriptType: string, devices: CheckData.DeviceCheckResult[]) => {
let flag = true let type = 1
let tempChnResult: CheckData.ChnCheckResultEnum[] = []
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
for (let j = 0; j < devices[i].chnResult.length; j++) { tempChnResult.push(...devices[i].chnResult)
if (devices[i].chnResult[j] === CheckData.ChnCheckResultEnum.FAIL) { }
flag = false
break if (tempChnResult.some(item => item === CheckData.ChnCheckResultEnum.TIMEOUT)) {
type = CheckData.ChnCheckResultEnum.TIMEOUT
for (let i = 0; i < devices.length; i++) {
if (devices[i].chnResult.some(item => item === CheckData.ChnCheckResultEnum.TIMEOUT)) {
testLogList.push({
type: 'warning',
log: `${new Date().toLocaleString()} ${devices[i].deviceName}连接超时`,
})
} }
} }
if (!flag) {
errorCheckItem.push({scriptType, type: 'error'})
break
} }
if (tempChnResult.some(item => item === CheckData.ChnCheckResultEnum.ERRORDATA)) {
type = CheckData.ChnCheckResultEnum.ERRORDATA
}
if (tempChnResult.some(item => item === CheckData.ChnCheckResultEnum.FAIL)) {
type = CheckData.ChnCheckResultEnum.FAIL
}
errorCheckItem.push({scriptType, type: type})
}
//判断该检测项(例如 频率准确度检测)是否全部合格(所有设备所有通道所有子检测项目全部合格为合格,否则为不合格)
function getErrorCheckItem(scriptType: string) {
let results = errorCheckItem.filter((item) => item.scriptType === scriptType)
if (results.length > 0) {
return results[0]
} else {
return null
} }
} }
const updateCheckResultView = (scriptCode: string, isStart: boolean, devices: any[] = []) => { const updateCheckResultView = (scriptCode: string, isStart: boolean, devices: CheckData.DeviceCheckResult[] = []) => {
let scriptType = scriptData.filter(item => item.code === scriptCode)[0]?.id let scriptType = scriptData.filter(item => item.code === scriptCode)[0]?.id
// devices = [{ // devices = [
// chnResult: [1, 1, 1, 1], // {
// chnResult: [3, 4],
// deviceId: "80b4b4f52a4c4064a18319525f8ac13c",
// deviceName: "240002"
// }, {
// chnResult: [3, 4, 4, 4],
// deviceId: "df23a4178d194467a432ddf45e835e48", // deviceId: "df23a4178d194467a432ddf45e835e48",
// deviceName: "240003" // deviceName: "240003"
// }, // },
// { // {
// chnResult: [1, 1, 1, 1], // chnResult: [4, 4, 4, 4],
// deviceId: "ae5a7628260349c0a5e7c86c81fbd417", // deviceId: "ae5a7628260349c0a5e7c86c81fbd417",
// deviceName: "240004" // deviceName: "240004"
// }] // }]
@@ -890,7 +926,7 @@ const getCheckResult = (scriptType: string) => {
let randomNum = getRandomInt(item.chnNum * 2) let randomNum = getRandomInt(item.chnNum * 2)
if (randomNum < item.chnNum && activeIndex >= 4 && activeIndex <= 8) { if (randomNum < item.chnNum && activeIndex >= 4 && activeIndex <= 8) {
tempChnResult[randomNum] = CheckData.ChnCheckResultEnum.FAIL tempChnResult[randomNum] = CheckData.ChnCheckResultEnum.FAIL
errorCheckItem.push({scriptType, type: 'error'}) errorCheckItem.push({scriptType, type: CheckData.ChnCheckResultEnum.FAIL})
} }
// } // }
@@ -1142,7 +1178,7 @@ const handleResumeTest = () => {
type: 'info', type: 'info',
log: `${new Date().toLocaleString()}:继续检测`, log: `${new Date().toLocaleString()}:继续检测`,
}) })
// startTimer() //startTimer()
console.log('开始继续检测') console.log('开始继续检测')
}; };