You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
7.3 KiB

6 days ago
  1. <script lang="ts" setup>
  2. import { getSelfFinish } from 'apis/self'
  3. import { ElMessageBox } from 'element-plus'
  4. import { socket } from 'libs/socket'
  5. import { useHomeStore } from 'stores/homeStore'
  6. import { useSystemStore } from 'stores/systemStore'
  7. import { onMounted, ref } from 'vue'
  8. const emits = defineEmits(['close'])
  9. const homeStore = useHomeStore()
  10. const systemStore = useSystemStore()
  11. const checkMap = ref(new Map([
  12. ['zOrigin', { status: '', ignoreKey: 'zOriginIsIgnore', name: 'Z轴回原点', params: { commandId: '', command: `check_z_origin`, params: {} } }],
  13. ['xyOrigin', { status: '', ignoreKey: 'xyOriginIsIgnore', name: '机械臂回原点', params: { commandId: '', command: `check_xy_origin`, params: {} } }],
  14. ['titrationOrigin', { status: '', ignoreKey: 'titrationOriginIsIgnore', name: '滴定电机回原点', params: { commandId: '', command: `check_titration_motor_origin`, params: {} } }],
  15. ['shakeOrigin', { status: '', ignoreKey: 'shakeOriginIsIgnore', name: '摇匀电机回原点', params: { commandId: '', command: `check_shake_motor_origin`, params: {} } }],
  16. ['stirOrigin', { status: '', ignoreKey: 'stirOriginIsIgnore', name: '磁子投放电机回原点', params: { commandId: '', command: `check_stir_motor_origin`, params: {} } }],
  17. ]))
  18. const checkList = ref<any[]>([])
  19. onMounted(async () => {
  20. socket.init(receiveMessage1, 'cmd_debug')
  21. socket.init(receiveMessage2, 'cmd_response')
  22. socket.init(receiveMessageSelfMove, 'self_move_test')
  23. await ElMessageBox.confirm(
  24. '设备转运机械臂、滴定电机、摇匀电机、磁子投放电机,请确认机械臂行进路径无杂物',
  25. '提示',
  26. {
  27. confirmButtonText: '确认',
  28. showClose: false,
  29. showCancelButton: false,
  30. closeOnClickModal: false,
  31. closeOnPressEscape: false,
  32. type: 'warning',
  33. customClass: 'init-message',
  34. },
  35. )
  36. const keys = [...checkMap.value.keys()]
  37. for (let i = 0; i < keys.length; i++) {
  38. checkList.value.push(checkMap.value.get(keys[i]))
  39. }
  40. })
  41. let currentCommandId = ''
  42. const receiveMessage1 = (data: Socket.cmdData) => {
  43. data.commandId === currentCommandId && systemStore.pushSystemList(data)
  44. }
  45. const receiveMessage2 = (data: Socket.cmdData) => {
  46. data.commandId === currentCommandId && systemStore.pushSystemList(data)
  47. const item = checkList.value.find(item => item.params.commandId === data.commandId)
  48. if (item && data.commandId === item.params.commandId && ['success', 'error'].includes(data.status)) {
  49. item.status = data.status
  50. }
  51. }
  52. const commandHandle = async (data: any) => {
  53. data.params.commandId = currentCommandId = Date.now().toString()
  54. await homeStore.sendControl(data!.params)
  55. }
  56. const onConfirm = async () => {
  57. await getSelfFinish(true)
  58. emits('close')
  59. }
  60. const percentage = ref(0)
  61. const checkHandle = async () => {
  62. activeStep.value = 1
  63. await ElMessageBox.confirm(
  64. '设备即将开始自检',
  65. '提示',
  66. {
  67. confirmButtonText: '确认',
  68. showClose: false,
  69. showCancelButton: false,
  70. closeOnClickModal: false,
  71. closeOnPressEscape: false,
  72. type: 'warning',
  73. customClass: 'init-message',
  74. },
  75. )
  76. currentCommandId = Date.now().toString()
  77. const params = {
  78. commandId: currentCommandId,
  79. command: 'check_move_test',
  80. params: {},
  81. }
  82. await homeStore.sendControl(params)
  83. }
  84. const checkTextList = ref<{ title: string, type: 'success' | 'error' }[]>([])
  85. const selfAgain = ref(true)
  86. const receiveMessageSelfMove = (data: any) => {
  87. checkTextList.value.push(data)
  88. percentage.value = data.schedule
  89. if (data.type === 'error') {
  90. selfAgain.value = true
  91. }
  92. }
  93. const activeStep = ref(0)
  94. const checkAgain = async () => {
  95. selfAgain.value = false
  96. checkTextList.value = []
  97. percentage.value = 0
  98. currentCommandId = Date.now().toString()
  99. const params = {
  100. commandId: currentCommandId,
  101. command: 'check_move_test',
  102. params: {},
  103. }
  104. await homeStore.sendControl(params)
  105. selfAgain.value = true
  106. }
  107. </script>
  108. <template>
  109. <FtDialog visible title="设备初始化" width="60%">
  110. <!-- <el-steps style="max-width: 600px" :active="activeStep" finish-status="success">
  111. <el-step title="初始化" />
  112. <el-step title="自检" />
  113. <el-step title="设备状态" />
  114. </el-steps> -->
  115. <div v-if="activeStep === 0" class="check-main">
  116. <div v-for="item in checkList" :key="item.name" class="check-item">
  117. <el-tag>{{ item.name }}</el-tag>
  118. <el-icon v-if="item.status === 'success'" color="#26D574">
  119. <CircleCheckFilled />
  120. </el-icon>
  121. <el-icon v-else-if="item.status === 'error'" color="#FE0A0A">
  122. <CircleCloseFilled />
  123. </el-icon>
  124. <el-icon v-else-if="item.status === ''" class="el-icon--loading">
  125. <Loading />
  126. </el-icon>
  127. <el-icon v-else-if="item.status === 'ignore'">
  128. <More />
  129. </el-icon>
  130. <ft-button v-if="!['ignore', 'success'].includes(item.status)" type="primary" size="small" :click-handle="() => commandHandle(item)">
  131. 回原点
  132. </ft-button>
  133. <!-- <ft-button v-if="!['ignore', 'success'].includes(item.status) && item.name === '门电机回原点'" size="small" type="primary" :click-handle="() => ignore(item)">
  134. 忽略
  135. </ft-button>
  136. <ft-button v-if="item.status === 'ignore' && item.name === '门电机回原点'" size="small" type="danger" :click-handle="() => ignoreFalse(item)">
  137. 取消忽略
  138. </ft-button> -->
  139. </div>
  140. </div>
  141. <div v-if="activeStep === 1" class="check-box">
  142. <div class="progress-box">
  143. <p>自检进度: </p>
  144. <el-progress
  145. :stroke-width="20"
  146. :percentage="percentage"
  147. />
  148. </div>
  149. <ul>
  150. <li v-for="(item, index) in checkTextList" :key="index">
  151. <span :style="{ color: item.type === 'success' ? '#14A656' : '#DF1515' }">{{ item.title }}</span>
  152. </li>
  153. </ul>
  154. </div>
  155. <template #footer>
  156. <div style="height: 40px">
  157. <FtButton v-if="activeStep === 0 && checkList.every(item => ['success', 'ignore'].includes(item.status))" type="primary" :click-handle="checkHandle">
  158. 下一步
  159. </FtButton>
  160. <FtButton v-if="activeStep === 1 && selfAgain" type="primary" :click-handle="checkAgain">
  161. 重新自检
  162. </FtButton>
  163. <FtButton v-if="activeStep === 1" :click-handle="onConfirm">
  164. 关闭
  165. </FtButton>
  166. </div>
  167. </template>
  168. </FtDialog>
  169. </template>
  170. <style scoped>
  171. .check-box {
  172. height: 30vh;
  173. ul {
  174. li {
  175. margin: 3px 0;
  176. }
  177. }
  178. }
  179. .progress-box {
  180. width: 100%;
  181. height: 40px;
  182. display: flex;
  183. align-items: center;
  184. p {
  185. margin-right: 10px;
  186. }
  187. span {
  188. margin-left: 10px;
  189. }
  190. .el-progress {
  191. width: 80%;
  192. }
  193. }
  194. .check-main{
  195. height: 25vh;
  196. overflow: auto;
  197. display: flex;
  198. flex-direction: column;
  199. justify-content: flex-start;
  200. margin-top: 20px;
  201. }
  202. .check-item {
  203. width: 100%;
  204. display: flex;
  205. align-items: center;
  206. justify-content: center;
  207. margin-bottom: 10px;
  208. .el-tag {
  209. width: 50%;
  210. }
  211. .el-icon {
  212. margin: 0 10px;
  213. font-size: 18px;
  214. }
  215. }
  216. .check-status{
  217. display: grid;
  218. grid-template-columns: 2fr 1fr 1fr;
  219. margin-top: 5px;
  220. height: 30px;
  221. }
  222. @keyframes spin {
  223. 0% {
  224. transform: rotate(0deg);
  225. }
  226. 100% {
  227. transform: rotate(360deg);
  228. }
  229. }
  230. .el-icon.el-icon--loading {
  231. animation: spin 1s linear infinite;
  232. }
  233. .ft-button {
  234. width:120px
  235. }
  236. </style>