修改mqtt连接方式

This commit is contained in:
GGJ
2024-12-30 10:07:26 +08:00
parent 0f57e4b746
commit 6a06652532
19 changed files with 173 additions and 93 deletions

View File

@@ -7,15 +7,30 @@
<script lang="ts" setup>
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import useSetTheme from '@/utils/setTheme'
import { provide, getCurrentInstance } from 'vue'
import { provide, onMounted, ref } from 'vue'
//线上mqtt
// 27服务器项目使用的MQTT:ws://pqmcn.com:8073/mqtt
// 102服务器项目使用的MQTT:wss://pqmcn.com:8087/mqtt
// let buildUrl = 'wss://pqmcn.com:8087/mqtt'//102
let buildUrl = 'ws://pqmcn.com:8073/mqtt'//27
let buildUrl = 'wss://pqmcn.com:8087/mqtt'//102
// let buildUrl = 'ws://pqmcn.com:8073/mqtt'//27
// 从 Nginx 获取 MQTT URL
const fetchMqttUrl = async () => {
const response = await fetch('/')
const mqttUrl = response.headers.get('X-MQTT-URL')
window.localStorage.setItem('MQTTURL', mqttUrl || buildUrl)
}
//本地mqtt
let devUrl = 'ws://192.168.1.24:8085/mqtt'
provide('MQTTURL', buildUrl)
// let devUrl = 'ws://192.168.1.24:8085/mqtt'
onMounted(() => {
fetchMqttUrl()
})
// provide('MQTTURL', buildUrl.value)
useSetTheme()
</script>

View File

@@ -1466,7 +1466,7 @@ export default {
//minInterval: 1,
type: "value",
axisLine: {
show: false,
show: true,
lineStyle: {
color: _this.DColor ? "#fff" : echartsColor.thread,
},

View File

@@ -188,7 +188,7 @@ export default {
' 暂降(骤升)幅值:' +
(featureAmplitude) +
'% 持续时间:' +
(this.boxoList.persistTime ? this.boxoList.persistTime.toFixed(2) : '-') +
(this.boxoList.persistTime || this.boxoList.evtParamTm || '-') +
's'
} else {
this.titles =

View File

@@ -1,49 +1,46 @@
const dataProcessing = (arr: any[]) => {
return arr
.filter(item => typeof item == 'number' || (typeof item == 'string' && !isNaN(parseFloat(item))))
.map(item => (typeof item == 'number' ? item : parseFloat(item)))
.filter(item => typeof item === 'number' || (typeof item === 'string' && !isNaN(parseFloat(item))))
.map(item => (typeof item === 'number' ? item : parseFloat(item)))
}
// 处理y轴最大最小值
export const yMethod = (arr: any) => {
const numList = dataProcessing(arr);
const maxValue = Math.max(...numList);
const minValue = Math.min(...numList);
const calculateBoundary = (value: number, base: number) => {
return Math[value > 0? 'ceil' : 'floor'](value / base) * base;
};
let max: number;
let min: number;
let numList = dataProcessing(arr)
let maxValue = 0
let minValue = 0
let max = 0
let min = 0
maxValue = Math.max(...numList)
minValue = Math.min(...numList)
if (maxValue > 1000 || minValue < -1000) {
max = calculateBoundary(maxValue, 100);
min = minValue == 0? 0 : calculateBoundary(minValue, 100);
} else if (maxValue < 60 && minValue > 40) {
max = 60;
min = 40;
} else if (maxValue == minValue) {
if (maxValue < 10 && minValue > 0) {
max = calculateBoundary(maxValue, 10);
min = calculateBoundary(minValue, 10);
} else if (maxValue!== 0 && minValue!== 0) {
max = calculateBoundary(maxValue / 10 + 1, 10);
min = calculateBoundary(minValue / 10 - 1, 10);
}
max = Math.ceil(maxValue / 100) * 100
if (minValue == 0) {
min = 0
} else {
max = calculateBoundary(maxValue, 10);
min = calculateBoundary(minValue, 10);
min = Math.floor(minValue / 100) * 100
}
} else if (maxValue < 60 && minValue > 40) {
max = 60
min = 40
} else if (maxValue == minValue && maxValue < 10 && minValue > 0) {
max = Math.ceil(maxValue / 10) * 10
min = Math.floor(minValue / 10) * 10
} else if (maxValue == minValue && maxValue != 0 && minValue != 0) {
max = Math.ceil(maxValue / 10 + 1) * 10
min = Math.floor(minValue / 10 - 1) * 10
} else {
max = Math.ceil(maxValue / 10) * 10
min = Math.floor(minValue / 10) * 10
}
if (maxValue > 0 && maxValue < 1) {
max = 1;
max = 1
} else if (max == 0 && minValue > -1 && minValue < 0) {
min = -1
}
if (max == 0 && minValue > -1 && minValue < 0) {
min = -1;
}
return [min, max];
};
return [min, max]
}
/**
* title['A相','B相',]
@@ -51,7 +48,7 @@ export const yMethod = (arr: any) => {
*/
// 导出csv文件
const convertToCSV = (title: object, data: any) => {
// console.log('🚀 ~ convertToCSV ~ data:', data)
console.log('🚀 ~ convertToCSV ~ data:', data)
let csv = ''
// 添加列头
csv += ',' + title.join(',') + '\n'

View File

@@ -4,7 +4,7 @@ import { requestPayload } from '@/utils/request'
import { Method } from 'axios'
import { mainHeight } from '@/utils/layout'
import { filtration } from './tableMethod'
import { ElMessage } from 'element-plus'
interface TableStoreParams {
url: string // 请求地址
pk?: string
@@ -183,6 +183,11 @@ export default class TableStore {
'export',
() => {
// this.index()
ElMessage({
message: '正在导出,请稍等...',
type: 'info',
duration: 1000
})
let params = { ...this.table.params, pageNum: 1, pageSize: this.table.total }
createAxios(
Object.assign(

View File

@@ -2,16 +2,16 @@
<div class="default-main">
<el-tabs v-model.trim="activeName" type="border-card" class="demo-tabs">
<el-tab-pane label="设备告警" name="1">
<Device v-if="activeName == '1'" :deviceTree="deviceTree" />
<Device v-if="activeName == '1'" :deviceTree="deviceTree" :key="key" />
</el-tab-pane>
<el-tab-pane label="稳态越限告警" name="2">
<Steady v-if="activeName == '2'" :deviceTree="deviceTree" />
<Steady v-if="activeName == '2'" :deviceTree="deviceTree" :key="key" />
</el-tab-pane>
<el-tab-pane label="暂态事件" name="3">
<Transient v-if="activeName == '3'" :deviceTree="deviceTree" />
<Transient v-if="activeName == '3'" :deviceTree="deviceTree" :key="key" />
</el-tab-pane>
<el-tab-pane label="异常事件" name="4">
<Abnormal v-if="activeName == '4'" :deviceTree="deviceTree" />
<Abnormal v-if="activeName == '4'" :deviceTree="deviceTree" :key="key" />
</el-tab-pane>
</el-tabs>
</div>
@@ -28,6 +28,7 @@ defineOptions({
})
const deviceTree = ref([])
const activeName = ref('1')
const key = ref(0)
getDeviceTree().then(res => {
res.data.forEach((item: any) => {
item.value = item.id
@@ -43,6 +44,7 @@ getDeviceTree().then(res => {
})
})
deviceTree.value = res.data
key.value += 1
})
onMounted(() => { })

View File

@@ -86,7 +86,7 @@ const zblist = ref<any[]>([])
const init = () => {
return new Promise((resolve, reject) => {
queryByCode('Harmonic_Type').then(res => {
queryCsDictTree(res.data.id).then(res => {
queryCsDictTree(res.data?.id).then(res => {
zblist.value = res.data.map((item: any) => {
return {
value: item.id,
@@ -302,11 +302,11 @@ const search = () => {
} else {
echartsData.value = null
}
})
setTimeout(() => {
loading.value = false
}, 0)
}).catch(() => {
loading.value = false
})
}
</script>

View File

@@ -1,13 +1,15 @@
<template>
<div class="default-main">
<div class="analyze-dvr" v-show="view" :style="{ height: pageHeight.height }" v-loading="loading">
<div class="analyze-dvr" v-show="!isWaveCharts" :style="{ height: pageHeight.height }" v-loading="loading">
<DeviceTree @node-click="nodeClick" @init="nodeClick"></DeviceTree>
<div class="analyze-dvr-right" v-if="tableStore.table.params.deviceId">
<Table v-if="view" ref="tableRef"></Table>
</div>
<el-empty v-else description="请选择设备" class="analyze-dvr-right" />
</div>
<div :style="{ height: pageHeight.height }" style="padding: 10px; overflow: hidden" v-if="!view">
<waveFormAnalysis v-loading="loading" v-if="isWaveCharts" ref="waveFormAnalysisRef"
@handleHideCharts="isWaveCharts = false" :wp="wp" style="padding: 10px;"/>
<!-- <div :style="{ height: pageHeight.height }" style="padding: 10px; overflow: hidden" v-if="!view">
<el-row>
<el-col :span="12">
<div v-if="view2" style="display: flex">
@@ -38,20 +40,21 @@
</rmsboxi>
</el-tab-pane>
</el-tabs>
<!-- <xiebofenxi ref="child" :bxshuju="bxshuju" @backfh="back"></xiebofenxi> -->
</div>
</div> -->
</div>
</template>
<script setup lang="ts">
import { ref, reactive, provide, onMounted } from 'vue'
import { ref, nextTick, provide, onMounted } from 'vue'
import { mainHeight } from '@/utils/layout'
import DeviceTree from '@/components/tree/govern/deviceTree.vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import waveFormAnalysis from '@/views/govern/device/control/tabs/components/waveFormAnalysis.vue';
import { analyseWave } from '@/api/common'
import shushiboxi from '@/components/echarts/shushiboxi.vue'
import rmsboxi from '@/components/echarts/rmsboxi.vue'
import { ElMessage } from 'element-plus'
defineOptions({
name: 'govern/analyze/DVR'
})
@@ -60,11 +63,12 @@ const loading = ref(false)
const view = ref(true)
const view2 = ref(false)
const showBoxi = ref(true)
const isWaveCharts = ref(false)
const bxactiveName = ref('ssbx')
const boxoList = ref({})
const boxoList: any = ref({})
const wp = ref({})
const value = ref(1)
const waveFormAnalysisRef = ref()
const options = ref([
{
value: 1,
@@ -79,7 +83,8 @@ const tableStore = new TableStore({
url: '/cs-harmonic-boot/eventUser/queryEventpageWeb',
method: 'POST',
column: [
{ title: '事件描述', field: 'evtParamPosition' },
{ title: '事件描述', field: 'showName' },
{ title: '发生位置', field: 'evtParamPosition' },
{ title: '持续时间(s)', field: 'evtParamTm' },
{ title: '暂降深度', field: 'evtParamVVaDepth' },
{ title: '发生时刻', field: 'startTime' },
@@ -100,19 +105,30 @@ const tableStore = new TableStore({
},
click: async row => {
row.loading = true
boxoList.value = row
row.loading1 = true
loading.value = true
isWaveCharts.value = true
await analyseWave(row.id)
.then(res => {
row.loading = false
row.loading1 = false
if (res != undefined) {
boxoList.value = row
boxoList.value.featureAmplitude = row.evtParamVVaDepth != '-' ? row.evtParamVVaDepth - 0 : null
// boxoList.value.systemType = 'WX'
wp.value = res.data
view.value = false
view2.value = true
}
loading.value = false
})
.catch(() => {
row.loading = false
row.loading1 = false
loading.value = false
})
nextTick(() => {
waveFormAnalysisRef.value && waveFormAnalysisRef.value.getWpData(wp.value, boxoList.value, true)
waveFormAnalysisRef.value && waveFormAnalysisRef.value.setHeight(false, 150)
})
}
},
@@ -127,7 +143,28 @@ const tableStore = new TableStore({
},
},
{
name: 'edit',
title: '波形下载',
type: 'primary',
icon: 'el-icon-Check',
loading: 'loading2',
render: 'basicButton',
disabled: row => {
// && row.evtParamTm < 20
return !row.wavePath
},
click: row => {
row.loading2 = true
const url = window.location.origin + '/api/cs-harmonic-boot/event/getFileZip?eventId=' + row.id
window.open(url, '_self')
setTimeout(() => {
ElMessage.success('波形下载成功!')
row.loading2 = false
}, 1500)
}
},
]
}
],

View File

@@ -790,7 +790,7 @@ const trendRef: any = ref()
//暂态事件组件
const eventRef: any = ref()
const mqttRef = ref()
const url: any = inject('MQTTURL')
const url: any = window.localStorage.getItem('MQTTURL')
const connectMqtt = () => {
if (mqttRef.value) {
if (mqttRef.value.connected) {
@@ -806,6 +806,8 @@ const connectMqtt = () => {
username: 't_user',
password: 'njcnpqs'
}
mqttRef.value = mqtt.connect(url, options)
}
const getRealDataMqttMsg = async () => {

View File

@@ -152,7 +152,7 @@ const clearRadioRowEvent = () => {
}
}
const mqttRef = ref()
const url: any = inject('MQTTURL')
const url: any = window.localStorage.getItem('MQTTURL')
const connectMqtt = () => {
if (mqttRef.value) {
if (mqttRef.value.connected) {

View File

@@ -1,4 +1,4 @@
<!-- 暂态事件-波形析组件 -->
<!-- 暂态事件-波形析组件 -->
<template>
<div class="home">
<div class="home_header">
@@ -132,8 +132,10 @@ const handleBack = () => {
emit('handleHideCharts')
}
const setHeight = (h: any, vh: any) => {
if (h != false) {
parentHeight.value = h
}
setTimeout(() => {
bxecharts.value = mainHeight(vh).height
}, 100)

View File

@@ -2,8 +2,8 @@
<div class="view">
<TableHeader datePicker ref="headerRef" v-if="!isWaveCharts" :showReset="false"></TableHeader>
<Table ref="tableRef" v-if="!isWaveCharts" />
<waveFormAnalysis v-loading="loading" v-if="isWaveCharts" ref="waveFormAnalysisRef" @handleHideCharts="isWaveCharts = false"
:wp="wp" />
<waveFormAnalysis v-loading="loading" v-if="isWaveCharts" ref="waveFormAnalysisRef"
@handleHideCharts="isWaveCharts = false" :wp="wp" />
</div>
</template>
<script lang="ts" setup>
@@ -79,7 +79,7 @@ const tableStore: any = new TableStore({
buttons: [
{
name: 'edit',
title: '波形析',
title: '波形析',
type: 'primary',
icon: 'el-icon-Check',
render: 'basicButton',

View File

@@ -523,7 +523,7 @@ watch(
}
)
const mqttRef = ref()
const url: any = inject('MQTTURL')
const url: any = window.localStorage.getItem('MQTTURL')
const connectMqtt = () => {
if (mqttRef.value) {
if (mqttRef.value.connected) {

View File

@@ -83,7 +83,7 @@ const tableStore = new TableStore({
buttons: [
{
name: 'edit',
title: '波形析',
title: '波形析',
type: 'primary',
icon: 'el-icon-Check',
render: 'basicButton',

View File

@@ -201,6 +201,7 @@ const tableStore = new TableStore({
}
},
{ title: '设备名称', field: 'name' },
{ title: '网络设备ID', field: 'ndid' },
{
title: '设备类型',
field: 'devType',
@@ -208,6 +209,7 @@ const tableStore = new TableStore({
return devTypeOptions.value.filter((item: any) => item.value == row.cellValue)[0]?.label
}
},
{
title: '设备型号',
field: 'devModel',
@@ -223,7 +225,7 @@ const tableStore = new TableStore({
}
},
{ title: '录入时间', field: 'createTime' },
{ title: '网络设备ID', field: 'ndid' },
{
title: '使用状态',
render: 'switch',
@@ -257,7 +259,7 @@ const tableStore = new TableStore({
}
}).then(({ value }) => {
passwordConfirm(value).then(res => {
editEquipmentDelivery({ ...row, status: row.status == 5 ? 1 : row.status, usageStatus: row.usageStatus == 1 ? 0 : 1 }).then(res => {
editEquipmentDelivery({ ...row, status: row.status == 5 ? 1 : row.status == 6 ? 2 : row.status, usageStatus: row.usageStatus == 1 ? 0 : 1 }).then(res => {
ElMessage.success(row.usageStatus == 1 ? '设备停用成功!' : '设备启用成功!')
tableStore.index()
})

View File

@@ -79,10 +79,13 @@ const preservation = () => {
ruleForm.value.validate((valid: boolean) => {
if (valid) {
emit('submitForm', formdata.value, title.value)
formVisible.value = false
}
})
}
const shutDown = () => {
formVisible.value = false
}
// 关闭
const closeDialog = () => {
@@ -99,6 +102,6 @@ const open = (text: string, row?: any) => {
formVisible.value = true
}
defineExpose({ open })
defineExpose({ open,shutDown })
</script>
<style lang="scss" scoped></style>

View File

@@ -1,14 +1,8 @@
<template>
<div class="default-main">
<div class="mb10" style="display: flex; justify-content: flex-end">
<el-upload
ref="upload"
action=""
:auto-upload="false"
:show-file-list="false"
:limit="1"
:on-change="beforeUpload"
>
<el-upload ref="upload" action="" :auto-upload="false" :show-file-list="false" :limit="1"
:on-change="beforeUpload">
<el-button icon="el-icon-Upload" type="primary" class="mr10">导入excel</el-button>
</el-upload>
<el-button @click="downloadExcel" class="" type="primary" icon="el-icon-Download">导出excel</el-button>
@@ -123,16 +117,25 @@ const submitForm = (formdata: any, text: string) => {
params.append('name', formdata.name)
params.append('reportType', formdata.reportType)
params.append('reportForm', formdata.reportForm)
ElMessage.info('正在保存请稍等!')
if (text == '新增报表模板') {
addTemplate(params).then(res => {
ElMessage.success('新增成功!')
formFer.value.shutDown()
emit('shutDown')
}).catch(err => {
ElMessage.error('保存失败!')
formFer.value.shutDown()
})
} else if (text == '编辑报表模板') {
params.append('id', list.value.id)
dateTemplateup(params).then(res => {
ElMessage.success('编辑成功!')
formFer.value.shutDown()
emit('shutDown')
}).catch(err => {
ElMessage.error('保存失败!')
formFer.value.shutDown()
})
}
}
@@ -147,7 +150,7 @@ const open = async (text: string, row?: any) => {
info()
}
defineExpose({ open })
onMounted(() => {})
onMounted(() => { })
</script>
<style lang="scss" scoped>
:deep(.el-tab-pane) {

View File

@@ -99,6 +99,9 @@ const open = (text: string, row?: any) => {
formVisible.value = true
}
defineExpose({ open })
const shutDown = () => {
formVisible.value = false
}
defineExpose({ open,shutDown})
</script>
<style lang="scss" scoped></style>

View File

@@ -125,16 +125,25 @@ const submitForm = (formdata: any, text: string) => {
params.append('name', formdata.name)
params.append('reportType', formdata.reportType)
params.append('reportForm', formdata.reportForm)
ElMessage.info('正在保存请稍等!')
if (text == '新增报表模板') {
addTemplate(params).then(res => {
ElMessage.success('新增成功!')
formFer.value.shutDown()
emit('shutDown')
}).catch(err => {
ElMessage.error('保存失败!')
formFer.value.shutDown()
})
} else if (text == '编辑报表模板') {
params.append('id', list.value.id)
dateTemplateup(params).then(res => {
ElMessage.success('编辑成功!')
formFer.value.shutDown()
emit('shutDown')
}).catch(err => {
ElMessage.error('保存失败!')
formFer.value.shutDown()
})
}
}