check.vue 17 KB

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