check.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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. }
  147. if(!init) previewKey.value++;
  148. showrEditRow.value = true
  149. loading.value = false;
  150. }
  151. // editRow 数据加载完成后调用,仅记录点位,首次不打开预览
  152. function onEditRowReady(point_name) {
  153. console.log('onEditRowReady,记录点位:' + point_name)
  154. currentPointName.value = point_name
  155. }
  156. const init = ref(true)
  157. function onRunMcuSingle (){
  158. if(init.value) {
  159. loading.value = false
  160. init.value = false
  161. }
  162. }
  163. const showrEditRow = ref(false)
  164. let interval:any = null
  165. let currentPointName = ref('A')
  166. let isVideoShowing = ref(false)
  167. let isHidingVideo = ref(false)
  168. let hideVideoTimer: any = null
  169. let pendingShowVideoPoint: string | null = null
  170. let isFirstShow = false // 标记是否已首次显示预览
  171. function clearPreviewInterval() {
  172. if (interval) {
  173. clearInterval(interval)
  174. interval = null
  175. }
  176. if (hideVideoTimer) {
  177. clearTimeout(hideVideoTimer)
  178. hideVideoTimer = null
  179. }
  180. }
  181. function showVideo(point_name = 'A') {
  182. if (isHidingVideo.value) {
  183. console.log('正在关闭预览中,延迟打开:' + point_name)
  184. pendingShowVideoPoint = point_name
  185. return
  186. }
  187. if (isVideoShowing.value && currentPointName.value === point_name) {
  188. console.log('预览已在显示,跳过重复调用')
  189. return
  190. }
  191. console.log('打开预览=====================' + point_name)
  192. clearPreviewInterval()
  193. isVideoShowing.value = true
  194. currentPointName.value = point_name
  195. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  196. clientStore.ipc.send(icpList.camera.PreviewShow, { point_name });
  197. clientStore.ipc.on(icpList.camera.PreviewShow, async (event, result) => {
  198. console.log('打开预览=====================')
  199. console.log(result)
  200. if (result.device_status === -1 && result.msg){
  201. ElMessage.error(result.msg)
  202. return;
  203. }
  204. clearPreviewInterval()
  205. hideVideoTimer = setTimeout(() => {
  206. interval = setInterval(() => {
  207. previewKey.value++;
  208. }, 200)
  209. }, 500)
  210. })
  211. }
  212. async function hideVideo(point_name = 'A') {
  213. console.log('关闭预览=====================' + point_name)
  214. clearPreviewInterval()
  215. isVideoShowing.value = false
  216. isHidingVideo.value = true
  217. return new Promise((resolve) => {
  218. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  219. clientStore.ipc.send(icpList.camera.PreviewHide, { point_name });
  220. clientStore.ipc.on(icpList.camera.PreviewHide, async (event, result) => {
  221. console.log('关闭预览回调=====================')
  222. console.log(result)
  223. if (result.device_status === -1 && result.msg){
  224. console.log(result.msg)
  225. resolve(true)
  226. }
  227. isHidingVideo.value = false
  228. // 如果有待执行的打开请求,执行它
  229. if (pendingShowVideoPoint) {
  230. const point = pendingShowVideoPoint
  231. pendingShowVideoPoint = null
  232. setTimeout(() => showVideo(point), 100)
  233. }
  234. resolve(true)
  235. })
  236. })
  237. }
  238. async function switchPreviewPoint(point_name = 'A') {
  239. console.log('switchPreviewPoint:' + point_name);
  240. // 如果点位相同,不做任何处理
  241. if (point_name === currentPointName.value) {
  242. console.log('点位相同,跳过切换');
  243. return;
  244. }
  245. // 首次显示预览之前不做切换
  246. /* if (!isFirstShow) {
  247. console.log('首次显示预览前,跳过切换');
  248. currentPointName.value = point_name;
  249. return;
  250. }*/
  251. // 执行切换
  252. await hideVideo(currentPointName.value)
  253. showVideo(point_name)
  254. }
  255. function goArts(){
  256. }
  257. function handleAutoFocus() {
  258. console.log('自动对焦,点位:' + currentPointName.value)
  259. socketStore.sendMessage({
  260. type: 'smart_shooter_auto_focus',
  261. data: {
  262. point_name: currentPointName.value || 'A'
  263. }
  264. });
  265. }
  266. const loading = ref(true)
  267. const editData = ref(null);
  268. const imageTplPath = ref(null)
  269. function takePictures() {
  270. if(loading.value) return;
  271. console.log(editData);
  272. console.log(editData.value.editRowData);
  273. if (clientStore.isClient) {
  274. loading.value = true;
  275. console.log('takePictures');
  276. hideVideo(currentPointName.value).then(() => {
  277. socketStore.sendMessage({
  278. type: 'run_mcu_single',
  279. data: {
  280. camera_height: Number(editData.value.editRowData.camera_height),
  281. camera_angle: Number(editData.value.editRowData.camera_angle),
  282. led_switch:editData.value.editRowData.led_switch,
  283. id:0,
  284. mode_type:editData.value.editRowData.mode_type,
  285. turntable_position:Number(editData.value.editRowData.turntable_position),
  286. action_name:editData.value.editRowData.action_name || '测试',
  287. turntable_angle: Number(editData.value.editRowData.turntable_angle),
  288. shoe_upturn: Number(editData.value.editRowData.shoe_upturn),
  289. action_index:1,
  290. number_focus:0,
  291. take_picture:true,
  292. pre_delay:0,
  293. after_delay:0,
  294. point_name:editData.value.editRowData.point_name || currentPointName.value || 'A',
  295. is_move_device:editData.value.editRowData.is_move_device
  296. }
  297. });
  298. })
  299. }
  300. }
  301. // 获取主图
  302. function createMainImage (file_path){
  303. loading.value = true;
  304. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  305. clientStore.ipc.send(icpList.takePhoto.createMainImage,{
  306. file_path:file_path
  307. });
  308. clientStore.ipc.on(icpList.takePhoto.createMainImage, async (event, result) => {
  309. if(result.code === 0 && result.data?.main_out_path){
  310. imageTplPath.value = result.data?.main_out_path
  311. // 预览已在 takePictures 中关闭,不再重复调用 hideVideo
  312. step.value = 2
  313. loading.value = false;
  314. }else if(result.msg){
  315. loading.value = false;
  316. console.log('createMainImage');
  317. showVideo(currentPointName.value)
  318. if(result.code !== 0) ElMessage.error(result.msg)
  319. }
  320. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  321. });
  322. }
  323. //拍照成功 SmartShooter
  324. clientStore.ipc.on(icpList.socket.message+'_smart_shooter_photo_take', async (event, result) => {
  325. console.log('_smart_shooter_photo_take');
  326. console.log(result);
  327. if(result.code === 0 && result.data?.photo_file_name){
  328. imageTplPath.value = result.data?.photo_file_name
  329. step.value = 2
  330. loading.value = false;
  331. // 首次拍摄完成后打开预览用于检查镜头
  332. if (!isFirstShow) {
  333. isFirstShow = true
  334. setTimeout(() => showVideo(currentPointName.value), 100)
  335. }
  336. }else {
  337. loading.value = false;
  338. console.log('_smart_shooter_photo_take');
  339. showVideo(currentPointName.value)
  340. if(result.code !== 0 && result.msg) ElMessage.error(result.msg)
  341. }
  342. })
  343. //运行的时候 直接拍照 digiCamControl
  344. clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, result) => {
  345. console.log('_run_mcu_single_check_on')
  346. console.log(result)
  347. if(result.code === 0 && result.data?.file_path){
  348. imageTplPath.value = result.data?.file_path
  349. step.value = 2
  350. loading.value = false;
  351. // 首次拍摄完成后打开预览用于检查镜头
  352. if (!isFirstShow) {
  353. isFirstShow = true
  354. setTimeout(() => showVideo(currentPointName.value), 100)
  355. }
  356. }else {
  357. loading.value = false;
  358. console.log('_run_mcu_single');
  359. showVideo(currentPointName.value)
  360. if(result.code !== 0 && result.msg) ElMessage.error(result.msg)
  361. }
  362. /* if(result.code === 0 && result.data?.file_path){
  363. createMainImage(result.data?.file_path)
  364. }else if(result.msg){
  365. if( result.msg.indexOf('处理失败,请重试') >= 0){
  366. ElMessage.error(result.msg)
  367. step.value = 1
  368. loading.value = false;
  369. showVideo()
  370. }
  371. }*/
  372. })
  373. const exampleImage = ref('https://huilimaimg.cnhqt.com/frontend/zhihuiyin/demo.jpg?x-oss-process=image/resize,w_400')
  374. onMounted(async ()=>{
  375. await configInfoStore.getAppConfig()
  376. if(configInfoStore.appConfig.controlType === "SmartShooter"){
  377. preview.value = configInfoStore.appConfig.userDataPath + "\\preview\\liveview.png"
  378. }
  379. exampleImage.value = configInfoStore.appConfig.exampleImage || 'https://huilimaimg.cnhqt.com/frontend/zhihuiyin/demo.jpg?x-oss-process=image/resize,w_400'
  380. })
  381. /**
  382. * 页面卸载时移除所有事件监听器。
  383. */
  384. onBeforeUnmount(() => {
  385. clearPreviewInterval()
  386. console.log('onBeforeUnmount');
  387. hideVideo(currentPointName.value)
  388. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  389. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  390. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  391. clientStore.ipc.removeAllListeners(icpList.socket.message+'_run_mcu_single');
  392. clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_photo_take');
  393. })
  394. </script>
  395. <style scoped lang="scss">
  396. .check-wrap {
  397. background-color: rgba(234, 236, 237, 1);
  398. display: flex;
  399. justify-content: left;
  400. }
  401. .check-page {
  402. width: calc(100% - 330px) ;
  403. position: relative;
  404. min-height: calc(100vh - 35px);
  405. overflow: hidden;
  406. background: #fff;
  407. .main-container {
  408. width: 100%;
  409. min-height: calc(100vh - 35px);
  410. margin-bottom: 1px;
  411. .content-wrapper {
  412. width:100%;
  413. padding: 10px;
  414. .left-panel {
  415. width: 100%;
  416. height: calc(100% - 80px);
  417. .tips-container {
  418. background-color: rgba(255, 241, 222, 0.8);
  419. border-radius: 4px;
  420. width: 100%;
  421. height: 40px;
  422. border: 1px solid rgba(255, 228, 190, 1);
  423. justify-content: flex-center;
  424. .tips-icon {
  425. width: 16px;
  426. height: 16px;
  427. margin: 12px 0 0 16px;
  428. }
  429. .tips-tex {
  430. width: 549px;
  431. height: 22px;
  432. overflow-wrap: break-word;
  433. color: rgba(0, 0, 0, 0.85);
  434. font-size: 14px;
  435. font-weight: NaN;
  436. text-align: left;
  437. white-space: nowrap;
  438. line-height: 22px;
  439. margin: 9px 0 0 7px;
  440. }
  441. .close-icon {
  442. width: 12px;
  443. height: 12px;
  444. margin: 14px 16px 0 17px;
  445. }
  446. }
  447. .camera-preview {
  448. background-color: rgba(255, 255, 255, 1);
  449. height: calc(100vh - 200px);
  450. position: relative;
  451. margin-top: 20px;
  452. position: relative;
  453. .camera-description {
  454. position: absolute;
  455. bottom: 20px;
  456. width: 60%;
  457. padding: 8px 20px;
  458. background: rgba($color: #ffffff, $alpha: .2);
  459. border-radius: 20px;
  460. font-size: 14px;
  461. }
  462. .camera-preview-img {
  463. display: inline-block;
  464. height: 100%;
  465. min-width: 300px;
  466. position: relative;
  467. }
  468. .auto-focus-btn {
  469. position: absolute;
  470. top: 10px;
  471. right: 10px;
  472. z-index: 10;
  473. }
  474. .camera-img {
  475. // width: 100%;
  476. display: block;
  477. position: relative;
  478. box-shadow: 0px 2px 10px 0px rgba(0, 32, 78, 0.1);
  479. height: 100%;
  480. object-fit:contain;
  481. }
  482. .example-image {
  483. position: absolute;
  484. right: 10px;
  485. bottom: 10px;
  486. background-color: rgba(216, 216, 216, 1);
  487. height: 135px;
  488. margin-top: 10px;
  489. width: 200px;
  490. img {
  491. width: 200px;
  492. height: 135px;
  493. display: block;
  494. }
  495. }
  496. }
  497. }
  498. }
  499. .action-button {
  500. width: 100%;
  501. text-align: center;
  502. margin-top: 28px;
  503. .check-button {
  504. .button-text {
  505. width: 180px;
  506. overflow-wrap: break-word;
  507. font-size: 16px;
  508. text-align: center;
  509. white-space: nowrap;
  510. height: 40px;
  511. line-height: 40px;
  512. }
  513. }
  514. }
  515. }
  516. }
  517. .check-page_seeting {
  518. min-height: calc(100vh - 92px);
  519. .main-container {
  520. min-height: calc(100vh - 92px);
  521. }
  522. }
  523. </style>