20260314:网关设备支持统一管理子设备轮询任务(即网关设备自己建轮询任务下发不再绑定到各个子设备)
This commit is contained in:
parent
afdadf84b9
commit
ec4f8be1ad
@ -81,6 +81,6 @@
|
||||
</table>
|
||||
|
||||
|
||||
## 若依前后端分离交流群
|
||||
## 业务记录
|
||||
|
||||
QQ群: [](https://jq.qq.com/?_wv=1027&k=5bVB1og) [](https://jq.qq.com/?_wv=1027&k=5eiA4DH) [](https://jq.qq.com/?_wv=1027&k=5AxMKlC) [](https://jq.qq.com/?_wv=1027&k=51G72yr) [](https://jq.qq.com/?_wv=1027&k=VvjN2nvu) [](https://jq.qq.com/?_wv=1027&k=5vYAqA05) [](https://jq.qq.com/?_wv=1027&k=kOIINEb5) [](https://jq.qq.com/?_wv=1027&k=UKtX5jhs) 点击按钮入群。
|
||||
1、建立每个设备的轮询iot_modbus_job任务之前会查看是否存在设备任务iot_device_job;
|
||||
@ -113,8 +113,8 @@ public class DevicePropFetchConsumer {
|
||||
log.info("=>TCP-线程=[{}],轮询指令:[{}]", Thread.currentThread().getName(), command);
|
||||
break;
|
||||
}
|
||||
//指令间隔时间
|
||||
Thread.sleep(1000);
|
||||
// 指令间隔时间
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -10,6 +10,7 @@ import com.fastbee.iot.service.IDeviceJobService;
|
||||
import com.fastbee.quartz.domain.SysJob;
|
||||
import com.fastbee.quartz.mapper.SysJobMapper;
|
||||
import com.fastbee.quartz.util.CronUtils;
|
||||
import com.fastbee.quartz.util.ScheduleUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobKey;
|
||||
@ -58,7 +59,7 @@ public class DeviceJobServiceImpl implements IDeviceJobService {
|
||||
// 系统定时任务
|
||||
List<SysJob> sysJobList = sysJobMapper.selectJobAll();
|
||||
for (SysJob job : sysJobList) {
|
||||
com.fastbee.quartz.util.ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
ScheduleUtils.createScheduleJob(scheduler, job);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -199,6 +199,10 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
device.setSlaveId(modbusParams.getSlaveId());
|
||||
}
|
||||
device.setCanConfigPoll(0 == modbusParams.getPollType());
|
||||
} else {
|
||||
if (device.getDeviceType() == DeviceType.GATEWAY.getCode()) {
|
||||
device.setCanConfigPoll(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return device;
|
||||
|
||||
@ -106,7 +106,8 @@ public class ModbusJobServiceImpl implements IModbusJobService {
|
||||
// 查询关联的网关设备
|
||||
DeviceAndProtocol deviceAndProtocol = deviceService.selectProtocolBySerialNumber(modbusJob.getSubSerialNumber());
|
||||
// 如果是网关子设备
|
||||
if (deviceAndProtocol.getDeviceType() == DeviceType.SUB_GATEWAY.getCode()) {
|
||||
if (deviceAndProtocol.getDeviceType() == DeviceType.SUB_GATEWAY.getCode() ||
|
||||
deviceAndProtocol.getDeviceType() == DeviceType.GATEWAY.getCode()) {
|
||||
// 如果有绑定网关
|
||||
if (!Objects.isNull(deviceAndProtocol.getGwDeviceId())) {
|
||||
DeviceJob deviceJob = new DeviceJob();
|
||||
@ -141,51 +142,23 @@ public class ModbusJobServiceImpl implements IModbusJobService {
|
||||
DeviceJob job = list.get(0);
|
||||
modbusJob.setJobId(job.getJobId());
|
||||
}
|
||||
} else if (deviceAndProtocol.getDeviceType() == DeviceType.GATEWAY.getCode()) {
|
||||
// 网关直接轮询,在网关自身上创建 DeviceJob
|
||||
DeviceJob deviceJob = new DeviceJob();
|
||||
deviceJob.setDeviceId(deviceAndProtocol.getDeviceId()); // 用网关自己的deviceId
|
||||
buildSaveDeviceJob(modbusJob, deviceAndProtocol, deviceJob);
|
||||
} else {
|
||||
throw new ServiceException("请先绑定网关");
|
||||
}
|
||||
modbusJob.setCreateTime(DateUtils.getNowDate());
|
||||
modbusJob.setDeviceType(deviceAndProtocol.getDeviceType());
|
||||
return modbusJobMapper.insertModbusJob(modbusJob);
|
||||
} else {
|
||||
// 直连设备
|
||||
DeviceJob deviceJob = new DeviceJob();
|
||||
deviceJob.setDeviceId(modbusJob.getSubDeviceId());
|
||||
deviceJob.setRemark(modbusJob.getRemark());
|
||||
deviceJob.setJobType(5);
|
||||
List<DeviceJob> list = deviceJobService.selectJobList(deviceJob);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
// 创建定时任务
|
||||
// 如果不存在定时任务则新建(设备创建定时任务之前会创建一个)
|
||||
deviceJob.setJobName("modbus poll");
|
||||
deviceJob.setJobGroup("MODBUS");
|
||||
deviceJob.setMisfirePolicy("2");
|
||||
deviceJob.setConcurrent("1");
|
||||
deviceJob.setIsAdvance(0);
|
||||
deviceJob.setStatus("0");
|
||||
deviceJob.setSerialNumber(deviceAndProtocol.getSerialNumber());
|
||||
deviceJob.setProductId(deviceAndProtocol.getProductId());
|
||||
deviceJob.setCreateTime(DateUtils.getNowDate());
|
||||
// 处理时间转换
|
||||
// 检查是否是设备上电触发(使用 cycleType 判断)
|
||||
if (isPowerOnTrigger(modbusJob.getCycleType())) {
|
||||
// 设备上电触发不需要 cron 表达式,设置为null
|
||||
// DeviceJobServiceImpl.insertJob 会检查并跳过创建定时任务
|
||||
deviceJob.setCronExpression(null);
|
||||
} else {
|
||||
SceneModelTagCycleVO sceneModelTagCycleVO = JobCronUtils.handleCronCycle(1, deviceJob.getRemark());
|
||||
deviceJob.setCronExpression(sceneModelTagCycleVO.getCron());
|
||||
}
|
||||
deviceJobService.insertJob(deviceJob);
|
||||
modbusJob.setJobId(deviceJob.getJobId());
|
||||
} else {
|
||||
DeviceJob job = list.get(0);
|
||||
modbusJob.setJobId(job.getJobId());
|
||||
buildSaveDeviceJob(modbusJob, deviceAndProtocol, deviceJob);
|
||||
}
|
||||
modbusJob.setCreateTime(DateUtils.getNowDate());
|
||||
modbusJob.setDeviceType(deviceAndProtocol.getDeviceType());
|
||||
return modbusJobMapper.insertModbusJob(modbusJob);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
@ -270,10 +243,55 @@ public class ModbusJobServiceImpl implements IModbusJobService {
|
||||
// 网关设备需要查询所有子设备的modbus任务
|
||||
List<SubDeviceBo> subDeviceList = subGatewayService.getSubDeviceListByGw(serialNumber);
|
||||
List<String> serialNumberList = subDeviceList.stream().map(SubDeviceBo::getSubDeviceNo).collect(Collectors.toList());
|
||||
// 把网关自身SN也加入查询
|
||||
serialNumberList.add(serialNumber);
|
||||
modbusJob.setSubDeviceList(serialNumberList);
|
||||
return this.selectModbusJobList(modbusJob);
|
||||
default:
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装并保存设备任务
|
||||
* @param modbusJob 待新增的modbus任务
|
||||
* @param deviceAndProtocol 设备协议
|
||||
* @param deviceJob 设备任务
|
||||
*/
|
||||
private void buildSaveDeviceJob(ModbusJob modbusJob, DeviceAndProtocol deviceAndProtocol, DeviceJob deviceJob) {
|
||||
deviceJob.setRemark(modbusJob.getRemark());
|
||||
deviceJob.setJobType(5);
|
||||
List<DeviceJob> list = deviceJobService.selectJobList(deviceJob);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
// 如果不存在定时任务则新建
|
||||
deviceJob.setJobName("modbus poll");
|
||||
deviceJob.setJobGroup("MODBUS");
|
||||
deviceJob.setMisfirePolicy("2");
|
||||
deviceJob.setConcurrent("1");
|
||||
deviceJob.setIsAdvance(0);
|
||||
deviceJob.setStatus("0");
|
||||
deviceJob.setSerialNumber(deviceAndProtocol.getSerialNumber()); // 网关自己的SN
|
||||
deviceJob.setProductId(deviceAndProtocol.getProductId());
|
||||
deviceJob.setCreateTime(DateUtils.getNowDate());
|
||||
// 检查是否是设备上电触发(使用 cycleType 判断)
|
||||
if (isPowerOnTrigger(modbusJob.getCycleType())) {
|
||||
// 设备上电触发不需要 cron 表达式,设置为null
|
||||
// DeviceJobServiceImpl.insertJob 会检查并跳过创建定时任务
|
||||
deviceJob.setCronExpression(null);
|
||||
} else {
|
||||
// 处理时间转换
|
||||
SceneModelTagCycleVO sceneModelTagCycleVO = JobCronUtils.handleCronCycle(1, deviceJob.getRemark());
|
||||
deviceJob.setCronExpression(sceneModelTagCycleVO.getCron());
|
||||
}
|
||||
try {
|
||||
deviceJobService.insertJob(deviceJob);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
modbusJob.setJobId(deviceJob.getJobId());
|
||||
} else {
|
||||
DeviceJob job = list.get(0);
|
||||
modbusJob.setJobId(job.getJobId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,17 +175,6 @@
|
||||
<device-sub ref="deviceSub" :device="form"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- 子设备轮询任务管理(仅网关设备 + Modbus协议显示) -->
|
||||
<el-tab-pane
|
||||
name="gwSubModbusTask"
|
||||
:disabled="form.deviceId == 0"
|
||||
v-if="form.deviceType == 2 && (form.protocolCode == 'MODBUS-RTU' || form.protocolCode == 'MODBUS-TCP')"
|
||||
lazy
|
||||
>
|
||||
<span slot="label">{{$t('device.device-edit.subDevicePollingManage')}}</span>
|
||||
<gw-sub-modbus-task ref="gwSubModbusTask" :device="form"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane name="sipChannel" :disabled="form.deviceId == 0" v-if="form.deviceType === 3" lazy>
|
||||
<span slot="label">{{ $t('device.device-edit.148398-44') }}</span>
|
||||
<channel ref="Channel" :device="form" @playerEvent="getPlayerData($event)"/>
|
||||
@ -386,7 +375,6 @@ import deviceInlineVideo from './device-inline-video';
|
||||
import deviceFuncLog from './device-functionlog';
|
||||
import deviceSub from './device-sub';
|
||||
import deviceThingsModel from './device-things-model.vue';
|
||||
import gwSubModbusTask from './gw-sub-modbus-task';
|
||||
import vueQr from 'vue-qr';
|
||||
import {loadMap} from '@/utils/map.js';
|
||||
import {
|
||||
@ -436,7 +424,6 @@ export default {
|
||||
deviceModbusTask,
|
||||
deviceInlineVideo,
|
||||
deviceThingsModel,
|
||||
gwSubModbusTask,
|
||||
},
|
||||
watch: {
|
||||
activeName(val) {
|
||||
|
||||
@ -1,5 +1,45 @@
|
||||
<template>
|
||||
<div class="instruction-parsing">
|
||||
<el-row :gutter="12" class="modbus-task-row">
|
||||
<!-- 左侧子设备面板(网关模式,仅展示) -->
|
||||
<el-col v-if="isGatewayMode" :span="5">
|
||||
<div class="sub-device-side-panel" v-loading="subListLoading">
|
||||
<div class="side-panel-title">
|
||||
<i class="el-icon-connection"></i>
|
||||
<span>{{$t('device.sub-device-create.deviceListTitle')}}</span>
|
||||
<el-tag size="mini" type="info" style="margin-left: 6px">{{ subDeviceList.length }}</el-tag>
|
||||
</div>
|
||||
<div class="side-panel-list">
|
||||
<div
|
||||
v-for="item in subDeviceList"
|
||||
:key="item.subDeviceId"
|
||||
class="side-panel-item"
|
||||
>
|
||||
<div class="side-panel-item__name">
|
||||
<i class="el-icon-cpu"></i>
|
||||
{{ item.subDeviceName || item.subDeviceNo }}
|
||||
</div>
|
||||
<div class="side-panel-item__meta" style="color: blue;">
|
||||
<span>{{$t('device.sub-device-create.slaveIdLabel')}}: {{ item.slaveId || '-' }}</span>
|
||||
<el-badge
|
||||
:type="item.status === 3 ? 'success' : 'info'"
|
||||
is-dot
|
||||
style="margin-left: 6px"
|
||||
/>
|
||||
</div>
|
||||
<div class="side-panel-item__sn" style="color: red;">{{ item.subDeviceNo }}</div>
|
||||
</div>
|
||||
<el-empty
|
||||
v-if="!subListLoading && subDeviceList.length === 0"
|
||||
description="暂无子设备"
|
||||
:image-size="60"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
|
||||
<!-- 右侧任务内容 -->
|
||||
<el-col :span="isGatewayMode ? 19 : 24">
|
||||
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="70px">
|
||||
<el-form-item :label="$t('device.device-modbus-task.384302-0')" prop="jobName">
|
||||
<el-input v-model="queryParams.jobName" :placeholder="$t('device.device-modbus-task.384302-1')" clearable size="small" @keyup.enter.native="handleQuery" />
|
||||
@ -53,6 +93,9 @@
|
||||
|
||||
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
|
||||
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-dialog :title="editName ? $t('device.device-modbus-task.384302-12') : $t('device.device-modbus-task.384302-13')" :visible.sync="editDialog" :width="editName ? '30%' : '40%'" v-dialogDrag>
|
||||
<div class="dialog-content beautify-scroll-def">
|
||||
<el-form :model="createForm" label-position="top">
|
||||
@ -318,6 +361,7 @@ import { hex2int, int2hex, copyText } from '@/utils/common';
|
||||
import { parseTime } from '@/utils/ruoyi';
|
||||
import { encode } from '@/api/iot/mqttTest';
|
||||
import { listJob, getJob, delJob, addJob, updateJob, getSlaveId } from '@/api/iot/modbusJob';
|
||||
import { listGateway } from '@/api/iot/gateway';
|
||||
|
||||
export default {
|
||||
name: 'device-modbus-task',
|
||||
@ -327,15 +371,27 @@ export default {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
// 是否启用左侧子设备面板(网关模式下有效),嵌套使用时传 false 避免重复
|
||||
showSubPanel: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
device: {
|
||||
deep: true,
|
||||
handler(newVal, oldVal) {
|
||||
if (newVal.deviceId && newVal.deviceId !== oldVal.deviceId) {
|
||||
this.queryParams.subDeviceId = newVal.deviceId;
|
||||
this.deviceInfo = newVal;
|
||||
if (this.isGatewayMode) {
|
||||
this.subDeviceList = [];
|
||||
this.queryParams.subDeviceId = newVal.deviceId;
|
||||
this.loadSubDeviceList();
|
||||
this.getList();
|
||||
} else {
|
||||
this.queryParams.subDeviceId = newVal.deviceId;
|
||||
this.getList();
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
@ -359,6 +415,10 @@ export default {
|
||||
return this.$t('device.device-modbus-task.384302-32');
|
||||
}
|
||||
},
|
||||
/** 是否为网关模式(显示左侧子设备面板) */
|
||||
isGatewayMode() {
|
||||
return this.showSubPanel && this.device && this.device.deviceType === 2;
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -439,6 +499,9 @@ export default {
|
||||
//父组件传过来的对象
|
||||
deviceInfo: {},
|
||||
subdeviceId: '',
|
||||
// 网关模式:子设备列表(仅展示)
|
||||
subDeviceList: [],
|
||||
subListLoading: false,
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
@ -559,13 +622,11 @@ export default {
|
||||
|
||||
// 如果是设备上电触发,不需要 cron 表达式
|
||||
if (this.createForm.cycleType === 3) {
|
||||
// 设备上电触发,remark 不再存储特殊标识,cycleType=3 即可标识
|
||||
this.createForm.subDeviceId = this.device.deviceId;
|
||||
this.createForm.subSerialNumber = this.device.serialNumber;
|
||||
this.createForm.command = this.createCode;
|
||||
this.createForm.remark = ''; // remark 留空或可填写真正的备注
|
||||
this.createForm.remark = '';
|
||||
this.createForm.cronExpression = '';
|
||||
// 确保 cycleType 被传递
|
||||
this.submitForm();
|
||||
this.editDialog = false;
|
||||
return;
|
||||
@ -597,7 +658,13 @@ export default {
|
||||
/**打开编辑框 */
|
||||
openEdit() {
|
||||
this.resetCreateForm();
|
||||
// 网关设备(deviceType=2)直接轮询:跳过从机地址校验,由用户手动填写
|
||||
if (this.device && this.device.deviceType === 2) {
|
||||
this.createForm.path = '';
|
||||
this.editDialog = true;
|
||||
} else {
|
||||
this.getSlaveId();
|
||||
}
|
||||
this.editName = false;
|
||||
},
|
||||
// 表单重置
|
||||
@ -760,11 +827,22 @@ export default {
|
||||
this.resetForm('queryForm');
|
||||
this.handleQuery();
|
||||
},
|
||||
/** 加载子设备列表(仅展示,网关模式) */
|
||||
loadSubDeviceList() {
|
||||
if (!this.isGatewayMode) return;
|
||||
this.subListLoading = true;
|
||||
listGateway({ gwDeviceId: this.device.deviceId, pageSize: 999 })
|
||||
.then((res) => {
|
||||
this.subDeviceList = res.rows || [];
|
||||
})
|
||||
.finally(() => {
|
||||
this.subListLoading = false;
|
||||
});
|
||||
},
|
||||
getSlaveId() {
|
||||
if (this.device.deviceType === 4) {
|
||||
this.subdeviceId = this.device.deviceId;
|
||||
}
|
||||
getSlaveId(this.device.productId, this.subdeviceId).then((response) => {
|
||||
const productId = this.device.productId;
|
||||
const subDeviceId = this.subdeviceId;
|
||||
getSlaveId(productId, subDeviceId).then((response) => {
|
||||
if (!response.data) {
|
||||
this.$confirm(this.$t('device.device-modbus-task.384302-66'), this.$t('device.device-modbus-task.384302-67'), {
|
||||
confirmButtonText: this.$t('device.device-modbus-task.384302-68'),
|
||||
@ -910,9 +988,16 @@ export default {
|
||||
mounted() {
|
||||
const { deviceId } = this.device;
|
||||
if (deviceId) {
|
||||
if (this.isGatewayMode) {
|
||||
// 网关模式:加载子设备列表(仅展示),任务列表始终查网关自身
|
||||
this.queryParams.subDeviceId = deviceId;
|
||||
this.loadSubDeviceList();
|
||||
this.getList();
|
||||
} else {
|
||||
this.queryParams.subDeviceId = deviceId;
|
||||
this.getList();
|
||||
}
|
||||
}
|
||||
this.resetCreateForm();
|
||||
},
|
||||
};
|
||||
@ -922,6 +1007,97 @@ export default {
|
||||
$border-color: #dcdfe6;
|
||||
$right-btn-color: #1890ff;
|
||||
|
||||
.modbus-task-row {
|
||||
min-height: 400px;
|
||||
}
|
||||
|
||||
.sub-device-side-panel {
|
||||
border: 1px solid $border-color;
|
||||
border-radius: 4px;
|
||||
min-height: 400px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
.side-panel-title {
|
||||
padding: 10px 14px;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
background: #f5f7fa;
|
||||
border-bottom: 1px solid $border-color;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
i {
|
||||
margin-right: 6px;
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.side-panel-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
.side-panel-item {
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
border-left: 3px solid transparent;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
background: #ecf5ff;
|
||||
border-left-color: #409eff;
|
||||
|
||||
.side-panel-item__name {
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
&__name {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
i {
|
||||
margin-right: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
&__meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-top: 3px;
|
||||
font-size: 11px;
|
||||
color: #909399;
|
||||
|
||||
.self-tag {
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
&__sn {
|
||||
font-size: 11px;
|
||||
color: #c0c4cc;
|
||||
margin-top: 2px;
|
||||
font-family: monospace;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .el-dialog__body {
|
||||
border-top: 1px solid $border-color;
|
||||
border-bottom: 1px solid $border-color;
|
||||
|
||||
@ -1,260 +0,0 @@
|
||||
<template>
|
||||
<div class="gw-sub-modbus-task">
|
||||
<el-row :gutter="12" style="height: 100%">
|
||||
<!-- 左侧:子设备列表 -->
|
||||
<el-col :span="6">
|
||||
<div class="sub-device-panel">
|
||||
<div class="panel-title">
|
||||
<i class="el-icon-connection"></i>
|
||||
<span>子设备列表</span>
|
||||
<el-tag size="mini" type="info" style="margin-left: 8px">{{ subDeviceList.length }}</el-tag>
|
||||
</div>
|
||||
<div v-loading="listLoading" class="sub-device-list">
|
||||
<div
|
||||
v-for="item in subDeviceList"
|
||||
:key="item.subDeviceId"
|
||||
class="sub-device-item"
|
||||
:class="{ active: selectedSubDevice && selectedSubDevice.deviceId === item.subDeviceId }"
|
||||
@click="handleSelectSubDevice(item)"
|
||||
>
|
||||
<div class="sub-device-name">
|
||||
<i class="el-icon-cpu"></i>
|
||||
{{ item.subDeviceName || item.subDeviceNo }}
|
||||
</div>
|
||||
<div class="sub-device-meta">
|
||||
<span class="meta-item">
|
||||
<i class="el-icon-document"></i>
|
||||
从机地址:{{ item.slaveId || '-' }}
|
||||
</span>
|
||||
<span class="meta-item">
|
||||
<el-badge
|
||||
:type="item.status === 3 ? 'success' : 'info'"
|
||||
is-dot
|
||||
style="margin-right: 4px"
|
||||
/>
|
||||
{{ item.status === 3 ? '在线' : '离线' }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="sub-device-sn">{{ item.subDeviceNo }}</div>
|
||||
</div>
|
||||
<el-empty
|
||||
v-if="!listLoading && subDeviceList.length === 0"
|
||||
description="暂无子设备"
|
||||
:image-size="80"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</el-col>
|
||||
|
||||
<!-- 右侧:轮询任务 -->
|
||||
<el-col :span="18">
|
||||
<div class="task-panel">
|
||||
<div v-if="selectedSubDevice" class="task-panel-header">
|
||||
<span class="selected-device-info">
|
||||
<i class="el-icon-right" style="color: #409eff"></i>
|
||||
当前设备:<strong>{{ selectedSubDevice.deviceName }}</strong>
|
||||
<el-tag size="mini" style="margin-left: 8px">SN: {{ selectedSubDevice.serialNumber }}</el-tag>
|
||||
<el-tag size="mini" type="warning" style="margin-left: 4px">从机地址: {{ selectedSubDevice.slaveId }}</el-tag>
|
||||
</span>
|
||||
</div>
|
||||
<device-modbus-task
|
||||
v-if="selectedSubDevice"
|
||||
ref="modbusTask"
|
||||
:device="selectedSubDevice"
|
||||
/>
|
||||
<el-empty
|
||||
v-else
|
||||
description="请从左侧选择子设备以管理其轮询任务"
|
||||
:image-size="120"
|
||||
style="margin-top: 80px"
|
||||
/>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listGateway } from '@/api/iot/gateway';
|
||||
import deviceModbusTask from './device-modbus-task';
|
||||
|
||||
export default {
|
||||
name: 'gw-sub-modbus-task',
|
||||
components: {
|
||||
deviceModbusTask,
|
||||
},
|
||||
props: {
|
||||
device: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
listLoading: false,
|
||||
subDeviceList: [],
|
||||
selectedSubDevice: null,
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
device: {
|
||||
handler(newVal) {
|
||||
if (newVal && newVal.deviceId && newVal.deviceId != 0) {
|
||||
this.selectedSubDevice = null;
|
||||
this.loadSubDeviceList();
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
if (this.device && this.device.deviceId && this.device.deviceId != 0) {
|
||||
this.loadSubDeviceList();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
loadSubDeviceList() {
|
||||
this.listLoading = true;
|
||||
listGateway({ gwDeviceId: this.device.deviceId, pageSize: 999 })
|
||||
.then((response) => {
|
||||
this.subDeviceList = response.rows || [];
|
||||
// 默认选中第一个有从机地址的子设备
|
||||
if (this.subDeviceList.length > 0 && !this.selectedSubDevice) {
|
||||
this.handleSelectSubDevice(this.subDeviceList[0]);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.listLoading = false;
|
||||
});
|
||||
},
|
||||
handleSelectSubDevice(item) {
|
||||
// 构造 device-modbus-task 组件所需的 device 对象
|
||||
this.selectedSubDevice = {
|
||||
deviceId: item.subDeviceId,
|
||||
deviceName: item.subDeviceName || item.subDeviceNo,
|
||||
serialNumber: item.subDeviceNo,
|
||||
productId: item.subProductId,
|
||||
protocolCode: this.device.protocolCode,
|
||||
deviceType: 4, // SUB_GATEWAY
|
||||
slaveId: item.slaveId,
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.gw-sub-modbus-task {
|
||||
padding: 8px 0;
|
||||
min-height: 500px;
|
||||
}
|
||||
|
||||
.sub-device-panel {
|
||||
border: 1px solid #e4e7ed;
|
||||
border-radius: 4px;
|
||||
height: 100%;
|
||||
min-height: 500px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
|
||||
.panel-title {
|
||||
padding: 12px 16px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: #303133;
|
||||
background: #f5f7fa;
|
||||
border-bottom: 1px solid #e4e7ed;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
i {
|
||||
margin-right: 6px;
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.sub-device-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
.sub-device-item {
|
||||
padding: 10px 16px;
|
||||
cursor: pointer;
|
||||
border-left: 3px solid transparent;
|
||||
transition: all 0.2s;
|
||||
|
||||
&:hover {
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: #ecf5ff;
|
||||
border-left-color: #409eff;
|
||||
|
||||
.sub-device-name {
|
||||
color: #409eff;
|
||||
}
|
||||
}
|
||||
|
||||
.sub-device-name {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
color: #303133;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
i {
|
||||
margin-right: 4px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.sub-device-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 4px;
|
||||
|
||||
.meta-item {
|
||||
font-size: 11px;
|
||||
color: #909399;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.sub-device-sn {
|
||||
font-size: 11px;
|
||||
color: #c0c4cc;
|
||||
margin-top: 2px;
|
||||
font-family: monospace;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.task-panel {
|
||||
.task-panel-header {
|
||||
padding: 8px 0 12px;
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
border-bottom: 1px dashed #e4e7ed;
|
||||
margin-bottom: 12px;
|
||||
|
||||
.selected-device-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
strong {
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Loading…
Reference in New Issue
Block a user