修改设备控制界面

This commit is contained in:
WindowBird 2025-10-14 08:50:09 +08:00
parent e9154239e4
commit 3ffd4c9ed1

View File

@ -19,12 +19,18 @@
type="text" type="text"
/> />
</view> </view>
<view class="machao"> MAC号{{ obj.mac == undefined ? '--' : obj.mac }}</view>
<view class="machao"> 电压{{ obj.voltage == undefined ? '--' : obj.voltage }}V</view>
<view class="machao"> <view class="machao">
功率{{ obj.realTimePower == undefined ? '--' : obj.realTimePower }}W MAC号{{ obj.mac == undefined ? "--" : obj.mac }}
</view>
<view class="machao">
电压{{ obj.voltage == undefined ? "--" : obj.voltage }}V
</view>
<view class="machao">
功率{{ obj.realTimePower == undefined ? "--" : obj.realTimePower }}W
</view>
<view class="machao">
电流{{ obj.electricity == undefined ? "--" : obj.electricity }}A
</view> </view>
<view class="machao"> 电流{{ obj.electricity == undefined ? '--' : obj.electricity }}A</view>
<view class="machao"> <view class="machao">
网络 网络
<text v-if="onlineStatus == '离线'" style="color: red">离线</text> <text v-if="onlineStatus == '离线'" style="color: red">离线</text>
@ -35,12 +41,18 @@
<text v-if="powerStatus == '关闭'" style="color: red">关闭</text> <text v-if="powerStatus == '关闭'" style="color: red">关闭</text>
<text v-if="powerStatus == '开启'" style="color: green">开启</text> <text v-if="powerStatus == '开启'" style="color: green">开启</text>
</view> </view>
<view class="machao"> 版本号{{ obj.version == undefined ? '--' : obj.version }}</view>
<view class="machao"> <view class="machao">
最后更新时间{{ obj.lastPullTime == undefined ? '--' : obj.lastPullTime }} 版本号{{ obj.version == undefined ? "--" : obj.version }}
</view> </view>
<view class="machao"> <view class="machao">
最后在线时间{{ obj.lastOnlineTime == undefined ? '--' : obj.lastOnlineTime }} 最后更新时间{{
obj.lastPullTime == undefined ? "--" : obj.lastPullTime
}}
</view>
<view class="machao">
最后在线时间{{
obj.lastOnlineTime == undefined ? "--" : obj.lastOnlineTime
}}
</view> </view>
<view class="jiaozhun"> <view class="jiaozhun">
@ -68,190 +80,199 @@
</template> </template>
<script> <script>
import { sendCommand } from "../../api/device/device";
export default { export default {
data() { data() {
return { return {
bgc: { bgc: {
backgroundColor: '#F7FAFE', backgroundColor: "#F7FAFE",
}, },
storeId: '', storeId: "",
obj: {}, obj: {},
id: '', id: "",
onlineStatus: '--', onlineStatus: "--",
powerStatus: '--', powerStatus: "--",
valuedian: 220, valuedian: 220,
xshu: '1', xshu: "1",
x: '', x: "",
} };
}, },
onLoad(options) { onLoad(options) {
if (options.sn) { if (options.sn) {
this.storeId = options.sn this.storeId = options.sn;
this.getsn() this.getsn();
} }
}, },
// //
onShareAppMessage: function () { onShareAppMessage: function () {
return { return {
title: '创想物联', title: "创想物联",
path: '/pages/shouye/index', path: "/pages/shouye/index",
} };
}, },
// //
onShareTimeline: function () { onShareTimeline: function () {
return { return {
title: '创想物联', title: "创想物联",
query: '', query: "",
path: '/pages/shouye/index', path: "/pages/shouye/index",
} };
}, },
methods: { methods: {
sendCommand,
btncq() { btncq() {
this.$u.put(`/app/device/admin/reboot?sn=${this.storeId}`).then(res => { this.$u.put(`/app/device/admin/reboot?sn=${this.storeId}`).then((res) => {
if (res.code == 200) { if (res.code == 200) {
uni.showToast({ uni.showToast({
title: '重启成功', title: "重启成功",
icon: 'success', icon: "success",
duration: 2000, duration: 2000,
}) });
} else { } else {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
icon: 'none', icon: "none",
duration: 2000, duration: 2000,
}) });
} }
}) });
}, },
btnsxs() { btnsxs() {
this.$u.put(`/app/device/admin/uploadData?sn=${this.storeId}`).then(res => { this.$u
if (res.code == 200) { .put(`/app/device/admin/uploadData?sn=${this.storeId}`)
this.obj = res.data .then((res) => {
this.id = res.data.deviceId if (res.code == 200) {
if (res.data.vxs == null) { this.obj = res.data;
this.xshu = 1 this.id = res.data.deviceId;
if (res.data.vxs == null) {
this.xshu = 1;
} else {
this.xshu = res.data.vxs;
}
if (res.data.onlineStatus == 0) {
this.onlineStatus = "离线";
} else if (res.data.onlineStatus == 1) {
this.onlineStatus = "在线";
}
if (res.data.powerStatus == 0) {
this.powerStatus = "关闭";
} else if (res.data.powerStatus == 1) {
this.powerStatus = "开启";
}
uni.showToast({
title: res.msg,
icon: "success",
duration: 2000,
});
uni.hideLoading();
} else { } else {
this.xshu = res.data.vxs uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
} }
if (res.data.onlineStatus == 0) { });
this.onlineStatus = '离线'
} else if (res.data.onlineStatus == 1) {
this.onlineStatus = '在线'
}
if (res.data.powerStatus == 0) {
this.powerStatus = '关闭'
} else if (res.data.powerStatus == 1) {
this.powerStatus = '开启'
}
uni.showToast({
title: res.msg,
icon: 'success',
duration: 2000,
})
uni.hideLoading()
} else {
uni.showToast({
title: res.msg,
icon: 'none',
duration: 2000,
})
}
})
}, },
btnjian() { btnjian() {
this.valuedian = Number(this.valuedian) - 1 this.valuedian = Number(this.valuedian) - 1;
}, },
btnadd() { btnadd() {
this.valuedian = Number(this.valuedian) + 1 this.valuedian = Number(this.valuedian) + 1;
}, },
btnjiaozhun() { btnjiaozhun() {
this.x = (this.valuedian / this.obj.voltage) * this.xshu this.x = (this.valuedian / this.obj.voltage) * this.xshu;
this.x = this.x.toFixed(3) this.x = this.x.toFixed(3);
console.log(this.x) console.log(this.x);
this.$u.put(`/app/device/admin/${this.obj.deviceId}/vxs?vxs=${this.x}`).then(res => { this.$u
if (res.code == 200) { .put(`/app/device/admin/${this.obj.deviceId}/vxs?vxs=${this.x}`)
uni.showToast({ .then((res) => {
title: '校准成功', if (res.code == 200) {
icon: 'success', uni.showToast({
duration: 2000, title: "校准成功",
}) icon: "success",
this.getsn() duration: 2000,
} else { });
uni.showToast({ this.getsn();
title: res.msg, } else {
icon: 'none', uni.showToast({
}) title: res.msg,
} icon: "none",
}) });
}
});
}, },
btnmy() { btnmy() {
uni.reLaunch({ uni.reLaunch({
url: '/pages/my', url: "/pages/my",
}) });
}, },
qrcode() { qrcode() {
uni.scanCode({ uni.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['qrCode'], scanType: ["qrCode"],
success: res => { success: (res) => {
function getQueryParam(url, paramName) { function getQueryParam(url, paramName) {
let regex = new RegExp(`[?&]${paramName}=([^&]*)`) let regex = new RegExp(`[?&]${paramName}=([^&]*)`);
let results = regex.exec(url) let results = regex.exec(url);
return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null return results
? decodeURIComponent(results[1].replace(/\+/g, " "))
: null;
} }
let sceneValue = res.result let sceneValue = res.result;
let decodedValue = decodeURIComponent(sceneValue) let decodedValue = decodeURIComponent(sceneValue);
let id = getQueryParam(decodedValue, 's') let id = getQueryParam(decodedValue, "s");
this.storeId = id this.storeId = id;
this.getsn() this.getsn();
}, },
fail: err => { fail: (err) => {
console.error('扫描失败:', err) console.error("扫描失败:", err);
uni.showToast({ uni.showToast({
title: '扫描失败', title: "扫描失败",
icon: 'none', icon: "none",
}) });
}, },
}) });
}, },
getsn() { getsn() {
this.$u.get(`/app/device/admin/get?sn=${this.storeId}`).then(res => { this.$u.get(`/app/device/admin/get?sn=${this.storeId}`).then((res) => {
if (res.code == 200) { if (res.code == 200) {
this.obj = res.data this.obj = res.data;
this.id = res.data.deviceId this.id = res.data.deviceId;
if (res.data.vxs == null) { if (res.data.vxs == null) {
this.xshu = 1 this.xshu = 1;
} else { } else {
this.xshu = res.data.vxs this.xshu = res.data.vxs;
} }
if (res.data.onlineStatus == 0) { if (res.data.onlineStatus == 0) {
this.onlineStatus = '离线' this.onlineStatus = "离线";
} else if (res.data.onlineStatus == 1) { } else if (res.data.onlineStatus == 1) {
this.onlineStatus = '在线' this.onlineStatus = "在线";
} }
if (res.data.powerStatus == 0) { if (res.data.powerStatus == 0) {
this.powerStatus = '关闭' this.powerStatus = "关闭";
} else if (res.data.powerStatus == 1) { } else if (res.data.powerStatus == 1) {
this.powerStatus = '开启' this.powerStatus = "开启";
} }
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
icon: 'success', icon: "success",
duration: 2000, duration: 2000,
}) });
uni.hideLoading() uni.hideLoading();
} else { } else {
uni.showToast({ uni.showToast({
title: res.msg, title: res.msg,
icon: 'none', icon: "none",
duration: 2000, duration: 2000,
}) });
} }
}) });
}, },
// //
@ -259,82 +280,106 @@ export default {
uni.navigateBack({ uni.navigateBack({
delta: 1, // 1 delta: 1, // 1
success: () => { success: () => {
console.log('返回上一页成功') console.log("返回上一页成功");
}, },
fail: err => { fail: (err) => {
console.error('返回上一页失败:', err) console.error("返回上一页失败:", err);
}, },
}) });
}, },
// //
btnkq() { async btnkq() {
uni.showLoading({ uni.showLoading({
title: '设备开启中...', title: "设备开启中...",
}) });
this.$u.put(`/app/device/admin/${this.id}/switch?open=true`).then(res => {
if (res.code == 200) { try {
const res = await sendCommand({
command: "11open",
mac: "44D6DA263B38",
tryCount: "2",
timeout: "10",
reason: "测试",
});
console.log("open-res", res);
uni.hideLoading();
if (res.code === 200) {
uni.showToast({ uni.showToast({
title: '开启成功', title: "开启成功",
icon: 'success', icon: "success",
duration: 2000, duration: 2000,
}) });
this.powerStatus = '开启' this.powerStatus = "开启";
} else { } else {
uni.showToast({ uni.showToast({
title: '开启失败', title: res.msg || "开启失败",
icon: 'none', icon: "none",
duration: 2000, duration: 2000,
}) });
} }
}) } catch (error) {
console.error("开启设备失败:", error);
uni.hideLoading();
uni.showToast({
title: "开启失败",
icon: "none",
duration: 2000,
});
}
}, },
// //
btngb() { btngb() {
uni.showLoading({ uni.showLoading({
title: '设备关闭中...', title: "设备关闭中...",
}) });
this.$u.put(`/app/device/admin/${this.id}/switch?open=false`).then(res => { this.$u
if (res.code == 200) { .put(`/app/device/admin/${this.id}/switch?open=false`)
// setTimeout(()=>{ .then((res) => {
// this.btnsx() if (res.code == 200) {
// },1000) // setTimeout(()=>{
uni.showToast({ // this.btnsx()
title: '关闭成功', // },1000)
icon: 'success', uni.showToast({
duration: 2000, title: "关闭成功",
}) icon: "success",
this.powerStatus = '关闭' duration: 2000,
} else { });
uni.showToast({ this.powerStatus = "关闭";
title: '关闭失败', } else {
icon: 'none', uni.showToast({
duration: 2000, title: "关闭失败",
}) icon: "none",
} duration: 2000,
}) });
}
});
}, },
// //
btnsx() { btnsx() {
this.$u.get(`/app/device/v2/refreshIot?deviceNo=${this.storeId}`).then(res => { this.$u
if (res.code == 200) { .get(`/app/device/v2/refreshIot?deviceNo=${this.storeId}`)
this.getsn() .then((res) => {
uni.showToast({ if (res.code == 200) {
title: '同步成功', this.getsn();
icon: 'success', uni.showToast({
duration: 2000, title: "同步成功",
}) icon: "success",
} else { duration: 2000,
uni.showToast({ });
title: '同步失败', } else {
icon: 'none', uni.showToast({
duration: 2000, title: "同步失败",
}) icon: "none",
} duration: 2000,
}) });
}
});
}, },
}, },
} };
</script> </script>
<style lang="less"> <style lang="less">