您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

viewfinderCar.vue 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view style="width: 100%;height: 100vh;position: fixed;left: 0;top:0;z-index: 111111;">
  3. <view class="viewfinder">
  4. <!-- <view v-if="phoneType == 1"
  5. style="display: flex;align-items: center;justify-content: flex-end;width: 100%;height: 100%;">
  6. <image :src="fileURL + 'image/index/etc_bd_ocr_id_card_locator_back.png'"
  7. style="height: 220rpx;margin-right: 30rpx;" mode="heightFix"></image>
  8. </view>
  9. <view v-if="phoneType == 2" style="margin: 30rpx 0 0 30rpx;">
  10. <image :src="fileURL + 'image/index/etc_bd_ocr_id_card_locator_front.png'" style="height: 160rpx;"
  11. mode="heightFix">
  12. </image>
  13. </view> -->
  14. <view v-if="phoneType == 1"
  15. style="margin: -30rpx 0 0 30rpx;display: flex;height: 100%;align-self: flex-end;flex-direction: column;justify-content: flex-end;">
  16. <view style="border: 1px solid #fff;height: 160rpx;width: 160rpx;">
  17. </view>
  18. </view>
  19. <view v-if="phoneType == 2"
  20. style="margin: -30rpx 30rpx 0 0;display: flex;height: 100%;justify-content: flex-end;align-items: flex-end;">
  21. <view style="border: 1px solid #fff;height: 60rpx;width: 300rpx;">
  22. </view>
  23. </view>
  24. </view>
  25. <!-- camera -->
  26. <camera v-if="showStartPhoto" id="camera" style="height: 70vh;width: 100vh;background-color: black;width: 100%;"
  27. mode="normal" :device-position="cameraPosition" :flash="flash" @stop="cameraStop" @error="cameraError" />
  28. <image v-if="!showStartPhoto" :src="srcImg" style="height: 98vh;width: 100vh;"></image>
  29. <view style="background-color: #A5A5A5;top: 60%;width: 100%;height: 40%;position: absolute;">
  30. <view style="display: flex;flex-direction: row;justify-content: center;align-items: center;height: 100%;">
  31. <view style="flex: 1;"></view>
  32. <image v-if="!showStartPhoto" @click="camera" :src="fileURL + 'image/index/etc_bd_ocr_cancel.png'"
  33. style="width: 50rpx;height: 50rpx;"></image>
  34. <view style="flex: 1;"></view>
  35. <image @click="takePhoto" :src="fileURL + 'image/index/etc_bd_ocr_take_photo_normal.png'"
  36. style="width: 140rpx;height: 140rpx;"></image>
  37. <view style="flex: 1;"></view>
  38. <image v-if="!showStartPhoto" @click="success" :src="fileURL + 'image/index/etc_bd_ocr_confirm.png'"
  39. style="width: 50rpx;height: 50rpx;"></image>
  40. <view style="flex: 1;"></view>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script setup lang="ts">
  46. import {
  47. fileURL
  48. } from "@/datas/fileURL.js";
  49. import {
  50. ref
  51. } from 'vue'
  52. let prop = defineProps({
  53. phoneType: {
  54. type: Number,
  55. default: function () {
  56. return 3 //1 身份证正面 2 身份证反面 3 行驶证正面 4 行驶证反面
  57. }
  58. },
  59. });
  60. console.log('输出内容', prop.phoneType)
  61. const emit = defineEmits<{
  62. (e : "confirmReturn", content : any) : void;
  63. (e : "failReturn", content : any) : void;
  64. }>();
  65. let cameraPosition = 'back' // 'back'为后置摄像头,'front'为前置摄像头
  66. let flash = 'off' // 'off'为关闭闪光灯,'on'为打开闪光灯
  67. let showStartPhoto = ref(true)
  68. let srcImg = ref('')
  69. let resItem = ref(null);
  70. function takePhoto() {
  71. console.log('输出内容', '===123')
  72. let cameraContext = null
  73. // #ifdef MP-WEIXIN
  74. cameraContext = uni.createCameraContext();
  75. // #endif
  76. // #ifdef MP-ALIPAY
  77. cameraContext = my.createCameraContext('camera');
  78. // #endif
  79. // 调用拍照方法
  80. cameraContext.takePhoto({
  81. quality: 'normal',
  82. success: (res) => {
  83. // 在这里处理拍照成功后的逻辑,res.tempImagePath 为拍照的图片路径
  84. console.log('拍照成功:', res.tempImagePath);
  85. srcImg.value = res.tempImagePath
  86. // showStartPhoto.value = false
  87. // resItem.value = res
  88. // // #ifdef MP-ALIPAY
  89. // cameraContext.stopRecord();
  90. // emit('confirmReturn', res)
  91. // // #endif
  92. cameraContext.stopRecord();
  93. emit('confirmReturn', res)
  94. },
  95. fail: (error) => {
  96. console.error('拍照失败:', error);
  97. emit('failReturn', error);
  98. },
  99. });
  100. }
  101. //成功
  102. function success() {
  103. console.log('成功:', resItem.value);
  104. emit('confirmReturn', resItem.value)
  105. }
  106. //重新拍摄
  107. function camera() {
  108. showStartPhoto.value = true
  109. }
  110. function cameraStop() {
  111. // 相机停止时的回调
  112. console.log('相机已停止');
  113. }
  114. function cameraError(e) {
  115. // 相机出错时的回调
  116. console.error('相机错误:', e.detail.errMsg);
  117. }
  118. </script>
  119. <style>
  120. .viewfinder {
  121. position: absolute;
  122. top: 20%;
  123. left: 10%;
  124. width: 80%;
  125. height: 400rpx;
  126. border: 2px solid #fff;
  127. box-sizing: border-box;
  128. border-radius: 16rpx;
  129. z-index: 2;
  130. }
  131. </style>