check.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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"><img src="https://huilimaimg.cnhqt.com/frontend/zhihuiyin/demo.jpg?x-oss-process=image/resize,w_400"></div>
  25. </div>
  26. <template v-if="step === 2" >
  27. <img class="camera-img" :src="getFilePath(imageTplPath)" />
  28. <span class="camera-description">这是一张用于检查镜头是否合适的测试图</span>
  29. </template>
  30. </div>
  31. </div>
  32. </div>
  33. <template v-if="!isSetting">
  34. <div v-if="step === 1" class="action-button flex cente">
  35. <div @click="takePictures" class="check-button button--primary1 flex-col"><span class="button-text" v-loading="loading">拍照检查</span>
  36. </div>
  37. </div>
  38. <div v-else class="action-button flex center">
  39. <div @click="checkConfirm(false)" class="check-button button--white flex-col">
  40. <span class="button-text cu-p">重新拍照检查</span>
  41. </div>
  42. <router-link class="mar-left-20 " :to="{
  43. name: 'PhotographyShot'
  44. }">
  45. <div class="check-button button--primary1 flex-col">
  46. <span class="button-text cu-p">确认无误,下一步</span>
  47. </div>
  48. </router-link>
  49. </div>
  50. </template>
  51. </div>
  52. </div>
  53. <editRow
  54. v-if="showrEditRow || isSetting"
  55. :id="id"
  56. @confirm="confirm"
  57. ref="editData"
  58. @onClose="onClose"
  59. @onRunMcuSingle="onRunMcuSingle"
  60. :addRowData="addRowData"
  61. />
  62. </div>
  63. <hardware-check v-if="!isSetting"
  64. isInitCheck
  65. @confirm="checkConfirm(true)"
  66. />
  67. </template>
  68. <script setup lang="ts">
  69. import {watchEffect, ref, reactive, defineEmits, defineProps, computed, onBeforeUnmount, onMounted} from 'vue'
  70. import client from "@/stores/modules/client";
  71. import socket from "@/stores/modules/socket";
  72. import icpList from '@/utils/ipc'
  73. import useUserInfo from "@/stores/modules/user";
  74. import headerBar from '@/components/header-bar/index.vue'
  75. import editRow from './components/editRow'
  76. const clientStore = client();
  77. const socketStore = socket(); // WebSocket状态管理实例
  78. const emit = defineEmits([ 'confirm','onClose']);
  79. import configInfo from '@/stores/modules/config';
  80. const configInfoStore = configInfo();
  81. const confirm = ()=>{
  82. hideVideo()
  83. emit('confirm')
  84. }
  85. const onClose = ()=>{
  86. hideVideo()
  87. emit('onClose')
  88. }
  89. // 定义 props
  90. const props = defineProps({
  91. id:{
  92. type: Number||String,
  93. default: 0
  94. },
  95. addRowData:{
  96. type: Object,
  97. default: () => {
  98. return { }
  99. }
  100. }
  101. })
  102. const menu = reactive([])
  103. const show = ref(true)
  104. const isSetting = computed(()=>{
  105. return props.id || props.addRowData.mode_type
  106. })
  107. const useUserInfoStore = useUserInfo()
  108. import HardwareCheck from '@/components/check/index.vue'
  109. import { digiCamControlWEB } from '@/utils/appconfig'
  110. import { getFilePath } from '@/utils/appfun'
  111. import {ElMessage} from "element-plus";
  112. const previewKey = ref(0)
  113. const preview = ref(digiCamControlWEB+'liveview.jpg')
  114. const previewSrc = computed(()=>{
  115. let time = new Date().getTime()
  116. return preview.value+'?key='+previewKey.value+'&time='+time
  117. })
  118. const step = ref(1)
  119. async function checkConfirm(init){
  120. step.value =1
  121. if(menu.length === 0){
  122. menu.push({
  123. type:'developer'
  124. })
  125. menu.push({
  126. type:'toggleModel'
  127. })
  128. }
  129. if(!init) previewKey.value++;
  130. showVideo()
  131. showrEditRow.value = true
  132. }
  133. const init = ref(true)
  134. function onRunMcuSingle (){
  135. if(init.value) {
  136. loading.value = false
  137. init.value = false
  138. }
  139. }
  140. const showrEditRow = ref(false)
  141. let interval:any = null
  142. function showVideo(){
  143. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  144. clientStore.ipc.send(icpList.camera.PreviewShow);
  145. clientStore.ipc.on(icpList.camera.PreviewShow, async (event, result) => {
  146. setTimeout(()=>{
  147. interval = setInterval(()=>{
  148. previewKey.value++;
  149. },200)
  150. },500)
  151. })
  152. }
  153. function hideVideo(){
  154. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  155. clientStore.ipc.send(icpList.camera.PreviewHide);
  156. clientStore.ipc.on(icpList.camera.PreviewHide, async (event, result) => {
  157. if(interval) clearInterval(interval)
  158. })
  159. }
  160. function goArts(){
  161. }
  162. const loading = ref(true)
  163. const editData = ref(null);
  164. const imageTplPath = ref(null)
  165. function takePictures() {
  166. console.log(editData);
  167. console.log(editData.value.editRowData);
  168. if (clientStore.isClient) {
  169. loading.value = true;
  170. hideVideo()
  171. socketStore.sendMessage({
  172. type: 'run_mcu_single',
  173. data: {
  174. camera_height: Number(editData.value.editRowData.camera_height),
  175. camera_angle: Number(editData.value.editRowData.camera_angle),
  176. led_switch:editData.value.editRowData.led_switch,
  177. id:0,
  178. mode_type:editData.value.editRowData.mode_type,
  179. turntable_position:Number(editData.value.editRowData.turntable_position),
  180. action_name:editData.value.editRowData.action_name || '测试',
  181. turntable_angle: Number(editData.value.editRowData.turntable_angle),
  182. shoe_upturn: Number(editData.value.editRowData.shoe_upturn),
  183. action_index:1,
  184. number_focus:0,
  185. take_picture:true,
  186. pre_delay:0,
  187. after_delay:0,
  188. }
  189. });
  190. }
  191. }
  192. // 获取主图
  193. function createMainImage (file_path){
  194. loading.value = true;
  195. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  196. clientStore.ipc.send(icpList.takePhoto.createMainImage,{
  197. file_path:file_path
  198. });
  199. clientStore.ipc.on(icpList.takePhoto.createMainImage, async (event, result) => {
  200. if(result.code === 0 && result.data?.main_out_path){
  201. imageTplPath.value = result.data?.main_out_path
  202. hideVideo()
  203. step.value = 2
  204. loading.value = false;
  205. }else if(result.msg){
  206. loading.value = false;
  207. showVideo()
  208. if(result.code !== 0) ElMessage.error(result.msg)
  209. }
  210. clientStore.ipc.removeAllListeners(icpList.takePhoto.createMainImage);
  211. });
  212. }
  213. //拍照成功 SmartShooter
  214. clientStore.ipc.on(icpList.socket.message+'_smart_shooter_photo_take', async (event, result) => {
  215. console.log('_smart_shooter_photo_take');
  216. console.log(result);
  217. if(result.code === 0 && result.data?.photo_file_name){
  218. createMainImage(result.data?.photo_file_name)
  219. }
  220. })
  221. //运行的时候 直接拍照 digiCamControl
  222. clientStore.ipc.on(icpList.socket.message+'_run_mcu_single', async (event, result) => {
  223. console.log('_run_mcu_single_check_on')
  224. console.log(result)
  225. if(result.code === 0 && result.data?.file_path){
  226. createMainImage(result.data?.file_path)
  227. }else if(result.msg){
  228. if( result.msg.indexOf('处理失败,请重试') >= 0){
  229. ElMessage.error(result.msg)
  230. step.value = 1
  231. loading.value = false;
  232. showVideo()
  233. }
  234. }
  235. })
  236. onMounted(async ()=>{
  237. if(isSetting.value) showVideo()
  238. await configInfoStore.getAppConfig()
  239. if(configInfoStore.appConfig.controlType === "SmartShooter"){
  240. preview.value = configInfoStore.appConfig.userDataPath + "\\preview\\liveview.png"
  241. }
  242. })
  243. /**
  244. * 页面卸载时移除所有事件监听器。
  245. */
  246. onBeforeUnmount(() => {
  247. hideVideo()
  248. clientStore.ipc.removeAllListeners(icpList.camera.takePictures);
  249. clientStore.ipc.removeAllListeners(icpList.camera.PreviewHide);
  250. clientStore.ipc.removeAllListeners(icpList.camera.PreviewShow);
  251. clientStore.ipc.removeAllListeners(icpList.socket.message+'_run_mcu_single');
  252. clientStore.ipc.removeAllListeners(icpList.socket.message+'_smart_shooter_photo_take');
  253. })
  254. </script>
  255. <style scoped lang="scss">
  256. .check-wrap {
  257. background-color: rgba(234, 236, 237, 1);
  258. display: flex;
  259. justify-content: left;
  260. }
  261. .check-page {
  262. width: calc(100% - 330px) ;
  263. position: relative;
  264. min-height: calc(100vh - 35px);
  265. overflow: hidden;
  266. background: #fff;
  267. .main-container {
  268. width: 100%;
  269. min-height: calc(100vh - 35px);
  270. margin-bottom: 1px;
  271. .content-wrapper {
  272. width:100%;
  273. padding: 10px;
  274. .left-panel {
  275. width: 100%;
  276. height: calc(100% - 80px);
  277. .tips-container {
  278. background-color: rgba(255, 241, 222, 0.8);
  279. border-radius: 4px;
  280. width: 100%;
  281. height: 40px;
  282. border: 1px solid rgba(255, 228, 190, 1);
  283. justify-content: flex-center;
  284. .tips-icon {
  285. width: 16px;
  286. height: 16px;
  287. margin: 12px 0 0 16px;
  288. }
  289. .tips-tex {
  290. width: 549px;
  291. height: 22px;
  292. overflow-wrap: break-word;
  293. color: rgba(0, 0, 0, 0.85);
  294. font-size: 14px;
  295. font-weight: NaN;
  296. text-align: left;
  297. white-space: nowrap;
  298. line-height: 22px;
  299. margin: 9px 0 0 7px;
  300. }
  301. .close-icon {
  302. width: 12px;
  303. height: 12px;
  304. margin: 14px 16px 0 17px;
  305. }
  306. }
  307. .camera-preview {
  308. background-color: rgba(255, 255, 255, 1);
  309. height: calc(100vh - 200px);
  310. position: relative;
  311. margin-top: 20px;
  312. position: relative;
  313. .camera-description {
  314. position: absolute;
  315. bottom: 20px;
  316. width: 60%;
  317. padding: 8px 20px;
  318. background: rgba($color: #ffffff, $alpha: .2);
  319. border-radius: 20px;
  320. font-size: 14px;
  321. }
  322. .camera-preview-img {
  323. display: inline-block;
  324. height: 100%;
  325. min-width: 300px;
  326. position: relative;
  327. }
  328. .camera-img {
  329. // width: 100%;
  330. display: block;
  331. position: relative;
  332. box-shadow: 0px 2px 10px 0px rgba(0, 32, 78, 0.1);
  333. height: 100%;
  334. object-fit:contain;
  335. }
  336. .example-image {
  337. position: absolute;
  338. right: 10px;
  339. bottom: 10px;
  340. background-color: rgba(216, 216, 216, 1);
  341. height: 135px;
  342. margin-top: 10px;
  343. width: 200px;
  344. img {
  345. width: 200px;
  346. height: 135px;
  347. display: block;
  348. }
  349. }
  350. }
  351. }
  352. }
  353. .action-button {
  354. width: 100%;
  355. text-align: center;
  356. margin-top: 28px;
  357. .check-button {
  358. .button-text {
  359. width: 180px;
  360. overflow-wrap: break-word;
  361. font-size: 16px;
  362. text-align: center;
  363. white-space: nowrap;
  364. height: 40px;
  365. line-height: 40px;
  366. }
  367. }
  368. }
  369. }
  370. }
  371. .check-page_seeting {
  372. min-height: calc(100vh - 92px);
  373. .main-container {
  374. min-height: calc(100vh - 92px);
  375. }
  376. }
  377. </style>