@@ -88,22 +68,11 @@
-
+
发送指令
-
+
重置选择
@@ -139,14 +108,14 @@ export default {
signalStrength: 2,
productModels: [],
pageList: [
- { name: '显示设置', icon: 'el-icon-data-line' },
- { name: '声卡设置', icon: 'el-icon-headset' },
- { name: '车牌识别', icon: 'el-icon-camera' },
- { name: '预警设置', icon: 'el-icon-warning' },
- { name: '远程喊话', icon: 'el-icon-microphone' },
- { name: '网关设置', icon: 'el-icon-connection' },
- { name: '路锥控制', icon: 'el-icon-place' },
- { name: '翻转屏', icon: 'el-icon-monitor' }
+ { name: '显示单元', icon: 'el-icon-data-line', code: 102 },
+ { name: '声卡设置', icon: 'el-icon-headset', code: 103 },
+ // { name: '车牌识别', icon: 'el-icon-camera' },
+ // { name: '预警设置', icon: 'el-icon-warning' },
+ // { name: '远程喊话', icon: 'el-icon-microphone' },
+ { name: '网关设置', icon: 'el-icon-connection', code: 1 },
+ { name: '路锥控制', icon: 'el-icon-place', code: 104 },
+ { name: '激光单元', icon: 'el-icon-monitor', code: 105 }
],
loadingProducts: false,
deviceInfo: {
@@ -188,6 +157,15 @@ export default {
if (!this.selectedProduct) return '未选择';
const product = this.productModels.find(p => p.id === this.selectedProduct);
return product ? `${product.name} (${product.id})` : this.selectedProduct;
+ },
+ productArray() {
+ const arr = [Number(this.selectedProduct)];
+ this.selectedPages.forEach((selected, idx) => {
+ if (selected && this.pageList[idx] && this.pageList[idx].code) {
+ arr.push(this.pageList[idx].code);
+ }
+ });
+ return arr;
}
},
watch: {
@@ -205,7 +183,7 @@ export default {
isShadow: newVal.isShadow,
protocolCode: newVal.protocolCode
};
-
+
// 初始化distribute模型的shadow值
const distributeModel = this.deviceInfo.thingsModels.find(
model => model.id === 'distribute'
@@ -225,7 +203,7 @@ export default {
methods: {
async loadProductList() {
if (this.productModels.length > 0 || this.loadingProducts) return;
-
+
this.loadingProducts = true;
try {
const params = {
@@ -243,13 +221,13 @@ export default {
this.loadingProducts = false;
}
},
-
+
togglePage(index) {
this.$set(this.selectedPages, index, this.selectedPages[index] ? 0 : 1);
// 更新distribute模型的shadow值
this.updateDistributeModel();
},
-
+
updateDistributeModel() {
const distributeModel = this.deviceInfo.thingsModels.find(
model => model.id === 'distribute'
@@ -258,7 +236,8 @@ export default {
distributeModel.shadow = this.fullCommand;
}
},
-
+
+
async sendControlCommand() {
if (!this.selectedProduct) {
this.$message.warning('请选择产品');
@@ -268,80 +247,97 @@ export default {
this.$message.warning('设备信息未初始化');
return;
}
-
+
this.sending = true;
-
+ const payload = { product: this.productArray };
try {
- const distributeModel = this.deviceInfo.thingsModels.find(
- model => model.id === 'productpram'
- );
-
- if (!distributeModel) {
- throw new Error('未找到分发控制模型');
- }
+ // 发送102#model指令,值为1
+ const model = this.deviceInfo.thingsModels.find(m => m.id === '1#productpram');
+ if (model) {
+ model.shadow = 'JSON=' + JSON.stringify(payload);
+ await this.mqttPublish(this.deviceInfo, model);
+ this.$message.success('已发送刷新指令,编译信息将自动更新');
+ this.sending = false;
- // 确保shadow值是最新的
- distributeModel.shadow = this.fullCommand;
-
- await this.mqttPublish(this.deviceInfo, distributeModel);
-
- this.$message.success('控制指令发送成功');
- } catch (error) {
- console.error('发送控制指令失败:', error);
- this.$message.error(`控制指令发送失败: ${error.message}`);
- } finally {
- this.sending = false;
- }
- },
-
- async mqttPublish(device, model) {
- try {
- if (!device || !device.deviceId) {
- throw new Error('无效的设备信息');
- }
- if (!model || !model.id) {
- throw new Error('无效的模型信息');
- }
-
- const command = {};
- command[model.id] = model.shadow;
-
- const params = {
- deviceId: device.deviceId,
- modelId: model.modelId,
- };
-
- const response = await getOrderControl(params);
- if (response.code != 200) {
- throw new Error(response.msg || '获取控制指令失败');
- }
-
- const data = {
- serialNumber: device.serialNumber,
- productId: device.productId,
- remoteCommand: command,
- identifier: model.id,
- modelName: model.name,
- isShadow: device.status != 3,
- type: model.type,
- };
-
- if (device.status !== 3 && device.isShadow !== 1) {
- throw new Error('设备不在线且未启用影子模式');
- }
-
- if ((device.protocolCode === 'MODBUS-TCP' || device.protocolCode === 'MODBUS-RTU') && device.status === 3) {
- await serviceInvokeReply(data);
} else {
- await serviceInvoke(data);
+ this.$message.warning('未找到102#model物模型');
+ this.sending = false;
+
}
-
} catch (error) {
- console.error('MQTT发布失败:', error);
- throw error;
+ console.error('发送刷新指令失败:', error);
+ this.sending = false;
+
+ this.$message.error('发送刷新指令失败');
}
},
-
+
+ //发送指令
+ async mqttPublish(device, model) {
+ const command = {};
+ command[model.id] = model.shadow;
+ const params = {
+ deviceId: device.deviceId,
+ modelId: model.modelId,
+ };
+ const response = await getOrderControl(params);
+ if (response.code != 200) {
+ this.$message({
+ type: 'warning',
+ message: response.msg,
+ });
+ return;
+ }
+ const data = {
+ serialNumber: device.serialNumber,
+ productId: device.productId,
+ remoteCommand: command,
+ identifier: model.id,
+ modelName: model.name,
+ isShadow: device.status != 3,
+ type: model.type,
+ };
+ //设备在线状态判断
+ if (this.device.status !== 3 && this.device.isShadow !== 1) {
+ let title = '';
+ if (this.device.status === 1) {
+ title = this.$t('device.device-variable.930930-0');
+ } else if (this.device.status === 2) {
+ title = this.$t('device.device-variable.930930-1');
+ } else {
+ title = this.$t('device.device-variable.930930-2');
+ }
+ this.$message({
+ type: 'warning',
+ message: title,
+ });
+ return;
+ }
+ if ((this.deviceInfo.protocolCode === 'MODBUS-TCP' || this.deviceInfo.protocolCode === 'MODBUS-RTU') && this.device.status === 3) {
+ await serviceInvokeReply(data).then((response) => {
+ if (response.code === 200) {
+ this.$message({
+ type: 'success',
+ message: this.$t('device.running-status.866086-25'),
+ });
+ } else {
+ this.$message.error(response.msg);
+ }
+ });
+ } else {
+ await serviceInvoke(data).then((response) => {
+ if (response.code === 200) {
+ this.$message({
+ type: 'success',
+ message: this.$t('device.running-status.866086-25'),
+ });
+ } else {
+ this.$message.error(response.msg);
+ }
+ });
+ }
+ },
+
resetSettings() {
this.selectedPages = [0, 0, 0, 0, 0, 0, 0, 0];
this.updateDistributeModel();