buddhism/page_user/luru/controlDevice.vue

548 lines
13 KiB
Vue
Raw Normal View History

<template>
<view class="">
<view class="title"> 控制台</view>
<view class="shuom"> 请扫描设备上的二维码</view>
<view class="iptbox">
<view class="qrcode" @click="qrcode()">
<image
mode="aspectFit"
src="https://api.ccttiot.com/smartmeter/img/static/uy7BNwAMIKwvstqFnRhs"
>
</image>
</view>
<input
v-model="storeId"
class="ips"
placeholder="请扫描设备上的二维码"
placeholder-class="my-placeholder"
style="margin-left: 32rpx"
type="text"
/>
</view>
<view class="machao">
2025-10-14 08:50:09 +08:00
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 class="machao">
网络
<text v-if="onlineStatus == '离线'" style="color: red">离线</text>
<text v-if="onlineStatus == '在线'" style="color: green">在线</text>
</view>
<view class="machao">
状态
<text v-if="powerStatus == '关闭'" style="color: red">关闭</text>
<text v-if="powerStatus == '开启'" style="color: green">开启</text>
</view>
<view class="machao">
2025-10-14 08:50:09 +08:00
版本号{{ obj.version == undefined ? "--" : obj.version }}
</view>
<view class="machao">
最后更新时间{{
obj.lastPullTime == undefined ? "--" : obj.lastPullTime
}}
</view>
<view class="machao">
2025-10-14 08:50:09 +08:00
最后在线时间{{
obj.lastOnlineTime == undefined ? "--" : obj.lastOnlineTime
}}
</view>
<view class="jiaozhun">
<view class="input">
<button @click="btnjian">-</button>
<input v-model="valuedian" placeholder="输入校准电压" type="text" />
<button @click="btnadd">+</button>
</view>
<view class="view" @click="btnjiaozhun"> 校准电压</view>
</view>
<view class="list">
<view class="anniulist">
<view class="anniu" @click="btncq"> 重启</view>
<view class="anniu" @click="btnsxs"> 刷新</view>
</view>
<view class="anniulist">
<view class="anniu" @click="btnkq"> 开启</view>
<view class="anniu" @click="btngb"> 关闭</view>
<view class="anniu" @click="btnsx"> 同步</view>
</view>
<view class="fanhui" @click="btnfh"> 返回</view>
</view>
</view>
</template>
<script>
2025-10-14 08:50:09 +08:00
import { sendCommand } from "../../api/device/device";
export default {
data() {
return {
bgc: {
2025-10-14 08:50:09 +08:00
backgroundColor: "#F7FAFE",
},
2025-10-14 08:50:09 +08:00
storeId: "",
obj: {},
2025-10-14 08:50:09 +08:00
id: "",
onlineStatus: "--",
powerStatus: "--",
valuedian: 220,
2025-10-14 08:50:09 +08:00
xshu: "1",
x: "",
};
},
onLoad(options) {
2025-10-14 09:02:17 +08:00
if (options.mac) {
this.storeId = options.mac;
this.mac = options.mac;
2025-10-14 08:50:09 +08:00
this.getsn();
}
},
// 分享到好友(会话)
onShareAppMessage: function () {
return {
2025-10-14 08:50:09 +08:00
title: "创想物联",
path: "/pages/shouye/index",
};
},
// 分享到朋友圈
onShareTimeline: function () {
return {
2025-10-14 08:50:09 +08:00
title: "创想物联",
query: "",
path: "/pages/shouye/index",
};
},
methods: {
2025-10-14 08:50:09 +08:00
sendCommand,
btncq() {
2025-10-14 08:50:09 +08:00
this.$u.put(`/app/device/admin/reboot?sn=${this.storeId}`).then((res) => {
if (res.code == 200) {
uni.showToast({
2025-10-14 08:50:09 +08:00
title: "重启成功",
icon: "success",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
} else {
uni.showToast({
title: res.msg,
2025-10-14 08:50:09 +08:00
icon: "none",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
}
2025-10-14 08:50:09 +08:00
});
},
btnsxs() {
2025-10-14 08:50:09 +08:00
this.$u
.put(`/app/device/admin/uploadData?sn=${this.storeId}`)
.then((res) => {
if (res.code == 200) {
this.obj = res.data;
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 {
2025-10-14 08:50:09 +08:00
uni.showToast({
title: res.msg,
icon: "none",
duration: 2000,
});
}
2025-10-14 08:50:09 +08:00
});
},
btnjian() {
2025-10-14 08:50:09 +08:00
this.valuedian = Number(this.valuedian) - 1;
},
btnadd() {
2025-10-14 08:50:09 +08:00
this.valuedian = Number(this.valuedian) + 1;
},
btnjiaozhun() {
2025-10-14 08:50:09 +08:00
this.x = (this.valuedian / this.obj.voltage) * this.xshu;
this.x = this.x.toFixed(3);
console.log(this.x);
this.$u
.put(`/app/device/admin/${this.obj.deviceId}/vxs?vxs=${this.x}`)
.then((res) => {
if (res.code == 200) {
uni.showToast({
title: "校准成功",
icon: "success",
duration: 2000,
});
this.getsn();
} else {
uni.showToast({
title: res.msg,
icon: "none",
});
}
});
},
btnmy() {
uni.reLaunch({
2025-10-14 08:50:09 +08:00
url: "/pages/my",
});
},
qrcode() {
uni.scanCode({
onlyFromCamera: true,
2025-10-14 08:50:09 +08:00
scanType: ["qrCode"],
success: (res) => {
function getQueryParam(url, paramName) {
2025-10-14 08:50:09 +08:00
let regex = new RegExp(`[?&]${paramName}=([^&]*)`);
let results = regex.exec(url);
return results
? decodeURIComponent(results[1].replace(/\+/g, " "))
: null;
}
2025-10-14 08:50:09 +08:00
let sceneValue = res.result;
let decodedValue = decodeURIComponent(sceneValue);
let id = getQueryParam(decodedValue, "s");
this.storeId = id;
this.getsn();
},
2025-10-14 08:50:09 +08:00
fail: (err) => {
console.error("扫描失败:", err);
uni.showToast({
2025-10-14 08:50:09 +08:00
title: "扫描失败",
icon: "none",
});
},
2025-10-14 08:50:09 +08:00
});
},
getsn() {
2025-10-14 08:50:09 +08:00
this.$u.get(`/app/device/admin/get?sn=${this.storeId}`).then((res) => {
if (res.code == 200) {
2025-10-14 08:50:09 +08:00
this.obj = res.data;
this.id = res.data.deviceId;
if (res.data.vxs == null) {
2025-10-14 08:50:09 +08:00
this.xshu = 1;
} else {
2025-10-14 08:50:09 +08:00
this.xshu = res.data.vxs;
}
if (res.data.onlineStatus == 0) {
2025-10-14 08:50:09 +08:00
this.onlineStatus = "离线";
} else if (res.data.onlineStatus == 1) {
2025-10-14 08:50:09 +08:00
this.onlineStatus = "在线";
}
if (res.data.powerStatus == 0) {
2025-10-14 08:50:09 +08:00
this.powerStatus = "关闭";
} else if (res.data.powerStatus == 1) {
2025-10-14 08:50:09 +08:00
this.powerStatus = "开启";
}
uni.showToast({
title: res.msg,
2025-10-14 08:50:09 +08:00
icon: "success",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
uni.hideLoading();
} else {
uni.showToast({
title: res.msg,
2025-10-14 08:50:09 +08:00
icon: "none",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
}
2025-10-14 08:50:09 +08:00
});
},
// 返回录入
btnfh() {
uni.navigateBack({
delta: 1, // 返回的页面数默认1
success: () => {
2025-10-14 08:50:09 +08:00
console.log("返回上一页成功");
},
2025-10-14 08:50:09 +08:00
fail: (err) => {
console.error("返回上一页失败:", err);
},
2025-10-14 08:50:09 +08:00
});
},
// 开启
2025-10-14 08:50:09 +08:00
async btnkq() {
uni.showLoading({
2025-10-14 08:50:09 +08:00
title: "设备开启中...",
});
2025-10-14 09:02:17 +08:00
2025-10-14 08:50:09 +08:00
try {
const res = await sendCommand({
2025-10-14 10:00:05 +08:00
command: "open",
2025-10-14 09:02:17 +08:00
mac: this.mac,
2025-10-14 08:50:09 +08:00
tryCount: "2",
timeout: "10",
reason: "测试",
});
console.log("open-res", res);
uni.hideLoading();
2025-10-14 10:00:05 +08:00
if (res.code === 200 && res.data.code === "0") {
//0表示成功
uni.showToast({
2025-10-14 08:50:09 +08:00
title: "开启成功",
icon: "success",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
this.powerStatus = "开启";
} else {
uni.showToast({
2025-10-14 08:50:09 +08:00
title: res.msg || "开启失败",
icon: "none",
duration: 2000,
2025-10-14 08:50:09 +08:00
});
}
2025-10-14 08:50:09 +08:00
} catch (error) {
console.error("开启设备失败:", error);
uni.hideLoading();
uni.showToast({
title: "开启失败",
icon: "none",
duration: 2000,
});
}
},
// 关闭
2025-10-14 10:05:21 +08:00
async btngb() {
uni.showLoading({
2025-10-14 08:50:09 +08:00
title: "设备关闭中...",
});
2025-10-14 10:05:21 +08:00
try {
const res = await sendCommand({
command: "close",
mac: this.mac,
tryCount: "2",
timeout: "10",
reason: "测试",
2025-10-14 08:50:09 +08:00
});
2025-10-14 10:05:21 +08:00
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() {
2025-10-14 08:50:09 +08:00
this.$u
.get(`/app/device/v2/refreshIot?deviceNo=${this.storeId}`)
.then((res) => {
if (res.code == 200) {
this.getsn();
uni.showToast({
title: "同步成功",
icon: "success",
duration: 2000,
});
} else {
uni.showToast({
title: "同步失败",
icon: "none",
duration: 2000,
});
}
});
},
},
2025-10-14 08:50:09 +08:00
};
</script>
<style lang="less">
.jiaozhun {
display: flex;
padding: 50rpx;
box-sizing: border-box;
width: 100%;
justify-content: space-between;
button {
height: 80rpx;
line-height: 80rpx;
background-color: #8883f0;
color: #fff;
}
.input {
input {
height: 80rpx;
line-height: 80rpx;
}
border: 1px solid #ccc;
border-radius: 20rpx;
display: flex;
width: 400rpx;
height: 80rpx;
text-align: center;
}
.view {
width: 200rpx;
height: 80rpx;
border-radius: 20rpx;
background-color: #8883f0;
color: #fff;
text-align: center;
line-height: 80rpx;
font-size: 28rpx;
}
}
.list {
position: fixed;
bottom: 50rpx;
left: 50%;
transform: translateX(-50%);
.anniulist {
width: 658rpx;
margin: auto;
margin-top: 20rpx;
text-align: left;
font-size: 32rpx;
display: flex;
.anniu {
margin-right: 20rpx;
width: 30%;
height: 90rpx;
border-radius: 20rpx;
background-color: #8883f0;
color: #fff;
font-size: 32rpx;
text-align: center;
line-height: 90rpx;
}
}
.fanhui {
width: 658rpx;
height: 90rpx;
border-radius: 20rpx;
background-color: #8883f0;
color: #fff;
font-size: 32rpx;
text-align: center;
line-height: 90rpx;
margin: auto;
margin-top: 50rpx;
}
}
.machao {
width: 658rpx;
margin: auto;
margin-top: 20rpx;
text-align: left;
font-size: 32rpx;
}
.title {
font-size: 70rpx;
font-weight: 600;
text-align: left;
width: 658rpx;
margin: auto;
margin-top: 30rpx;
}
.shuom {
width: 658rpx;
margin: auto;
margin-top: 30rpx;
text-align: left;
font-size: 32rpx;
}
.iptbox {
display: flex;
align-items: center;
flex-wrap: nowrap;
padding: 22rpx;
margin: 28rpx auto 0;
width: 658rpx;
height: 88rpx;
background: #ffffff;
box-shadow: 0rpx 0rpx 8rpx 0rpx rgba(0, 0, 0, 0.15);
border-radius: 20rpx 20rpx 20rpx 20rpx;
.qrcode {
padding-right: 20rpx;
border-right: 2rpx solid #d8d8d8;
image {
width: 54rpx;
height: 54rpx;
}
}
.ips {
width: 630rpx;
}
image {
width: 18rpx;
height: 32rpx;
}
.my-placeholder {
font-weight: 400;
font-size: 32rpx;
color: #808080;
}
}
</style>