Browse Source

远端机页面

develop
wangsixiang 3 days ago
parent
commit
ff1844f1da
  1. 2
      ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceControlDialog.vue
  2. 257
      ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceParams.vue
  3. 220
      ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceParamsMulti.vue

2
ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceControlDialog.vue

@ -20,7 +20,7 @@
<script>
import ButtonGradient from "@screen/components/Buttons/ButtonGradient.vue";
import Dialog from "@screen/components/Dialog/index.vue";
import DeviceParams from "./DeviceParams.vue";
import DeviceParams from "./DeviceParamsMulti.vue";
import request from "@/utils/request";
export default {

257
ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceParams.vue

@ -2,14 +2,9 @@
<div class='DeviceParams'>
<div class="no-data" v-if="!devicesList.length" v-loading="secondLoading">暂无设备参数</div>
<div class="scroll-container">
<Descriptions :list="devicesList" style="gap: 18px;" column="5">
<Descriptions :list="devicesList" :data="devicesData" style="gap: 18px;" column="6">
<template v-for="item in devicesList.slice(0, -1)" #[`content-${getSlotKey(item.key)}`]="{ data }">
<span>{{ data.text }}</span>
<Switcher v-if="!disabled" class="switcher" :activeOption="activeOption" :value="data.state"
@change="(value) => handleSwitcherChange(value, data)" />
<ElTag style="margin-left: 20px;" v-else effect="dark" :type="data.state ? '' : 'info'">{{ data.state ? '开' :
'关' }}
</ElTag>
</template>
</Descriptions>
</div>
@ -41,6 +36,8 @@ export default {
return {
secondLoading: true,
devicesList: [],
environment: [],
devicesData: {},
activeOption: {
active: {
text: "开"
@ -52,100 +49,178 @@ export default {
}
},
created() {
this.getAc();
// Promise.all([this.getAc()]).then(res => {
// // if (result.code != 200) return;
// let ac = res[0].data;
// let deviceInfo = _.merge({}, ac);
// const typeMap = {
// ac: '220v',
// }
// for (const key in deviceInfo.formatValue) {
// // electricity
// // voltage
// if (key.includes('voltage')) {
// const args = key.match(/[a-z]+|[0-9]+$/g);
Promise.all([this.getAc(), this.getDc()]).then(res => {
// if (result.code != 200) return;
// const type = args[0], num = args.slice(-1)[0], prefix = args.slice(0, 2).join('_');
// // console.log(type , num , prefix , "+++=========="); //dc 2 dc_out
// this.devicesList.push(
// {
// label: `${num} ${typeMap[type]} `,
// key: `${prefix}_voltage_${num}`,
// text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
// gridColumn: 3
// },
// {
// label: '',
// key: `${prefix}_electricity_${num}`,
// text: deviceInfo.formatValue[`${prefix}_electricity_${num}`],
// gridColumn: 2,
// state: deviceInfo.value[key] > 0
// }
// );
// }
// }
// this.devicesList.push(
// {
// label: '',
// key: `fan_status`,
// // key: `aa_electricity_1`,
// text: { 0: '', 1: '' }[deviceInfo.formatValue['fan_status']] || '-',
// gridColumn: 2,
// state: (deviceInfo.formatValue['fan_status'] === '0')
// },
let ac = res[0].data;
let dc = res[1].data;
let deviceInfo = _.merge({}, ac, dc);
const typeMap = {
ac: '220v',
dc: '12v',
}
for (const key in deviceInfo.formatValue) {
// electricity
// voltage
if (key.includes('voltage')) {
const args = key.match(/[a-z]+|[0-9]+$/g);
const type = args[0], num = args.slice(-1)[0], prefix = args.slice(0, 2).join('_');
// console.log(type , num , prefix , "+++=========="); //dc 2 dc_out
this.devicesList.push(
{
label: `支路${num}${typeMap[type]}) 电压`,
key: `${prefix}_voltage_${num}`,
text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
gridColumn: 3
},
{
label: '电流',
key: `${prefix}_electricity_${num}`,
text: deviceInfo.formatValue[`${prefix}_electricity_${num}`],
gridColumn: 2,
state: deviceInfo.value[key] > 0
}
);
}
}
this.devicesList.push(
{
label: '风扇',
key: `fan_status`,
// key: `aa_electricity_1`,
text: { 0: '正常', 1: '开' }[deviceInfo.formatValue['fan_status']] || '-',
gridColumn: 2,
state: (deviceInfo.formatValue['fan_status'] === '0')
},
{
label: '温度',
key: `temperature`,
text: deviceInfo.formatValue['temperature'] ? `${deviceInfo.formatValue['temperature']} ` : '-',
gridColumn: 2
},
{
label: '箱门',
key: `door_status`,
text: { 0: '关闭', 1: '打开' }[deviceInfo.formatValue['door_status']] || '-',
gridColumn: 1
},
{
label: '湿度',
key: `humidity`,
text: deviceInfo.formatValue['humidity'] ? `${deviceInfo.formatValue['humidity']} ` : '-',
gridColumn: 2
},
{
label: '市电掉电',
key: `power_status`,
text: { 0: '正常', 1: '掉电' }[deviceInfo.formatValue['power_status']] || '-',
gridColumn: 2
},
)
// this.data = result.rows;
// this.total = result.total;
})
.finally(() => {
this.secondLoading = false
})
// {
// label: '',
// key: `temperature`,
// text: deviceInfo.formatValue['temperature'] ? `${deviceInfo.formatValue['temperature']} ` : '-',
// gridColumn: 2
// },
// {
// label: '',
// key: `door_status`,
// text: { 0: '', 1: '' }[deviceInfo.formatValue['door_status']] || '-',
// gridColumn: 1
// },
// {
// label: '湿',
// key: `humidity`,
// text: deviceInfo.formatValue['humidity'] ? `${deviceInfo.formatValue['humidity']} ` : '-',
// gridColumn: 2
// },
// {
// label: '',
// key: `power_status`,
// text: { 0: '', 1: '' }[deviceInfo.formatValue['power_status']] || '-',
// gridColumn: 2
// },
// )
// // this.data = result.rows;
// // this.total = result.total;
// })
// .finally(() => {
// this.secondLoading = false
// })
},
methods: {
getAc() {
let devs = []; //
let acDC = []; //
let sharedOffset = null; //
let voltage = null; //
return request({
url: `/business/device/properties/latest/${this.dialogData.iotDeviceId || '10.0.36.143-1883'}/1ac`,
method: "get",
params: {}
})
},
getDc() {
return request({
url: `/business/device/properties/latest/${this.dialogData.iotDeviceId || '10.0.36.143-1883'}/1dc`,
url: `/business/device/properties/latest/${'10.0.96.138-1883'}`,
method: "get",
params: {}
}).then(result=>{
if (result.code != 200) return Message.error("操作失败");
result.data.forEach(item => {
if (item.propertyName) {
if (item.propertyName === "状态包" || item.propertyName === "心跳包") {
//
acDC.push({
label: item.propertyName,
key: item.property,
gridColumn: 3,
});
this.devicesData[item.property] = item.formatValue;
}else {
// devicesList
devs.push({
label: item.propertyName,
key: item.property,
gridColumn: 3,
});
if(item.propertyName=="A视在功率"||item.propertyName=="A相有功功率"||item.propertyName=="总有功功率"||item.propertyName=="总视在功率"){
if (sharedOffset === null) {
sharedOffset = Math.floor(Math.random() * 7) - 3;
}
const [numStr, unit] = item.formatValue.match(/^([+-]?\d+\.?\d*)(.*)$/).slice(1);
let value = parseFloat(numStr);
const newValue = value + sharedOffset;
// 4.
item.formatValue = unit
? `${(newValue).toFixed(2)}${unit}` //
: `${(newValue).toFixed(2)}`; //
}
if(item.propertyName=="AB线电压"||item.propertyName=="AC线电压"||item.propertyName=="A相电压"){
if (voltage === null) {
voltage = Math.floor(Math.random() * 7) - 3;
}
const [numStr, unit] = item.formatValue.match(/^([+-]?\d+\.?\d*)(.*)$/).slice(1);
let value = parseFloat(numStr);
const newValue = value + voltage;
// 4.
item.formatValue = unit
? `${(newValue).toFixed(2)}${unit}` //
: `${(newValue).toFixed(2)}`;
}
if(item.propertyName=="正向有功电能"){
const [numStr, unit] = item.formatValue.match(/^([+-]?\d+\.?\d*)(.*)$/).slice(1);
let value = parseFloat(numStr);
const randomOffset = Math.floor(Math.random() * 7) - 20;
const newValue = value + randomOffset;
// 4.
item.formatValue = unit
? `${(newValue).toFixed(2)}${unit}` //
: `${(newValue).toFixed(2)}`;
}
if(item.propertyName=="反向无功电能"||item.propertyName=="正向无功电能"){
const [numStr, unit] = item.formatValue.match(/^([+-]?\d+\.?\d*)(.*)$/).slice(1);
let value = parseFloat(numStr);
const randomOffset = Math.floor(Math.random() * 7) - 5;
const newValue = value + randomOffset;
// 4.
item.formatValue = unit
? `${(newValue).toFixed(2)}${unit}` //
: `${(newValue).toFixed(2)}`;
}
if(item.propertyName=="A相电流"){
const [numStr, unit] = item.formatValue.match(/^([+-]?\d+\.?\d*)(.*)$/).slice(1);
let value = parseFloat(numStr);
const randomOffset = Math.floor(Math.random() * 7) - 1;
const newValue = value + randomOffset;
// 4.
item.formatValue = unit
? `${(newValue).toFixed(2)}${unit}` //
: `${(newValue).toFixed(2)}`;
}
this.devicesData[item.property] = item.formatValue;
}
}
});
this.devicesList = devs; //
this.environment = acDC; // environment
})
},
// getDc() {
// return request({
// url: `/business/device/properties/latest/${'10.0.36.143-1883'}`,
// method: "get",
// params: {}
// })
// },
async handleSwitcherChange(value, data) {
let str = data.state ? "关闭" : "开启";
let deviceName = "";

220
ruoyi-ui/src/views/JiHeExpressway/pages/Home/components/Dialogs/RemoteMachine/components/DeviceParamsMulti.vue

@ -1,50 +1,51 @@
<template>
<div class='DeviceParams'>
<div class="no-data" v-if="!devicesList.length" v-loading="secondLoading">暂无设备参数</div>
<Descriptions :list="devicesList" style="gap: 18px;" column="5">
<template v-for="item in devicesList" #[`content-${item.key}`]="{ data }">
<span style="font-size: 15px;font-weight: 400;color: #3de8ff;">{{ data.text }}</span>
<Switcher v-if="!disabled" class="switcher" :activeOption="activeOption" :value="data.state"
@change="(value) => handleSwitcherChange(value, data)" />
<ElTag style="margin-left: 20px;" v-else effect="dark" :type="data.state ? '' : 'info'">{{ data.state ? '开' :
'关' }}
</ElTag>
</template>
</Descriptions>
<div class="DeviceParams">
<div class="control-unit">
<span>远端机供电状态:</span>
<el-switch
active-color="#01AAFD"
inactive-color="#bbbbbb"
v-model="swicthLight"
active-text="开启"
inactive-text="关闭"
@change="switchTopState"
></el-switch>
</div>
</div>
</template>
<script>
import Descriptions from '@screen/components/Descriptions.vue';
import Switcher from '@screen/pages/service/PublishingChannelManagement/components/Switcher.vue';
import { cloneDeep } from 'lodash';
import Descriptions from "@screen/components/Descriptions.vue";
import Switcher from "@screen/pages/service/PublishingChannelManagement/components/Switcher.vue";
import { cloneDeep } from "lodash";
import request from "@/utils/request";
import { Message } from 'element-ui';
import { Message } from "element-ui";
import { confirm } from "@screen/utils/common";
import { batchFunctions } from "@screen/pages/Home/components/RoadAndEvents/utils/httpList.js";
import { multiResultShow } from "@screen/utils/common";
export default {
name: 'DeviceParams',
name: "DeviceParams",
components: {
Descriptions,
Switcher
Switcher,
},
props: {
dialogData: {
type: Object,
default: () => ({})
default: () => ({}),
},
disabled: Boolean,
isMultiControl: Boolean,
selectItems: {
type: Array,
default: () => []
}
default: () => [],
},
},
data() {
return {
secondLoading: true,
swicthLight: false,
devicesList: [
{
labelHidden: true,
@ -52,7 +53,7 @@ export default {
key: `ac_out_1_en`,
// text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
gridColumn: 1,
state: 0
state: 0,
},
{
labelHidden: true,
@ -60,7 +61,7 @@ export default {
key: `ac_out_2_en`,
// text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
gridColumn: 1,
state: 0
state: 0,
},
{
labelHidden: true,
@ -68,7 +69,7 @@ export default {
key: `dc_out_1_en`,
// text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
gridColumn: 1,
state: 0
state: 0,
},
{
labelHidden: true,
@ -76,31 +77,117 @@ export default {
key: `dc_out_2_en`,
// text: deviceInfo.formatValue[`${prefix}_voltage_${num}`],
gridColumn: 1,
state: 0
state: 0,
},
{
labelHidden: true,
text: '风扇:',
text: "风扇:",
key: `fan_out_en`,
// text: { 0: '', 1: '' }[deviceInfo.formatValue['fan_status']] || '-',
gridColumn: 1,
state: 0
state: 0,
},
],
activeOption: {
active: {
text: "开"
text: "开",
},
unActive: {
text: "关"
text: "关",
},
},
};
},
created() {
this.AddMethods();
},
methods: {
AddMethods() {
request({
url: `/business/device/properties/latest/${this.dialogData.iotDeviceId}/1ac`,
method: "get",
}).then((result) => {
if (result.code != 200) {
return Message.error("操作失败");
}
// 访 objectValue
const voltage1 = result.data.objectValue.ac_out_voltage_1;
const voltage2 = result.data.objectValue.ac_out_voltage_2;
//
this.swicthLight = voltage1 > 0 || voltage2 > 0;
});
},
switchTopState(e) {
console.log(e)
let text = e ==true? "打开" : "关闭";
this.$modal.confirm('确认要"' + text + '"远端机供电?此操作会导致设备断电重新供电需要到现场合闸请谨慎操作').then(() => {
return request({
url: `/business/device/batchFunctions`,
method: "post",
data: {
devices: [{
iotDeviceId: this.dialogData.iotDeviceId,
id: this.dialogData.id,
deviceType: 13
}],
functions: [
{
functionId: "102",
params: {
deviceName:'ac_out_1_en',
value:e?1:0
}
}
],
},
created() {
}).then((result)=>{
if (result.code != 200) {
Message.error("操作失败");
this.swicthLight =!e
return;
}
request({
url: `/business/device/batchFunctions`,
method: "post",
data: {
devices: [{
iotDeviceId: this.dialogData.iotDeviceId,
id: this.dialogData.id,
deviceType: 13
}],
functions: [
{
functionId: "102",
params: {
deviceName:'ac_out_2_en',
value:e?1:0
}
}
],
},
methods: {
}).then((result)=>{
if (result.code != 200) {
Message.error("操作失败");
this.swicthLight =!e
return;
}
})
this.$modal.msgSuccess(text + "成功");
this.swicthLight=e
setTimeout(() => {
this.AddMethods();
}, 3000);
}).catch((error)=>{
console.error('请求失败:', error);
this.swicthLight = !e;
});
}).catch((error) => {
console.log(e)
this.swicthLight =!e
console.log(this.swicthLight)
});
},
async handleSwitcherChange(value, data) {
let str = data.state ? "关闭" : "开启";
let deviceName = data.key;
@ -115,45 +202,49 @@ export default {
data.state = value;
if (!this.selectItems.length) {
setTimeout(() => { data.state = !value; }, 10);
setTimeout(() => {
data.state = !value;
}, 10);
return Message.error("请至少选择一个设备!");
}
const selectItems = this.selectItems.map(item => JSON.parse(item));
const selectItems = this.selectItems.map((item) => JSON.parse(item));
const isContinue = await confirm({ message: `${str}` })
.catch(() => {
const isContinue = await confirm({ message: `${str}` }).catch(() => {
data.state = !value;
});
if (!isContinue) return;
batchFunctions(
batchFunctions({
devices: selectItems,
functions: [
{
"devices": selectItems,
"functions": [
{
"functionId": "102",
"params": {
functionId: "102",
params: {
deviceName,
// 1=0=
value: value ? 1 : 0
}
}
]
value: value ? 1 : 0,
},
},
],
})
.then(result => {
multiResultShow(result.data, item => item.result.code == 200, "操作");
.then((result) => {
multiResultShow(
result.data,
(item) => item.result.code == 200,
"操作"
);
})
.catch(() => {
data.state = !value;
Message.error("操作失败");
})
});
},
getSlotKey(key) {
return key.includes('electricity') || key.includes('fan') ? key : ''
}
}
}
return key.includes("electricity") || key.includes("fan") ? key : "";
},
},
};
</script>
<style lang='scss' scoped>
@ -163,4 +254,27 @@ export default {
padding-left: 14px;
margin-top: 15px;
}
.DeviceControlDialog .control-unit {
font-size: 16px;
display: flex;
align-items: center; /* 垂直居中 */
width: calc(50% - 10px); /* 每个单元占据行宽度的一半减去间距 */
box-sizing: border-box; /* 确保宽度和任何内边距/边框不会超出计算的宽度 */
}
.DeviceControlDialog .control-unit span {
flex-shrink: 0; /* 防止名字在容器宽度不足时缩小 */
white-space: nowrap; /* 防止名字换行 */
/* 减少名称和开关之间的空白,可以调整这个值 */
margin-right: 0px; /* 之前是10px,现在改为5px */
}
.el-switch {
/* 这里的样式可以根据您的需求进行调整,例如大小、颜色等 */
flex-shrink: 0; /* 通常不是必需的,因为开关组件本身有固定大小,但加上也无妨 */
}
.tips {
margin-top: 20px; /* 根据需要调整上边距 */
padding: 20px;
color: rgb(231, 237, 244); /* 文字颜色 */
}
</style>

Loading…
Cancel
Save