From 6924802b1f52598dc6d71bc251c241ca03ca46c5 Mon Sep 17 00:00:00 2001
From: kerwincui <164770707@qq.com>
Date: Sat, 6 Aug 2022 01:23:48 +0800
Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BC=96=E5=8F=B7=E6=A0=A1?=
=?UTF-8?q?=E9=AA=8C=EF=BC=8C=E5=8F=AA=E8=83=BD=E4=B8=BA=E5=AD=97=E6=AF=8D?=
=?UTF-8?q?=E5=92=8C=E6=95=B0=E5=AD=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
vue/src/views/index.vue | 2 +-
vue/src/views/iot/device/device-edit.vue | 135 +++++++++++++----------
2 files changed, 78 insertions(+), 59 deletions(-)
diff --git a/vue/src/views/index.vue b/vue/src/views/index.vue
index aa3dfc75..093e4d7c 100644
--- a/vue/src/views/index.vue
+++ b/vue/src/views/index.vue
@@ -230,7 +230,7 @@
赞助用户:
-
可用于商业用途,并提供移动端源码,包含一年的更新。但是不能低价或批量转售源码,不能随意分发源码。目前赞助费为3000元,项目不断完善后会对应增加费用。
+
可用于商业用途,并提供移动端源码,包含一年的更新。但是不能低价或批量转售源码,不能随意分发源码。目前赞助费为3500元,项目不断完善后会对应增加费用。
diff --git a/vue/src/views/iot/device/device-edit.vue b/vue/src/views/iot/device/device-edit.vue
index 6d404a66..6d5ad7e6 100644
--- a/vue/src/views/iot/device/device-edit.vue
+++ b/vue/src/views/iot/device/device-edit.vue
@@ -15,7 +15,7 @@
* 设备编号
-
+
生成
@@ -152,7 +152,7 @@
@@ -232,7 +232,7 @@ export default {
data() {
return {
// 二维码内容
- qrText:'wumei-smart',
+ qrText: 'wumei-smart',
// 打开设备配置对话框
openSummary: false,
// 是否加载完成
@@ -271,6 +271,11 @@ export default {
required: true,
message: "设备名称不能为空",
trigger: "blur"
+ }, {
+ min: 2,
+ max: 5,
+ message: '设备名称长度在 2 到 5 个字符',
+ trigger: 'blur'
}],
firmwareVersion: [{
required: true,
@@ -294,61 +299,61 @@ export default {
},
destroyed() {
// 取消订阅主题
- this.mqttUnSubscribe(this.form);
+ this.mqttUnSubscribe(this.form);
},
methods: {
/* 连接Mqtt消息服务器 */
- async connectMqtt() {
- if (this.$mqttTool.client == null) {
- await this.$mqttTool.connect(this.vuex_token);
- }
- this.mqttCallback();
- },
+ async connectMqtt() {
+ if (this.$mqttTool.client == null) {
+ await this.$mqttTool.connect(this.vuex_token);
+ }
+ this.mqttCallback();
+ },
/* Mqtt回调处理 */
- mqttCallback() {
- this.$mqttTool.client.on('message', (topic, message, buffer) => {
- let topics = topic.split('/');
- let productId = topics[1];
- let deviceNum = topics[2];
- message = JSON.parse(message.toString());
- if (topics[3] == 'status') {
- console.log('接收到【设备状态-详情】主题:', topic);
- console.log('接收到【设备状态-详情】内容:', message);
- // 更新列表中设备的状态
- if (this.form.serialNumber == deviceNum) {
+ mqttCallback() {
+ this.$mqttTool.client.on('message', (topic, message, buffer) => {
+ let topics = topic.split('/');
+ let productId = topics[1];
+ let deviceNum = topics[2];
+ message = JSON.parse(message.toString());
+ if (topics[3] == 'status') {
+ console.log('接收到【设备状态-详情】主题:', topic);
+ console.log('接收到【设备状态-详情】内容:', message);
+ // 更新列表中设备的状态
+ if (this.form.serialNumber == deviceNum) {
this.oldDeviceStatus = message.status;
this.form.status = message.status;
- this.form.isShadow = message.isShadow;
- this.form.rssid = message.rssid;
- }
- }
- });
- },
+ this.form.isShadow = message.isShadow;
+ this.form.rssid = message.rssid;
+ }
+ }
+ });
+ },
/** Mqtt订阅主题 */
- mqttSubscribe(device) {
- // 订阅当前设备状态和实时监测
- let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post';
- let topicProperty = '/' + device.productId + '/' + device.serialNumber + '/property/post';
- let topicFunction = '/' + device.productId + '/' + device.serialNumber + '/function/post';
- let topics = [];
- topics.push(topicStatus);
- topics.push(topicProperty);
- topics.push(topicFunction);
- this.$mqttTool.subscribe(topics);
- },
- /** Mqtt取消订阅主题 */
- mqttUnSubscribe(device) {
- // 订阅当前设备状态和实时监测
- let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post';
- let topicProperty = '/' + device.productId + '/' + device.serialNumber + '/property/post';
- let topicFunction = '/' + device.productId + '/' + device.serialNumber + '/function/post';
- let topics = [];
- topics.push(topicStatus);
- topics.push(topicProperty);
- topics.push(topicFunction);
- console.log('取消订阅', topics);
- this.$mqttTool.unsubscribe(topics);
- },
+ mqttSubscribe(device) {
+ // 订阅当前设备状态和实时监测
+ let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post';
+ let topicProperty = '/' + device.productId + '/' + device.serialNumber + '/property/post';
+ let topicFunction = '/' + device.productId + '/' + device.serialNumber + '/function/post';
+ let topics = [];
+ topics.push(topicStatus);
+ topics.push(topicProperty);
+ topics.push(topicFunction);
+ this.$mqttTool.subscribe(topics);
+ },
+ /** Mqtt取消订阅主题 */
+ mqttUnSubscribe(device) {
+ // 订阅当前设备状态和实时监测
+ let topicStatus = '/' + device.productId + '/' + device.serialNumber + '/status/post';
+ let topicProperty = '/' + device.productId + '/' + device.serialNumber + '/property/post';
+ let topicFunction = '/' + device.productId + '/' + device.serialNumber + '/function/post';
+ let topics = [];
+ topics.push(topicStatus);
+ topics.push(topicProperty);
+ topics.push(topicFunction);
+ console.log('取消订阅', topics);
+ this.$mqttTool.unsubscribe(topics);
+ },
// 获取子组件订阅的设备状态
getDeviceStatus(status) {
@@ -374,7 +379,7 @@ export default {
this.oldDeviceStatus = this.form.status;
this.loadMap();
//Mqtt订阅
- this.mqttSubscribe(this.form);
+ this.mqttSubscribe(this.form);
});
},
/**加载地图*/
@@ -429,6 +434,20 @@ export default {
},
/** 提交按钮 */
submitForm() {
+ if (this.form.serialNumber == null || this.form.serialNumber == 0) {
+ this.$modal.alertError("设备编号不能为空");
+ return;
+ }
+ let reg = /^[0-9a-zA-Z]+$/;
+ if (!reg.test(this.form.serialNumber)) {
+ this.$modal.alertError("设备编号只能是字母和数字");
+ return;
+ }
+ if (this.form.productId == null || this.form.productId == 0) {
+ this.$modal.alertError("所属产品不能为空");
+ return;
+ }
+
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.deviceId != 0) {
@@ -476,13 +495,13 @@ export default {
},
/**关闭物模型 */
openSummaryDialog() {
- let json={
- type:1,// 1=扫码关联设备
- deviceNumber:this.form.serialNumber,
- productId:this.form.productId,
- productName:this.form.productName,
+ let json = {
+ type: 1, // 1=扫码关联设备
+ deviceNumber: this.form.serialNumber,
+ productId: this.form.productId,
+ productName: this.form.productName,
};
- this.qrText=JSON.stringify(json);
+ this.qrText = JSON.stringify(json);
this.openSummary = true;
},
/**关闭物模型 */