毕设
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.6 KiB

4 months ago
<template>
<div v-loading="loading" style="padding: 16px;min-height: calc(100vh - 84px);display: flex; justify-content: center;align-items: center;">
4 months ago
<div class="div-box">
<div class="div-box-title"> 智能生猪饲喂系统 </div>
4 months ago
<div class="div-ul">
<div class="div-li">
<div>
<span>当前重量</span>{{deviceInfo.weight || '-'}}g
4 months ago
</div>
</div>
<!-- ON开启 OFF关闭 -->
<div class="div-li">
<div>
<span>电机状态</span>
<el-switch disabled v-model="value2" active-color="#13ce66" inactive-color="#ff4949">
4 months ago
</el-switch>
</div>
</div>
</div>
<div class="div-tips"><span>阈值设定</span>{{deviceInfo.threshold || '-'}} <i class="el-icon-edit"
style="color: rgb(64, 158, 255);margin-left: 4px;cursor: pointer;" @click="handleSettings"></i></div>
4 months ago
</div>
<!-- 添加或修改公告对话框 -->
<el-dialog title="阈值设定" :visible.sync="open" width="780px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
4 months ago
<el-form-item label="阈值" prop="threshold">
<el-input v-model="form.threshold" placeholder="请输入阈值" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="open = false"> </el-button>
</div>
</el-dialog>
4 months ago
</div>
</template>
<script>
import { queryProjectInfoByKey, deviceList, attributes, sendAttribute, sendCommand } from "@/api/school";
4 months ago
export default {
name: "Index",
data() {
return {
deviceId: "", // 设备id
deviceInfo: {
weight: 0, // 重量
threshold: 0, // 阈值
},
open: false,
4 months ago
value2: false,
loading: false,
// 表单参数
form: {},
// 表单校验
rules: {
threshold: [
{ required: true, message: "阈值不能为空", trigger: "blur" }
],
},
4 months ago
// 版本号
version: "3.8.9",
};
},
created() {
this.getqueryProjectInfoByKey() // 根据项目key查找项目id
},
4 months ago
methods: {
// 阈值设定弹窗
handleSettings() {
this.open = true;
this.form = {
threshold: this.deviceInfo.threshold,
};
// this.$message.success('');
},
// 根据项目key查找项目id
getqueryProjectInfoByKey() {
this.loading = true;
queryProjectInfoByKey({
projectKey: "qKStHKKt"
}).then(res => {
this.getDeviceList(res.data.id) // 根据项目id查找设备列表
});
},
// 根据项目id查找设备列表
getDeviceList(_id) {
deviceList({
projectId: _id
}).then(res => {
const w2Device = res.rows.find(device => device.deviceName === "P1");
this.deviceId = w2Device.id;
this.getAttributes(this.deviceId); // 根据设备id查找设备信息
})
},
// 根据设备id查找设备信息
getAttributes(_id) {
attributes({
deviceId: _id,
}).then(res => {
this.loading = false;
// 获取重量和阈值信息,并赋值给deviceInfo
let deviceAttr = res.data.deviceAttributesList
let weight = deviceAttr.find(row => row.id === 447247498590464)?.attributeValue;
let threshold = deviceAttr.find(row => row.id === 447247498590465)?.attributeValue;
console.log('threshold',threshold);
// 阈值 threshold 特殊处理
if (threshold && threshold.indexOf("#") !== -1) {
threshold = threshold.slice(1); // 去掉#
}
this.deviceInfo = {
weight: weight,
threshold: threshold,
}
// 根基重量值是否低于阈值,设置报警器、加热器的状态
this.value2 = false;
// 转为数字类型判断
this.deviceInfo.weight = Number(this.deviceInfo.weight);
this.deviceInfo.threshold = Number(this.deviceInfo.threshold);
if (this.deviceInfo.weight < this.deviceInfo.threshold) {
this.value2 = true;
}
});
},
/** 下发属性 */
submitForm: function () {
this.$refs["form"].validate(valid => {
if (valid) {
sendAttribute({
"attributeAndValues": [
{
"attributeIdentifier": "Value",
"attributeValue": this.form.threshold
}
],
"deviceId": this.deviceId // 设备id
}).then(response => {
this.getAttributes(this.deviceId); // 根据设备id查找设备信息
this.$modal.msgSuccess("操作成功");
this.open = false;
});
}
});
4 months ago
},
},
};
</script>
<style scoped lang="scss">
4 months ago
.div-box {
transform: scale(1.4);
4 months ago
width: 500px;
box-sizing: border-box;
padding: 16px;
border: 1px solid #ccc;
border-radius: 10px;
4 months ago
4 months ago
.div-box-title {
font-size: 20px;
font-weight: bold;
margin-bottom: 20px;
text-align: center;
border-bottom: 1px solid #ccc;
padding-bottom: 16px;
4 months ago
}
4 months ago
}
4 months ago
4 months ago
.div-ul {
// .div-li>div:nth-of-type(1) {
// border-right: 1px solid #ccc;
// margin-right: 16px;
// }
4 months ago
.div-li {
font-size: 18px;
display: flex;
justify-content: space-between;
margin-bottom: 12px;
div {
flex: 1;
align-items: center;
}
4 months ago
span {
color: #666;
4 months ago
}
}
}
.div-tips {
font-size: 18px;
line-height: 22px;
display: flex;
align-items: center;
span {
color: #666;
}
}
4 months ago
</style>