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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 {
  20. uploadFile,
  21. compressImage,
  22. chooseImageCompress,
  23. compareDates
  24. } from "@/utils/utils";
  25. let prop = defineProps({
  26. phoneType: {
  27. type: Number,
  28. default: function () {
  29. return 0 //1 身份证正面 2 身份证反面 3 行驶证正面 4 行驶证反面
  30. }
  31. },
  32. isTakePhotoModeShow: {
  33. type: Boolean,
  34. default: function () {
  35. return false
  36. }
  37. },
  38. });
  39. const emit = defineEmits<{
  40. (e : "close", content : any) : void;
  41. (e : "ocrResult", content : any) : void;
  42. }>();
  43. const state = reactive({
  44. showImg: true,
  45. phoneType: 0, // 1 身份证正面 2 身份证反面 3行驶证正面 4行驶证反面
  46. choiceIndex: 1, // 1 身份证正面 2 身份证反面
  47. isTakePhotoModeShow:false, //选择拍照方式是否出来
  48. images: '',
  49. })
  50. const xiangce = (val) => {
  51. console.log("val", val)
  52. chooseImageCompress((res) => {
  53. console.log("res",res,state.choiceIndex)
  54. state.images = res.tempFilePath ? res.tempFilePath : res.tempFilePaths[0]
  55. state.showImg = false
  56. emit('close', false)
  57. uploadFile(state.images, state.choiceIndex).then((data) => {
  58. console.log("身份证上传", data)
  59. var allData={
  60. ...data,
  61. tempFilePath:state.images
  62. }
  63. emit('ocrResult', allData)
  64. })
  65. })
  66. }
  67. const takePhoto = (val) => {
  68. state.showImg = true
  69. console.log("拍照", val)
  70. state.phoneType = val;
  71. state.choiceIndex=val
  72. }
  73. const confirmReturn = (val) => {
  74. console.log("图片地址val", val)
  75. state.phoneType = 0
  76. uploadFile(val.tempImagePath, state.choiceIndex).then((data) => {
  77. console.log("身份证上传", data)
  78. emit('close', false)
  79. emit('ocrResult', data)
  80. })
  81. }
  82. const cancle = () => {
  83. emit('close', false)
  84. }
  85. const camera = () => {
  86. state.phoneType = 0
  87. }
  88. </script>
  89. <style scoped>
  90. .choice-takePhoto {
  91. position: absolute;
  92. bottom: 0;
  93. background-color: white;
  94. width: 100%;
  95. border-radius: 20rpx 20rpx 0 0;
  96. }
  97. .choice-takePhoto>view:first-child {
  98. text-align: center;
  99. height: 80rpx;
  100. line-height: 80rpx;
  101. border-bottom: 1rpx solid rgba(127, 127, 127, 0.3);
  102. background-color: white;
  103. }
  104. .choice-takePhoto>view:last-child {
  105. text-align: center;
  106. height: 80rpx;
  107. line-height: 80rpx;
  108. border-top: 6rpx solid rgba(127, 127, 127, 0.1);
  109. background-color: white;
  110. }
  111. .choice-takePhoto>view {
  112. text-align: center;
  113. height: 80rpx;
  114. line-height: 80rpx;
  115. background-color: white;
  116. }
  117. .choice-takePhoto-wrap {
  118. width: 100%;
  119. height: 100vh;
  120. background-color: rgba(127, 127, 127, 0.2);
  121. position: fixed;
  122. left: 0;
  123. top: 0;
  124. z-index: 11111;
  125. }
  126. </style>