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

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