Browse Source

fix:自检重构

master
guoapeng 2 months ago
parent
commit
a59fec47a2
  1. 17
      src/assets/styles/element.scss
  2. 0
      src/components/Stop/index.vue
  3. 393
      src/components/check/index.vue
  4. 318
      src/components/check1/index.vue
  5. 32
      src/layouts/default.vue
  6. 2
      src/libs/utils.ts
  7. 3
      src/router/index.ts
  8. 4
      src/views/container/liquidItem.vue
  9. 2
      tsconfig.json

17
src/assets/styles/element.scss

@ -41,4 +41,21 @@
.el-icon {
margin: 0;
}
}
.init-message {
.el-message-box__content {
.el-message-box__container {
align-items: flex-start;
ul {
padding-left: 10px;
font-size: 15px;
li {
font-weight: 700;
color: #FE0A0A;
}
}
}
}
}

0
src/components/home/Stop/index.vue → src/components/Stop/index.vue

393
src/components/check/index.vue

@ -1,313 +1,156 @@
<script lang="ts" setup>
import { getSelfFinish, getSelfStatus } from '@/apis/self'
import { ElMessage } from 'element-plus'
import { getSelfFinish, getSelfStatus } from 'apis/self'
import { socket } from 'libs/socket'
import { useHomeStore } from 'stores/homeStore'
import { useSystemStore } from 'stores/systemStore'
import { onMounted, onUnmounted, ref } from 'vue'
import { onMounted, ref } from 'vue'
interface SelfStatus {
name: string
isOrign: boolean
value: string
type: string
}
const emits = defineEmits(['close'])
const homeStore = useHomeStore()
const systemStore = useSystemStore()
const loading = ref(false)
onMounted(() => {
socket.init(receiveMessage, 'cmd_debug')
socket.init(receiveMessage, 'cmd_response')
onStartSelfTest()
})
onUnmounted(() => {
clearInterval(patrolTimes.value)
socket.unregisterCallback(receiveMessage, 'cmd_debug')
socket.unregisterCallback(receiveMessage, 'cmd_response')
})
const receiveMessage = (data: Socket.cmdData) => {
data.commandId === currentCommandId && systemStore.pushSystemList(data)
}
const onStartSelfTest = () => {
patrolSelfStatus()
}
const statusMap: Record<string, Record<string, string>> = {
doorOrigin: {
name: '门',
value: '',
type: 'door',
},
shakeOrigin: {
name: '摇匀电机',
value: '',
type: 'shake',
},
gantryXOrigin: {
name: '机械臂x轴',
value: 'x',
type: 'axis',
},
gantryYOrigin: {
name: '机械臂y轴',
value: 'y',
type: 'axis',
},
gantryZOrigin: {
name: '机械臂z轴',
value: 'z',
type: 'axis',
},
dualRobotOrigin: {
name: '加液机械臂',
value: '',
type: 'liquid',
},
// dualRobotJoint2Origin: {
// name: '02',
// value: 'smallArm',
// type: 'liquid',
// },
capLiftingOrigin: {
name: '拍子电机升降',
value: '',
type: 'cap',
},
trayLifting01Origin: {
name: '加热区01托盘升降',
value: 'heat_module_01',
type: 'heat',
},
trayLifting02Origin: {
name: '加热区02托盘升降',
value: 'heat_module_02',
type: 'heat',
},
trayLifting03Origin: {
name: '加热区03托盘升降',
value: 'heat_module_03',
type: 'heat',
},
trayLifting04Origin: {
name: '加热区04托盘升降',
value: 'heat_module_04',
type: 'heat',
},
trayLifting05Origin: {
name: '加热区05托盘升降',
value: 'heat_module_05',
type: 'heat',
},
trayLifting06Origin: {
name: '加热区06托盘升降',
value: 'heat_module_06',
type: 'heat',
},
}
const patrolTimes = ref()
const patrolSelfStatus = () => {
loading.value = true
patrolTimes.value = setInterval(() => {
querySelfStatus()
}, 1000)
}
const deviceStatusList = ref<SelfStatus[]>([])
const selfStateComplete = ref(false)
const querySelfStatus = () => {
const orignStatusList = []
getSelfStatus().then((res) => {
console.log('res', res)
loading.value = false
if (res) {
try {
const list: SelfStatus[] = []
const keys = Object.keys(res)
keys.forEach((item) => {
list.push({
name: statusMap[item].name,
isOrign: res[item],
value: statusMap[item].value,
type: statusMap[item].type,
})
if (res[item]) {
orignStatusList.push(item)
}
if (orignStatusList.length === keys.length) {
clearInterval(patrolTimes.value)
selfStateComplete.value = true
}
})
deviceStatusList.value = list
console.log('deviceStatusList', list)
}
catch (e) {
console.log('error', e)
}
const checkMap = ref(new Map([
['gantryZOrigin', { status: '', name: '龙门架z轴回原点', params: { commandId: '', command: `gantry_z_origin`, params: {} } }],
['gantryXOrigin', { status: '', name: '龙门架x轴回原点', params: { commandId: '', command: `gantry_x_origin`, params: {} } }],
['gantryYOrigin', { status: '', name: '龙门架y轴回原点', params: { commandId: '', command: `gantry_y_origin`, params: {} } }],
['trayLifting01Origin', { status: '', name: 'A-1托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_01' } } }],
['trayLifting02Origin', { status: '', name: 'A-2托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_02' } } }],
['trayLifting03Origin', { status: '', name: 'A-3托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_03' } } }],
['trayLifting04Origin', { status: '', name: 'A-4托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_04' } } }],
['trayLifting05Origin', { status: '', name: 'A-5托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_05' } } }],
['trayLifting06Origin', { status: '', name: 'A-6托盘升降电机回原点', params: { commandId: '', command: `tray_lifting_origin`, params: { heatId: 'heat_module_06' } } }],
['capLiftingOrigin', { status: '', name: '拍子升降电机回原点', params: { commandId: '', command: `cap_lifting_origin` } }],
['doorOrigin', { status: '', name: '门电机回原点', params: { commandId: '', command: `door_origin`, params: {} } }],
['shakeOrigin', { status: '', name: '摇匀电机回原点', params: { commandId: '', command: `shake_origin`, params: {} } }],
['dualRobotOrigin', { status: '', name: '加液机械臂回原点', params: { commandId: '', command: `dual_robot_origin`, params: {} } }],
]))
onMounted(async () => {
socket.init(receiveMessage1, 'cmd_debug')
socket.init(receiveMessage2, 'cmd_response')
const res = await getSelfStatus()
for (const key in res) {
const entry = checkMap.value.get(key)
if (entry) {
entry.status = res[key] ? 'success' : ''
}
}).catch(() => {
loading.value = false
})
}
const resetOrign = (item: SelfStatus) => {
if (item.type === 'door') {
door_origin()
}
if (item.type === 'shake') {
shake_origin()
}
else if (item.value === 'x' || item.value === 'y' || item.value === 'z') {
gantry_origin(item.value)
}
else if (item.type === 'liquid') {
dual_robot_origin()
}
else if (item.type === 'heat') {
tray_lifting_origin(item.value)
}
else if (item.type === 'cap') {
cap_lifting_origin()
}
}
console.log(checkMap)
await getCheckItem()
})
const shake_origin = async () => {
currentCommandId = Date.now().toString()
let currentCommandId = ''
const params = {
commandId: currentCommandId,
command: `shake_origin`,
params: {},
}
await homeStore.sendControl(params)
const receiveMessage1 = (data: Socket.cmdData) => {
data.commandId === currentCommandId && systemStore.pushSystemList(data)
}
const door_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: `door_origin`,
params: {},
const receiveMessage2 = (data: Socket.cmdData) => {
data.commandId === currentCommandId && systemStore.pushSystemList(data)
const item = checkList.value.find(item => item.params.commandId === currentCommandId)
if (data.commandId === item.params.commandId && ['success', 'error'].includes(data.status)) {
item.status = data.status
}
await homeStore.sendControl(params)
}
// TODO
// const currentPumpId = ref()
// const onPumpChange = (value: string) => {
// currentPumpId.value = value
// }
// const onPumpEmpty = () => {
// console.log('===currentPumpId===', currentPumpId.value)
// }
let currentCommandId = ''
const gantry_origin = async (motor: 'x' | 'y' | 'z') => {
currentCommandId = Date.now().toString()
const checkList = ref<any[]>([])
const params = {
commandId: currentCommandId,
command: `gantry_${motor}_origin`,
params: {},
const getCheckItem = async () => {
console.log('checkList', checkList.value.length)
const keys = [...checkMap.value.keys()]
if (!keys.length) {
return
}
await homeStore.sendControl(params)
}
const dual_robot_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'dual_robot_origin',
params: {},
const value = checkMap.value.get(keys[0])
if (value?.params) {
value.params.commandId = currentCommandId = Date.now().toString()
}
await homeStore.sendControl(params)
}
const cap_lifting_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'cap_lifting_origin',
params: {},
const index = checkList.value.push(value)
if (value?.status !== 'success') {
await homeStore.sendControl(value!.params)
}
await homeStore.sendControl(params)
const poll = setInterval(async () => {
if (['success', 'error'].includes(checkList.value[index - 1].status)) {
checkMap.value.delete(keys[0])
await getCheckItem()
clearInterval(poll)
}
}, 500)
}
const tray_lifting_origin = async (heatId: string) => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'tray_lifting_origin',
params: {
heatId,
},
const alginHandle = async () => {
let index = 0
const algin = async (item: any) => {
if (!item) {
return
}
if (item.status !== 'success') {
item.params.commandId = currentCommandId = Date.now().toString()
item.status = ''
await homeStore.sendControl(item.params)
const poll = setInterval(async () => {
if (['success', 'error'].includes(item.status)) {
await algin(checkList.value[index++])
clearInterval(poll)
}
}, 1000)
}
}
await homeStore.sendControl(params)
await algin(checkList.value[index])
}
const onComplete = () => {
getSelfFinish().then(() => {
ElMessage.success('自检完成')
emits('close')
})
const onConfirm = async () => {
await getSelfFinish()
emits('close')
}
// const cancel = () => {
// emits('update:checking', false)
// visible.value = false
// }
</script>
<template>
<FtDialog visible title="自检" width="50%">
<div v-loading="loading" class="check-main">
<!-- <div v-if="type !== 'cancel'"> -->
<!-- <span style="color: red">所有电机回原点后才可操作</span> -->
<!-- </div> -->
<div class="check-status">
<h3>名称</h3>
<h3>是否在原点</h3>
<h3 style="text-align: center;">
操作
</h3>
</div>
<div v-for="(item) in deviceStatusList" :key="item.name" class="check-status">
<div>
{{ item.name }}
</div>
<div style="margin-left: 2rem;">
<el-icon v-if="!item.isOrign" style="color:red;font-size: 25px;">
<CloseBold />
</el-icon>
<el-icon v-else style="color:#25be25;font-size: 25px;">
<Select />
</el-icon>
</div>
<div v-if="!item.isOrign" style="text-align: center;">
<ft-button type="primary" :click-handle="() => resetOrign(item)">
回原点
</ft-button>
</div>
<FtDialog visible title="设备初始化" width="40%">
<div class="check-main">
<div v-for="item in checkList" :key="item.name" class="check-item">
<el-tag>{{ item.name }}</el-tag>
<el-icon v-if="item.status === 'success'" color="#26D574">
<CircleCheckFilled />
</el-icon>
<el-icon v-else-if="item.status === 'error'" color="#FE0A0A">
<CircleCloseFilled />
</el-icon>
<el-icon v-else-if="item.status === ''" class="el-icon--loading">
<Loading />
</el-icon>
</div>
</div>
<template #footer>
<FtButton :disabled="!selfStateComplete" :click-handle="onComplete">
关闭
</FtButton>
<div style="height: 40px">
<FtButton v-if="checkList.length === 13 && checkList.every(item => item.status !== 'success')" type="primary" :click-handle="alginHandle">
重试
</FtButton>
<FtButton v-if="checkList.length === 13 && checkList.every(item => item.status === 'success')" :click-handle="onConfirm">
关闭
</FtButton>
</div>
</template>
</FtDialog>
</template>
<style scoped>
.check-main{
max-height: 70vh;
height: 60vh;
overflow: auto;
.check-item {
display: flex;
align-items: center;
margin-bottom: 10px;
.el-tag {
flex: 1;
}
.el-icon {
margin: 0 10px;
font-size: 18px;
}
}
}
.check-status{
display: grid;
@ -315,4 +158,16 @@ const onComplete = () => {
margin-top: 5px;
height: 30px;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.el-icon.el-icon--loading {
animation: spin 1s linear infinite;
}
</style>

318
src/components/check1/index.vue

@ -0,0 +1,318 @@
<script lang="ts" setup>
import { getSelfFinish, getSelfStatus } from '@/apis/self'
import { ElMessage } from 'element-plus'
import { socket } from 'libs/socket'
import { useHomeStore } from 'stores/homeStore'
import { useSystemStore } from 'stores/systemStore'
import { onMounted, onUnmounted, ref } from 'vue'
interface SelfStatus {
name: string
isOrign: boolean
value: string
type: string
}
const emits = defineEmits(['close'])
const homeStore = useHomeStore()
const systemStore = useSystemStore()
const loading = ref(false)
onMounted(() => {
socket.init(receiveMessage, 'cmd_debug')
socket.init(receiveMessage, 'cmd_response')
onStartSelfTest()
})
onUnmounted(() => {
clearInterval(patrolTimes.value)
socket.unregisterCallback(receiveMessage, 'cmd_debug')
socket.unregisterCallback(receiveMessage, 'cmd_response')
})
const receiveMessage = (data: Socket.cmdData) => {
data.commandId === currentCommandId && systemStore.pushSystemList(data)
}
const onStartSelfTest = () => {
patrolSelfStatus()
}
const statusMap: Record<string, Record<string, string>> = {
doorOrigin: {
name: '门',
value: '',
type: 'door',
},
shakeOrigin: {
name: '摇匀电机',
value: '',
type: 'shake',
},
gantryXOrigin: {
name: '机械臂x轴',
value: 'x',
type: 'axis',
},
gantryYOrigin: {
name: '机械臂y轴',
value: 'y',
type: 'axis',
},
gantryZOrigin: {
name: '机械臂z轴',
value: 'z',
type: 'axis',
},
dualRobotOrigin: {
name: '加液机械臂',
value: '',
type: 'liquid',
},
// dualRobotJoint2Origin: {
// name: '02',
// value: 'smallArm',
// type: 'liquid',
// },
capLiftingOrigin: {
name: '拍子电机升降',
value: '',
type: 'cap',
},
trayLifting01Origin: {
name: '加热区01托盘升降',
value: 'heat_module_01',
type: 'heat',
},
trayLifting02Origin: {
name: '加热区02托盘升降',
value: 'heat_module_02',
type: 'heat',
},
trayLifting03Origin: {
name: '加热区03托盘升降',
value: 'heat_module_03',
type: 'heat',
},
trayLifting04Origin: {
name: '加热区04托盘升降',
value: 'heat_module_04',
type: 'heat',
},
trayLifting05Origin: {
name: '加热区05托盘升降',
value: 'heat_module_05',
type: 'heat',
},
trayLifting06Origin: {
name: '加热区06托盘升降',
value: 'heat_module_06',
type: 'heat',
},
}
const patrolTimes = ref()
const patrolSelfStatus = () => {
loading.value = true
patrolTimes.value = setInterval(() => {
querySelfStatus()
}, 1000)
}
const deviceStatusList = ref<SelfStatus[]>([])
const selfStateComplete = ref(false)
const querySelfStatus = () => {
const orignStatusList = []
getSelfStatus().then((res) => {
console.log('res', res)
loading.value = false
if (res) {
try {
const list: SelfStatus[] = []
const keys = Object.keys(res)
keys.forEach((item) => {
list.push({
name: statusMap[item].name,
isOrign: res[item],
value: statusMap[item].value,
type: statusMap[item].type,
})
if (res[item]) {
orignStatusList.push(item)
}
if (orignStatusList.length === keys.length) {
clearInterval(patrolTimes.value)
selfStateComplete.value = true
}
})
deviceStatusList.value = list
console.log('deviceStatusList', list)
}
catch (e) {
console.log('error', e)
}
}
}).catch(() => {
loading.value = false
})
}
const resetOrign = (item: SelfStatus) => {
if (item.type === 'door') {
door_origin()
}
if (item.type === 'shake') {
shake_origin()
}
else if (item.value === 'x' || item.value === 'y' || item.value === 'z') {
gantry_origin(item.value)
}
else if (item.type === 'liquid') {
dual_robot_origin()
}
else if (item.type === 'heat') {
tray_lifting_origin(item.value)
}
else if (item.type === 'cap') {
cap_lifting_origin()
}
}
const shake_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: `shake_origin`,
params: {},
}
await homeStore.sendControl(params)
}
const door_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: `door_origin`,
params: {},
}
await homeStore.sendControl(params)
}
// TODO
// const currentPumpId = ref()
// const onPumpChange = (value: string) => {
// currentPumpId.value = value
// }
// const onPumpEmpty = () => {
// console.log('===currentPumpId===', currentPumpId.value)
// }
let currentCommandId = ''
const gantry_origin = async (motor: 'x' | 'y' | 'z') => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: `gantry_${motor}_origin`,
params: {},
}
await homeStore.sendControl(params)
}
const dual_robot_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'dual_robot_origin',
params: {},
}
await homeStore.sendControl(params)
}
const cap_lifting_origin = async () => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'cap_lifting_origin',
params: {},
}
await homeStore.sendControl(params)
}
const tray_lifting_origin = async (heatId: string) => {
currentCommandId = Date.now().toString()
const params = {
commandId: currentCommandId,
command: 'tray_lifting_origin',
params: {
heatId,
},
}
await homeStore.sendControl(params)
}
const onComplete = () => {
getSelfFinish().then(() => {
ElMessage.success('自检完成')
emits('close')
})
}
// const cancel = () => {
// emits('update:checking', false)
// visible.value = false
// }
</script>
<template>
<FtDialog visible title="自检" width="50%">
<div v-loading="loading" class="check-main">
<!-- <div v-if="type !== 'cancel'"> -->
<!-- <span style="color: red">所有电机回原点后才可操作</span> -->
<!-- </div> -->
<div class="check-status">
<h3>名称</h3>
<h3>是否在原点</h3>
<h3 style="text-align: center;">
操作
</h3>
</div>
<div v-for="(item) in deviceStatusList" :key="item.name" class="check-status">
<div>
{{ item.name }}
</div>
<div style="margin-left: 2rem;">
<el-icon v-if="!item.isOrign" style="color:red;font-size: 25px;">
<CloseBold />
</el-icon>
<el-icon v-else style="color:#25be25;font-size: 25px;">
<Select />
</el-icon>
</div>
<div v-if="!item.isOrign" style="text-align: center;">
<ft-button type="primary" :click-handle="() => resetOrign(item)">
回原点
</ft-button>
</div>
</div>
</div>
<template #footer>
<FtButton :disabled="!selfStateComplete" :click-handle="onComplete">
关闭
</FtButton>
</template>
</FtDialog>
</template>
<style scoped>
.check-main{
height: 70vh;
overflow: auto;
}
.check-status{
display: grid;
grid-template-columns: 2fr 1fr 1fr;
margin-top: 5px;
height: 30px;
}
</style>

32
src/layouts/default.vue

@ -1,7 +1,7 @@
<script setup lang="ts">
import logoutIcon from 'assets/images/logout.svg'
import Check from 'components/check/index.vue'
import Stop from 'components/home/Stop/index.vue'
import Stop from 'components/Stop/index.vue'
import { ElMessageBox } from 'element-plus'
import { useActivateDebug } from 'hooks/useActivateDebug'
import { isClose } from 'libs/socket'
@ -24,17 +24,25 @@ const timeInterval = setInterval(() => {
onMounted(async () => {
if (!systemStore.systemStatus.selfTest && systemStore.systemStatus.currentUser?.username !== 'test') {
ElMessageBox.confirm('设备转运机械臂x、y、z需进行初始化,请确认机械臂行进路径是否有杂物,夹爪是否正在夹取物品', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
showClose: false,
closeOnClickModal: false,
type: 'warning',
}).then(() => {
}).catch(() => {
})
await ElMessageBox.confirm(
'<p>即将对设备进行初始化, 请确保以下内容: </p>'
+ '<ul>'
+ '<li>1. 设备内部无杂物</li>'
+ '<li>2. 夹爪没有夹取物品</li>'
+ '<li>3. 加液区无试管架<li>'
+ '</ul> ',
'提示',
{
confirmButtonText: '确认',
showClose: false,
dangerouslyUseHTMLString: true,
showCancelButton: false,
closeOnClickModal: false,
type: 'warning',
customClass: 'init-message',
},
)
isCheck.value = true
}
})

2
src/libs/utils.ts

@ -44,7 +44,7 @@ export const cmdNameMap = {
tray_down: '降下托盘',
shake_start: '开始摇匀',
shake_stop: '停止摇匀',
dual_robot_joint_origin: '加液机械臂回原点',
dual_robot_origin: '加液机械臂回原点',
gantry_x_origin: '机械臂x轴回原点',
gantry_y_origin: '机械臂y轴回原点',
gantry_z_origin: '机械臂z轴回原点',

3
src/router/index.ts

@ -12,6 +12,9 @@ const router = createRouter({
router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
const systemStore = useSystemStore()
if (getToken() && systemStore.systemStatus.currentUser?.username) {
if (to.name === 'login') {
next({ name: from.name })
}
next()
}
else {

4
src/views/container/liquidItem.vue

@ -30,9 +30,9 @@ const solutionInfo = ref(props.solutionItem)
const solutionStyle = computed(() => {
const difference = solutionInfo.value.capacityUsed / solutionInfo.value.capacityTotal
const process = 100 - (difference * 100)
const color = difference > 0.4 ? '#26D574' : difference > 10 ? '#EE8223' : '#FE0A0A'
// const color = difference > 0.4 ? '#26D574' : difference > 10 ? '#EE8223' : '#FE0A0A'
return {
'-webkit-mask': `linear-gradient(to bottom, transparent ${process}%, #EEEFF8 ${process + 0.1}%, ${color})`,
'-webkit-mask': `linear-gradient(to bottom, transparent ${process}%, #EEEFF8 ${process + 0.1}%)`,
}
})
const onInputBlur = () => {

2
tsconfig.json

@ -32,7 +32,7 @@
"skipLibCheck": true
},
"types": ["vite/client", "jest", "node", "element-plus/global.d.ts", "lodash"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/**/*.vue"],
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "src/**/**/*.vue", "components/**/*.vue"],
"exclude": [
]
}
Loading…
Cancel
Save