diff --git a/dist.zip b/dist.zip index 27e56cd..3175394 100644 Binary files a/dist.zip and b/dist.zip differ diff --git a/src/views/iot/device/device-edit.vue b/src/views/iot/device/device-edit.vue index e071bb5..9a203a0 100644 --- a/src/views/iot/device/device-edit.vue +++ b/src/views/iot/device/device-edit.vue @@ -23,100 +23,136 @@ - + {{ $t('device.device-edit.148398-0') }} - - {{ $t('device.device-edit.148398-3') }} + + {{ + $t('device.device-edit.148398-3') }} - - {{ $t('device.device-edit.148398-6') }} + + {{ $t('device.device-edit.148398-6') + }} - - + + {{ $t('device.device-edit.148398-9') }} - + {{ $t('device.device-edit.148398-9') }} - + - + - + - + {{ $t('device.device-edit.148398-85') }} {{ $t('device.device-edit.148398-86') }} - + - + - - + + - - + + {{ $t('device.device-edit.148398-23') }} - - + + {{ $t('device.device-edit.148398-23') }} - + - + - + - - + + - - + + {{ $t('device.device-edit.148398-35') }} - {{ $t('device.device-edit.148398-36') }} + {{ + $t('device.device-edit.148398-36') }} -
-
{{ $t('device.device-edit.148398-37') }}
+
+
{{ + $t('device.device-edit.148398-37') }}
@@ -124,24 +160,45 @@ - + {{ $t('update') }} - + {{ $t('add') }} - + {{ $t('device.device-edit.148398-42') }} - - + + + + + + + + + + + + + + {{ $t('device.device-edit.148398-74') }} @@ -150,23 +207,22 @@ {{ $t('device.device-edit.148398-76') }} - + lazy> {{ $t('device.device-edit.148398-43') }} - + {{ $t('device.device-edit.148398-77') }} - + {{ $t('device.device-edit.148398-73') }} @@ -221,7 +277,8 @@ - + {{ $t('device.device-edit.148398-80') }} @@ -251,11 +308,13 @@ - +
- +
@@ -272,14 +331,17 @@
-
+
{{ $t('device.device-edit.148398-56') }}
- - + + @@ -299,7 +361,8 @@ - + @@ -308,7 +371,8 @@ - + @@ -320,7 +384,8 @@ - + @@ -339,7 +404,8 @@ @@ -382,7 +448,8 @@ import DeviceFunc from '@/views/iot/device/device-functionlog'; import RealTimeStatus from '@/views/iot/device/realTime-status'; import { clientOut } from '@/api/iot/netty'; import defaultSettings from '@/settings'; - +import gatewayRunningStatus from './gatewayrunning-status.vue'; +import relay from './relay.vue' export default { name: 'DeviceEdit', dicts: ['iot_device_status', 'iot_location_way'], @@ -414,6 +481,8 @@ export default { instructionParsing, deviceModbusTask, deviceInlineVideo, + gatewayRunningStatus, + relay }, watch: { activeName(val) { @@ -1012,7 +1081,7 @@ export default { //是否设备设置为禁用状态,则踢出设备 if (this.form.status === 2) { const params = { clientId: this.form.serialNumber }; - clientOut(params).then((res) => {}); + clientOut(params).then((res) => { }); } } }); @@ -1090,7 +1159,7 @@ export default { this.form.serialNumber = devsipid; }, // 获取选中的用户 - getUserData(user) {}, + getUserData(user) { }, /**关闭物模型 */ openSummaryDialog() { let json = { diff --git a/src/views/iot/device/gatewayrunning-status.vue b/src/views/iot/device/gatewayrunning-status.vue new file mode 100644 index 0000000..28be35b --- /dev/null +++ b/src/views/iot/device/gatewayrunning-status.vue @@ -0,0 +1,1176 @@ + + + + + diff --git a/src/views/iot/device/running-status.vue b/src/views/iot/device/running-status.vue index d4d65af..1bb8fc9 100644 --- a/src/views/iot/device/running-status.vue +++ b/src/views/iot/device/running-status.vue @@ -1,436 +1,420 @@ {{ firmware.firmwareName - }} + }} {{ firmware.productName - }} + }} Version {{ firmware.version - }} + }} {{ getDownloadUrl(firmware.filePath) }} {{ firmware.remark - }} + }} - - - - - - - - - -
-
- {{ getRelayName(index + 1) }}: - - - - 吸合 - - - - 断开 - - -
-
-
- - - - - - - - - - - -
- -
@@ -617,12 +512,9 @@ export default { if (newVal && newVal.deviceId != 0) { this.deviceInfo = newVal; this.updateDeviceStatus(this.deviceInfo); - // console.log("设备信息", JSON.stringify(this.deviceInfo.productName)); - this.initTimeScheduleList(); this.$nextTick(function () { this.MonitorChart(); }); - // console.log("物模型", JSON.stringify(this.deviceInfo.thingsModels)); //物模型排序 if (this.deviceInfo.thingsModels && this.deviceInfo.thingsModels.length > 0) { this.deviceInfo.thingsModels = this.device.thingsModels.sort((a, b) => b.order - a.order); @@ -630,7 +522,6 @@ export default { if (this.deviceInfo.chartList && this.deviceInfo.chartList.length > 0) { this.deviceInfo.chartList = this.deviceInfo.chartList.sort((a, b) => b.order - a.order); } - // console.log("图表数据", JSON.stringify(this.deviceInfo.chartList)); // 添加message事件监听器 // this.mqttCallback(); } @@ -649,7 +540,7 @@ export default { statusColor: { background: '#67C23A', color: '#fff', - maxWidth: '200px', + minWidth: '100px', }, // 最新固件信息 firmware: {}, @@ -659,17 +550,6 @@ export default { loading: true, // 设备信息 deviceInfo: { - deviceId: 0, - serialNumber: '', - productId: '', - productName: '', - status: 0, - isShadow: 0, - rssi: 0, - firmwareVersion: '', - wirelessVersion: '', - firmwareType: 1, - protocolCode: '', boolList: [], enumList: [], stringList: [], @@ -716,51 +596,21 @@ export default { }, ], }, - relay1Status: false, - relay2Status: false, - relay3Status: false, - relay4Status: false, - timeScheduleList: [], // 时间方案列表 - dialogVisible: false, - dialogTitle: '添加时间方案', - scheduleForm: { - startTime: '', - actions: ['0', '0', '0', '0'], - repeat: [] - }, - currentEditIndex: -1, - scheduleRules: { - startTime: [ - { required: true, message: '请选择执行时间', trigger: 'change' } - ], - actions: [ - { required: true, message: '请选择执行动作', trigger: 'change' } - ], - repeat: [ - { required: true, message: '请选择重复周期', trigger: 'change' } - ] - }, - relayRemarks: { - 1: { value: '', isEditing: false }, - 2: { value: '', isEditing: false }, - 3: { value: '', isEditing: false }, - 4: { value: '', isEditing: false } - }, }; }, mounted() { - if (this.device && this.device.deviceId) { - this.handleDeviceChange(this.device); + this.handleDeviceChange(this.device); + const { deviceId, serialNumber } = this.device; + if (deviceId) { this.initDataStatus(); this.initData(); - this.initRelayRemarks(); } }, methods: { //监听设备状态(设备联动) handleDeviceChange(device) { - if (device && device.deviceId != 0) { + if (device && device.deviceId != 0 && this.device.thingsModels) { const { firmwareVersion, wirelessVersion, firmwareType, ...res } = device; const data = { version: firmwareType === 1 ? firmwareVersion : wirelessVersion, @@ -771,15 +621,10 @@ export default { this.updateDeviceStatus(this.deviceInfo); this.$nextTick(() => { this.MonitorChart(); - this.initTimeScheduleList(); }); //物模型排序 - if (this.deviceInfo.thingsModels && this.deviceInfo.thingsModels.length > 0) { - this.deviceInfo.thingsModels = this.deviceInfo.thingsModels.sort((a, b) => b.order - a.order); - } - if (this.deviceInfo.chartList && this.deviceInfo.chartList.length > 0) { - this.deviceInfo.chartList = this.deviceInfo.chartList.sort((a, b) => b.order - a.order); - } + this.deviceInfo.thingsModels = this.deviceInfo.thingsModels.sort((a, b) => b.order - a.order); + this.deviceInfo.chartList = this.deviceInfo.chartList.sort((a, b) => b.order - a.order); } }, initData() { @@ -811,7 +656,6 @@ export default { let isComplete = false; data = data.message; if (data) { - // console.log("cesces ces ", JSON.stringify(data)) for (let j = 0; j < data.length; j++) { for (let k = 0; k < this.deviceInfo.thingsModels.length && !isComplete; k++) { if (this.deviceInfo.thingsModels[k].id == data[j].id) { @@ -821,10 +665,7 @@ export default { variable.shadow = Number(data[j].value); } else { variable.shadow = data[j].value; - variable.value = data[j].value; } - this.getRelayName(k + 1); - // console.log("更新后的物模型数据", JSON.stringify(this.deviceInfo.thingsModels[k])) } if (this.deviceInfo.thingsModels[k].datatype.type == 'object') { // 对象类型 @@ -1229,524 +1070,49 @@ export default { option && this.monitorChart[i].chart.setOption(option); } }, - // 获取继电器状态 - getRelayStatus(id) { - const relay = this.deviceInfo.thingsModels.find(item => item.id === id); - return relay && relay.shadow === '1'; - }, - - // 切换继电器1状态 - toggleRelay1() { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - if (this.shadowUnEnable) return; - const relay = this.deviceInfo.thingsModels.find(item => item.id === 'sw_ch1'); - if (relay) { - relay.shadow = relay.shadow === '1' ? '0' : '1'; - this.mqttPublish(this.deviceInfo, relay); - } - }, - - // 切换继电器2状态 - toggleRelay2() { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - if (this.shadowUnEnable) return; - const relay = this.deviceInfo.thingsModels.find(item => item.id === 'sw_ch2'); - if (relay) { - relay.shadow = relay.shadow === '1' ? '0' : '1'; - this.mqttPublish(this.deviceInfo, relay); - } - }, - - // 切换继电器3状态 - toggleRelay3() { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - if (this.shadowUnEnable) return; - const relay = this.deviceInfo.thingsModels.find(item => item.id === 'sw_ch3'); - if (relay) { - relay.shadow = relay.shadow === '1' ? '0' : '1'; - this.mqttPublish(this.deviceInfo, relay); - } - }, - - // 切换继电器4状态 - toggleRelay4() { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - if (this.shadowUnEnable) return; - const relay = this.deviceInfo.thingsModels.find(item => item.id === 'sw_ch4'); - if (relay) { - relay.shadow = relay.shadow === '1' ? '0' : '1'; - this.mqttPublish(this.deviceInfo, relay); - - } - }, - - // 格式化时间 - formatTime(time) { - if (!time) return ''; - const date = new Date(time); - return `${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}`; - }, - - // 添加时间方案 - addTimeSchedule() { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - if (this.timeScheduleList.length >= 10) { - this.$message.warning('最多只能添加10个时间方案'); - return; - } - this.dialogTitle = '添加时间方案'; - this.scheduleForm = { - startTime: '', - actions: [0, 0, 0, 0], - repeat: [] - }; - this.currentEditIndex = -1; - this.dialogVisible = true; - }, - - // 编辑时间方案 - editTimeSchedule(index) { - this.dialogTitle = '编辑时间方案'; - this.scheduleForm = { ...this.timeScheduleList[index] }; - this.currentEditIndex = index; - this.dialogVisible = true; - }, - - // 删除时间方案 - deleteTimeSchedule(index) { - if (this.title === '离线模式') { - this.$message.warning('设备处于离线模式中'); - return; - } - this.$confirm('确认删除该时间方案?', '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - this.timeScheduleList.splice(index, 1); - - // 转换为物模型格式 - const shedule = this.timeScheduleList.map(item => { - // 转换时间为秒数 - const startSeconds = item.startTime.getHours() * 3600 + - item.startTime.getMinutes() * 60 + - item.startTime.getSeconds(); - - // 转换周几为字符串 - const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; - const repeat = item.repeat.map((day, index) => { - return day === '1' ? weekDays[index] : null; - }).filter(day => day); - - return { - time_s: startSeconds, - sw1_s: item.actions[0], - sw2_s: item.actions[1], - sw3_s: item.actions[2], - sw4_s: item.actions[3], - week: repeat.join(''), - }; - }); - - // 更新物模型 - const cfgParam = this.deviceInfo.thingsModels.find(item => item.id === 'cfg_param'); - if (cfgParam) { - cfgParam.shadow = 'JSON=' + JSON.stringify({ shedule }); - this.mqttPublish(this.deviceInfo, cfgParam); - } - - this.$message.success('删除成功'); - }).catch(() => { }); - }, - - // 初始化时间方案列表 - initTimeScheduleList() { - if (!this.deviceInfo || !this.deviceInfo.thingsModels) { - this.timeScheduleList = []; - return; - } - - const cfgParam = this.deviceInfo.thingsModels.find(item => item.id === 'cfg_param'); - if (cfgParam && cfgParam.shadow) { - try { - const cfg = JSON.parse(cfgParam.shadow.replace('JSON=', '')); - if (cfg.shedule && Array.isArray(cfg.shedule)) { - this.timeScheduleList = cfg.shedule.map(item => { - // 转换秒数为时间 - const startTime = new Date(); - startTime.setHours(Math.floor(item.time_s / 3600)); - startTime.setMinutes(Math.floor((item.time_s % 3600) / 60)); - startTime.setSeconds(item.time_s % 60); - - // 转换周几为数组 - const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; - const repeat = []; - if (item.week) { - item.week.split('').forEach((day, index) => { - if (day === '1') { - repeat.push(weekDays[index]); - } - }); - } - - return { - startTime, - actions: [ - item.sw1_s || 0, - item.sw2_s || 0, - item.sw3_s || 0, - item.sw4_s || 0 - ], - repeat - }; - }); - } else { - this.timeScheduleList = []; - } - } catch (e) { - console.error('解析定时配置失败:', e); - this.timeScheduleList = []; - } - } else { - this.timeScheduleList = []; - } - }, - - // 保存时间方案 - saveTimeSchedule() { - if (!this.deviceInfo || !this.deviceInfo.thingsModels) { - this.$message.error('设备信息不完整'); - return; - } - - this.$refs.scheduleForm.validate((valid) => { - if (valid) { - if (this.currentEditIndex === -1) { - if (this.timeScheduleList.length >= 10) { - this.$message.warning('最多只能添加10个时间方案'); - return; - } - this.timeScheduleList.push({ ...this.scheduleForm }); - } else { - this.timeScheduleList[this.currentEditIndex] = { ...this.scheduleForm }; - } - - // 转换为物模型格式 - const shedule = this.timeScheduleList.map(item => { - // 转换时间为秒数 - const startSeconds = item.startTime.getHours() * 3600 + - item.startTime.getMinutes() * 60 + - item.startTime.getSeconds(); - - // 转换周几为字符串 - const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; - const week = weekDays.map(day => { - return item.repeat.includes(day) ? '1' : '0'; - }).join(''); - - return { - time_s: startSeconds, - sw1_s: item.actions[0] || 0, - sw2_s: item.actions[1] || 0, - sw3_s: item.actions[2] || 0, - sw4_s: item.actions[3] || 0, - week - }; - }); - - // 更新物模型 - const cfgParam = this.deviceInfo.thingsModels.find(item => item.id === 'cfg_param'); - if (cfgParam) { - cfgParam.shadow = 'JSON=' + JSON.stringify({ shedule }); - this.mqttPublish(this.deviceInfo, cfgParam); - } - - this.dialogVisible = false; - this.$message.success('保存成功'); - } - }); - }, - getRelayName(index) { - const remark = this.deviceInfo.thingsModels.find(item => item.id === `remark_ch${index}`); - return remark ? remark.value : `继电器${index}`; - }, - startEditRemark(index) { - this.relayRemarks[index].isEditing = true; - this.$nextTick(() => { - const input = this.$el.querySelector(`.relay-remark input`); - if (input) { - input.focus(); - } - }); - }, - saveRelayRemark(index) { - const remark = this.deviceInfo.thingsModels.find(item => item.id === `remark_ch${index}`); - if (remark) { - remark.shadow = this.relayRemarks[index].value; - this.mqttPublish(this.deviceInfo, remark); - } - this.relayRemarks[index].isEditing = false; - }, - initRelayRemarks() { - for (let i = 1; i <= 4; i++) { - const remark = this.deviceInfo.thingsModels.find(item => item.id === `remark_ch${i}`); - if (remark) { - this.relayRemarks[i] = { - value: remark.value || '', - isEditing: false - }; - } - } - } - }, - computed: { - isRelayProduct() { - return this.deviceInfo.productName === '多路控制器'; - } }, };