check.vue 12 KB

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