check.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <template>
  2. <headerBar
  3. v-if="!isSetting"
  4. title="拍摄物体镜头矫正"
  5. :menu="menu"
  6. showUser
  7. showDeviceStatus
  8. />
  9. <div class="check-wrap">
  10. <div class="check-page flex-col" :class="isSetting ? 'check-page_seeting' : '' ">
  11. <div class="main-container flex-col">
  12. <div class="content-wrapper flex-row justify-between">
  13. <div class="left-panel flex-col justify-between">
  14. <div class="tips-container flex-row" v-if="show">
  15. <spanc v-if="isSetting" class="tips-tex">
  16. 请在圆盘上摆上鞋子(注意左右脚),要求鞋外侧朝向拍照机,鞋子中轴线和红外线对齐,如果光亮不够,可以打开环境光源,关闭闪光灯。
  17. </spanc>
  18. <span v-else class="tips-tex">
  19. 请在圆盘上摆上鞋子(注意左右脚),要求鞋外侧朝向拍照机,鞋子中轴线和红外线对齐,如果光亮不够,可以打开环境光源,关闭闪光灯。
  20. </span>
  21. </div>
  22. <div class="camera-preview flex col center ">
  23. <div class="camera-preview-img" v-if="step === 1">
  24. <img v-if="previewKey" class="camera-img" :src="previewSrc" />
  25. <el-button class="auto-focus-btn" @click="handleAutoFocus" v-if="previewKey">
  26. <span>点击对焦</span>
  27. </el-button>
  28. <div class="example-image flex-col" v-if="!isSetting && previewKey > 1">
  29. <img :src="exampleImage">
  30. </div>
  31. </div>
  32. <template v-if="step === 2" >
  33. <img class="camera-img" :src="getFilePath(imageTplPath)" />
  34. <span class="camera-description">这是一张用于检查镜头是否合适的测试图</span>
  35. </template>
  36. </div>
  37. </div>
  38. </div>
  39. <template v-if="!isSetting">
  40. <div v-if="step === 1" class="action-button flex cente">
  41. <div @click="takePictures" class="check-button button--primary1 flex-col" v-log="{ describe: { action: '点击拍照检查' } }"><span class="button-text" v-loading="loading">拍照检查</span>
  42. </div>
  43. </div>
  44. <div v-else class="action-button flex center">
  45. <div @click="checkConfirm(false)" class="check-button button--white flex-col" v-log="{ describe: { action: '点击重新拍照检查' } }">
  46. <span class="button-text cu-p">重新拍照检查</span>
  47. </div>
  48. <router-link class="mar-left-20 " :to="{
  49. name: 'PhotographyShot'
  50. }">
  51. <div class="check-button button--primary1 flex-col" v-log="{ describe: { action: '点击确认无误下一步' } }">
  52. <span class="button-text cu-p">确认无误,下一步</span>
  53. </div>
  54. </router-link>
  55. </div>
  56. </template>
  57. </div>
  58. </div>
  59. <editRow
  60. v-if="showrEditRow || isSetting"
  61. :id="id"
  62. :key="id"
  63. @confirm="confirm"
  64. ref="editData"
  65. @onClose="onClose"
  66. @onRunMcuSingle="onRunMcuSingle"
  67. @onReady="onEditRowReady"
  68. @onPointChange="switchPreviewPoint"
  69. :addRowData="addRowData"
  70. :disablePointConfig="!isSetting"
  71. />
  72. </div>
  73. <hardware-check v-if="!isSetting"
  74. isInitCheck
  75. @confirm="checkConfirm(true)"
  76. />
  77. </template>
  78. <script setup lang="ts">
  79. import {watchEffect, ref, defineEmits, defineProps, computed, onBeforeUnmount, onMounted} from 'vue'
  80. import client from "@/stores/modules/client";
  81. import socket from "@/stores/modules/socket";
  82. import icpList from '@/utils/ipc'
  83. import useUserInfo from "@/stores/modules/user";
  84. import headerBar from '@/components/header-bar/index.vue'
  85. import editRow from './components/editRow'
  86. const clientStore = client();
  87. const socketStore = socket(); // WebSocket状态管理实例
  88. const emit = defineEmits([ 'confirm','onClose']);
  89. import configInfo from '@/stores/modules/config';
  90. const configInfoStore = configInfo();
  91. const useUserInfoStore = useUserInfo();
  92. const confirm = async () => {
  93. console.log('confirm');
  94. setTimeout(()=>{
  95. hideVideo(currentPointName.value)
  96. },1000)
  97. emit('confirm')
  98. }
  99. const onClose = async () => {
  100. console.log('onClose');
  101. setTimeout(()=>{
  102. hideVideo(currentPointName.value)
  103. },1000)
  104. emit('onClose')
  105. }
  106. // 定义 props
  107. const props = defineProps({
  108. id:{
  109. type: Number||String,
  110. default: 0
  111. },
  112. addRowData:{
  113. type: Object,
  114. default: () => {
  115. return { }
  116. }
  117. }
  118. })
  119. const show = ref(true)
  120. const previewKey = ref(0)
  121. const isSetting = computed(()=>{
  122. return props.id || props.addRowData.mode_type
  123. })
  124. import HardwareCheck from '@/components/check/index.vue'
  125. import { digiCamControlWEB } from '@/utils/appconfig'
  126. import { getFilePath } from '@/utils/appfun'
  127. import {ElMessage} from "element-plus";
  128. const preview = ref(digiCamControlWEB+'liveview.jpg')
  129. const previewSrc = computed(()=>{
  130. let time = new Date().getTime()
  131. return preview.value+'?key='+previewKey.value+'&time='+time
  132. })
  133. const step = ref(1)
  134. async function checkConfirm(init){
  135. step.value =1
  136. if(!init) previewKey.value++;
  137. showrEditRow.value = true
  138. loading.value = false;
  139. }
  140. // 打开输出目录:appConfig.appPath + '/build/extraResources/py/output'
  141. const openOutputDir = () => {
  142. try {
  143. const appPath = configInfoStore?.appConfig?.appPath || ''
  144. if (!appPath) {
  145. ElMessage.error('未获取到应用目录 appPath')
  146. return
  147. }
  148. const fullPath = `${appPath}\\output`
  149. clientStore.ipc.removeAllListeners(icpList.utils.shellFun);
  150. clientStore.ipc.send(icpList.utils.shellFun, {
  151. action: 'openMkPath',
  152. params: fullPath.replace(/\//g, '\\')
  153. });
  154. } catch (e) {
  155. console.error(e)
  156. ElMessage.error('打开目录失败')
  157. }
  158. }
  159. // 快捷操作菜单子项(不含生成图目录)
  160. const quickActionsChildren = [
  161. {
  162. type: 'OneClickRelease'
  163. },
  164. {
  165. type: 'OneKeyDown'
  166. }
  167. ]
  168. // 重构 menu 为带快捷操作和开发工具的下拉菜单结构
  169. const menu = computed(() => {
  170. // 生成图目录(独立菜单项,点击直接打开目录)
  171. const outputDirMenu = {
  172. name: '生成图目录',
  173. click() {
  174. openOutputDir()
  175. }
  176. }
  177. // 开发者模式:设置 + 快捷操作 + 开发工具 + 生成图目录
  178. if (useUserInfoStore.isHLM || configInfoStore.appConfig.debug) {
  179. return [
  180. {
  181. type: 'setting'
  182. },
  183. {
  184. name: '快捷操作',
  185. children: quickActionsChildren
  186. },
  187. {
  188. name: '开发工具',
  189. children: [
  190. {
  191. type: 'developer'
  192. }
  193. ]
  194. },
  195. outputDirMenu
  196. ]
  197. }
  198. // 普通模式:设置 + 快捷操作 + 生成图目录
  199. return [
  200. {
  201. type: 'setting'
  202. },
  203. {
  204. name: '快捷操作',
  205. children: quickActionsChildren
  206. },
  207. outputDirMenu
  208. ]
  209. })
  210. // editRow 数据加载完成后调用,仅记录点位,首次不打开预览
  211. function onEditRowReady(point_name) {
  212. console.log('onEditRowReady,记录点位:' + point_name)
  213. currentPointName.value = point_name
  214. }
  215. const init = ref(true)
  216. function onRunMcuSingle (){
  217. if(init.value) {
  218. loading.value = false
  219. init.value = false
  220. }
  221. }
  222. const showrEditRow = ref(false)
  223. let interval:any = null
  224. let currentPointName = ref('A')
  225. let isVideoShowing = ref(false)
  226. let isHidingVideo = ref(false)
  227. let hideVideoTimer: any = null
  228. let pendingShowVideoPoint: string | null = null
  229. let isFirstShow = false // 标记是否已首次显示预览
  230. function clearPreviewInterval() {
  231. if (interval) {
  232. clearInterval(interval)
  233. interval = null
  234. }
  235. if (hideVideoTimer) {
  236. clearTimeout(hideVideoTimer)
  237. hideVideoTimer = null
  238. }
  239. }
  240. function showVideo(point_name = 'A') {
  241. if (isHidingVideo.value) {
  242. console.log('正在关闭预览中,延迟打开:' + point_name)
  243. pendingShowVideoPoint = point_name
  244. return
  245. }
  246. if (isVideoShowing.value && currentPointName.value === point_name) {
  247. console.log('预览已在显示,跳过重复调用')
  248. return
  249. }
  250. console.log('打开预览=====================' + point_name)
  251. clearPreviewInterval()
  252. isVideoShowing.value = true
  253. currentPointName.value = point_name
  254. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  255. clientStore.ipc.send(icpList.camera.PreviewShow, { point_name });
  256. clientStore.ipc.on(icpList.camera.PreviewShow, async (event, result) => {
  257. console.log('打开预览=====================')
  258. console.log(result)
  259. if (result.device_status === -1 && result.msg){
  260. ElMessage.error(result.msg)
  261. return;
  262. }
  263. clearPreviewInterval()
  264. hideVideoTimer = setTimeout(() => {
  265. interval = setInterval(() => {
  266. previewKey.value++;
  267. }, 200)
  268. }, 500)
  269. })
  270. }
  271. async function hideVideo(point_name = 'A') {
  272. console.log('关闭预览=====================' + point_name)
  273. clearPreviewInterval()
  274. isVideoShowing.value = false
  275. isHidingVideo.value = true
  276. return new Promise((resolve) => {
  277. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  278. clientStore.ipc.send(icpList.camera.PreviewHide, { point_name });
  279. clientStore.ipc.on(icpList.camera.PreviewHide, async (event, result) => {
  280. console.log('关闭预览回调=====================')
  281. console.log(result)
  282. if (result.device_status === -1 && result.msg){
  283. console.log(result.msg)
  284. resolve(true)
  285. }
  286. isHidingVideo.value = false
  287. // 如果有待执行的打开请求,执行它
  288. if (pendingShowVideoPoint) {
  289. const point = pendingShowVideoPoint
  290. pendingShowVideoPoint = null
  291. setTimeout(() => showVideo(point), 100)
  292. }
  293. resolve(true)
  294. })
  295. })
  296. }
  297. async function switchPreviewPoint(point_name = 'A') {
  298. console.log('switchPreviewPoint:' + point_name);
  299. // 如果点位相同,不做任何处理
  300. /* if (point_name === currentPointName.value) {
  301. console.log('点位相同,跳过切换');
  302. return;
  303. }*/
  304. // 首次显示预览之前不做切换
  305. /* if (!isFirstShow) {
  306. console.log('首次显示预览前,跳过切换');
  307. currentPointName.value = point_name;
  308. return;
  309. }*/
  310. // 执行切换
  311. await hideVideo(currentPointName.value)
  312. showVideo(point_name)
  313. }
  314. function goArts(){
  315. }
  316. function handleAutoFocus() {
  317. console.log('自动对焦,点位:' + currentPointName.value)
  318. socketStore.sendMessage({
  319. type: 'smart_shooter_auto_focus',
  320. data: {
  321. point_name: currentPointName.value || 'A'
  322. }
  323. });
  324. }
  325. const loading = ref(true)
  326. const editData = ref(null);
  327. const imageTplPath = ref(null)
  328. function takePictures() {
  329. if(loading.value) return;
  330. console.log(editData);
  331. console.log(editData.value.editRowData);
  332. if (clientStore.isClient) {
  333. loading.value = true;
  334. console.log('takePictures');
  335. console.log({
  336. camera_height: Number(editData.value.editRowData.camera_height),
  337. camera_angle: Number(editData.value.editRowData.camera_angle),
  338. led_switch:editData.value.editRowData.led_switch,
  339. id:0,
  340. mode_type:editData.value.editRowData.mode_type,
  341. turntable_position:Number(editData.value.editRowData.turntable_position),
  342. action_name:editData.value.editRowData.action_name || '测试',
  343. turntable_angle: Number(editData.value.editRowData.turntable_angle),
  344. shoe_upturn: Number(editData.value.editRowData.shoe_upturn),
  345. camera_focal_distance: Number(editData.value.editRowData.camera_focal_distance),
  346. action_index:1,
  347. number_focus:0,
  348. take_picture:true,
  349. pre_delay:0,
  350. after_delay:0,
  351. point_name:editData.value.editRowData.point_name || currentPointName.value || 'A',
  352. is_move_device:editData.value.editRowData.is_move_device
  353. })
  354. hideVideo(currentPointName.value).then(() => {
  355. socketStore.sendMessage({
  356. type: 'run_mcu_single',
  357. data: {
  358. camera_height: Number(editData.value.editRowData.camera_height),
  359. camera_angle: Number(editData.value.editRowData.camera_angle),
  360. led_switch:editData.value.editRowData.led_switch,
  361. id:0,
  362. mode_type:editData.value.editRowData.mode_type,
  363. turntable_position:Number(editData.value.editRowData.turntable_position),
  364. action_name:editData.value.editRowData.action_name || '测试',
  365. turntable_angle: Number(editData.value.editRowData.turntable_angle),
  366. shoe_upturn: Number(editData.value.editRowData.shoe_upturn),
  367. camera_focal_distance: Number(editData.value.editRowData.camera_focal_distance),
  368. action_index:1,
  369. number_focus:0,
  370. take_picture:true,
  371. pre_delay:0,
  372. after_delay:0,
  373. point_name:editData.value.editRowData.point_name || currentPointName.value || 'A',
  374. is_move_device:editData.value.editRowData.is_move_device
  375. }
  376. });
  377. })
  378. }
  379. }
  380. // 获取主图
  381. function createMainImage (file_path){
  382. loading.value = true;
  383. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  384. clientStore.ipc.send(icpList.takePhoto.createMainImage,{
  385. file_path:file_path
  386. });
  387. clientStore.ipc.on(icpList.takePhoto.createMainImage, async (event, result) => {
  388. if(result.code === 0 && result.data?.main_out_path){
  389. imageTplPath.value = result.data?.main_out_path
  390. // 预览已在 takePictures 中关闭,不再重复调用 hideVideo
  391. step.value = 2
  392. loading.value = false;
  393. }else if(result.msg){
  394. loading.value = false;
  395. console.log('createMainImage');
  396. showVideo(currentPointName.value)
  397. if(result.code !== 0) ElMessage.error(result.msg)
  398. }
  399. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  400. });
  401. }
  402. //拍照成功 SmartShooter
  403. clientStore.ipc.on(icpList.socket.message+'_smart_shooter_photo_take', async (event, result) => {
  404. console.log('_smart_shooter_photo_take');
  405. console.log(result);
  406. if(result.code === 0 && result.data?.photo_file_name){
  407. imageTplPath.value = result.data?.photo_file_name
  408. step.value = 2
  409. loading.value = false;
  410. // 首次拍摄完成后打开预览用于检查镜头
  411. if (!isFirstShow) {
  412. isFirstShow = true
  413. setTimeout(() => showVideo(currentPointName.value), 100)
  414. }
  415. }else {
  416. loading.value = false;
  417. console.log('_smart_shooter_photo_take');
  418. showVideo(currentPointName.value)
  419. if(result.code !== 0 && result.msg) ElMessage.error(result.msg)
  420. }
  421. })
  422. //运行的时候 直接拍照 digiCamControl
  423. clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, result) => {
  424. console.log('_run_mcu_single_check_on')
  425. console.log(result)
  426. if(result.code === 0 && result.data?.file_path){
  427. imageTplPath.value = result.data?.file_path
  428. step.value = 2
  429. loading.value = false;
  430. // 首次拍摄完成后打开预览用于检查镜头
  431. if (!isFirstShow) {
  432. isFirstShow = true
  433. setTimeout(() => showVideo(currentPointName.value), 100)
  434. }
  435. }else {
  436. loading.value = false;
  437. console.log('_run_mcu_single');
  438. showVideo(currentPointName.value)
  439. if(result.code !== 0 && result.msg) ElMessage.error(result.msg)
  440. }
  441. /* if(result.code === 0 && result.data?.file_path){
  442. createMainImage(result.data?.file_path)
  443. }else if(result.msg){
  444. if( result.msg.indexOf('处理失败,请重试') >= 0){
  445. ElMessage.error(result.msg)
  446. step.value = 1
  447. loading.value = false;
  448. showVideo()
  449. }
  450. }*/
  451. })
  452. const exampleImage = ref('https://huilimaimg.cnhqt.com/frontend/zhihuiyin/demo.jpg?x-oss-process=image/resize,w_400')
  453. onMounted(async ()=>{
  454. await configInfoStore.getAppConfig()
  455. if(configInfoStore.appConfig.controlType === "SmartShooter"){
  456. preview.value = configInfoStore.appConfig.userDataPath + "\\preview\\liveview.png"
  457. }
  458. exampleImage.value = configInfoStore.appConfig.exampleImage || 'https://huilimaimg.cnhqt.com/frontend/zhihuiyin/demo.jpg?x-oss-process=image/resize,w_400'
  459. })
  460. /**
  461. * 页面卸载时移除所有事件监听器。
  462. */
  463. onBeforeUnmount(() => {
  464. clearPreviewInterval()
  465. console.log('onBeforeUnmount');
  466. hideVideo(currentPointName.value)
  467. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  468. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  469. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  470. clientStore.ipc.removeAllListeners(icpList.socket.message+'_run_mcu_single');
  471. clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_photo_take');
  472. })
  473. </script>
  474. <style scoped lang="scss">
  475. .check-wrap {
  476. background-color: rgba(234, 236, 237, 1);
  477. display: flex;
  478. justify-content: left;
  479. }
  480. .check-page {
  481. width: calc(100% - 330px) ;
  482. position: relative;
  483. min-height: calc(100vh - 35px);
  484. overflow: hidden;
  485. background: #fff;
  486. .main-container {
  487. width: 100%;
  488. min-height: calc(100vh - 35px);
  489. margin-bottom: 1px;
  490. .content-wrapper {
  491. width:100%;
  492. padding: 10px;
  493. .left-panel {
  494. width: 100%;
  495. height: calc(100% - 80px);
  496. .tips-container {
  497. background-color: rgba(255, 241, 222, 0.8);
  498. border-radius: 4px;
  499. width: 100%;
  500. height: 40px;
  501. border: 1px solid rgba(255, 228, 190, 1);
  502. justify-content: flex-center;
  503. .tips-icon {
  504. width: 16px;
  505. height: 16px;
  506. margin: 12px 0 0 16px;
  507. }
  508. .tips-tex {
  509. width: 549px;
  510. height: 22px;
  511. overflow-wrap: break-word;
  512. color: rgba(0, 0, 0, 0.85);
  513. font-size: 14px;
  514. font-weight: NaN;
  515. text-align: left;
  516. white-space: nowrap;
  517. line-height: 22px;
  518. margin: 9px 0 0 7px;
  519. }
  520. .close-icon {
  521. width: 12px;
  522. height: 12px;
  523. margin: 14px 16px 0 17px;
  524. }
  525. }
  526. .camera-preview {
  527. background-color: rgba(255, 255, 255, 1);
  528. height: calc(100vh - 200px);
  529. position: relative;
  530. margin-top: 20px;
  531. position: relative;
  532. .camera-description {
  533. position: absolute;
  534. bottom: 20px;
  535. width: 60%;
  536. padding: 8px 20px;
  537. background: rgba($color: #ffffff, $alpha: .2);
  538. border-radius: 20px;
  539. font-size: 14px;
  540. }
  541. .camera-preview-img {
  542. display: inline-block;
  543. height: 100%;
  544. min-width: 300px;
  545. position: relative;
  546. }
  547. .auto-focus-btn {
  548. position: absolute;
  549. top: 10px;
  550. right: 10px;
  551. z-index: 10;
  552. }
  553. .camera-img {
  554. // width: 100%;
  555. display: block;
  556. position: relative;
  557. box-shadow: 0px 2px 10px 0px rgba(0, 32, 78, 0.1);
  558. height: 100%;
  559. object-fit:contain;
  560. }
  561. .example-image {
  562. position: absolute;
  563. right: 10px;
  564. bottom: 10px;
  565. background-color: rgba(216, 216, 216, 1);
  566. height: 135px;
  567. margin-top: 10px;
  568. width: 200px;
  569. img {
  570. width: 200px;
  571. height: 135px;
  572. display: block;
  573. }
  574. }
  575. }
  576. }
  577. }
  578. .action-button {
  579. width: 100%;
  580. text-align: center;
  581. margin-top: 28px;
  582. .check-button {
  583. .button-text {
  584. width: 180px;
  585. overflow-wrap: break-word;
  586. font-size: 16px;
  587. text-align: center;
  588. white-space: nowrap;
  589. height: 40px;
  590. line-height: 40px;
  591. }
  592. }
  593. }
  594. }
  595. }
  596. .check-page_seeting {
  597. min-height: calc(100vh - 92px);
  598. .main-container {
  599. min-height: calc(100vh - 92px);
  600. }
  601. }
  602. </style>