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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // 更改typeindex
  53. state.choiceIndex = val;
  54. chooseImageCompress((res) => {
  55. console.log("res",res,state.choiceIndex)
  56. state.images = res.tempFilePath ? res.tempFilePath : res.tempFilePaths[0]
  57. state.showImg = false
  58. emit('close', false)
  59. uploadFile(state.images, state.choiceIndex).then((data) => {
  60. console.log("身份证上传", data)
  61. // var allData={
  62. // ...data,
  63. // tempFilePath:state.images
  64. // }
  65. emit('ocrResult', data)
  66. })
  67. })
  68. }
  69. const takePhoto = (val) => {
  70. state.showImg = true
  71. console.log("拍照", val)
  72. state.phoneType = val;
  73. state.choiceIndex=val
  74. }
  75. const confirmReturn = (val) => {
  76. console.log("图片地址val", val)
  77. state.phoneType = 0
  78. uploadFile(val.tempImagePath, state.choiceIndex).then((data) => {
  79. console.log("身份证上传", data)
  80. emit('close', false)
  81. emit('ocrResult', data)
  82. })
  83. }
  84. const cancle = () => {
  85. emit('close', false)
  86. }
  87. const camera = () => {
  88. state.phoneType = 0
  89. }
  90. </script>
  91. <style scoped>
  92. .choice-takePhoto {
  93. position: absolute;
  94. bottom: 0;
  95. background-color: white;
  96. width: 100%;
  97. border-radius: 20rpx 20rpx 0 0;
  98. }
  99. .choice-takePhoto>view:first-child {
  100. text-align: center;
  101. height: 80rpx;
  102. line-height: 80rpx;
  103. border-bottom: 1rpx solid rgba(127, 127, 127, 0.3);
  104. background-color: white;
  105. }
  106. .choice-takePhoto>view:last-child {
  107. text-align: center;
  108. height: 80rpx;
  109. line-height: 80rpx;
  110. border-top: 6rpx solid rgba(127, 127, 127, 0.1);
  111. background-color: white;
  112. }
  113. .choice-takePhoto>view {
  114. text-align: center;
  115. height: 80rpx;
  116. line-height: 80rpx;
  117. background-color: white;
  118. }
  119. .choice-takePhoto-wrap {
  120. width: 100%;
  121. height: 100vh;
  122. background-color: rgba(127, 127, 127, 0.2);
  123. position: fixed;
  124. left: 0;
  125. top: 0;
  126. z-index: 11111;
  127. }
  128. </style>