check.vue 11 KB

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