feat: 点检报警功能
This commit is contained in:
parent
5493068847
commit
c6adf30b68
|
@ -40,3 +40,21 @@ export function exportExcel(deviceId, inputTime, shift) {
|
|||
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
|
||||
})
|
||||
}
|
|
@ -294,7 +294,7 @@
|
|||
<IxButton Outline class="btnStyle"> 流量:{{ productFlowRate }} </IxButton>
|
||||
<IxButton Outline class="btnStyle"> 配方:{{ formula }} </IxButton>
|
||||
<IxButton Outline class="btnStyle"> 持续时长:{{ duration }} </IxButton>
|
||||
<IxButton Outline id="triggerId"> {{ selectedReason ? '停机原因:' + selectedReason : '请选择停机原因 ▲' }} </IxButton>
|
||||
<IxButton Outline id="triggerId" :disabled="currentStatus !== '停机'"> {{ selectedReason ? '停机原因:' + selectedReason : '请选择停机原因 ▲' }} </IxButton>
|
||||
<IxDropdown trigger="triggerId" class="drop-down">
|
||||
<IxDropdownHeader label="停机原因"></IxDropdownHeader>
|
||||
<IxDropdownItem v-for="reason in stopReasons" :key="reason" :label="reason"
|
||||
|
@ -422,6 +422,7 @@ const updateAlarmCount = () => {
|
|||
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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@
|
|||
<span class="fixed-width"></span>
|
||||
<span class="fixed-width"></span>
|
||||
<span class="fixed-width" v-for="(hour, index) in hours" :key="hour">
|
||||
<IxButton :disabled="confirmedHours.includes(hour)" class="custom-button" @click="handleInspection(hour, index)">
|
||||
{{ confirmedHours.includes(hour) ? confirmedTimes[hour] : '确认' }}
|
||||
<IxButton :disabled="confirmedHours.includes(hour) || hourCheckStatus[hour] !== null" class="custom-button" @click="handleInspection(hour, index)">
|
||||
{{ hourCheckStatus[hour] !== null ? hourCheckTime[hour] : '确认' }}
|
||||
</IxButton>
|
||||
</span>
|
||||
</div>
|
||||
|
@ -65,9 +65,12 @@
|
|||
<span class="fixed-width">{{ item.reference || '--' }}</span>
|
||||
<span class="fixed-width">{{ item.current }}</span> <!-- 确保这里绑定的是 item.current -->
|
||||
<span class="fixed-width" v-for="hour in hours" :key="hour"
|
||||
:class="{ 'highlight-cell': item.data[hour] < 0.5 }"
|
||||
@click="item.data[hour] < 0.5 ? handleInspection(hour, index) : null">
|
||||
{{ 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 || '--' }}
|
||||
</span>
|
||||
</div>
|
||||
</IxEventListItem>
|
||||
|
@ -75,7 +78,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- 点检表单 -->
|
||||
<InspectionForm v-if="showForm" :itemName="selectedItemName" :itemTime="selectedItemTime" :timezone="timezone" @close="showForm = false" @submit="handleFormSubmit" />
|
||||
<InspectionForm v-if="showForm" :itemName="selectedItemName" :itemTime="selectedItemTime" :timezone="timezone" @close="showForm = false" @submit="(currentTime, reason) => handleFormSubmit(selectedItemIndex, reason)" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue