Files
app-govern/pages/device/APF/detail.vue

483 lines
18 KiB
Vue
Raw Normal View History

2023-02-06 13:34:15 +08:00
<template>
2023-07-24 08:47:20 +08:00
<Cn-page :loading="loading" noPadding>
<view slot="body">
<view class="detail">
2023-02-22 08:43:52 +08:00
<view class="detail-header">
2023-03-14 09:09:05 +08:00
<Cn-htmlToImg domId="header" @renderFinish="renderFinish">
<view class="header" ref="header" @click="previewImg">
2023-07-24 08:47:20 +08:00
<image :src="deviceInfo.filePath" style="width: 375px" mode="widthFix" />
<view
class="point"
:style="{ left: item.lat + 'px', top: item.lng + 'px' }"
v-for="(item, index) in showtTarget"
:key="index"
>
<view class="grid-card mt10" style="width: fit-content">
<view class="grid-card-content-1">
<view class="item">{{ item.label }}</view>
<view class="item" v-for="(child, childIndex) in item.value" :key="childIndex">
{{ child.showText }}
2023-03-08 13:45:57 +08:00
</view>
2023-02-23 08:44:46 +08:00
</view>
2023-03-14 09:09:05 +08:00
</view>
</view>
<view class="module">
<view class="grid-card">
<view class="grid-card-content-2">
<view class="item">模块一</view>
<view class="item">
<view class="status-point-success mr10"></view>
2023-07-24 08:47:20 +08:00
<view style="width: 30rpx"> 15 </view>
<view> °C </view>
2023-03-08 13:45:57 +08:00
</view>
2023-03-14 09:09:05 +08:00
<view class="item">模块二</view>
<view class="item">
<view class="status-point-error mr10"></view>
2023-07-24 08:47:20 +08:00
<view style="width: 30rpx"> 0 </view>
<view> °C </view>
2023-03-08 13:45:57 +08:00
</view>
2023-03-14 09:09:05 +08:00
<view class="item">模块三</view>
<view class="item">
<view class="status-point-success mr10"></view>
2023-07-24 08:47:20 +08:00
<view style="width: 30rpx"> 15 </view>
<view> °C </view>
2023-03-08 13:45:57 +08:00
</view>
2023-03-14 09:09:05 +08:00
<view class="item">模块四</view>
<view class="item">
<view class="status-point-success mr10"></view>
2023-07-24 08:47:20 +08:00
<view style="width: 30rpx"> 15 </view>
<view> °C </view>
2023-03-08 13:45:57 +08:00
</view>
2023-02-23 08:44:46 +08:00
</view>
</view>
</view>
</view>
2023-03-14 09:09:05 +08:00
</Cn-htmlToImg>
2023-02-22 08:43:52 +08:00
<!-- <view class="des">
<text>设备基础信息</text>
<text class="ml10">设备状态</text>
</view> -->
2023-07-24 08:47:20 +08:00
<view class="nav" style="margin-top: -10rpx">
<view
class="nav-menu"
:class="{ 'nav-menu-active': navMenuActive == index }"
v-for="(item, index) in navMenuList"
:key="index"
@click="navMenuClick(index)"
>{{ item.text }}
2023-02-22 08:43:52 +08:00
</view>
2023-02-06 13:34:15 +08:00
</view>
</view>
2023-02-23 08:44:46 +08:00
<view class="content">
2023-02-07 17:59:54 +08:00
<view v-if="navMenuActive == 0">
2023-07-24 08:47:20 +08:00
<basic :deviceInfo="deviceInfo"></basic>
2023-02-06 13:34:15 +08:00
</view>
2023-02-07 17:59:54 +08:00
<view v-else-if="navMenuActive == 1">
2023-02-06 13:34:15 +08:00
<xieBo></xieBo>
</view>
2023-02-07 17:59:54 +08:00
<view v-else-if="navMenuActive == 2">
2023-07-24 08:47:20 +08:00
<power :deviceInfo="deviceInfo"></power>
2023-02-06 13:34:15 +08:00
</view>
2023-02-07 17:59:54 +08:00
<view v-else-if="navMenuActive == 3">
<oscillogram></oscillogram>
2023-02-06 13:34:15 +08:00
</view>
2023-02-07 17:59:54 +08:00
<view v-else-if="navMenuActive == 4">
2023-07-24 08:47:20 +08:00
<IO :deviceInfo="deviceInfo"></IO>
2023-02-06 13:34:15 +08:00
</view>
2023-07-24 08:47:20 +08:00
<view style="height: 20rpx"></view>
2023-02-06 13:34:15 +08:00
</view>
2023-07-24 08:47:20 +08:00
<uni-fab
ref="fab"
direction="vertical"
horizontal="right"
vertical="bottom"
:content="content"
@trigger="trigger"
/>
2023-02-06 13:34:15 +08:00
</view>
</view>
</Cn-page>
</template>
<script>
2023-07-24 08:47:20 +08:00
import basic from './comp/basic.vue'
import xieBo from './comp/xieBo.vue'
import power from './comp/power.vue'
import oscillogram from './comp/oscillogram.vue'
import IO from './comp/IO.vue'
import { queryTopologyDiagram } from '@/common/api/device'
import { MQTT_IP, MQTT_OPTIONS } from '@/common/js/mqtt.js'
import mqtt from 'mqtt/dist/mqtt.js'
2023-02-06 13:34:15 +08:00
export default {
components: {
basic,
2023-02-07 17:59:54 +08:00
xieBo,
power,
oscillogram,
2023-02-23 08:44:46 +08:00
IO,
2023-02-06 13:34:15 +08:00
},
2023-07-24 08:47:20 +08:00
data() {
2023-02-06 13:34:15 +08:00
return {
2023-07-24 08:47:20 +08:00
loading: true,
deviceInfo: {},
2023-02-06 13:34:15 +08:00
navMenuActive: 0,
navHeight: 0,
2023-03-14 09:09:05 +08:00
img: '',
2023-07-24 08:47:20 +08:00
navMenuList: [
{
text: '基本',
},
{
text: '谐波',
},
{
text: '功率',
},
{
text: '波形',
},
{
text: 'I/O',
},
],
content: [
{
iconPath: '/static/report.png',
text: '告警',
},
{
iconPath: '/static/record.png',
text: '记录',
},
{
iconPath: '/static/about.png',
text: '关于',
},
],
client: null,
timer: null,
devId: '',
dictData: [],
2023-02-06 13:34:15 +08:00
}
},
2023-07-24 08:47:20 +08:00
computed: {
showtTarget() {
if (this.loading) {
return
}
let arr = JSON.parse(JSON.stringify(this.deviceInfo.appsLineTopologyDiagramPO))
arr.forEach((item) => {
item.value = item.value?.filter((item2) => {
return item2.showText
})
})
return arr
},
},
2023-02-06 13:34:15 +08:00
methods: {
2023-07-24 08:47:20 +08:00
trigger(e) {
console.log(e)
2023-02-09 16:37:53 +08:00
if (e.item.text === '分享') {
2023-02-07 17:59:54 +08:00
this.$refs.share.open()
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '删除') {
2023-02-07 17:59:54 +08:00
uni.showModal({
title: '提示',
content: '确定删除该设备吗?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
2023-07-24 08:47:20 +08:00
},
})
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '下载') {
2023-02-07 17:59:54 +08:00
this.$util.toast('下载成功')
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '记录') {
2023-02-10 09:16:17 +08:00
uni.navigateTo({ url: '/pages/device/APF/record' })
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '告警') {
2023-02-10 09:16:17 +08:00
uni.navigateTo({ url: '/pages/device/APF/report' })
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '关于') {
2023-02-10 09:16:17 +08:00
uni.navigateTo({ url: '/pages/device/APF/about' })
2023-02-09 16:37:53 +08:00
} else if (e.item.text === '移交') {
uni.navigateTo({ url: '/pages/device/transfer' })
} else if (e.item.text === '反馈') {
uni.navigateTo({ url: '/pages/device/feedback' })
2023-02-10 16:32:41 +08:00
} else if (e.item.text === '用户') {
uni.navigateTo({ url: '/pages/device/user' })
2023-02-23 08:44:46 +08:00
} else if (e.item.text === '报表') {
this.$util.toast('效果是直接打开报表')
2023-02-28 14:03:38 +08:00
} else if (e.item.text === '版本') {
2023-02-27 14:56:08 +08:00
this.$util.toast('功能暂未开放')
2023-02-28 14:03:38 +08:00
} else if (e.item.text === '模版') {
2023-02-27 14:56:08 +08:00
this.$util.toast('效果是功能暂未开放直接打开报表')
2023-02-07 17:59:54 +08:00
}
2023-02-09 16:37:53 +08:00
this.$refs.fab.close()
2023-02-07 17:59:54 +08:00
},
2023-07-24 08:47:20 +08:00
navMenuClick(idx) {
2023-02-06 13:34:15 +08:00
this.navMenuActive = idx
2023-02-23 08:44:46 +08:00
uni.pageScrollTo({ scrollTop: 0, duration: 0 })
2023-02-06 13:34:15 +08:00
},
2023-07-24 08:47:20 +08:00
init() {
2023-02-09 16:37:53 +08:00
let userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
2023-07-24 08:47:20 +08:00
console.log(userInfo.authorities)
2023-07-03 20:29:24 +08:00
switch (userInfo.authorities) {
2023-02-27 14:56:08 +08:00
case 1:
2023-03-01 08:51:06 +08:00
this.content.splice(0, 1)
2023-07-24 08:47:20 +08:00
this.content.splice(
0,
0,
{
iconPath: '/static/version.png',
text: '版本',
},
{
iconPath: '/static/template.png',
text: '模版',
},
)
break
2023-03-01 08:51:06 +08:00
case 2:
this.content.splice(0, 1)
2023-07-24 08:47:20 +08:00
break
2023-02-09 16:37:53 +08:00
case 3:
this.content.splice(0, 0, {
iconPath: '/static/transfer.png',
text: '移交',
})
2023-07-24 08:47:20 +08:00
break
2023-02-09 16:37:53 +08:00
case 4:
2023-07-24 08:47:20 +08:00
this.content.splice(
1,
0,
{
iconPath: '/static/delate.png',
text: '报表',
},
{
iconPath: '/static/table.png',
text: '删除',
},
{
iconPath: '/static/feedback.png',
text: '反馈',
},
)
break
2023-02-09 16:37:53 +08:00
case 5:
2023-07-24 08:47:20 +08:00
this.content.splice(
2,
0,
{
iconPath: '/static/table.png',
text: '报表',
},
{
iconPath: '/static/feedback.png',
text: '反馈',
},
)
break
2023-02-09 16:37:53 +08:00
default:
2023-07-24 08:47:20 +08:00
break
2023-02-09 16:37:53 +08:00
}
2023-03-08 13:45:57 +08:00
},
2023-07-24 08:47:20 +08:00
renderFinish(e) {
2023-03-14 09:09:05 +08:00
this.img = e
},
2023-07-24 08:47:20 +08:00
previewImg() {
2023-03-14 14:03:33 +08:00
if (!this.img) {
uni.showLoading({
title: '图片生成中',
2023-07-24 08:47:20 +08:00
mask: false,
2023-03-14 14:03:33 +08:00
})
setTimeout(() => {
this.previewImg()
2023-07-24 08:47:20 +08:00
}, 500)
2023-03-14 14:03:33 +08:00
} else {
uni.hideLoading()
uni.previewImage({
urls: [this.img],
})
}
2023-07-24 08:47:20 +08:00
},
initMqtt() {
MQTT_OPTIONS.clientId = uni.getStorageSync('devCode')
// #ifdef APP-PLUS
this.client = mqtt.connect('wx://' + MQTT_IP, MQTT_OPTIONS)
// #endif
// #ifdef H5
this.client = mqtt.connect('ws://' + MQTT_IP, MQTT_OPTIONS)
// #endif
this.client
.on('connect', () => {
console.log('连接成功')
this.client.subscribe(`/zl/devData/${this.devId}`, (err) => {
if (!err) {
console.log(`订阅成功:/zl/devData/${this.devId}`)
this.client.publish(`/zl/askDevData/${this.devId}`)
this.timer = setInterval(() => {
this.client.publish(`/zl/askDevData/${this.devId}`)
}, 10000)
}
})
})
.on('reconnect', function (error) {
console.log(error)
console.log('正在重连...', that.topic)
})
.on('error', function (error) {
console.log('连接失败...', error)
})
.on('end', function () {
console.log('连接断开')
})
.on('message', (topic, message) => {
console.log('接收推送信息:', message.toString())
this.loading = false
let dataList = []
this.deviceInfo.appsLineTopologyDiagramPO.forEach((element) => {
element.value = []
})
JSON.parse(message.toString()).forEach((item) => {
this.deviceInfo.appsLineTopologyDiagramPO.forEach((element) => {
if (element.linePostion === item.position) {
// element.value.push({
// label: item.statisticalName,
// value: item.statisticalData,
// })
element.value.push({
...item,
showText:
item.statisticalName.indexOf('ThdPh') > -1 && item.phase === 'avg'
? item.statisticalName + '' + item.statisticalData
: '',
})
}
})
})
this.$forceUpdate()
console.log(this.deviceInfo.appsLineTopologyDiagramPO)
})
},
},
// 页面销毁
onUnload() {
clearInterval(this.timer)
this.client.end()
2023-02-06 13:34:15 +08:00
},
2023-07-24 08:47:20 +08:00
onLoad(options) {
this.dictData = uni.getStorageSync(this.$cacheKey.dictData)
this.devId = options.id
2023-02-06 13:34:15 +08:00
this.init()
2023-07-24 08:47:20 +08:00
queryTopologyDiagram(options.id).then((res) => {
this.deviceInfo = res.data
console.log(this.dictData);
this.dictData.forEach((item) => {
if (item.code == 'Line_Position') {
item.children.forEach((item2) => {
this.deviceInfo.appsLineTopologyDiagramPO.forEach((element) => {
if (element.linePostion === item2.id) {
element.label = item2.name
}
})
})
}
})
this.initMqtt()
console.log(this.loading, 'loading')
// this.$nextTick(() => {
// // 获取nav高度
// uni.createSelectorQuery()
// .select('.nav')
// .boundingClientRect((rect) => {
// this.navHeight = rect.height
// })
// .exec()
// })
})
2023-02-06 13:34:15 +08:00
},
}
</script>
2023-03-14 09:09:05 +08:00
2023-07-24 08:47:20 +08:00
<style lang="scss">
2023-02-06 13:34:15 +08:00
.detail {
2023-02-07 17:59:54 +08:00
// background: $uni-theme-white;
2023-07-24 08:47:20 +08:00
.header-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-size: 100% 100%;
}
2023-02-23 08:44:46 +08:00
.header {
position: relative;
2023-07-24 08:47:20 +08:00
width: 375px;
margin: 0 auto;
2023-02-23 08:44:46 +08:00
2023-07-24 08:47:20 +08:00
image {
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: crisp-edges;
-ms-interpolation-mode: nearest-neighbor;
}
2023-02-23 08:44:46 +08:00
.point {
position: absolute;
color: #111;
z-index: 2;
text-align: center;
color: #111;
2023-03-08 13:45:57 +08:00
width: 110rpx;
font-size: 16rpx;
2023-07-24 08:47:20 +08:00
.grid-card-content-2,
.grid-card-content-1 {
2023-03-08 13:45:57 +08:00
font-size: 16rpx;
.item {
min-height: unset;
2023-07-24 08:47:20 +08:00
white-space: nowrap;
2023-03-08 13:45:57 +08:00
}
}
2023-02-23 08:44:46 +08:00
}
.module {
position: absolute;
bottom: 0;
2023-03-08 13:45:57 +08:00
right: 20rpx;
width: 200rpx;
2023-02-23 08:44:46 +08:00
2023-07-24 08:47:20 +08:00
.grid-card-content-2,
.grid-card-content-1 {
2023-03-08 13:45:57 +08:00
font-size: 16rpx;
2023-02-23 08:44:46 +08:00
.item {
min-height: unset;
}
}
}
}
2023-02-06 13:34:15 +08:00
.des {
padding: 20rpx 20rpx 0;
font-size: 28rpx;
color: #999;
}
.content {
box-sizing: border-box;
padding: 0 20rpx;
}
2023-02-23 08:44:46 +08:00
.detail-header {
2023-02-22 08:43:52 +08:00
position: sticky;
top: 0;
left: 0;
z-index: 2;
background: #f3f4f5;
}
2023-02-06 13:34:15 +08:00
}
2023-07-24 08:47:20 +08:00
</style>