feat:天平连接
This commit is contained in:
@@ -3,27 +3,16 @@
|
||||
<navbar-back title="天平状态"></navbar-back>
|
||||
<up-grid border :col="3">
|
||||
<up-grid-item v-for="(auncel, index) in auncelList" :index="index" :key="index">
|
||||
<view
|
||||
class="auncel-item"
|
||||
:style="{
|
||||
backgroundImage: `url(${require('@/static/images/auncel.png')})`
|
||||
}"
|
||||
>
|
||||
<view class="auncel-item" :style="{ backgroundImage: `url(${balanceBackground})` }">
|
||||
<view class="auncel-header">
|
||||
<view class="auncel-code">{{ auncel.code }}</view>
|
||||
<view class="auncel-code">{{ auncel.deviceCode }}</view>
|
||||
<view class="auncel-name">{{ auncel.controlRealName }}</view>
|
||||
</view>
|
||||
<view class="weight">
|
||||
<view
|
||||
:class="{
|
||||
'weight-data-yellow': auncel.weightStable === 0,
|
||||
'weight-data': auncel.weightStable === 1,
|
||||
'weight-data-warning': auncel.weightStable === 2
|
||||
}"
|
||||
>
|
||||
{{ auncel.weightData || '' }}
|
||||
<view :class="getWeightClass(auncel)" :style="getWeightStyle(auncel)">
|
||||
{{ getWeightText(auncel) }}
|
||||
</view>
|
||||
<view class="weight-unit">{{ auncel.weightUnit }}</view>
|
||||
<view v-if="auncel.isConnected === 1" class="weight-unit">{{ auncel.weightUnit }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</up-grid-item>
|
||||
@@ -36,6 +25,7 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { onUnload, onHide } from '@dcloudio/uni-app'
|
||||
import { getTenantId } from '@/defaultBaseUrl'
|
||||
import nx from '@/nx'
|
||||
const balanceBackground = new URL('/static/images/auncel.png', import.meta.url).href
|
||||
|
||||
// refs
|
||||
const auncelList = ref([])
|
||||
@@ -45,7 +35,7 @@ const userInfo = computed(() => nx.$store('user').userInfo)
|
||||
|
||||
// 页面加载
|
||||
onMounted(() => {
|
||||
// getPageData()
|
||||
getPageData()
|
||||
// #ifdef H5
|
||||
const regData = {
|
||||
msgId: nx.$helper.uuid(),
|
||||
@@ -87,24 +77,14 @@ function cleanup() {
|
||||
function getPageData() {
|
||||
nx.$api.laboratory
|
||||
.getDeviceLaboratoryListBy({
|
||||
deviceType: 'auncel',
|
||||
status: '1',
|
||||
isEnable: '1',
|
||||
pageNo: 0,
|
||||
pageSize: -1
|
||||
pageNo: 1,
|
||||
pageSize: 999,
|
||||
collectDeviceType: 'balance',
|
||||
deviceStatus: '0',
|
||||
isEnable: '1'
|
||||
})
|
||||
.then(res => {
|
||||
const dataList = res.records || []
|
||||
dataList.forEach(i => {
|
||||
i.weightData = ''
|
||||
i.weightUnit = ''
|
||||
i.isConnected = 0
|
||||
i.weightStable = 0
|
||||
i.temperature = 0
|
||||
i.humidity = 0
|
||||
i.controlRealName = ''
|
||||
})
|
||||
auncelList.value = dataList
|
||||
auncelList.value = res.list
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('获取天平列表失败', err)
|
||||
@@ -113,46 +93,71 @@ function getPageData() {
|
||||
|
||||
// WebSocket 事件处理器
|
||||
function handleDeviceData(res) {
|
||||
if (res.deviceType !== 'auncel') return
|
||||
auncelList.value = auncelList.value.map(item => {
|
||||
if (item.id === res.deviceId) {
|
||||
return {
|
||||
...item,
|
||||
weightData: res.weightData,
|
||||
weightUnit: res.weightUnit,
|
||||
weightStable: res.weightStable,
|
||||
isConnected: 1,
|
||||
controlRealName: res.controlRealName
|
||||
if (res.deviceType === 'balance') {
|
||||
auncelList.value.forEach(item => {
|
||||
if (item.id === res.deviceId) {
|
||||
item.weightData = res.weightData
|
||||
item.weightUnit = res.weightUnit
|
||||
item.weightStable = res.weightStable
|
||||
item.isConnected = 1
|
||||
item.controlRealName = res.controlRealName
|
||||
}
|
||||
}
|
||||
return item
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function handleDeviceStatus(res) {
|
||||
auncelList.value = auncelList.value.map(item => {
|
||||
if (item.id === res.deviceId) {
|
||||
const updated = { ...item, isConnected: res.connected }
|
||||
if (res.connected === 0) {
|
||||
updated.weightData = '天平断开'
|
||||
updated.weightUnit = ''
|
||||
updated.weightStable = 0
|
||||
if (res.deviceType === 'balance') {
|
||||
auncelList.value.forEach(item => {
|
||||
if (item.id === res.deviceId) {
|
||||
item.isConnected = res.connected
|
||||
if (res.connected == 0) {
|
||||
item.weightData = '天平断开'
|
||||
item.weightUnit = ''
|
||||
item.weightStable = 0
|
||||
}
|
||||
}
|
||||
return updated
|
||||
}
|
||||
return item
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function handleConnClose() {
|
||||
auncelList.value = auncelList.value.map(i => ({
|
||||
...i,
|
||||
weightData: '',
|
||||
weightUnit: '',
|
||||
weightStable: 0,
|
||||
controlRealName: '',
|
||||
isConnected: 0
|
||||
}))
|
||||
auncelList.value.forEach(item => {
|
||||
item.weightData = ''
|
||||
item.weightUnit = ''
|
||||
item.weightStable = 0
|
||||
item.controlRealName = ''
|
||||
item.isConnected = 0
|
||||
})
|
||||
}
|
||||
|
||||
function getWeightText(auncel) {
|
||||
if (auncel.isConnected !== 1) {
|
||||
return '天平断开'
|
||||
}
|
||||
return auncel.weightData || ''
|
||||
}
|
||||
|
||||
function getWeightClass(auncel) {
|
||||
if (auncel.weightStable === 0) return 'weight-data-yellow'
|
||||
if (auncel.weightStable === 1) return 'weight-data'
|
||||
if (auncel.weightStable === 2) return 'weight-data-warning'
|
||||
return 'weight-data-yellow'
|
||||
}
|
||||
|
||||
function getWeightStyle(auncel) {
|
||||
if (auncel.isConnected !== 1) {
|
||||
return {
|
||||
textAlign: 'center',
|
||||
paddingTop: '0',
|
||||
fontSize: '28px'
|
||||
}
|
||||
}
|
||||
return {
|
||||
textAlign: 'right',
|
||||
paddingTop: '10px',
|
||||
fontSize: '32px'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -170,7 +175,6 @@ function handleConnClose() {
|
||||
}
|
||||
|
||||
.auncel-header {
|
||||
height: 100px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
@@ -184,27 +188,18 @@ function handleConnClose() {
|
||||
|
||||
.auncel-name {
|
||||
margin-top: 5px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.weight {
|
||||
width: 100%;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
height: 60px;
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.weight-data,
|
||||
.weight-data-yellow,
|
||||
.weight-data-warning {
|
||||
flex-grow: 1;
|
||||
height: 100%;
|
||||
text-align: right;
|
||||
line-height: 40px;
|
||||
letter-spacing: 2px;
|
||||
font-size: 32px;
|
||||
font-family: zzjc-lcd;
|
||||
}
|
||||
|
||||
@@ -221,9 +216,10 @@ function handleConnClose() {
|
||||
}
|
||||
|
||||
.weight-unit {
|
||||
position: absolute;
|
||||
right: 3px;
|
||||
top: 8px;
|
||||
color: #ffffff;
|
||||
font-size: 24px;
|
||||
line-height: 40px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user