@@ -77,7 +76,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 } from '@/api/inspection';
+import { getInspectionCurrent, getInspectionData, getCheckParas, getDeviceList } from '@/api/inspection';
const emit = defineEmits(['send-data']);
@@ -85,24 +84,26 @@ const emit = defineEmits(['send-data']);
const timezone = 'Asia/Shanghai';
// 全局响应式变量
-const globalDeviceId = ref(null);
const globalTime = ref(moment().tz(timezone).format('YYYY-MM-DD HH:mm'));
const isAutoUpdate = ref(true); // 是否自动更新
-const deviceType = ref(false);
const sendDataToParent = () => {
- emit('send-data', '点检界面');
+ emit('send-data', '点检界面', 'other-app');
};
// 获取当前时间的小时数
const currentHour = new Date().getHours();
// 根据当前时间确定默认班次
-const defaultShift = currentHour >= 7 && currentHour < 19 ? 'day' : 'night';
+const defaultShift = currentHour >= 7 && currentHour < 19 ? '0' : '1'; // 早班为0,晚班为1
// 定义响应式变量
-const shift = ref('day'); // 确保 shift 变量已定义
-const status = ref('1'); // 确保 status 变量已定义
+const shift = ref(defaultShift); // 设置默认班次
+const status = ref('0'); // 确保 status 变量已定义
+
+// 设备列表
+const deviceList = ref([]);
+const selectedDeviceId = ref(null);
const showForm = ref(false);
const selectedItemName = ref('');
@@ -121,9 +122,8 @@ const currentDate = formatDate(new Date());
// 计算当前班次的时间段
const hours = computed(() => {
const shiftValue = shift.value;
- console.log("🚀 ~ hours ~ shiftValue:", shiftValue)
const hours = [];
- if (shiftValue === 'day') {
+ if (shiftValue === '0') {
for (let i = 7; i <= 18; i++) {
hours.push(`${i < 10 ? '0' : ''}${i}:00`); // 白班 07:00-18:00
}
@@ -138,10 +138,6 @@ const hours = computed(() => {
return hours;
});
-const handleShiftClick = (shift) => {
- state.value.selectedShift = shift;
-};
-
// JSON 数据
const data = ref({});
@@ -174,14 +170,44 @@ const toLowerCaseFirstLetter = (str) => {
const handleDateChange = (event) => {
selectedDate.value = event.target.value;
+ console.log("🚀 ~ handleDateChange ~ selectedDate.value:", selectedDate.value)
};
+const handleShiftChange = (event) => {
+ shift.value = event.detail;
+ console.log("🚀 ~ handleShiftChange ~ shift.value:", shift.value)
+ fetchInspectionData();
+ fetchCurrentValues();
+};
+
+// 切换设备
+const handleDeviceListChange = (id) => {
+ selectedDeviceId.value = id;
+ fetchInspectionData();
+ fetchCurrentValues();
+};
+
+// 获取设备列表
+const fetchDeviceList = async () => {
+ try {
+ const response = await getDeviceList();
+ if (response.code === 200) {
+ deviceList.value = response.data;
+ selectedDeviceId.value = deviceList.value[2].id; // 默认选中第一个设备
+ }
+ } catch (error) {
+ console.error('Error fetching device list:', error);
+ }
+};
+
+// 获取当前值、参考值、单位等信息
const fetchCurrentValues = async () => {
try {
- const deviceId = 7; // 根据实际情况设置设备ID
- const inputTime = new Date().toISOString(); // 获取当前时间
- const response = await getInspectionCurrent(deviceId, inputTime);
- const params = await getCheckParas(deviceId, inputTime);
+ const deviceId = selectedDeviceId.value; // 根据实际情况设置设备ID
+ const dateValue = selectedDate.value || currentDate;
+ // const inputTime = selectedDate.value; //new Date().toISOString(); // 获取当前时间
+ const response = await getInspectionCurrent(deviceId, dateValue);
+ const params = await getCheckParas(deviceId, dateValue);
if (response.code === 200) {
const currentValues = response.data.data;
@@ -192,13 +218,11 @@ const fetchCurrentValues = async () => {
if (params.code === 200) {
const paramData = params.data;
- console.log("🚀 ~ fetchCurrentValues ~ paramData:", paramData)
inspectionItems.value.forEach(item => {
const param = paramData.find(param => {
return toLowerCaseFirstLetter(param.keyname) === item.name;
});
- console.log("🚀 ~ fetchCurrentValues ~ param:", param)
if (param) {
item.label = param.projectDescription;
@@ -208,23 +232,20 @@ const fetchCurrentValues = async () => {
});
}
- console.log("🚀 ~ fetchCurrentValues ~ inspectionItems.value:", inspectionItems.value)
} catch (error) {
console.error('Error fetching current values:', error);
}
};
+// 获取点检数据
const fetchInspectionData = async () => {
try {
- const deviceId = 7; // globalDeviceId // 根据实际情况设置设备ID
- const inputTime = new Date().toISOString(); // globalTime; // 获取当前时间
+ const deviceId = selectedDeviceId.value; // 根据实际情况设置设备ID
+ // const inputTime = new Date().toISOString(); // globalTime; // 获取当前时间
const shiftValue = shift.value;
const statusValue = status.value;
const dateValue = selectedDate.value || currentDate;
- console.log("🚀 ~ fetchInspectionData ~ shift:", shiftValue)
- console.log("🚀 ~ fetchInspectionData ~ status:", statusValue)
- console.log("🚀 ~ fetchInspectionData ~ date:", dateValue)
- const response = await getInspectionData(deviceId, inputTime);
+ const response = await getInspectionData(deviceId, dateValue, shiftValue);
if (response.code === 200) {
const inspectionData = response.data;
const itemsMap = {};
@@ -248,15 +269,21 @@ const fetchInspectionData = async () => {
});
inspectionItems.value = Object.values(itemsMap);
}
- console.log("🚀 ~ fetchInspectionData ~ inspectionItems.value:", inspectionItems.value)
} catch (error) {
console.error('Error fetching inspection data:', error);
}
};
+// 查询接口数据
+const handleSearch = () => {
+ fetchInspectionData();
+ fetchCurrentValues();
+};
+
let autoUpdateInterval = null;
-onMounted(() => {
+onMounted(async () => {
+ await fetchDeviceList();
fetchCurrentValues();
fetchInspectionData();
sendDataToParent();
@@ -278,7 +305,7 @@ onMounted(() => {
// 监听 update-history 事件
window.addEventListener('update-history', (event) => {
isAutoUpdate.value = false;
- globalTime.value = event.detail;
+ selectedDate.value = event.detail;
fetchCurrentValues();
fetchInspectionData();
setupAutoUpdate();
@@ -287,7 +314,7 @@ onMounted(() => {
// 监听 reset 事件
window.addEventListener('reset', (event) => {
isAutoUpdate.value = true;
- globalTime.value = moment().tz(timezone).format('YYYY-MM-DD HH:mm');
+ selectedDate.value = moment().tz(timezone).format('YYYY-MM-DD HH:mm');
// fetchData();
// fetchGanttData();
setupAutoUpdate();
@@ -303,7 +330,8 @@ onUnmounted(() => {
\ No newline at end of file