Browse Source

智能居家接口对接,阈值回显有问题

kqqd
lzp 4 months ago
parent
commit
95f3d9dabe
  1. 131
      src/views/index.vue

131
src/views/index.vue

@ -5,32 +5,38 @@
<div class="div-ul"> <div class="div-ul">
<div class="div-li"> <div class="div-li">
<div> <div>
<span>温度</span>22.2 <span>温度</span>{{ deviceInfo.temperature || '-' }}
</div> </div>
<div> <span>湿度</span>50% <div> <span>湿度</span>{{ deviceInfo.humidity || '-' }}%
</div> </div>
</div> </div>
<!-- ON开启 OFF关闭 --> <!-- ON开启 OFF关闭 -->
<div class="div-li"> <div class="div-li">
<div> <div>
<span>CO</span>5PPM <span>CO</span>{{ deviceInfo.co || '-' }}PPM
</div> </div>
<div> <div>
<span>预警</span> <span>预警</span>
<el-switch v-model="value2" active-color="#13ce66" inactive-color="#ff4949"> <el-switch active-value="1" inactive-value="0" v-model="deviceInfo.warning" active-color="#13ce66"
inactive-color="#ff4949">
</el-switch> </el-switch>
</div> </div>
</div> </div>
</div> </div>
<div class="div-tips"><span>阈值设定</span>30 <i class="el-icon-edit" <div class="div-tips"><span>阈值设定</span>{{ getThreshold() }} <i class="el-icon-edit"
style="color: rgb(64, 158, 255);margin-left: 4px;cursor: pointer;" @click="handleSettings"></i></div> style="color: rgb(64, 158, 255);margin-left: 4px;cursor: pointer;" @click="handleSettings"></i></div>
</div> </div>
<!-- 添加或修改公告对话框 --> <!-- 添加或修改公告对话框 -->
<el-dialog title="阈值设定" :visible.sync="open" width="780px" append-to-body> <el-dialog title="阈值设定" :visible.sync="open" width="780px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px"> <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="温度" prop="temperature">
<el-form-item label="阈值" prop="noticeTitle"> <el-input v-model="form.temperature" placeholder="请输入温度" />
<el-input v-model="form.noticeTitle" placeholder="请输入阈值" /> </el-form-item>
<el-form-item label="湿度" prop="humidity">
<el-input v-model="form.humidity" placeholder="请输入湿度" />
</el-form-item>
<el-form-item label="CO" prop="co">
<el-input v-model="form.co" placeholder="请输入CO" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
@ -42,46 +48,126 @@
</template> </template>
<script> <script>
import { updateNotice } from "@/api/system/notice"; import { queryProjectInfoByKey, deviceList, attributes, sendAttribute, sendCommand } from "@/api/school";
export default { export default {
name: "Index", name: "Index",
data() { data() {
return { return {
deviceId: "", // id
deviceInfo: {
temperature: 0, //
threshold: 0, //
},
open: false, open: false,
value2: false, value2: false,
loading: false,
// //
form: {}, form: {},
// //
rules: { rules: {
noticeTitle: [ temperature: [
{ required: true, message: "公告标题不能为空", trigger: "blur" } { required: true, message: "温度不能为空", trigger: "blur" }
],
humidity: [
{ required: true, message: "湿度不能为空", trigger: "blur" }
],
co: [
{ required: true, message: "CO不能为空", trigger: "blur" }
], ],
noticeType: [
{ required: true, message: "公告类型不能为空", trigger: "change" }
]
}, },
// //
version: "3.8.9", version: "3.8.9",
}; };
}, },
created() {
this.getqueryProjectInfoByKey() // keyid
},
methods: { methods: {
// //
handleSettings() { handleSettings() {
this.open = true; this.open = true;
this.form = { this.form = {
noticeTitle: "30", temperature: this.deviceInfo.temperature1, //
humidity: this.deviceInfo.humidity1, // 湿
co: this.deviceInfo.co1, // CO
}; };
// this.$message.success(''); // this.$message.success('');
}, },
/** 提交按钮 */
submitForm: function() { // keyid
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 === "S1");
this.deviceId = w2Device.id;
this.getAttributes(this.deviceId); // id
})
},
// id
getAttributes(_id) {
attributes({
deviceId: _id,
}).then(res => {
this.loading = false;
// deviceInfo
let deviceAttributesList = res.data.deviceAttributesList
//
let temperature = deviceAttributesList.find(row => row.id === 447247444691968)?.attributeValue;
let temperature1 = deviceAttributesList.find(row => row.id === 447247458859777)?.attributeValue;
// 湿湿
let humidity = deviceAttributesList.find(row => row.id === 447247449387520)?.attributeValue;
let humidity1 = deviceAttributesList.find(row => row.id === 447247458859778)?.attributeValue;
// COCO
let co = deviceAttributesList.find(row => row.id === 447247453780224)?.attributeValue;
let co1 = deviceAttributesList.find(row => row.id === 447247458859779)?.attributeValue;
//
let warning = deviceAttributesList.find(row => row.id === 447247458859776)?.attributeValue;
this.deviceInfo = {
temperature: temperature, //
temperature1: temperature1, //
humidity: humidity, // 湿
humidity1: humidity1, // 湿
co: co, // CO
co1: co1, // CO
warning: warning || 0, //
}
});
},
getThreshold() {
return `温度:${this.deviceInfo.temperature1 || '-'}℃ 湿度:${this.deviceInfo.humidity1 || '-'}% CO:${this.deviceInfo.co1 || '-'}PPM`;
},
/** 下发属性 */
submitForm: function () {
this.$refs["form"].validate(valid => { this.$refs["form"].validate(valid => {
if (valid) { if (valid) {
updateNotice(this.form).then(response => { let attributeParams = {
this.$modal.msgSuccess("操作成功"); temperature: this.form.temperature, //
this.open = false; humidity: this.form.humidity, // 湿
this.getList(); co: this.form.co, // CO
}); }
sendAttribute({
"attributeParams": JSON.stringify(attributeParams), // JSON
"deviceId": this.deviceId // id
}).then(response => {
this.getAttributes(this.deviceId); // id
this.$modal.msgSuccess("操作成功");
this.open = false;
});
} }
}); });
}, },
@ -91,6 +177,7 @@ export default {
<style scoped lang="scss"> <style scoped lang="scss">
.div-box { .div-box {
transform: scale(1.4);
width: 500px; width: 500px;
box-sizing: border-box; box-sizing: border-box;
padding: 16px; padding: 16px;

Loading…
Cancel
Save