diff --git a/page_user/luru/controlDevice.vue b/page_user/luru/controlDevice.vue index 844efe1..6cc6902 100644 --- a/page_user/luru/controlDevice.vue +++ b/page_user/luru/controlDevice.vue @@ -333,31 +333,47 @@ export default { } }, // 关闭 - btngb() { + async btngb() { uni.showLoading({ title: "设备关闭中...", }); - this.$u - .put(`/app/device/admin/${this.id}/switch?open=false`) - .then((res) => { - if (res.code == 200) { - // setTimeout(()=>{ - // this.btnsx() - // },1000) - uni.showToast({ - title: "关闭成功", - icon: "success", - duration: 2000, - }); - this.powerStatus = "关闭"; - } else { - uni.showToast({ - title: "关闭失败", - icon: "none", - duration: 2000, - }); - } + + try { + const res = await sendCommand({ + command: "close", + mac: this.mac, + tryCount: "2", + timeout: "10", + reason: "测试", }); + + console.log("close-res", res); + uni.hideLoading(); + + if (res.code === 200 && res.data.code === "0") { + //0表示成功 + uni.showToast({ + title: "关闭成功", + icon: "success", + duration: 2000, + }); + this.powerStatus = "关闭"; + } else { + uni.showToast({ + title: res.msg || "关闭失败", + icon: "none", + duration: 2000, + }); + } + } catch (error) { + console.error("关闭设备失败:", error); + uni.hideLoading(); + uni.showToast({ + title: "关闭失败", + icon: "none", + duration: 2000, + }); + } }, // 刷新 btnsx() {