feat:天平连接

This commit is contained in:
houjunxiang
2025-10-10 18:16:14 +08:00
parent 2b50debcd3
commit c8b2d8683e
16 changed files with 182 additions and 622 deletions

View File

@@ -7,23 +7,15 @@
<u-grid-item v-for="(auncel, index) in auncelList" :index="index" :key="index">
<view class="auncel-item">
<view class="auncel-name">
{{ auncel.code }}
{{ auncel.deviceCode }}
<view style="text-align: center">{{ auncel.controlRealName }}</view>
</view>
<view class="weight">
<view
:class="
auncel.weightStable === 0
? 'weight-data-yellow'
: auncel.weightStable === 1
? 'weight-data'
: 'weight-data-warning'
"
>
{{ 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>
</u-grid-item>
@@ -72,30 +64,19 @@ const close = () => {
const getPageData = () => {
nx.$api.laboratory
.getDeviceLaboratoryListBy({
deviceType: 'auncel',
pageNo: 0,
pageSize: -1,
status: '1',
pageNo: 1,
pageSize: 999,
collectDeviceType: 'balance',
deviceStatus: '0',
isEnable: '1'
})
.then(res => {
const dataList = res.records.map(item => ({
...item,
weightData: '',
weightUnit: '',
isConnected: 0,
weightStable: 0,
temperature: 0,
humidity: 0,
controlRealName: ''
}))
auncelList.value = dataList
auncelList.value = res.list
})
}
const doSelect = index => {
const currentAuncel = auncelList.value[index]
if (currentAuncel.isConnected !== 1) {
uni.showToast({ title: '天平设备尚未连接!', icon: 'none' })
return
@@ -121,8 +102,8 @@ const doSelect = index => {
clientType: 'caaClient',
data: {
deviceId: currentAuncel.id,
deviceCode: currentAuncel.code,
deviceName: currentAuncel.name,
deviceCode: currentAuncel.deviceCode,
deviceName: currentAuncel.productName,
isControl: true,
controlRealName: userInfo.value.nickname
}
@@ -164,29 +145,32 @@ const listenDeviceData = () => {
}
const handleDeviceData = res => {
if (res.deviceType !== 'auncel') return
auncelList.value.forEach(item => {
if (item.id === res.deviceId) {
item.weightData = res.weightData ?? ''
item.weightUnit = res.weightUnit ?? ''
item.weightStable = res.weightStable ?? 0
item.isConnected = 1
item.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
}
})
}
}
const handleDeviceStatus = res => {
auncelList.value.forEach(item => {
if (item.id === res.deviceId) {
item.isConnected = res.connected ?? 0
if (res.connected === 0) {
item.weightData = '天平断开'
item.weightUnit = ''
item.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
}
}
}
})
})
}
}
const handleConnClose = () => {
@@ -213,6 +197,32 @@ onMounted(() => {
onUnmounted(() => {
closeDeviceListener()
})
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',
fontSize: '28px'
}
}
return {
textAlign: 'right',
fontSize: '32px'
}
}
</script>
<style scoped lang="scss">
@@ -236,33 +246,34 @@ onUnmounted(() => {
}
.weight {
flex: 1;
display: flex;
flex-direction: row;
font-size: 32px;
letter-spacing: 2px;
font-size: 28px;
padding-top: 10px;
padding: 10px 30px 0 30px;
position: relative;
}
.weight-data,
.weight-data-yellow,
.weight-data-warning {
font-family: zzjc-lcd;
}
.weight-data {
flex: 1;
color: #4cd964;
text-align: right;
font-family: zzjc-lcd;
}
.weight-data-yellow {
flex: 1;
color: #ffff00;
text-align: center;
font-family: zzjc-lcd;
}
.weight-data-warning {
color: #ff3333;
text-align: right;
font-family: zzjc-lcd;
}
.weight-unit {
position: absolute;
right: 10px;
top: 10px;
color: #ffffff;
font-size: 24px;
padding: 0 10px;
font-size: 20px;
}
@media (max-width: 700px) {
.auncel-item {

View File

@@ -64,6 +64,7 @@ const props = defineProps({
}
})
const emit = defineEmits(['update:showPopup'])
// Data
const curSample = ref({})
const curParameterKey = ref('')
@@ -79,7 +80,7 @@ const getAllIndexes = arr => {
}
const close = () => {
uni.$emit('sample-detail-popup_close')
emit('update:showPopup', false)
}
const getSampleData = () => {