From 677a8679b5140ca6019f974c092de103df8f8559 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 01 六月 2026 17:52:16 +0800
Subject: [PATCH] 新疆马铃薯 1.库存管理绑定设备,添加查看数采功能
---
src/views/inventoryManagement/stockManagement/IotDataDialog.vue | 48 +++++++++++++++++++++++++++++++++++++++---------
1 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/views/inventoryManagement/stockManagement/IotDataDialog.vue b/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
index 2f12009..8a34b8f 100644
--- a/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
+++ b/src/views/inventoryManagement/stockManagement/IotDataDialog.vue
@@ -29,7 +29,7 @@
</div>
<div class="device-status">
<span class="status-dot" :class="getStatusClass(device.status)"></span>
- <span :class="getStatusTextClass(device.status)">{{ device.status || '鏈煡' }}</span>
+ <span :class="getStatusTextClass(device.status)">{{ getStatusLabel(device.status) }}</span>
</div>
</div>
</template>
@@ -83,7 +83,7 @@
</el-row>
</div>
<div v-else class="device-offline">
- <el-alert :title="device.statusMessage || '璁惧绂荤嚎'" type="warning" :closable="false" show-icon />
+ <el-alert :title="device.statusMessage || (device.status === 'error' ? '璁惧寮傚父' : '璁惧绂荤嚎')" :type="device.status === 'error' ? 'error' : 'warning'" :closable="false" show-icon />
</div>
</el-card>
</div>
@@ -99,7 +99,7 @@
<script setup>
import { ref, computed, onMounted, onUnmounted, watch } from "vue";
- import { getIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js";
+ import { batchGetIotRealtimeData } from "@/api/inventoryManagement/stockInventory.js";
import { Refresh, Sunny, Drizzling, WindPower, Sunrise, Lightning } from "@element-plus/icons-vue";
const props = defineProps({
@@ -163,13 +163,36 @@
}
};
+ const getStatusLabel = (status) => {
+ switch (status) {
+ case "鍦ㄧ嚎":
+ return "鍦ㄧ嚎";
+ case "offline":
+ return "绂荤嚎";
+ case "error":
+ return "寮傚父";
+ default:
+ return "绂荤嚎";
+ }
+ };
+
const fetchData = async () => {
- if (!props.record.id) return;
+ const deviceIdsStr = props.record?.warehouse;
+ console.log("fetchData called, warehouse:", deviceIdsStr);
+ if (!deviceIdsStr) {
+ console.warn("warehouse is empty, skip fetch");
+ deviceData.value = { inventoryId: null, iotDeviceIds: "", devices: [] };
+ return;
+ }
loading.value = true;
try {
- const res = await getIotRealtimeData(props.record.id);
+ const deviceIds = deviceIdsStr.split(",").map(id => id.trim()).filter(id => id);
+ const res = await batchGetIotRealtimeData(deviceIds);
+
if (res.code === 200 && res.data) {
deviceData.value = res.data;
+ } else {
+ deviceData.value = { inventoryId: null, iotDeviceIds: deviceIdsStr, devices: [] };
}
} catch (error) {
console.error("鑾峰彇鐗╄仈璁惧鏁版嵁澶辫触:", error);
@@ -183,6 +206,17 @@
isShow.value = false;
};
+ // 鐩戝惉寮圭獥鏄剧ず鐘舵�侊紝姣忔鎵撳紑鏃惰幏鍙栨暟鎹�
+ watch(() => props.visible, (val) => {
+ console.log("visible changed:", val, "record:", props.record);
+ if (val) {
+ fetchData();
+ } else {
+ // 鍏抽棴鏃跺仠姝㈣嚜鍔ㄥ埛鏂�
+ autoRefresh.value = false;
+ }
+ }, { immediate: true });
+
// 鑷姩鍒锋柊
watch(autoRefresh, (val) => {
if (val) {
@@ -195,10 +229,6 @@
refreshTimer = null;
}
}
- });
-
- onMounted(() => {
- fetchData();
});
onUnmounted(() => {
--
Gitblit v1.9.3