This commit is contained in:
sjl
2025-02-26 10:52:39 +08:00
parent 5004e319b6
commit 28203f2621
3 changed files with 50 additions and 227 deletions

View File

@@ -92,7 +92,7 @@
<script lang="tsx" setup name="FactorTest"> <script lang="tsx" setup name="FactorTest">
import {type Device} from '@/api/device/interface/device'; import {type Device} from '@/api/device/interface/device';
import {Failed} from '@element-plus/icons-vue' import {Failed} from '@element-plus/icons-vue'
import {type Ref, ref, toRef, watch} from 'vue' import {onBeforeMount, type Ref, ref, toRef, watch} from 'vue'
import {dialogBig} from '@/utils/elementBind' import {dialogBig} from '@/utils/elementBind'
import {ElMessageBox} from 'element-plus'; import {ElMessageBox} from 'element-plus';
import {getCoefficientCheck} from '@/api/home/channelsTest/index' import {getCoefficientCheck} from '@/api/home/channelsTest/index'
@@ -134,28 +134,34 @@ const big_I_Adjust = ref('')
const small_V_Adjust = ref('') const small_V_Adjust = ref('')
const small_I_Adjust = ref('') const small_I_Adjust = ref('')
const props = defineProps({ const props = defineProps({
testStatus: {
type: String,
default: 'wait'
},
webMsgSend: { webMsgSend: {
type: Object, type: Object,
default: () => ({}) default: () => ({})
} },
}) })
const testStatus = toRef(props, 'testStatus');
const tableDataMap = new Map<number, Ref<ChannelsTest.CoefficientVO[]>>([]); const tableDataMap = new Map<number, Ref<ChannelsTest.CoefficientVO[]>>([]);
const currentStepStatus = ref<'error' | 'finish' | 'wait' | 'success' | 'process'>('finish'); const currentStepStatus = ref<'error' | 'finish' | 'wait' | 'success' | 'process'>('finish');
const webMsgSend = toRef(props, 'webMsgSend'); const webMsgSend = toRef(props, 'webMsgSend');
onBeforeMount(() => { onBeforeMount(() => {
// 初始化 // 初始化
initData() initData()
}) })
const initData = () => { const initData = () => {
checkStore.devices[0]
CurV.value = checkStore.devices[0]?.devVolt || 57.74; CurV.value = checkStore.devices[0]?.devVolt || 57.74;
isButtonDisabled.value = false; // 恢复按钮 isButtonDisabled.value = false; // 恢复按钮
select_Plan.value = plan select_Plan.value = checkStore.plan
planId.value = checkStore.devices[0]?.planId || ''; planId.value = checkStore.devices[0]?.planId || '';
devIdArray.value = checkStore.devices.map(item => item.deviceId); devIdArray.value = checkStore.devices.map(item => item.deviceId);
name.value = checkStore.devices.map(item => item.deviceName) name.value = checkStore.devices.map(item => item.deviceName)
@@ -166,7 +172,7 @@ const initData = () => {
// 初始化 loadingStates 为 false // 初始化 loadingStates 为 false
// loadingStates.value = new Array(selection.length).fill(false); // loadingStates.value = new Array(selection.length).fill(false);
errorStates.value = new Array(selection.length).fill(false); errorStates.value = new Array(checkStore.devices.length).fill(false);
for (let i = 0; i < channel.value.length; i++) { for (let i = 0; i < channel.value.length; i++) {
const currentTableData = initializeTableData(dataTemplates, i); const currentTableData = initializeTableData(dataTemplates, i);
@@ -176,6 +182,13 @@ const initData = () => {
} }
watch(testStatus, function (newValue, oldValue) {
if (newValue === 'start') {
// 开始系数校准操作
handleSubmit()
}
})
watch(webMsgSend, function (newValue, oldValue) { watch(webMsgSend, function (newValue, oldValue) {
if (newValue.code == 10520) { if (newValue.code == 10520) {
ElMessageBox.alert('报文解析异常!', '初始化失败', { ElMessageBox.alert('报文解析异常!', '初始化失败', {
@@ -381,6 +394,7 @@ watch(webMsgSend, function (newValue, oldValue) {
//editableTabsValue.value = (tabNumber.value).toString();//显示下一个tab //editableTabsValue.value = (tabNumber.value).toString();//显示下一个tab
isButtonDisabled.value = false; // 恢复按钮 isButtonDisabled.value = false; // 恢复按钮
emit('update:testStatus', 'success')
break; break;
} }
switch (newValue.operateCode) { switch (newValue.operateCode) {
@@ -501,23 +515,16 @@ watch(webMsgSend, function (newValue, oldValue) {
//出错系数检测初始化 //出错系数检测初始化
const TableInit = () => { const TableInit = () => {
console.log("TableInitactive", active.value); emit('update:testStatus', 'test_init_fail')
isButtonDisabled.value = false; // 恢复按钮
for (let i = 0; i < channel.value.length; i++) {
const currentTableData = initializeTableData(dataTemplates, i);
tableDataMap.set(i, currentTableData)
// const targetArrayRef = tableDataMap.get(i); // isButtonDisabled.value = false; // 恢复按钮
// if (targetArrayRef) { // for (let i = 0; i < channel.value.length; i++) {
// const targetArray = targetArrayRef.value; // const currentTableData = initializeTableData(dataTemplates, i);
// if (targetArray.length > 0) { // tableDataMap.set(i, currentTableData)
// targetArray.forEach(item => item.loading =false) // }
// } // activeIndex.value = 0
// } // qualified.value = 0
} // active.value = 0
activeIndex.value = 0
qualified.value = 0
active.value = 0
} }
@@ -646,133 +653,19 @@ const dataTemplates: ChannelsTest.CoefficientVO[] = [
]; ];
const dataTemplates2: ChannelsTest.CoefficientVO[] = [
{
monitorNum: '1',
desc: '系数下装',
type: 'big',
aVuData: '—',
aVuXi: '—',
bVuData: '—',
bVuXi: '—',
cVuData: '—',
cVuXi: '—',
aIeData: '—',
aIeXi: '—',
bIeData: '—',
bIeXi: '—',
cIeData: '—',
cIeXi: '—',
loading: false,
devName: ''
},
{
monitorNum: '2',
desc: '系数下装',
type: 'small',
aVuData: '—',
aVuXi: '—',
bVuData: '—',
bVuXi: '—',
cVuData: '—',
cVuXi: '—',
aIeData: '—',
aIeXi: '—',
bIeData: '—',
bIeXi: '—',
cIeData: '—',
cIeXi: '—',
loading: false,
devName: ''
},
{
monitorNum: '3',
desc: '系数校准',
type: 'big',
aVuData: '—',
aVuXi: '不合格',
bVuData: '—',
bVuXi: '—',
cVuData: '—',
cVuXi: '—',
aIeData: '—',
aIeXi: '—',
bIeData: '—',
bIeXi: '—',
cIeData: '—',
cIeXi: '—',
loading: false,
devName: ''
},
{
monitorNum: '4',
desc: '系数校准',
type: 'small',
aVuData: '—',
aVuXi: '—',
bVuData: '—',
bVuXi: '—',
cVuData: '—',
cVuXi: '—',
aIeData: '—',
aIeXi: '—',
bIeData: '—',
bIeXi: '—',
cIeData: '—',
cIeXi: '—',
loading: false,
devName: ''
},
];
// 更新错误状态的方法 // 更新错误状态的方法
const updateErrorState = (index: number, hasError: boolean) => { const updateErrorState = (index: number, hasError: boolean) => {
errorStates.value[index] = hasError; errorStates.value[index] = hasError;
}; };
// 打开弹窗,可能是新增,也可能是编辑
const open = (selection: Device.ResPqDev[], plan: Plan.ReqPlan) => {
CurV.value = selection[0]?.devVolt || 57.74;
isButtonDisabled.value = false; // 恢复按钮
select_Plan.value = plan
planId.value = selection[0]?.planId || '';
devIdArray.value = selection.map(item => item.id);
name.value = selection.map(item => item.name)
channel.value = selection.map(item => item.devChns)
dialogVisible.value = true;
total.value = name.value.length
// const emit = defineEmits<{
// 初始化 loadingStates 为 false // (e: 'submitClicked', callback: (resolve: (value: boolean) => void) => void): void;
// loadingStates.value = new Array(selection.length).fill(false); // }>();
errorStates.value = new Array(selection.length).fill(false);
for (let i = 0; i < channel.value.length; i++) { const emit = defineEmits(['update:testStatus']);
const currentTableData = initializeTableData(dataTemplates, i);
tableDataMap.set(i, currentTableData)
}
//console.log('tableDataMap',tableDataMap);
}
const emit = defineEmits<{
(e: 'quitClicked'): void;
(e: 'submitClicked', callback: (resolve: (value: boolean) => void) => void): void;
}>();
const handleCancel = () => {
// 清空 name, channel, total
name.value = [];
channel.value = [];
total.value = 0;
activeIndex.value = 0
qualified.value = 0
active.value = 0
dialogVisible.value = false
editableTabsValue.value = '0'
emit('quitClicked'); // 触发事件
}
const getTableDataForChannel = (index: number): any[] => { const getTableDataForChannel = (index: number): any[] => {
const data = tableDataMap.get(index); const data = tableDataMap.get(index);
@@ -802,13 +695,13 @@ const checkForErrors = (data: ChannelsTest.CoefficientVO[]): boolean => {
const handleSubmit = async () => { const handleSubmit = async () => {
// 创建一个 Promise 来等待父组件的回调 // 创建一个 Promise 来等待父组件的回调
const response = await new Promise<boolean>((resolve) => { // const response = await new Promise<boolean>((resolve) => {
emit('submitClicked', resolve); // emit('submitClicked', resolve);
}); // });
if (!response) { // if (!response) {
return; // return;
} // }
isButtonDisabled.value = true; // 禁用按钮 isButtonDisabled.value = true; // 禁用按钮
tableLoading('big', '系数下装') tableLoading('big', '系数下装')
@@ -821,71 +714,6 @@ const handleSubmit = async () => {
operateType: '0' // '0'为预检测、1为正式检测 operateType: '0' // '0'为预检测、1为正式检测
}) })
active.value++; active.value++;
// 初始化 loadingStates 为 true
// loadingStates.value = new Array(name.value.length).fill(true);
return;
// 初始化 currentTableData
let isTimer2Completed = false;
//"80b4b4f52a4c4064a18319525f8ac13c",
for (let i = 0; i < channel.value.length; i++) {
// 重置状态变量
active.value = 0;
//activeIndex.value = 0;
editableTabsValue.value = i.toString();
// 初始化并填充 currentTableData
const currentTableData = initializeTableData(dataTemplates2, i);
tableDataMap.set(i, currentTableData);
//activeIndex.value++;
// 清除之前的 timer1
clearInterval(timer1);
// 启动 timer1
timer1 = setInterval(() => {
active.value++;
if (active.value > 5) {
clearInterval(timer1);
}
}, 3000);
// 清除之前的 timer2
clearInterval(timer2);
// 启动 timer2
timer2 = setInterval(() => {
// 初始化并填充 currentTableData
const currentTableData = initializeTableData(i > 0 ? dataTemplates2 : dataTemplates2, i);
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;
}
}; };
// 提取初始化并填充 currentTableData 的函数 // 提取初始化并填充 currentTableData 的函数
@@ -905,9 +733,6 @@ const initializeTableData = (templates: ChannelsTest.CoefficientVO[], index: num
return currentTableData; return currentTableData;
}; };
// 对外映射
defineExpose({open})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@@ -69,7 +69,7 @@
</template> </template>
<script lang="tsx" setup name="preTest"> <script lang="tsx" setup name="preTest">
import {ElMessage, ElMessageBox} from "element-plus"; import {ElMessage, ElMessageBox} from "element-plus";
import {defineExpose} from 'vue'; import {defineExpose, toRef} from 'vue';
const step1InitLog = ref([ const step1InitLog = ref([
{ {
@@ -556,7 +556,6 @@ watch(activeIndex, function (newValue, oldValue) {
//监听goods_sn的变化 //监听goods_sn的变化
watch(testStatus, function (newValue, oldValue) { watch(testStatus, function (newValue, oldValue) {
ts.value = props.testStatus; ts.value = props.testStatus;
if (ts.value === 'start') { if (ts.value === 'start') {
ts.value = 'process' ts.value = 'process'

View File

@@ -23,7 +23,7 @@
<el-button type="primary" :icon="DArrowRight" v-if="stepsActiveIndex < stepsTotalNum && ActiveStatue != 'success'" @click="nextStep">跳过</el-button> <el-button type="primary" :icon="DArrowRight" v-if="stepsActiveIndex < stepsTotalNum && ActiveStatue != 'success'" @click="nextStep">跳过</el-button>
<el-button type="primary" :icon="VideoPlay" v-if="ActiveStatue === 'waiting'" @click="handleSubmit">开始检测</el-button> <el-button type="primary" :icon="VideoPlay" v-if="ActiveStatue === 'waiting'" @click="handleSubmit">开始检测</el-button>
<el-button type="primary" <el-button type="primary"
v-if="ActiveStatue !== 'test_init' && ActiveStatue !=='paused_ing' && ActiveStatue !=='paused' && ActiveStatue !== 'waiting' && ActiveStatue !== 'error' && ActiveStatue !== 'test_init_fail' && ActiveStatue !== 'connect_timeout' && ActiveStatue!=='pause_timeout'" v-if="(stepsActive != stepsTotalNum-1) && (ActiveStatue !== 'test_init' && ActiveStatue !=='paused_ing' && ActiveStatue !=='paused' && ActiveStatue !== 'waiting' && ActiveStatue !== 'error' && ActiveStatue !== 'test_init_fail' && ActiveStatue !== 'connect_timeout' && ActiveStatue!=='pause_timeout')"
disabled> disabled>
<el-icon class="loading-box" style="color: #fff;margin-right: 8px;"> <el-icon class="loading-box" style="color: #fff;margin-right: 8px;">
<component :is="Refresh"/> <component :is="Refresh"/>
@@ -175,8 +175,6 @@ const open = (title: string) => {
// let loading; // let loading;
const handleSubmit = () => { const handleSubmit = () => {
console.log('=============', stepsActiveIndex.value)
let deviceIds = checkStore.devices.map((item) => item.deviceId) let deviceIds = checkStore.devices.map((item) => item.deviceId)
let planId = checkStore.plan.id let planId = checkStore.plan.id
@@ -243,6 +241,7 @@ const handleSubmit = () => {
} }
}; };
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'quitClicked'): void; (e: 'quitClicked'): void;
}>(); }>();
@@ -269,7 +268,7 @@ watch(TestStatus, function (newValue, oldValue) {
}) })
watch(ActiveStatue, function (newValue, oldValue) { watch(ActiveStatue, function (newValue, oldValue) {
if (newValue === 'error' && stepsActive.value === 1) { if (newValue === 'error') {
// stepsActiveIndex.value = stepsTotalNum.value + 2 // stepsActiveIndex.value = stepsTotalNum.value + 2
nextStepText.value = '检测失败' nextStepText.value = '检测失败'
} }
@@ -277,15 +276,15 @@ watch(ActiveStatue, function (newValue, oldValue) {
stepsActiveIndex.value += 2 stepsActiveIndex.value += 2
nextStepText.value = '检测完成' nextStepText.value = '检测完成'
} }
if (newValue === 'test_init_fail' && stepsActive.value === 4) { if (newValue === 'test_init_fail' ) {
stepsActiveIndex.value += 2 stepsActiveIndex.value += 2
nextStepText.value = '初始化失败' nextStepText.value = '初始化失败'
} }
if (newValue === 'connect_timeout' && stepsActive.value === 4) { if (newValue === 'connect_timeout' ) {
stepsActiveIndex.value += 2 stepsActiveIndex.value += 2
nextStepText.value = '连接超时' nextStepText.value = '连接超时'
} }
if (newValue === 'pause_timeout' && stepsActive.value === 4) { if (newValue === 'pause_timeout' ) {
stepsActiveIndex.value += 2 stepsActiveIndex.value += 2
nextStepText.value = '结束测试' nextStepText.value = '结束测试'
} }