You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uploadOcr.vue 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="choice-takePhoto-wrap" v-if="prop.isTakePhotoModeShow" @click="cancle">
  3. <view class="choice-takePhoto">
  4. <view @click.stop="takePhoto(prop.phoneType)" style="border-radius: 20rpx 20rpx 0 0;">拍照</view>
  5. <view @click.stop="xiangce(prop.phoneType)">从手机相册选择</view>
  6. <view @click.stop="cancle">取消</view>
  7. </view>
  8. </view>
  9. <viewfinder v-if="state.phoneType" :phoneType="state.phoneType" :images="state.images" :showStartPhoto="state.showImg"
  10. @confirmReturn="confirmReturn" @camera="camera"></viewfinder>
  11. </template>
  12. <script setup lang="ts">
  13. import {
  14. reactive,
  15. ref,
  16. onMounted
  17. } from "vue";
  18. import viewfinder from "./viewfinder.vue"
  19. import { idCardOcr,vehicleLicenseOcr} from "@/utils/network/api.js";
  20. import {
  21. uploadFile,
  22. compressImage,
  23. chooseImageCompress,
  24. compareDates
  25. } from "@/utils/utils";
  26. let prop = defineProps({
  27. phoneType: {
  28. type: Number,
  29. default: function () {
  30. return 0 //1 身份证正面 2 身份证反面 3 行驶证正面 4 行驶证反面
  31. }
  32. },
  33. isTakePhotoModeShow: {
  34. type: Boolean,
  35. default: function () {
  36. return false
  37. }
  38. },
  39. });
  40. const emit = defineEmits<{
  41. (e : "close", content : any) : void;
  42. (e : "ocrResult", content : any) : void;
  43. }>();
  44. const state = reactive({
  45. showImg: true,
  46. phoneType: 0, // 1 身份证正面 2 身份证反面 3行驶证正面 4行驶证反面
  47. choiceIndex: 1, // 1 身份证正面 2 身份证反面
  48. isTakePhotoModeShow:false, //选择拍照方式是否出来
  49. images: '',
  50. })
  51. const xiangce = (val) => {
  52. console.log("val", val)
  53. var imageType=""
  54. state.choiceIndex=val
  55. if(state.choiceIndex == 1 || state.choiceIndex == 2){
  56. imageType = val;
  57. }else{
  58. if (state.choiceIndex == 3) {
  59. imageType = '1';
  60. } else {
  61. imageType = '2';
  62. }
  63. }
  64. chooseImageCompress((res) => {
  65. console.log("res",res,state.choiceIndex)
  66. state.images = res.tempFilePath ? res.tempFilePath : res.tempFilePaths[0]
  67. state.showImg = false
  68. emit('close', false)
  69. if(state.choiceIndex==1 || state.choiceIndex==2){
  70. var issfz=idCardOcr
  71. }else{
  72. var issfz=vehicleLicenseOcr
  73. }
  74. uploadFile(state.images, imageType, issfz).then((data) => {
  75. console.log("身份证上传", data)
  76. emit('ocrResult', data)
  77. })
  78. })
  79. }
  80. const takePhoto = (val) => {
  81. state.showImg = true
  82. console.log("拍照", val)
  83. state.phoneType = val;
  84. state.choiceIndex=val
  85. }
  86. const confirmReturn = (val) => {
  87. console.log("图片地址val", val)
  88. state.phoneType = 0
  89. if(state.choiceIndex==1 || state.choiceIndex==2){
  90. var imageType = state.choiceIndex;
  91. var issfz=idCardOcr
  92. }else{
  93. if (state.choiceIndex == 3) {
  94. var imageType = 1;
  95. } else {
  96. var imageType = 2;
  97. }
  98. var issfz=vehicleLicenseOcr
  99. }
  100. uploadFile(val.tempImagePath, imageType, issfz).then((data) => {
  101. console.log("身份证上传", data)
  102. emit('close', false)
  103. emit('ocrResult', data)
  104. })
  105. }
  106. const cancle = () => {
  107. emit('close', false)
  108. }
  109. const camera = () => {
  110. state.phoneType = 0
  111. }
  112. </script>
  113. <style scoped>
  114. .choice-takePhoto {
  115. position: absolute;
  116. bottom: 0;
  117. background-color: white;
  118. width: 100%;
  119. border-radius: 20rpx 20rpx 0 0;
  120. }
  121. .choice-takePhoto>view:first-child {
  122. text-align: center;
  123. height: 80rpx;
  124. line-height: 80rpx;
  125. border-bottom: 1rpx solid rgba(127, 127, 127, 0.3);
  126. background-color: white;
  127. }
  128. .choice-takePhoto>view:last-child {
  129. text-align: center;
  130. height: 80rpx;
  131. line-height: 80rpx;
  132. border-top: 6rpx solid rgba(127, 127, 127, 0.1);
  133. background-color: white;
  134. }
  135. .choice-takePhoto>view {
  136. text-align: center;
  137. height: 80rpx;
  138. line-height: 80rpx;
  139. background-color: white;
  140. }
  141. .choice-takePhoto-wrap {
  142. width: 100%;
  143. height: 100vh;
  144. background-color: rgba(127, 127, 127, 0.2);
  145. position: fixed;
  146. left: 0;
  147. top: 0;
  148. z-index: 11111;
  149. }
  150. </style>