device detail websocket

This commit is contained in:
cxc
2023-02-27 10:28:04 +08:00
parent df8c12e03b
commit 6dd0bd0c63
3 changed files with 51 additions and 36 deletions

View File

@ -3,4 +3,4 @@ ENV = 'production'
# 管理系统/生产环境 # 管理系统/生产环境
# VUE_APP_BASE_API = 'http://47.115.73.110:8080' # VUE_APP_BASE_API = 'http://47.115.73.110:8080'
VUE_APP_BASE_API = 'http://192.168.110.10:8080' VUE_APP_BASE_API = '/api'

View File

@ -56,6 +56,7 @@
"nprogress": "0.2.0", "nprogress": "0.2.0",
"path-to-regexp": "2.4.0", "path-to-regexp": "2.4.0",
"quill": "1.3.7", "quill": "1.3.7",
"reconnecting-websocket": "^4.4.0",
"screenfull": "4.2.0", "screenfull": "4.2.0",
"sortablejs": "1.8.4", "sortablejs": "1.8.4",
"vue": "2.6.10", "vue": "2.6.10",

View File

@ -12,8 +12,7 @@
<span <span
>设备类型{{ >设备类型{{
info.deviceType info.deviceType
? this.deviceTypeList.find((v) => v.value == info.deviceType) ? this.deviceTypeList.find(v => v.value == info.deviceType).label
.label
: '' : ''
}}</span }}</span
> >
@ -208,6 +207,7 @@
import { getKeyHistory, info, updateValue } from '@/api/hardware/device'; import { getKeyHistory, info, updateValue } from '@/api/hardware/device';
import { getProvinceByCode } from '@/api/hardware/province'; import { getProvinceByCode } from '@/api/hardware/province';
import { handleOffsetAndRange } from '../../../utils/offsetMap'; import { handleOffsetAndRange } from '../../../utils/offsetMap';
import ReconnectingWebSocket from 'reconnecting-websocket';
export default { export default {
name: 'DeviceDetail', name: 'DeviceDetail',
@ -236,17 +236,18 @@ export default {
centerChart: null, centerChart: null,
queryParams: { queryParams: {
deviceId: '', deviceId: '',
key: '', key: ''
}, },
id: '', id: '',
info: {}, info: {},
signal: [], signal: [],
websocket: null,
defaultSignal: [], defaultSignal: [],
signalUpdateTime: '', signalUpdateTime: '',
deviceTypeList: [ deviceTypeList: [
{ label: '锐能设备', value: 'rn' }, { label: '锐能设备', value: 'rn' },
{ label: '铁塔设备', value: 'tt' }, { label: '铁塔设备', value: 'tt' }
], ]
}; };
}, },
watch: { watch: {
@ -254,29 +255,29 @@ export default {
if (!this.selectDate) { if (!this.selectDate) {
this.selectDate = ''; this.selectDate = '';
} }
}, }
}, },
computed: { computed: {
// 过充 单体过充阈值 // 过充 单体过充阈值
overcharge() { overcharge() {
let a = this.signal.find((item) => item.keyCN == '单体过充阈值'); let a = this.signal.find(item => item.keyCN == '单体过充阈值');
return a ? a.valueCN - 0 : null; return a ? a.valueCN - 0 : null;
}, },
// 过放 单体过放阈值 // 过放 单体过放阈值
overdischarge() { overdischarge() {
let a = this.signal.find((item) => item.keyCN == '单体过放阈值'); let a = this.signal.find(item => item.keyCN == '单体过放阈值');
return a ? a.valueCN - 0 : null; return a ? a.valueCN - 0 : null;
}, },
// 过压 单体过压阈值 // 过压 单体过压阈值
overVoltage() { overVoltage() {
let a = this.signal.find((item) => item.keyCN == '单体过压阈值'); let a = this.signal.find(item => item.keyCN == '单体过压阈值');
return a ? a.valueCN - 0 : null; return a ? a.valueCN - 0 : null;
}, },
// 欠压 单体欠压阈值 // 欠压 单体欠压阈值
underVoltage() { underVoltage() {
let a = this.signal.find((item) => item.keyCN == '单体欠压阈值'); let a = this.signal.find(item => item.keyCN == '单体欠压阈值');
return a ? a.valueCN - 0 : null; return a ? a.valueCN - 0 : null;
}, }
}, },
created() { created() {
let { id } = this.$route.query; let { id } = this.$route.query;
@ -288,13 +289,16 @@ export default {
this.id = id; this.id = id;
this.getDetail(); this.getDetail();
}, },
mounted() {
this.initWebsocket();
},
methods: { methods: {
handleOffsetAndRange, handleOffsetAndRange,
handleCommand(item, command) { handleCommand(item, command) {
this.$confirm('确认提交?', '提示', { this.$confirm('确认提交?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning', type: 'warning'
}) })
.then(() => { .then(() => {
item.value = command; item.value = command;
@ -325,7 +329,7 @@ export default {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
inputPattern: /^[1-9]\d*$/, inputPattern: /^[1-9]\d*$/,
inputErrorMessage: '校验失败', inputErrorMessage: '校验失败'
}) })
.then(({ value }) => { .then(({ value }) => {
item.value = value; item.value = value;
@ -355,8 +359,8 @@ export default {
let deviceSignal = JSON.parse(info.deviceSignal.signalJsonTurn); let deviceSignal = JSON.parse(info.deviceSignal.signalJsonTurn);
this.signal = deviceSignal.signal; this.signal = deviceSignal.signal;
this.defaultSignal = info.defaultSignal; this.defaultSignal = info.defaultSignal;
console.log(info.deviceSignal.signalJsonTurn); // console.log(info.deviceSignal.signalJsonTurn);
console.log(this.signal); // console.log(this.signal);
// let a = deviceSignal.signal.find( // let a = deviceSignal.signal.find(
// item => item.keyCN == '单体过充阈值' // item => item.keyCN == '单体过充阈值'
// ); // );
@ -379,7 +383,7 @@ export default {
reject({ msg, code }); reject({ msg, code });
} }
}) })
.catch((error) => { .catch(error => {
reject(error); reject(error);
}); });
}); });
@ -410,7 +414,7 @@ export default {
this.getChartData(); this.getChartData();
}, },
getChartData() { getChartData() {
getKeyHistory(this.queryParams).then((data) => { getKeyHistory(this.queryParams).then(data => {
this.$nextTick(() => { this.$nextTick(() => {
this.initChart(data); this.initChart(data);
}); });
@ -421,7 +425,7 @@ export default {
this.centerChart = echarts.init(this.$refs.echa); this.centerChart = echarts.init(this.$refs.echa);
let months = []; let months = [];
let nums = []; let nums = [];
data.map((item) => { data.map(item => {
for (const k in item) { for (const k in item) {
months.push(k); months.push(k);
nums.push(item[k]); nums.push(item[k]);
@ -429,7 +433,7 @@ export default {
}); });
let option = { let option = {
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis'
}, },
toolbox: { toolbox: {
show: true, show: true,
@ -458,11 +462,11 @@ export default {
} }
table += '</tbody></table>'; table += '</tbody></table>';
return table; return table;
}, }
}, },
// restore: {}, // restore: {},
saveAsImage: {}, saveAsImage: {}
}, }
}, },
xAxis: { xAxis: {
name: '时间', name: '时间',
@ -470,11 +474,11 @@ export default {
boundaryGap: false, boundaryGap: false,
data: months.map(function(str) { data: months.map(function(str) {
return str.replace(' ', '\n'); return str.replace(' ', '\n');
}), })
}, },
yAxis: { yAxis: {
name: '数值', name: '数值',
type: 'value', type: 'value'
}, },
series: [ series: [
{ {
@ -482,14 +486,24 @@ export default {
type: 'line', type: 'line',
data: nums, data: nums,
lineStyle: { lineStyle: {
color: '#46a6ff', color: '#46a6ff'
}, }
}, }
], ]
}; };
this.centerChart.setOption(option); this.centerChart.setOption(option);
}, },
}, initWebsocket() {
const wsBaseUrl =
process.env.NODE_ENV === 'development'
? '192.168.110.10:8080'
: `${window.location.host}${process.env.VUE_APP_BASE_API}`;
this.websocket = new ReconnectingWebSocket(`ws://${wsBaseUrl}/ws`);
this.websocket.addEventListener('message', e => {
this.$message.success(e.data);
});
}
}
}; };
</script> </script>