Browse Source

智能化衣柜接口对接,除湿、杀菌下发命令接口报错

znhyg
lzp 4 months ago
parent
commit
7a91504062
  1. 122
      src/views/index.vue

122
src/views/index.vue

@ -5,44 +5,146 @@
<div class="div-ul">
<div class="div-li">
<div>
<span>温度</span>22.2
<span>温度</span>{{ deviceInfo.temperature }}
</div>
<div> <span>湿度</span>50%
<div> <span>湿度</span>{{ deviceInfo.humidity }}%
</div>
</div>
<!-- ON开启 OFF关闭 -->
<div class="div-li">
<div>
<span>除湿</span>
<el-switch v-model="value2" active-color="#13ce66" inactive-color="#ff4949">
<el-switch active-value="1" inactive-value="0" v-model="deviceInfo.dehumidification" active-color="#13ce66"
inactive-color="#ff4949" @change="handleDehumidification">
</el-switch>
</div>
<div>
<span>杀菌</span>
<el-switch v-model="value2" active-color="#13ce66" inactive-color="#ff4949">
<el-switch active-value="1" inactive-value="0" v-model="deviceInfo.light" active-color="#13ce66"
inactive-color="#ff4949" @change="handleLight">
</el-switch>
</div>
</div>
</div>
<div class="div-tips"><span>标签序列号</span>AE0B01 </div>
<div class="div-tips"><span>标签序列号</span>{{ deviceInfo.serialNumber }} </div>
</div>
</div>
</template>
<script>
import { queryProjectInfoByKey, deviceList, attributes, sendAttribute, sendCommand } from "@/api/school";
export default {
name: "Index",
data() {
return {
deviceId: "", // id
deviceInfo: {
temperature: 0, //
threshold: 0, //
},
open: false,
value2: false,
loading: false,
//
form: {},
//
rules: {
threshold: [
{ required: true, message: "阈值不能为空", trigger: "blur" }
],
},
//
version: "3.8.9",
};
},
created() {
this.getqueryProjectInfoByKey() // keyid
},
methods: {
goTarget(href) {
window.open(href, "_blank");
// 湿
handleDehumidification() {
sendCommand({
"commandId": "447173913707264", // 湿,
"commandParams": this.deviceInfo.dehumidification, // 0 1 ,
"deviceId": this.deviceId
}).then(res => {
this.getDeviceList(res.data.id) // id
});
},
//
handleLight(){
sendCommand({
"commandId": "447173913707264", // 湿,
"commandParams": this.deviceInfo.dehumidification, // 0 1 ,
"deviceId": this.deviceId
}).then(res => {
this.getDeviceList(res.data.id) // id
});
},
//
handleSettings() {
this.open = true;
this.form = {
threshold: this.deviceInfo.threshold,
};
// this.$message.success('');
},
// 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 === "W1");
this.deviceId = w2Device.id;
this.getAttributes(this.deviceId); // id
})
},
// id
getAttributes(_id) {
attributes({
deviceId: _id,
}).then(({ data: { deviceAttributeRecordList: records } }) => {
this.loading = false;
// id
const findAttr = (id, defaultValue = '-') =>
records.find(row => row.id === id)?.attributeValue || defaultValue;
//
this.deviceInfo = {
temperature: findAttr(447173909669888), //
humidity: findAttr(447173911846400), // 湿
serialNumber: findAttr(447173913707263), //
light: findAttr(447173913707265, '0'), // ()
dehumidification: findAttr(447173913707264, '0'), // 湿()
};
});
},
/** 下发属性 */
submitForm: function () {
this.$refs["form"].validate(valid => {
if (valid) {
let param = { "Wen": `#${this.form.threshold}` } //
sendAttribute({
"attributeParams": JSON.stringify(param), // JSON
"deviceId": this.deviceId // id
}).then(response => {
this.getAttributes(this.deviceId); // id
this.$modal.msgSuccess("操作成功");
this.open = false;
});
}
});
},
},
};
@ -50,6 +152,7 @@ export default {
<style scoped lang="scss">
.div-box {
transform: scale(1.4);
width: 500px;
box-sizing: border-box;
padding: 16px;
@ -77,15 +180,18 @@ export default {
display: flex;
justify-content: space-between;
margin-bottom: 12px;
div {
flex: 1
}
span {
color: #666;
}
}
}
.div-tips{
.div-tips {
span {
color: #666;
}

Loading…
Cancel
Save