This commit is contained in:
sjl
2025-01-02 13:12:13 +08:00
parent 012f7e3346
commit e95552e6b9
3 changed files with 255 additions and 125 deletions

View File

@@ -55,8 +55,8 @@
</el-steps> </el-steps>
</div> </div>
<div class="right-content"> <div class="right-content">
<el-tabs type="border-card"> <el-tabs type="border-card" :active-index="String(activeIndex)" >
<div > <!-- <div > -->
<el-tab-pane v-for="(device, index) in name" :key="index" :label="device"> <el-tab-pane v-for="(device, index) in name" :key="index" :label="device">
<template #label> <template #label>
<span class="custom-tabs-label"> <span class="custom-tabs-label">
@@ -68,8 +68,8 @@
</template> </template>
<channelsTestTable :tableData="getTableDataForChannel(index)" :loading="loadingStates[index]"></channelsTestTable> <channelsTestTable :tableData="getTableDataForChannel(index)" :loading="loadingStates[index]"></channelsTestTable>
</el-tab-pane> </el-tab-pane>
</div> <!-- </div> -->
<el-empty description="暂无数据,等待检测开始" v-if="activeIndex === 0" /> <!-- <el-empty description="暂无数据,等待检测开始" v-if="activeIndex === 0" /> -->
</el-tabs> </el-tabs>
<!-- <el-tabs type="border-card"> <!-- <el-tabs type="border-card">
@@ -120,7 +120,7 @@ import { type Device } from '@/api/device/interface/device';
import { SuccessFilled, Failed, Message, MessageBox } from '@element-plus/icons-vue' import { SuccessFilled, Failed, Message, MessageBox } from '@element-plus/icons-vue'
import { type Ref, ref, toRef, watch } from 'vue' import { type Ref, ref, toRef, watch } from 'vue'
import {dialogBig} from '@/utils/elementBind' import {dialogBig} from '@/utils/elementBind'
import { ElMessage, ElMessageBox } from 'element-plus'; import { ElMessage, ElMessageBox, TabsPaneContext } from 'element-plus';
const activeIndex = ref(0) const activeIndex = ref(0)
const activeTotalNum = ref(4) const activeTotalNum = ref(4)
const qualified = ref(0) const qualified = ref(0)
@@ -128,7 +128,6 @@ const outputDsc = ref('电压误差为±0.1Un% 电流误差为±0.5%')
const total = ref(0) const total = ref(0)
const dialogVisible = ref(false) const dialogVisible = ref(false)
const active = ref(0) const active = ref(0)
let intervalId: NodeJS.Timeout | null = null;
let timer1: NodeJS.Timeout | null = null; // 声明并初始化 timer1 let timer1: NodeJS.Timeout | null = null; // 声明并初始化 timer1
let timer2: NodeJS.Timeout | null = null; // 同样声明并初始化 timer2 let timer2: NodeJS.Timeout | null = null; // 同样声明并初始化 timer2
const name = ref<string[]>([])//系数校准所选设备名字数组 const name = ref<string[]>([])//系数校准所选设备名字数组
@@ -137,6 +136,21 @@ const channel = ref<number[]>([])//系数校准所选设备通道数组
const errorStates = ref(new Array(name.value.length).fill(false)); const errorStates = ref(new Array(name.value.length).fill(false));
const loadingStates = ref(new Array(name.value.length).fill(false)); // 初始化 loading 状态 const loadingStates = ref(new Array(name.value.length).fill(false)); // 初始化 loading 状态
const props = defineProps({
webMsgSend: {
type: Object,
default: () => ({})
}
})
const webMsgSend = toRef(props, 'webMsgSend');
watch(webMsgSend,function (newValue,oldValue){
switch (newValue.requestId){
}
})
// 定义 TableDataItem 接口 // 定义 TableDataItem 接口
interface TableDataItem { interface TableDataItem {
@@ -161,6 +175,8 @@ interface TableDataItem {
const dataTemplates3 = [ const dataTemplates3 = [
{ {
id: '', // 新增 id 属性
MonitorIdx: 1, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -176,6 +192,8 @@ const dataTemplates3 = [
IcChannel: '—', IcChannel: '—',
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 2, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -191,6 +209,8 @@ const dataTemplates3 = [
IcChannel: '—', IcChannel: '—',
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 3, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -207,6 +227,8 @@ const dataTemplates3 = [
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 4, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -226,6 +248,8 @@ const dataTemplates3 = [
const dataTemplates4 = [ const dataTemplates4 = [
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 57.74, UaData: 57.74,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -241,6 +265,8 @@ const dataTemplates4 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 5.774, UaData: 5.774,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -256,6 +282,8 @@ const dataTemplates4 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -271,6 +299,8 @@ const dataTemplates4 = [
IcChannel: '—', IcChannel: '—',
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: '—', UaData: '—',
UaChannel:'—', UaChannel:'—',
@@ -289,6 +319,8 @@ const dataTemplates4 = [
const dataTemplates5 = [ const dataTemplates5 = [
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 57.74, UaData: 57.74,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -304,6 +336,8 @@ const dataTemplates5 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 5.774, UaData: 5.774,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -319,6 +353,8 @@ const dataTemplates5 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: 57.74, UaData: 57.74,
UaChannel: '不合格', UaChannel: '不合格',
@@ -334,6 +370,8 @@ const dataTemplates5 = [
IcChannel: '合格', IcChannel: '合格',
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: 5.774, UaData: 5.774,
UaChannel: '不合格', UaChannel: '不合格',
@@ -352,6 +390,8 @@ const dataTemplates5 = [
const dataTemplates6 = [ const dataTemplates6 = [
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 57.74, UaData: 57.74,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -367,6 +407,8 @@ const dataTemplates6 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数下装', deviceName: '系数下装',
UaData: 5.774, UaData: 5.774,
UaChannel: 1.0003, UaChannel: 1.0003,
@@ -382,6 +424,8 @@ const dataTemplates6 = [
IcChannel: 1.0001, IcChannel: 1.0001,
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: 57.74, UaData: 57.74,
UaChannel: '合格', UaChannel: '合格',
@@ -397,6 +441,8 @@ const dataTemplates6 = [
IcChannel: '合格', IcChannel: '合格',
}, },
{ {
id: '', // 新增 id 属性
MonitorIdx: 0, // 新增 MonitorIdx 属性
deviceName: '系数校准', deviceName: '系数校准',
UaData: 5.774, UaData: 5.774,
UaChannel: '合格', UaChannel: '合格',
@@ -454,7 +500,6 @@ const activities = [
// 打开弹窗,可能是新增,也可能是编辑 // 打开弹窗,可能是新增,也可能是编辑
const open = (selection: Device.ResPqDev[]) => { const open = (selection: Device.ResPqDev[]) => {
const checkStates = selection.map(item => item.checkState); const checkStates = selection.map(item => item.checkState);
const allCheckStatesEqual = new Set(checkStates).size <= 1; const allCheckStatesEqual = new Set(checkStates).size <= 1;
@@ -483,21 +528,7 @@ const activities = [
errorStates.value = new Array(selection.length).fill(false); errorStates.value = new Array(selection.length).fill(false);
for (let i = 0; i < channel.value.length; i++) { for (let i = 0; i < channel.value.length; i++) {
const currentTableData = ref<TableDataItem[]>([]); const currentTableData = initializeTableData(dataTemplates3, i);
// 随机选择 dataTemplates 或 dataTemplates2
const selectedTemplates = dataTemplates3;
for(let j = 0; j < channel.value[i]; j++){
const id = (j + 1).toString();
selectedTemplates.forEach((template) => {
currentTableData.value.push({
id: id,
MonitorIdx: j + 1,
...template,
});
});
}
tableDataMap.set(i,currentTableData) tableDataMap.set(i,currentTableData)
} }
} }
@@ -569,7 +600,9 @@ watch(activeIndex, function (newValue, oldValue) {
outputDsc.value = "电压误差为±0.1Un% 电流误差为±0.5%"; outputDsc.value = "电压误差为±0.1Un% 电流误差为±0.5%";
// 当前源输出为Ua=Ub=Uc=57.74V Ia=Ib=Ic=1A" // 当前源输出为Ua=Ub=Uc=57.74V Ia=Ib=Ic=1A"
} }
})
});
// 示例的 checkForErrors 函数,根据实际需求进行调整 // 示例的 checkForErrors 函数,根据实际需求进行调整
const checkForErrors = (data: TableDataItem[]): boolean => { const checkForErrors = (data: TableDataItem[]): boolean => {
@@ -585,35 +618,21 @@ const checkForErrors = (data: TableDataItem[]): boolean => {
}; };
const handleSubmit = async () => { const handleSubmit = async () => {
if (intervalId !== null) {
clearInterval(intervalId);
}
// 初始化 currentTableData // 初始化 currentTableData
let isTimer2Completed = false; let isTimer2Completed = false;
// 初始化 loadingStates 为 true // 初始化 loadingStates 为 true
loadingStates.value = new Array(name.value.length).fill(true); loadingStates.value = new Array(name.value.length).fill(true);
for (let i = 0; i < channel.value.length; i++) { for (let i = 0; i < channel.value.length; i++) {
// 重置状态变量 // 重置状态变量
active.value = 0;activeIndex.value = 0; active.value = 0;
const currentTableData = ref<TableDataItem[]>([]); //activeIndex.value = 0;
const selectedTemplates = dataTemplates4;
for (let j = 0; j < channel.value[i]; j++) {
const id = (j + 1).toString();
selectedTemplates.forEach((template) => {
currentTableData.value.push({
id: id,
MonitorIdx: j + 1,
...template,
});
});
}
// 初始化并填充 currentTableData
const currentTableData = initializeTableData(dataTemplates4, i);
tableDataMap.set(i, currentTableData); tableDataMap.set(i, currentTableData);
activeIndex.value++; //activeIndex.value++;
// 清除之前的 timer1 // 清除之前的 timer1
clearInterval(timer1); clearInterval(timer1);
// 启动 timer1 // 启动 timer1
@@ -628,35 +647,8 @@ for (let i = 0; i < channel.value.length; i++) {
clearInterval(timer2); clearInterval(timer2);
// 启动 timer2 // 启动 timer2
timer2 = setInterval(() => { timer2 = setInterval(() => {
// 初始化 currentTableData // 初始化并填充 currentTableData
const currentTableData = ref<TableDataItem[]>([]); const currentTableData = initializeTableData(i > 0 ? dataTemplates5 : dataTemplates6, i);
if(i > 0){
const selectedTemplates = dataTemplates5;
for (let j = 0; j < channel.value[i]; j++) {
const id = (j + 1).toString();
selectedTemplates.forEach((template) => {
currentTableData.value.push({
id: id,
MonitorIdx: j + 1,
...template,
});
});
}
}else{
const selectedTemplates = dataTemplates6;
for (let j = 0; j < channel.value[i]; j++) {
const id = (j + 1).toString();
selectedTemplates.forEach((template) => {
currentTableData.value.push({
id: id,
MonitorIdx: j + 1,
...template,
});
});
}
}
tableDataMap.set(i, currentTableData); tableDataMap.set(i, currentTableData);
activeIndex.value++; activeIndex.value++;
@@ -681,16 +673,139 @@ for (let i = 0; i < channel.value.length; i++) {
while (!isTimer2Completed) { while (!isTimer2Completed) {
// 这里可以添加一个短暂的等待,避免死循环 // 这里可以添加一个短暂的等待,避免死循环
await new Promise(resolve => setTimeout(resolve, 100)); await new Promise(resolve => setTimeout(resolve, 100));
} }
// 重置标志变量 // 重置标志变量
isTimer2Completed = false; isTimer2Completed = false;
} }
}; };
// 提取初始化并填充 currentTableData 的函数
const initializeTableData = (templates: TableDataItem[], index: number): Ref<TableDataItem[]> => {
const currentTableData = ref<TableDataItem[]>([]);
for (let j = 0; j < channel.value[index]; j++) {
const id = (j + 1).toString();
templates.forEach((template) => {
// 使用解构赋值排除 id 和 MonitorIdx 属性
const { id: _, MonitorIdx: __, ...rest } = template;
currentTableData.value.push({
id,
MonitorIdx: j + 1,
...rest,
});
});
}
return currentTableData;
};
// const handleSubmit = async () => {
// // 初始化 currentTableData
// let isTimer2Completed = false;
// // 初始化 loadingStates 为 true
// loadingStates.value = new Array(name.value.length).fill(true);
// for (let i = 0; i < channel.value.length; i++) {
// // 重置状态变量
// active.value = 0;activeIndex.value = 0;
// const currentTableData = ref<TableDataItem[]>([]);
// const selectedTemplates = dataTemplates4;
// for (let j = 0; j < channel.value[i]; j++) {
// const id = (j + 1).toString();
// selectedTemplates.forEach((template) => {
// currentTableData.value.push({
// id: id,
// MonitorIdx: j + 1,
// ...template,
// });
// });
// }
// tableDataMap.set(i, currentTableData);
// activeIndex.value++;
// // 清除之前的 timer1
// clearInterval(timer1);
// // 启动 timer1
// timer1 = setInterval(() => {
// active.value++;
// if (active.value > 5) {
// clearInterval(timer1);
// }
// }, 500);
// // 清除之前的 timer2
// clearInterval(timer2);
// // 启动 timer2
// timer2 = setInterval(() => {
// // 初始化 currentTableData
// const currentTableData = ref<TableDataItem[]>([]);
// if(i > 0){
// const selectedTemplates = dataTemplates5;
// for (let j = 0; j < channel.value[i]; j++) {
// const id = (j + 1).toString();
// selectedTemplates.forEach((template) => {
// currentTableData.value.push({
// id: id,
// MonitorIdx: j + 1,
// ...template,
// });
// });
// }
// }else{
// const selectedTemplates = dataTemplates6;
// for (let j = 0; j < channel.value[i]; j++) {
// const id = (j + 1).toString();
// selectedTemplates.forEach((template) => {
// currentTableData.value.push({
// id: id,
// MonitorIdx: j + 1,
// ...template,
// });
// });
// }
// }
// tableDataMap.set(i, currentTableData);
// activeIndex.value++;
// clearInterval(timer2);
// const currentDataRef = tableDataMap.get(i);
// if (currentDataRef) {
// const currentData = currentDataRef.value;
// // 检查当前数据中有无不合格字段
// const hasError = checkForErrors(currentData);
// if (hasError) {
// } else {
// qualified.value++;
// }
// updateErrorState(i, hasError);
// }
// // 设置标志变量为 true表示 timer2 已经完成
// isTimer2Completed = true;
// }, 3000);
// // 等待 timer2 完成
// while (!isTimer2Completed) {
// // 这里可以添加一个短暂的等待,避免死循环
// await new Promise(resolve => setTimeout(resolve, 100));
// }
// // 重置标志变量
// isTimer2Completed = false;
// }
// };
// 对外映射 // 对外映射
defineExpose({ open }) defineExpose({ open })
</script> </script>

View File

@@ -290,8 +290,6 @@
// 监听 tableData 的变化 // 监听 tableData 的变化
</script> </script>
<style scoped> <style scoped>

View File

@@ -231,7 +231,7 @@
></matchPopup> ></matchPopup>
<!--系数校准--> <!--系数校准-->
<ChannelsTest ref="channelsTest"></ChannelsTest> <ChannelsTest ref="channelsTest" :webMsgSend="webMsgSend"></ChannelsTest>
</div> </div>
</template> </template>
@@ -262,7 +262,7 @@ import socketClient from '@/utils/webSocketClient';
const dictStore = useDictStore() const dictStore = useDictStore()
const checkStore = useCheckStore() const checkStore = useCheckStore()
const webMsgSend = ref();//webSocket推送的数据
let devNum = 0;//当前选取的被检设备数量 let devNum = 0;//当前选取的被检设备数量
let devChannelsNum = 0;//当前选择的被检设备通道总数 let devChannelsNum = 0;//当前选择的被检设备通道总数
let devTestedNum = 0;//当前选择的已完成检测的被检设备数量 let devTestedNum = 0;//当前选择的已完成检测的被检设备数量
@@ -855,12 +855,29 @@ const handleTest = async (val:string) => {
} }
if(val==='系数校准') if(val === '系数校准') {
{ // //开始创建webSocket客户端
// const data = reactive({
// socketServe: socketClient.Instance,
// });
// const url = 'ws://localhost:7777/hello?name=cdf';
// socketClient.Instance.connect(url);
// data.socketServe = socketClient.Instance;
// data.socketServe.registerCallBack('aaa', (res: { code: number; }) => {
// // 处理来自服务器的消息
// console.log('Received message:', res);
// // 根据需要在这里添加更多的处理逻辑
// if(res.code === 20000){
// ElMessage.error(message.message)
// loading.close()
// }else {
// webMsgSend.value = res
// }
// });
channelsTest.value?.open(channelsSelection.value) channelsTest.value?.open(channelsSelection.value);
return return;
} }
if(devTestedNum == 0) if(devTestedNum == 0)
{ {