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

@@ -1,257 +0,0 @@
<template>
<view>
<navbar-back title="选择天平"></navbar-back>
<u-grid :col="3" @click="click">
<u-grid-item v-for="(auncel, index) in auncelList" :index="index" :key="index">
<view
style="
height: 180px;
width: 180px;
background-image: url(../../static/images/auncel.png);
background-repeat: no-repeat;
background-size: 100%;
"
>
<view style="height: 100px">
<view style="padding-top: 20px; text-align: center; font-size: 20rpx"
><text>{{ auncel.code }}</text></view
>
<view style="padding-top: 5px; text-align: center"
><text>{{ auncel.controlRealName }}</text></view
>
</view>
<view class="weight">
<view
:class="
auncel.weightStable == 0
? 'weight-data-yellow'
: auncel.weightStable == 1
? 'weight-data'
: 'weight-data-warning'
"
>
{{ auncel.weightData }}
</view>
<view class="weight-unit">{{ auncel.weightUnit }}</view>
</view>
</view>
</u-grid-item>
</u-grid>
</view>
</template>
<script>
export default {
data() {
return {
auncelList: [],
currentAuncel: '',
currentTaskNo: '',
currentTaskType: ''
}
},
onLoad(param) {
this.currentTaskNo = param.currentTaskNo
this.currentTaskType = param.currentTaskType
//获取数据
this.getPageData()
console.log('onLoad')
},
onShow() {
console.log('onShow')
// #ifdef H5
//注册websocket
let regData = {
msgId: this.$helper.uuid(),
cmd: 'register',
clientType: 'caaClient',
data: {
userId: this.userInfo.user_id,
tenantId: this.userInfo.tenant_id,
userRealName: this.userInfo.real_name
}
}
this.$measure.setRegData(JSON.stringify(regData))
this.$measure.reOpen()
// #endif
//监听websocket返回来的数据
//设备数据
uni.$on('deviceData', res => {
switch (res.deviceType) {
case 'auncel':
this.auncelList.forEach((item, index) => {
if (item.id === res.deviceId) {
item.weightData = res.weightData
item.weightUnit = res.weightUnit
item.weightStable = res.weightStable
item.isConnected = 1
item.controlRealName = res.controlRealName
}
})
break
default:
break
}
})
//设备状态
uni.$on('deviceStatus', res => {
this.auncelList.forEach((item, index) => {
if (item.id === res.deviceId) {
item.isConnected = res.connected
if (res.connected == 0) {
item.weightData = '天平断开'
item.weightUnit = ''
item.weightStable = 0
}
}
})
})
//连接断开
uni.$on('connClose', res => {
//重置
this.auncelList.forEach(i => {
i.weightData = ''
i.weightUnit = ''
i.weightStable = 0
i.controlRealName = ''
i.isConnected = 0
})
})
},
onHide() {
console.log('onHide')
//移除监听websocket返回来的数据
uni.$off('deviceData')
uni.$off('deviceStatus')
uni.$off('connClose')
},
methods: {
getPageData() {
//显示loading
uni.showLoading({
title: '加载中...'
})
//获取计量点数量
this.$u.api
.getDeviceLaboratoryListBy({
deviceType: 'auncel',
pageNo: 0,
pageSize: -1,
status: '1',
isEnable: '1'
})
.then(res => {
let dataList = res.result.records
dataList.forEach(i => {
i.weightData = ''
i.weightUnit = ''
i.isConnected = 0
i.weightStable = 0
i.temperature = 0
i.humidity = 0
i.controlRealName = ''
})
this.auncelList = dataList
uni.hideLoading()
})
.catch(err => {
uni.hideLoading()
console.log(err)
})
},
click(index) {
// this.$refs.uToast.show({
// title: `点击了第${index + 1}宫格`,
// type: 'warning'
// });
console.log(this.auncelList[index])
this.currentAuncel = this.auncelList[index]
if (this.currentAuncel.isConnected != 1) {
this.$helper.showToast({
title: '天平设备尚未连接!'
})
return
}
if (this.currentAuncel.controlRealName && this.currentAuncel.controlRealName != this.userInfo.real_name) {
this.$helper.showToast({
title: '当前天平正被“' + this.currentAuncel.controlRealName + '”使用,请选择其他天平!'
})
return
}
//发送控制请求
let controlDevice = {
msgId: this.currentAuncel.id,
cmd: 'controlDevice',
clientType: 'caaClient',
data: {
deviceId: this.currentAuncel.id,
isControl: true,
controlRealName: this.userInfo.real_name
}
}
//发送控制数据
this.$measure.send(JSON.stringify(controlDevice))
uni.redirectTo({
url:
'/pages/auncel/auncel-weigh?currentTaskNo=' +
this.currentTaskNo +
'&currentTaskType=' +
this.currentTaskType +
'&currentAuncelId=' +
this.currentAuncel.id +
'&currentAuncelName=' +
this.currentAuncel.name +
'&currentAuncelCode=' +
this.currentAuncel.code
})
}
}
}
</script>
<style>
.weight {
width: 180px;
height: 40px;
padding: 0 10px;
display: flex;
flex-direction: row;
box-sizing: border-box;
}
.weight-data {
flex-grow: 1;
height: 100%;
color: #4cd964;
text-align: right;
line-height: 40px;
letter-spacing: 2px;
font-size: 32px;
font-family: zzjc-lcd;
}
.weight-data-yellow {
flex-grow: 1;
height: 100%;
color: #ffff00;
text-align: right;
line-height: 40px;
letter-spacing: 2px;
font-size: 32px;
font-family: zzjc-lcd;
}
.weight-data-warning {
flex-grow: 1;
height: 100%;
color: #ff3333;
text-align: right;
line-height: 40px;
font-size: 32px;
font-family: zzjc-lcd;
}
.weight-unit {
color: #ffffff;
font-size: 24px;
line-height: 40px;
padding-left: 10px;
}
</style>

View File

@@ -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>

View File

@@ -117,7 +117,7 @@
<!-- 样品详情 -->
<sample-detail-popup
ref="sampleDetailPopup"
:showPopup="showDetailPopup"
v-model:showPopup="showDetailPopup"
:detailPopupParam="detailPopupParam"
></sample-detail-popup>
</view>
@@ -324,11 +324,6 @@ const printTask = () => {
onMounted(() => {
getDicSampleProcessCodeList()
getAssayTask()
// 监听 popup 关闭
uni.$on('sample-detail-popup_close', () => {
showDetailPopup.value = false
})
})
onBackPress(() => {

View File

@@ -72,6 +72,7 @@
<view class="auncel-weight">
<view class="weight">
<view
:style="{ textAlign: currentAuncel.isConnected != 1 ? 'center' : 'right' }"
:class="
currentAuncel.weightStable === 0
? 'weight-data-yellow'
@@ -89,7 +90,7 @@
<u-button
class="btn-operation"
v-if="currentAuncel.code === ''"
v-if="currentAuncel.code !== ''"
type="success"
:disabled="confirmWeightDisabled"
shape="circle"
@@ -200,6 +201,7 @@
<script setup>
import { ref, reactive, computed, nextTick, onMounted } from 'vue'
import { onLoad, onBackPress, onShow, onHide, onUnload } from '@dcloudio/uni-app'
import request from '@/nx/request'
import { calcAnalysisValue } from '@/nx/helper/calcAnalysisValue'
import { number } from 'mathjs'
@@ -207,6 +209,7 @@ import AuncelSelectPopup from '@/components/sample/auncel-select-popup.vue'
import { getTenantId } from '@/defaultBaseUrl'
import { useScreenOrientation } from '@/nx/hooks/useScreenOrientation'
import nx from '@/nx'
import text from '@/uview-plus/components/u-text/text'
// 响应式数据定义
const elId = nx.$helper.uuid()
@@ -944,7 +947,7 @@ const listenDeviceData = () => {
//设备数据
uni.$on('deviceData', res => {
switch (res.deviceType) {
case 'auncel':
case 'balance':
if (currentAuncel.id === res.deviceId) {
currentAuncel.weightData = res.weightData
currentAuncel.weightUnit = res.weightUnit
@@ -1233,7 +1236,7 @@ onBackPress(() => {
}
.auncel {
width: 100%;
width: 90%;
height: 55vh;
background-image: url(/static/images/auncel.png);
background-repeat: no-repeat;
@@ -1263,31 +1266,29 @@ onBackPress(() => {
.weight {
font-size: 42px;
width: 100%;
padding-right: 10px;
padding: 0 60px;
}
.weight-data {
color: #4cd964;
text-align: right;
font-family: zzjc-lcd;
}
.weight-data-yellow {
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: 30px;
color: #ffffff;
font-size: 32px;
padding-right: 30px;
}
@media (max-width: 700px) {
.auncel {

View File

@@ -80,7 +80,7 @@
<script setup>
import { ref, computed } from 'vue'
import request from '@/nx/request'
import { cloneDeep } from 'lodash-es'
import { cloneDeep } from 'lodash'
import { calcAnalysisValue } from '@/nx/helper/calcAnalysisValue'
import nx from '@/nx'
import { onLoad } from '@dcloudio/uni-app'

View File

@@ -198,17 +198,9 @@ const applyRollbackSample = () => {
taskId: currentTask.value.id,
detailIds: detailIdList.join(',')
}
uni.showLoading({ title: '正在发起申请...' })
nx.$api.assayTask
.createRollbackApply(data)
.then(() => {
getAssayTaskDetail(currentTaskNo.value)
})
.catch(console.error)
.finally(() => {
uni.hideLoading()
})
nx.$api.assayTask.createRollbackApply(data).then(() => {
getAssayTaskDetail(currentTaskNo.value)
})
}
})
}