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.

204 lines
5.4 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <script setup lang="ts">
  2. import { deviceSelfTestFinish, getDeviceSelfTest } from 'apis/system'
  3. import FtDialog from 'components/common/FTDialog/index.vue'
  4. import { FtMessage } from 'libs/message'
  5. import { socket } from 'libs/socket'
  6. import { sendControl } from 'libs/utils'
  7. import { onMounted, ref, watch } from 'vue'
  8. const emits = defineEmits(['ok', 'cancel'])
  9. const okLoading = ref(false)
  10. const okHandle = () => {
  11. okLoading.value = true
  12. setTimeout(() => {
  13. okLoading.value = false
  14. FtMessage.success('保存成功')
  15. emits('ok')
  16. }, 300)
  17. }
  18. const list = ['x轴是否在原点', 'y轴是否在原点', 'z轴是否在原点']
  19. const status = ref<any>({})
  20. onMounted(async () => {
  21. socket.init(receiveMessage, 'cmd_response')
  22. await change()
  23. })
  24. const change = async () => {
  25. let num = 0
  26. // await nextTick(() => {
  27. // buttonCloseRef.value?.setLoading(true)
  28. // })
  29. status.value = await getDeviceSelfTest()
  30. const interval = async () => {
  31. if (num < list.length) {
  32. await addTextToCheckList(list[num], num)
  33. num++
  34. await interval() // 递归调用 interval 处理下一条数据
  35. }
  36. }
  37. await interval()
  38. // buttonCloseRef.value?.setLoading(false)
  39. }
  40. const receiveMessage = (data: any) => {
  41. if (data.status === 'success') {
  42. for (const cmdIdsKey in cmdIds) {
  43. if (data.cmdId === cmdIds[cmdIdsKey]) {
  44. checkList.value[cmdIdsKey].result = 'success'
  45. }
  46. }
  47. }
  48. if (data.status === 'finish') {
  49. for (const cmdIdsKey in cmdIds) {
  50. if (data.cmdId === cmdIds[cmdIdsKey]) {
  51. toHomeButtonRefs.value[cmdIdsKey].setLoading(false)
  52. }
  53. }
  54. }
  55. }
  56. const cancel = async () => {
  57. await deviceSelfTestFinish()
  58. emits('cancel')
  59. }
  60. let cmdId = ''
  61. // const motorXYZOrigin = async () => {
  62. // buttonRef.value.setLoading(true)
  63. // cmdId = Date.now().toString()
  64. // const params = {
  65. // cmdCode: 'device_self_test',
  66. // cmdId,
  67. // params: {},
  68. // }
  69. //
  70. // await sendControl(params)
  71. // }
  72. const cmdIds: any = {}
  73. const toHomeButtonRefs = ref()
  74. const toHome = async (index: number) => {
  75. cmdId = Date.now().toString()
  76. cmdIds[index] = cmdId
  77. const params = {
  78. cmdCode: ['motor_x_to_home', 'motor_y_to_home', 'motor_z_to_home'][index],
  79. cmdId,
  80. params: {},
  81. }
  82. toHomeButtonRefs.value[index].setLoading(true)
  83. await sendControl(params)
  84. }
  85. const checkList = ref<any>([])
  86. // const buttonRef = ref()
  87. const closeVisible = ref(true)
  88. const addTextToCheckList = async (text: string, id: number) => {
  89. // 检查 checkList 中是否存在该 id 的对象,如果不存在则初始化
  90. if (!checkList.value.some(item => item.id === id)) {
  91. checkList.value.push({ id, title: '', result: 'padding' })
  92. }
  93. let displayedText = ''
  94. return new Promise<void>((resolve) => {
  95. const interval = setInterval(() => {
  96. if (displayedText.length < text.length) {
  97. displayedText += text[displayedText.length]
  98. const itemIndex = checkList.value.findIndex(item => item.id === id)
  99. if (itemIndex !== -1) {
  100. checkList.value[itemIndex].title = displayedText
  101. }
  102. }
  103. else {
  104. clearInterval(interval)
  105. // 文字显示完毕后,设置 result 为 'success' 或 'failed' 以显示成功或失败图标
  106. const itemIndex = checkList.value.findIndex(item => item.id === id)
  107. if (itemIndex !== -1) {
  108. setTimeout(() => {
  109. checkList.value[itemIndex].result = status.value[['xAxisAtOrigin', 'yAxisAtOrigin', 'zAxisAtOrigin'][itemIndex]] ? 'success' : 'failed'
  110. resolve() // 解析 Promise,表示当前数据已完全展示
  111. }, Math.random() * 200) // 修改为随机数延时
  112. }
  113. }
  114. }, Math.random() * 100) // 修改为随机数延时
  115. })
  116. }
  117. watch(() => checkList.value, () => {
  118. if (checkList.value.every(item => item.result === 'success')) {
  119. closeVisible.value = false
  120. }
  121. }, { deep: true })
  122. </script>
  123. <template>
  124. <FtDialog visible title="自检" width="40%" :ok-handle="okHandle" @cancel="cancel">
  125. <div v-for="(item, index) in checkList" :key="item.id" class="mask-box">
  126. <el-tag> {{ item.title }}</el-tag>
  127. <el-icon v-show="item.result === 'success'" color="green">
  128. <SuccessFilled />
  129. </el-icon>
  130. <el-icon v-show="item.result === 'failed'" color="red">
  131. <CircleCloseFilled />
  132. </el-icon>
  133. <el-icon v-show="item.result === 'padding'" color="gray" class="el-icon--loading">
  134. <Loading />
  135. </el-icon>
  136. <ft-button ref="toHomeButtonRefs" class="check-button" type="primary" :disabled="item.result === 'success'" @click="() => toHome(index)">
  137. 回原点
  138. </ft-button>
  139. </div>
  140. <template #footer>
  141. <ft-button :disabled="closeVisible" @click="cancel">
  142. 关闭
  143. </ft-button>
  144. <!-- <ft-button v-else ref="buttonRef" type="primary" @click="motorXYZOrigin"> -->
  145. <!-- 回原点 -->
  146. <!-- </ft-button> -->
  147. </template>
  148. </FtDialog>
  149. </template>
  150. <style scoped lang="scss">
  151. .mask-box {
  152. display: flex;
  153. font-size: 35px;
  154. align-items: center;
  155. margin-bottom: 40px;
  156. .el-tag {
  157. margin-right: 20px;
  158. width: 100%;
  159. }
  160. }
  161. // 添加旋转动画
  162. @keyframes spin {
  163. 0% {
  164. transform: rotate(0deg);
  165. }
  166. 100% {
  167. transform: rotate(360deg);
  168. }
  169. }
  170. .el-icon.el-icon--loading {
  171. animation: spin 1s linear infinite; // 确保 Loading 图标应用 spin 动画
  172. }
  173. :deep(.el-tag) {
  174. padding: 30px 0;
  175. }
  176. :deep(.check-button) {
  177. margin-left: 10px;
  178. .my-button {
  179. width: 230px;
  180. }
  181. }
  182. </style>