index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <el-dialog
  3. v-model="visible"
  4. :title="title"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. :show-close="false"
  8. width="680px"
  9. class="hardware-check-dialog"
  10. >
  11. <div class="hardware-check-container">
  12. <el-timeline>
  13. <el-timeline-item type="primary" :hollow="true">
  14. <template #dot>
  15. <div class="step-dot">1</div>
  16. </template>
  17. <div class="step-content">
  18. <div class="step-title">
  19. <template v-if="checkLoading">正在初始化检测硬件......</template>
  20. <template v-else-if="checkSuccess">硬件检测完成</template>
  21. <template v-else>初始化检测硬件失败</template>
  22. </div>
  23. <el-progress
  24. v-if="checkLoading"
  25. :percentage="checkInfoStore.getProgress"
  26. :colors="['#2FB0FF', '#B863FB']"
  27. :stroke-width="8"
  28. />
  29. <div class="check-error-result" v-else-if="!checkSuccess">
  30. 失败的原因,{{ checkInfoStore.getErrorMsg }}
  31. </div>
  32. </div>
  33. </el-timeline-item>
  34. <el-timeline-item type="primary" :hollow="true">
  35. <template #dot>
  36. <div class="step-dot">2</div>
  37. </template>
  38. <div class="step-content">
  39. <div class="step-title">自我检查</div>
  40. <div class="check-result">
  41. <p>补光灯电源和连接器是否正常连上。</p>
  42. <p>请检查红外线器是否正常显示。</p>
  43. </div>
  44. </div>
  45. </el-timeline-item>
  46. </el-timeline>
  47. <div class="device-summary">
  48. <div class="device-row">
  49. <span class="device-label">MCU设备</span>
  50. <span class="device-value" :class="mcuConnected ? 'is-ok' : 'is-bad'">
  51. {{ mcuConnected ? '已连接MCU' : '未连接MCU' }}
  52. </span>
  53. <span class="device-serial" v-if="serialSummary">{{ serialSummary }}</span>
  54. </div>
  55. <div class="device-row">
  56. <span class="device-label">相机设备</span>
  57. <span class="device-value" :class="cameraConnected ? 'is-ok' : 'is-bad'">
  58. {{ cameraConnected ? '已连接相机' : '未连接相机' }}
  59. </span>
  60. </div>
  61. <div class="motor-grid">
  62. <div class="motor-item" v-for="item in motorItems" :key="item.key">
  63. <div class="motor-name">{{ item.label }}</div>
  64. <div class="motor-status" :class="getStatusClass(deviceStatusStore.runStatus[item.key])">
  65. {{ getStatusText(deviceStatusStore.runStatus[item.key]) }}
  66. </div>
  67. </div>
  68. </div>
  69. <div class="device-log-box">
  70. <div v-if="recentLogs.length === 0" class="log-empty">暂无设备上报信息</div>
  71. <div v-else class="log-list">
  72. <div v-for="(log, index) in recentLogs" :key="index" class="log-item">
  73. <span class="log-time">{{ log.current_time }}</span>
  74. <span class="log-message">{{ log.message }}</span>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <template #footer v-if="!checkLoading">
  81. <div class="flex" v-if="!checkSuccess">
  82. <div class="check-btn cu-p" style="width: 160px; margin-right: 10px;" @click="reCheck">重新监测一次</div>
  83. <div class="check-btn check-btn-secondary cu-p" style="width: 160px;" @click="openStatusDialog">查看设备状态</div>
  84. </div>
  85. <div class="flex" v-else>
  86. <div class="check-btn cu-p" style="width: 180px" @click="confirm()">检测成功,继续操作!</div>
  87. </div>
  88. </template>
  89. </el-dialog>
  90. </template>
  91. <script setup>
  92. import { ref, watch, watchEffect, computed, onUnmounted } from 'vue';
  93. import useUserInfo from "@/stores/modules/user";
  94. import checkInfo from "@/stores/modules/check";
  95. import client from "@/stores/modules/client";
  96. import useDeviceStatusStore from '@/stores/modules/deviceStatus';
  97. const useUserInfoStore = useUserInfo()
  98. const checkInfoStore = checkInfo()
  99. const clientStore = client()
  100. const deviceStatusStore = useDeviceStatusStore()
  101. const checkSuccess = ref(false);
  102. const checkLoading = ref(true);
  103. const props = defineProps({
  104. isInitCheck: {
  105. type: Boolean,
  106. default: false
  107. },
  108. title: {
  109. type: String,
  110. default: '检测硬件'
  111. }
  112. });
  113. const emit = defineEmits(['confirm']);
  114. const checkCount = ref(props.isInitCheck ? 0 : 1);
  115. const visible = ref(false);
  116. const motorItems = [
  117. { key: 'state_camera_motor', label: '相机升降' },
  118. { key: 'state_camera_steering', label: '相机角度' },
  119. { key: 'state_move_turntable_steering', label: '前后移动' },
  120. { key: 'state_turntable_steering', label: '转盘电机' },
  121. { key: 'state_overturn_steering', label: '翻板' },
  122. ]
  123. const stateTextMap = {
  124. 0: '未初始化',
  125. 1: '运动中',
  126. 2: '已停止',
  127. 3: '未在线',
  128. 4: '堵转'
  129. }
  130. const mcuConnected = computed(() => checkInfoStore.mcuConnected)
  131. const serialSummary = computed(() => checkInfoStore.serialSummary)
  132. const cameraConnected = computed(() => checkInfoStore.devices.cam_control.status === 2)
  133. const recentLogs = computed(() =>
  134. (deviceStatusStore.logs || []).filter((log) => log.message)
  135. )
  136. function getStatusText(status) {
  137. return stateTextMap[status] || '未知状态'
  138. }
  139. function getStatusClass(status) {
  140. const classMap = {
  141. 0: 'status-uninit',
  142. 1: 'status-moving',
  143. 2: 'status-stopped',
  144. 3: 'status-offline',
  145. 4: 'status-blocked'
  146. }
  147. return classMap[status] || 'status-unknown'
  148. }
  149. function syncMotorListen() {
  150. if (visible.value && checkInfoStore.mcuConnected) {
  151. deviceStatusStore.startRunStatusListen()
  152. } else {
  153. deviceStatusStore.stopRunStatusListen()
  154. if (!checkInfoStore.mcuConnected) {
  155. deviceStatusStore.resetRunStatus()
  156. }
  157. }
  158. }
  159. function startProgress() {
  160. checkInfoStore.set_isCheckStatus(true);
  161. checkLoading.value = true;
  162. checkSuccess.value = false;
  163. deviceStatusStore.resetRunStatus()
  164. checkInfoStore.reCheckAction()
  165. deviceStatusStore.fetchLogs()
  166. }
  167. function reCheck() {
  168. startProgress()
  169. }
  170. watchEffect(async ()=>{
  171. if( useUserInfoStore.userInfo.id && checkCount.value === 0 && checkInfoStore.isCheckStatus){
  172. if(clientStore.isClient){
  173. visible.value = true
  174. //python 启动有延时,延迟2秒执行
  175. setTimeout(()=>{
  176. startProgress()
  177. },5000)
  178. }
  179. checkCount.value++;
  180. }
  181. })
  182. watchEffect(async ()=>{
  183. if( checkCount.value >= 1 && checkInfoStore.getProgress !== 100 && !checkInfoStore.isCheckStatus){
  184. localStorage.setItem('check',false)
  185. visible.value = true
  186. checkLoading.value = false;
  187. checkSuccess.value = false;
  188. }
  189. })
  190. watchEffect(async ()=>{
  191. if(checkInfoStore.getProgress === 100 ){
  192. checkLoading.value = false;
  193. checkSuccess.value = true;
  194. }
  195. })
  196. watchEffect(async ()=>{
  197. if( checkInfoStore.getErrorMsg){
  198. checkLoading.value = false;
  199. checkSuccess.value = false;
  200. }
  201. })
  202. watchEffect(async ()=>{
  203. if( checkInfoStore.getProgress === 100){
  204. checkLoading.value = false;
  205. checkSuccess.value = true;
  206. }
  207. })
  208. watch(visible, (val) => {
  209. if (val) {
  210. deviceStatusStore.fetchLogs()
  211. checkInfoStore.requestHardwareCheckInfo()
  212. }
  213. syncMotorListen()
  214. })
  215. watch(() => checkInfoStore.mcuConnected, (connected) => {
  216. if (visible.value && connected) {
  217. checkInfoStore.requestHardwareCheckInfo()
  218. }
  219. syncMotorListen()
  220. })
  221. function confirm(){
  222. visible.value = false;
  223. checkInfoStore.set_isCheckStatus(false);
  224. localStorage.setItem('check',true)
  225. emit('confirm')
  226. }
  227. function openStatusDialog() {
  228. deviceStatusStore.openDialog();
  229. }
  230. onUnmounted(() => {
  231. deviceStatusStore.stopRunStatusListen()
  232. })
  233. </script>
  234. <style lang="scss" scoped>
  235. .hardware-check-container {
  236. padding: 8px 8px 0;
  237. text-align: left;
  238. }
  239. .step-content {
  240. flex: 1;
  241. }
  242. .step-title {
  243. font-weight: 600;
  244. font-size: 14px;
  245. color: #000000;
  246. margin-bottom: 12px;
  247. padding-top: 4px;
  248. text-align: left;
  249. }
  250. .check-result {
  251. color: rgba(0,0,0,0.45);
  252. text-align: left;
  253. p {
  254. margin: 8px 0;
  255. }
  256. }
  257. :deep(.el-progress-bar__inner) {
  258. background-image: linear-gradient(to right, #409EFF, #7e57c2);
  259. }
  260. :deep(.el-timeline) {
  261. padding-left: 4px;
  262. }
  263. :deep(.el-timeline-item__tail) {
  264. left: 7px;
  265. }
  266. .step-dot {
  267. width: 22px;
  268. height: 22px;
  269. border-radius: 50%;
  270. background: #2F6BFF;
  271. color: #fff;
  272. font-size: 13px;
  273. font-weight: 600;
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. position: relative;
  278. left: -5px;
  279. }
  280. .check-btn{
  281. width: 100px;
  282. height: 40px;
  283. background: linear-gradient( 135deg, #2FB0FF 0%, #B863FB 100%);
  284. border-radius: 4px;
  285. font-weight: 400;
  286. font-size: 16px;
  287. color: #FFFFFF;
  288. text-align: center;
  289. line-height: 40px;
  290. }
  291. .check-error-result{
  292. font-size: 14px;
  293. text-align: left;
  294. color: #FF4C00;
  295. }
  296. .check-btn-secondary {
  297. background: linear-gradient(135deg, #909399 0%, #C0C4CC 100%);
  298. }
  299. .device-summary {
  300. margin-top: 4px;
  301. padding-left: 36px;
  302. }
  303. .device-row {
  304. display: flex;
  305. align-items: center;
  306. margin-bottom: 10px;
  307. font-size: 14px;
  308. line-height: 22px;
  309. }
  310. .device-label {
  311. color: #333;
  312. min-width: 72px;
  313. margin-right: 12px;
  314. }
  315. .device-value {
  316. font-weight: 600;
  317. &.is-ok {
  318. color: #67C23A;
  319. }
  320. &.is-bad {
  321. color: #F56C6C;
  322. }
  323. }
  324. .device-serial {
  325. margin-left: auto;
  326. color: #F56C6C;
  327. font-size: 13px;
  328. text-align: right;
  329. max-width: 280px;
  330. }
  331. .motor-grid {
  332. display: grid;
  333. grid-template-columns: repeat(5, 1fr);
  334. gap: 8px;
  335. margin: 8px 0 14px;
  336. }
  337. .motor-item {
  338. text-align: left;
  339. }
  340. .motor-name {
  341. font-size: 13px;
  342. color: #333;
  343. margin-bottom: 4px;
  344. }
  345. .motor-status {
  346. font-size: 13px;
  347. font-weight: 500;
  348. &.status-uninit,
  349. &.status-unknown {
  350. color: #909399;
  351. }
  352. &.status-moving {
  353. color: #E6A23C;
  354. }
  355. &.status-stopped {
  356. color: #67C23A;
  357. }
  358. &.status-offline,
  359. &.status-blocked {
  360. color: #F56C6C;
  361. }
  362. }
  363. .device-log-box {
  364. background: #F5F6F7;
  365. border-radius: 8px;
  366. padding: 8px 12px;
  367. min-height: 108px;
  368. max-height: 180px;
  369. overflow-y: auto;
  370. width: 100%;
  371. box-sizing: border-box;
  372. text-align: left !important;
  373. }
  374. .log-empty {
  375. color: #999;
  376. font-size: 13px;
  377. line-height: 22px;
  378. text-align: left !important;
  379. }
  380. .log-list {
  381. width: 100%;
  382. text-align: left !important;
  383. }
  384. .log-item {
  385. display: flex;
  386. justify-content: flex-start;
  387. align-items: flex-start;
  388. width: 100%;
  389. box-sizing: border-box;
  390. padding: 8px 0;
  391. border-bottom: 1px solid #f0f0f0;
  392. font-size: 13px;
  393. text-align: left !important;
  394. &:last-child {
  395. border-bottom: none;
  396. }
  397. }
  398. .log-time {
  399. flex-shrink: 0;
  400. color: #999;
  401. margin-right: 12px;
  402. min-width: 150px;
  403. line-height: 20px;
  404. text-align: left !important;
  405. }
  406. .log-message {
  407. flex: 1;
  408. color: #333;
  409. word-break: break-all;
  410. line-height: 20px;
  411. text-align: left !important;
  412. }
  413. </style>
  414. <style lang="scss">
  415. .hardware-check-dialog {
  416. .el-dialog__title {
  417. display: block;
  418. width: 100%;
  419. text-align: center;
  420. font-size: 16px;
  421. font-weight: 400;
  422. color: #333;
  423. }
  424. .el-dialog__body {
  425. padding-top: 10px;
  426. text-align: left !important;
  427. }
  428. .device-log-box,
  429. .log-list,
  430. .log-item,
  431. .log-time,
  432. .log-message,
  433. .log-empty {
  434. text-align: left !important;
  435. }
  436. }
  437. </style>