From c6adf30b689531298e45b17f68bf3c4c23ff75b2 Mon Sep 17 00:00:00 2001 From: Zhao Zhao Shen Date: Sun, 9 Mar 2025 19:04:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=82=B9=E6=A3=80=E6=8A=A5=E8=AD=A6?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/inspection.js | 18 ++++ src/views/Dashboard/index.vue | 3 +- src/views/Inspection/InspectionForm.vue | 2 +- src/views/Inspection/index.vue | 109 +++++++++++++++++------- 4 files changed, 100 insertions(+), 32 deletions(-) diff --git a/src/api/inspection.js b/src/api/inspection.js index 6a8f7ec..5f02b6a 100644 --- a/src/api/inspection.js +++ b/src/api/inspection.js @@ -39,4 +39,22 @@ export function exportExcel(deviceId, inputTime, shift) { method: 'get', responseType: 'arraybuffer' // 关键:设置响应类型为 arraybuffer }); +} + +// 报警相关接口 +// 时间点确认点检,不传时间,默认当前时间 +export function sharpConfirm(alarmId, confirmTime, checkUser) { + return request({ + url: `/Check/sharpConfirm?alarmId=${alarmId}&checkUser=${checkUser}`, + method: 'post' + }); +} + +// 数据项点检 +export function alarmReasonConfirm(data) { + return request({ + url: '/Check/AlarmReason', + method: 'post', + data + }) } \ No newline at end of file diff --git a/src/views/Dashboard/index.vue b/src/views/Dashboard/index.vue index 87e8823..bedd7bb 100644 --- a/src/views/Dashboard/index.vue +++ b/src/views/Dashboard/index.vue @@ -294,7 +294,7 @@ 流量:{{ productFlowRate }} 配方:{{ formula }} 持续时长:{{ duration }} - {{ selectedReason ? '停机原因:' + selectedReason : '请选择停机原因 ▲' }} + {{ selectedReason ? '停机原因:' + selectedReason : '请选择停机原因 ▲' }} { const updateCurrentInfo = (segment) => { id.value = segment.id; currentStatus.value = segment.deviceStatus; + console.log("🚀 ~ updateCurrentInfo ~ currentStatus:", currentStatus.value); // 调试信息 startTimeFormatted.value = formatTime(segment.beginTime); endTimeFormatted.value = formatTime(segment.endTime); duration.value = segment.duration; diff --git a/src/views/Inspection/InspectionForm.vue b/src/views/Inspection/InspectionForm.vue index f13bb5d..99ab210 100644 --- a/src/views/Inspection/InspectionForm.vue +++ b/src/views/Inspection/InspectionForm.vue @@ -51,7 +51,7 @@ const emit = defineEmits(['close', 'submit']); const handleSubmit = () => { const currentTime = moment().tz(props.timezone).format('HH:mm'); - emit('submit', currentTime); + emit('submit', currentTime, reason.value); }; diff --git a/src/views/Inspection/index.vue b/src/views/Inspection/index.vue index c5adb10..df4f513 100644 --- a/src/views/Inspection/index.vue +++ b/src/views/Inspection/index.vue @@ -41,8 +41,8 @@ - - {{ confirmedHours.includes(hour) ? confirmedTimes[hour] : '确认' }} + + {{ hourCheckStatus[hour] !== null ? hourCheckTime[hour] : '确认' }} @@ -65,9 +65,12 @@ {{ item.reference || '--' }} {{ item.current }} - {{ item.data[hour] || '--' }} + :class="{ + 'highlight-cell': item.data[hour]?.checkStatus === 1, + 'alarm-cell': item.data[hour]?.checkStatus === 0 + }" + @click="item.data[hour]?.checkStatus === 0 ? handleAlarmInspection(hour, index) : null"> + {{ item.data[hour]?.value || '--' }} @@ -75,7 +78,7 @@ - + @@ -86,7 +89,7 @@ import momentTimezone from 'moment-timezone'; import { ref, computed, getCurrentInstance, onMounted, defineEmits, onUnmounted } from 'vue'; import { IxDatePicker, IxButton, IxDropdownItem, IxEventList, IxEventListItem, IxSelect, IxSelectItem, IxDateInput } from '@siemens/ix-vue'; import InspectionForm from './InspectionForm.vue'; -import { getInspectionCurrent, getInspectionData, getCheckParas, getDeviceList, exportExcel } from '@/api/inspection'; +import { getInspectionCurrent, getInspectionData, getCheckParas, getDeviceList, exportExcel, sharpConfirm, alarmReasonConfirm } from '@/api/inspection'; const emit = defineEmits(['send-data']); @@ -118,7 +121,7 @@ const selectedDeviceId = ref(null); const showForm = ref(false); const selectedItemName = ref(''); const selectedItemTime = ref(''); -const selectedItemIndex = ref(null); // 添加索引变量 +const selectedItemIndex = ref(null); const selectedDate = ref(null); @@ -158,18 +161,55 @@ const inspectionItems = ref([]); const confirmedHours = ref([]); const confirmedTimes = ref({}); -// 点检按钮点击事件 +// 点检状态 +const hourCheckStatus = ref({}); +const hourCheckTime = ref({}); +const alarmId = ref({}); + +const formatTime = (time) => { + const date = new Date(time); + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + return `${hours}:${minutes}`; +}; + +// 点检按钮点击事件 handleAlarmConfirm const handleInspection = (hour, index) => { selectedItemName.value = inspectionItems.value[index].label; selectedItemTime.value = hour; + selectedItemIndex.value = index; // 保存当前索引 + showConfirmMessage('确认要执行点检操作吗?', async () => { + await sharpConfirm(alarmId.value[hour], 'admin').then(() => { + confirmedHours.value.push(selectedItemTime.value); + confirmedTimes.value[selectedItemTime.value] = moment().tz(timezone).format('HH:mm'); + hourCheckStatus.value[hour] = 1; // 更新点检状态 + hourCheckTime.value[hour] = confirmedTimes.value[selectedItemTime.value]; // 更新点检时间 + }); + }, () => { + showWarningMessage('取消点检操作'); + }); +}; + +// 点检按钮点击事件 +const handleAlarmInspection = (hour, index) => { + selectedItemName.value = inspectionItems.value[index].label; + selectedItemTime.value = hour; + selectedItemIndex.value = index; // 确保在这里设置 selectedItemIndex showForm.value = true; }; // 点检表单提交事件 -const handleFormSubmit = (currentTime) => { - confirmedHours.value.push(selectedItemTime.value); - console.log("🚀 ~ handleFormSubmit ~ confirmedHours.value:", confirmedHours.value) - confirmedTimes.value[selectedItemTime.value] = currentTime; +const handleFormSubmit = async (index, reason) => { + await alarmReasonConfirm({ + alarmId: alarmId.value[selectedItemTime.value], + checkParamId: inspectionItems.value[index].data[selectedItemTime.value].checkParamId, + alarmReason: reason, + checkUser: 'admin' + }).then(() => { + inspectionItems.value[index].data[selectedItemTime.value].checkStatus = 1; // 更新点检项目状态 + inspectionItems.value[index].data[selectedItemTime.value].checkUser = 'admin'; // 更新点检人员 + inspectionItems.value[index].data[selectedItemTime.value].checkText = '点检正常'; // 更新点检结果 + }); showForm.value = false; }; @@ -195,11 +235,6 @@ const showConfirmMessage = (message, onConfirm, onCancel) => { proxy.$message.confirm(message, onConfirm, onCancel); }; -const toLowerCaseFirstLetter = (str) => { - if (!str) return str; - return str.charAt(0).toLowerCase() + str.slice(1); -} - // 日期变化处理函数 const handleDateChange = (event) => { selectedDate.value = event.target.value; @@ -225,7 +260,7 @@ const fetchDeviceList = async () => { const response = await getDeviceList(); if (response.code === 200) { deviceList.value = response.data; - selectedDeviceId.value = deviceList.value[2].id; // 默认选中第一个设备 + selectedDeviceId.value = deviceList.value[0].id; // 默认选中第一个设备 } else { showWarningMessage('获取设备列表失败!'); } @@ -256,7 +291,7 @@ const fetchCurrentValues = async () => { inspectionItems.value.forEach(item => { const param = paramData.find(param => { - return toLowerCaseFirstLetter(param.keyname) === item.name; + return param.keyname === item.name; }); if (param) { @@ -278,9 +313,7 @@ const fetchCurrentValues = async () => { const fetchInspectionData = async () => { try { const deviceId = selectedDeviceId.value; // 根据实际情况设置设备ID - // const inputTime = new Date().toISOString(); // globalTime; // 获取当前时间 const shiftValue = shift.value; - const statusValue = status.value; const dateValue = selectedDate.value || currentDate; const response = await getInspectionData(deviceId, dateValue, shiftValue); if (response.data) { @@ -289,8 +322,12 @@ const fetchInspectionData = async () => { inspectionData.forEach(record => { const recordTime = record.recordTime; const data = record.data; - for (const [name, value] of Object.entries(data)) { - if (value === -1) continue; // 过滤掉值为 -1 的属性 + hourCheckStatus.value[recordTime] = record.hourCheckStatus; + hourCheckTime.value[recordTime] = formatTime(record.hourCheckTime); + alarmId.value[recordTime] = record.alarmId; + + for (const [name, valueObj] of Object.entries(data)) { + if (valueObj === null || valueObj.valule === null) continue; // 过滤掉值为 null 的属性 if (!itemsMap[name]) { itemsMap[name] = { name, @@ -301,7 +338,15 @@ const fetchInspectionData = async () => { data: {} }; } - itemsMap[name].data[recordTime] = value; + itemsMap[name].data[recordTime] = { + value: valueObj.valule, + checkStatus: valueObj.checkStatus, + checkText: valueObj.checkText, + checkParamId: valueObj.checkParamId, + checkUser: valueObj.checkUser + // hourCheckStatus: valueObj.hourCheckStatus, + // hourCheckTime: valueObj.hourCheckTime + }; } }); inspectionItems.value = Object.values(itemsMap); @@ -390,11 +435,7 @@ onMounted(async () => { // setupAutoUpdate(); // }); }); -// 在 onUnmounted 中添加 -// onUnmounted(() => { -// window.removeEventListener('update-history', handleHistoryUpdate); -// window.removeEventListener('reset', handleReset); -// }); + onUnmounted(() => { if (autoUpdateInterval) { clearInterval(autoUpdateInterval); @@ -448,6 +489,10 @@ onUnmounted(() => { /* 添加水平滚动条 */ } +.table-container { + display: flex; +} + .table-container { display: flex; flex-direction: column; @@ -557,4 +602,8 @@ onUnmounted(() => { background-color: orange; cursor: pointer; } +.alarm-cell { + background-color: red; + cursor: pointer; +}