check.vue 16 KB

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