重构
This commit is contained in:
@ -41,9 +41,9 @@
|
||||
</view>
|
||||
</uni-group>
|
||||
<!-- 设备数据 -->
|
||||
<uni-group mode="card" class="data-card-group">
|
||||
<uni-row v-for="(infoDataItem,infoDataIndex) in infoData" :key="infoDataIndex+'infoData'"
|
||||
class="data-row">
|
||||
<uni-group mode="card" class="data-card-group">
|
||||
<uni-row v-for="(infoDataItem,infoDataIndex) in infoData" :key="infoDataIndex+'infoData'"
|
||||
class="data-row">
|
||||
<uni-col :span="8">
|
||||
<view class="title">{{infoDataItem.label}}</view>
|
||||
</uni-col>
|
||||
@ -51,37 +51,12 @@
|
||||
<view class="value">{{item[infoDataItem.attr] | formatNumber}}
|
||||
<text v-if="infoDataItem.unit" v-html="infoDataItem.unit"></text>
|
||||
</view>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</uni-group>
|
||||
<!-- 子设备表格 -->
|
||||
<uni-group mode="card" class="child-card-group" style="margin-bottom:20rpx;">
|
||||
<uni-table border stripe emptyText="暂无数据" class="child-table">
|
||||
<!-- 表头行 -->
|
||||
<uni-tr>
|
||||
<uni-th align="center">名称</uni-th>
|
||||
<uni-th align="center">单体平均值</uni-th>
|
||||
<uni-th align="center">单体最小值</uni-th>
|
||||
<uni-th align="center">单体最小值ID</uni-th>
|
||||
<uni-th align="center">单体最大值</uni-th>
|
||||
<uni-th align="center">单体最大值ID</uni-th>
|
||||
</uni-tr>
|
||||
<!-- 表格数据行 -->
|
||||
<uni-tr v-for="(tableItem, tableIndex) in item.batteryDataList"
|
||||
:key="tableIndex+'batteryDataList'">
|
||||
<uni-td align="center"
|
||||
v-html="`${tableItem.dataName}(${unitObj[tableItem.dataName]})`"></uni-td>
|
||||
<uni-td align="center">{{tableItem.avgData}}</uni-td>
|
||||
<uni-td align="center">{{tableItem.minData}}</uni-td>
|
||||
<uni-td align="center">{{tableItem.minDataID}}</uni-td>
|
||||
<uni-td align="center">{{tableItem.maxData}}</uni-td>
|
||||
<uni-td align="center">{{tableItem.maxDataID}}</uni-td>
|
||||
</uni-tr>
|
||||
</uni-table>
|
||||
</uni-group>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
</uni-col>
|
||||
</uni-row>
|
||||
</uni-group>
|
||||
</view>
|
||||
</uni-collapse-item>
|
||||
</uni-collapse>
|
||||
<view class="no-data" v-else>
|
||||
暂无数据
|
||||
</view>
|
||||
@ -89,14 +64,16 @@
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
getBMSBatteryCluster
|
||||
} from '@/api/ems/site.js'
|
||||
import {
|
||||
mapState
|
||||
} from 'vuex'
|
||||
export default {
|
||||
<script>
|
||||
import {
|
||||
getProjectDisplayData,
|
||||
getStackNameList,
|
||||
getClusterNameList
|
||||
} from '@/api/ems/site.js'
|
||||
import {
|
||||
mapState
|
||||
} from 'vuex'
|
||||
export default {
|
||||
computed: {
|
||||
...mapState({
|
||||
CLUSTERWorkStatusOptions: (state) =>
|
||||
@ -105,16 +82,13 @@
|
||||
state.ems.communicationStatusOptions,
|
||||
})
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
unitObj: {
|
||||
'电压': 'V',
|
||||
'温度': '℃',
|
||||
'SOC': '%'
|
||||
},
|
||||
list: [],
|
||||
siteId: '',
|
||||
infoData: [{
|
||||
data() {
|
||||
return {
|
||||
displayData: [],
|
||||
clusterDeviceList: [],
|
||||
list: [],
|
||||
siteId: '',
|
||||
infoData: [{
|
||||
label: '簇电压',
|
||||
attr: 'clusterVoltage',
|
||||
unit: 'V',
|
||||
@ -178,36 +152,157 @@
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleCardClass(item) {
|
||||
const {
|
||||
workStatus = ''
|
||||
} = item
|
||||
return !(Object.keys(this.CLUSTERWorkStatusOptions).includes(item.workStatus)) ? "timing-collapse-item" :
|
||||
workStatus === '9' ? 'warning-collapse-item' : 'running-collapse-item'
|
||||
},
|
||||
},
|
||||
onLoad(options) {
|
||||
uni.showLoading()
|
||||
this.siteId = options.siteId || ''
|
||||
getBMSBatteryCluster({
|
||||
siteId: this.siteId
|
||||
}).then(response => {
|
||||
this.list = response?.data || []
|
||||
if (this.list.length > 0) {
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
// this.$refs.collapse.resize()
|
||||
uni.hideLoading()
|
||||
}, 100)
|
||||
})
|
||||
} else {
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
}).catch(() => {
|
||||
uni.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
methods: {
|
||||
handleCardClass(item) {
|
||||
const {
|
||||
workStatus = ''
|
||||
} = item
|
||||
return !(Object.keys(this.CLUSTERWorkStatusOptions).includes(item.workStatus)) ? "timing-collapse-item" :
|
||||
workStatus === '9' ? 'warning-collapse-item' : 'running-collapse-item'
|
||||
},
|
||||
getModuleRows(menuCode, sectionName) {
|
||||
return (this.displayData || []).filter(item => item.menuCode === menuCode && item.sectionName === sectionName)
|
||||
},
|
||||
getFieldName(fieldCode) {
|
||||
const raw = String(fieldCode || '').trim()
|
||||
if (!raw) return ''
|
||||
const index = raw.lastIndexOf('__')
|
||||
return index >= 0 ? raw.slice(index + 2) : raw
|
||||
},
|
||||
getFieldRowMap(rows = [], deviceId = '') {
|
||||
const map = {}
|
||||
const targetDeviceId = String(deviceId || '')
|
||||
rows.forEach(item => {
|
||||
if (!item || !item.fieldCode) return
|
||||
const itemDeviceId = String(item.deviceId || '')
|
||||
if (itemDeviceId !== targetDeviceId) return
|
||||
const fieldName = this.getFieldName(item.fieldCode)
|
||||
map[fieldName] = item
|
||||
const displayName = String(item.fieldName || '').trim()
|
||||
if (displayName && !map[displayName]) {
|
||||
map[displayName] = item
|
||||
}
|
||||
})
|
||||
rows.forEach(item => {
|
||||
if (!item || !item.fieldCode) return
|
||||
const itemDeviceId = String(item.deviceId || '')
|
||||
if (itemDeviceId !== '') return
|
||||
const fieldName = this.getFieldName(item.fieldCode)
|
||||
if (map[fieldName] === undefined || map[fieldName] === null || map[fieldName] === '') {
|
||||
map[fieldName] = item
|
||||
}
|
||||
const displayName = String(item.fieldName || '').trim()
|
||||
if (displayName && !map[displayName]) {
|
||||
map[displayName] = item
|
||||
}
|
||||
})
|
||||
return map
|
||||
},
|
||||
getFieldMap(rows = [], deviceId = '') {
|
||||
const rowMap = this.getFieldRowMap(rows, deviceId)
|
||||
return Object.keys(rowMap).reduce((acc, fieldName) => {
|
||||
const row = rowMap[fieldName]
|
||||
if (acc[fieldName] === undefined) {
|
||||
acc[fieldName] = row?.fieldValue
|
||||
}
|
||||
return acc
|
||||
}, {})
|
||||
},
|
||||
getLatestTime(menuCode) {
|
||||
const times = (this.displayData || [])
|
||||
.filter(item => item.menuCode === menuCode && item.valueTime)
|
||||
.map(item => new Date(item.valueTime).getTime())
|
||||
.filter(ts => !isNaN(ts))
|
||||
if (times.length === 0) {
|
||||
return '-'
|
||||
}
|
||||
const date = new Date(Math.max(...times))
|
||||
const p = (n) => String(n).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${p(date.getMonth() + 1)}-${p(date.getDate())} ${p(date.getHours())}:${p(date.getMinutes())}:${p(date.getSeconds())}`
|
||||
},
|
||||
getClusterDeviceList() {
|
||||
return getStackNameList(this.siteId)
|
||||
.then(response => {
|
||||
const stackList = response?.data || []
|
||||
if (!stackList.length) {
|
||||
this.clusterDeviceList = []
|
||||
return
|
||||
}
|
||||
const requests = stackList.map(stack => {
|
||||
const stackDeviceId = stack.deviceId || stack.id || ''
|
||||
return getClusterNameList({
|
||||
stackDeviceId,
|
||||
siteId: this.siteId
|
||||
})
|
||||
.then(clusterResponse => {
|
||||
const clusterList = clusterResponse?.data || []
|
||||
return clusterList.map(cluster => ({
|
||||
...cluster,
|
||||
parentDeviceName: stack.deviceName || stack.name || stackDeviceId || '',
|
||||
}))
|
||||
})
|
||||
.catch(() => [])
|
||||
})
|
||||
return Promise.all(requests).then(results => {
|
||||
this.clusterDeviceList = results.flat()
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
this.clusterDeviceList = []
|
||||
})
|
||||
},
|
||||
buildList() {
|
||||
const devices = (this.clusterDeviceList && this.clusterDeviceList.length > 0) ? this.clusterDeviceList : [{
|
||||
deviceId: this.siteId,
|
||||
deviceName: 'BMS电池簇',
|
||||
parentDeviceName: ''
|
||||
}]
|
||||
this.list = devices.map(device => {
|
||||
const deviceId = device.deviceId || device.id || this.siteId
|
||||
const infoMap = this.getFieldMap(this.getModuleRows('SBJK_BMSDCC', '簇信息'), deviceId)
|
||||
const statusMap = this.getFieldMap(this.getModuleRows('SBJK_BMSDCC', '状态'), deviceId)
|
||||
return {
|
||||
...infoMap,
|
||||
workStatus: statusMap.workStatus,
|
||||
pcsCommunicationStatus: statusMap.pcsCommunicationStatus,
|
||||
emsCommunicationStatus: statusMap.emsCommunicationStatus,
|
||||
currentSoc: infoMap.currentSoc,
|
||||
siteId: this.siteId,
|
||||
deviceId,
|
||||
parentDeviceName: device.parentDeviceName || '',
|
||||
deviceName: device.deviceName || device.name || device.deviceId || device.id || 'BMS电池簇',
|
||||
dataUpdateTime: this.getLatestTime('SBJK_BMSDCC'),
|
||||
alarmNum: 0,
|
||||
}
|
||||
})
|
||||
},
|
||||
updateData() {
|
||||
return Promise.all([
|
||||
getProjectDisplayData(this.siteId),
|
||||
this.getClusterDeviceList()
|
||||
]).then(([displayResponse]) => {
|
||||
this.displayData = displayResponse?.data || []
|
||||
this.buildList()
|
||||
}).catch(() => {
|
||||
this.displayData = []
|
||||
this.list = []
|
||||
})
|
||||
},
|
||||
},
|
||||
onLoad(options) {
|
||||
uni.showLoading()
|
||||
this.siteId = options.siteId || ''
|
||||
this.updateData().finally(() => {
|
||||
if (this.list.length > 0) {
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
}, 100)
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.hideLoading()
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user