diff --git a/src/api/device.ts b/src/api/device.ts index 484628d..b807a3a 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -22,7 +22,9 @@ export function deviceUnbind(data){ } // 将设备及开关绑定到塘口 export function bandDeviceToPond(data){ - return httpService.put(API.POND.BIND_DEVICE(), {data}) + const store = useRootUserStore(); + const userId = store.getRootUserId || Taro.getStorageSync('UserId'); + return httpService.put(`${API.POND.BIND_DEVICE()}?rootUserId=${userId}`, {data}) } // 设备图表数据 export function deviceHistory(params){ diff --git a/src/pages/main/home.vue b/src/pages/main/home.vue index 94aaf72..695d5cf 100644 --- a/src/pages/main/home.vue +++ b/src/pages/main/home.vue @@ -1119,13 +1119,33 @@ function onconfirm(list) { if (res.code == 200) { state.show = true; state.msg = "操作成功"; - pond2(); - pond1(); - pondChildInfo.value.getDeviceList(); + // 先关闭弹窗 + bandDevShow.value = false; + // 延迟刷新数据,确保后端数据更新完成 + setTimeout(() => { + // 先刷新塘口列表(会自动选中当前塘口) + pond1(); + // 等待 pond1 完成后再刷新设备详情 + setTimeout(() => { + if (pondChildInfo.value && pondChildInfo.value.getDeviceList) { + pondChildInfo.value.getDeviceList(); + } + }, 500); + }, 500); + } else { + // 操作失败也关闭弹窗 + bandDevShow.value = false; + state.show = true; + state.msg = res.msg || "绑定失败,请重试"; + state.type = "fail"; } }) - .finally(() => { + .catch((error) => { + // 网络错误也关闭弹窗 bandDevShow.value = false; + state.show = true; + state.msg = "网络错误,请重试"; + state.type = "fail"; }); } else if (res.cancel) { bandDevShow.value = false;