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.

ocrHandle.ts 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import { reactive, ref } from "vue";
  2. import { request, requestNew } from "@/utils/network/request";
  3. import { Index, handleDataList } from "@/components/form-builder/tools";
  4. import { etcOcrCard, ocrAllQuery, fileUpload } from "@/utils/network/api.js";
  5. import { useQdOrderStore } from "@/stores/qdOrder.js";
  6. // 配合formBuilderVue3模板使用
  7. export default function () {
  8. let submitQuery = ref<any>({});
  9. let registerQuery = reactive<any>({});
  10. const qdOrderStore = useQdOrderStore();
  11. // 社会信用代码ocr识别
  12. function cardImageOcrYY(fileList, item, formData) {
  13. submitQuery.value.userIdType = "203"; //203 公司信用代码
  14. // 将图片上传
  15. //识别营业执照
  16. // return
  17. const data = {
  18. source: "1",
  19. agencyId: qdOrderStore.qdOrderVal.agencyId,
  20. // imageType: imageType,
  21. fileName: fileList.fileName,
  22. // imageBase64: fileList.path,
  23. url: fileList.url,
  24. };
  25. uni.showLoading({
  26. title: '正在识别图片...',
  27. mask: true
  28. });
  29. requestNew('/iaw/ocr/businessLicenseOcrNew', {
  30. data: data
  31. }).then(res => {
  32. if (res.code !== 0) return
  33. let data : any = res.data;
  34. let ocrData = [
  35. {
  36. title: "公司名称",
  37. key: "unitName"
  38. },
  39. {
  40. title: "社会信用代码",
  41. key: "screditCode"
  42. },
  43. {
  44. title: "住址",
  45. key: "adress"
  46. }
  47. ];
  48. const itemData = formData.value[Index(item.title, formData.value)]
  49. itemData[itemData.value] = fileList.pathDomain
  50. console.log(data, 'dataocr');
  51. // 处理数据展示
  52. handleDataList(ocrData, data, formData);
  53. console.log(formData, 'formData');
  54. }).finally(()=>{
  55. uni.hideLoading();
  56. });
  57. }
  58. // 委托书
  59. function cardFileImageUpdate(fileList, item, formData) {
  60. const dataItem = formData.value[Index(item.title, formData.value)];
  61. dataItem[dataItem.value] = fileList.pathDomain;
  62. }
  63. // 身份证类别识别
  64. function idCardOcr(fileList, item, formData) {
  65. let imageType;
  66. if (item.title == "人像面" || item.title == "经办人证件人像面") {
  67. imageType = "1";
  68. } else if (item.title == "国徽面" || item.title == "经办人证件国徽面") {
  69. imageType = "2";
  70. }
  71. const data = {
  72. source: "1",
  73. agencyId: qdOrderStore.qdOrderVal.agencyId,
  74. imageType: imageType,
  75. fileName: fileList.fileName,
  76. // imageBase64: fileList.path,
  77. url: fileList.url,
  78. };
  79. uni.showLoading({
  80. title: '正在识别图片...',
  81. mask: true
  82. });
  83. requestNew('/iaw/ocr/idCardOcr', {
  84. data: data
  85. }).then(res => {
  86. if (res.code !== 0) return
  87. let data : any = res.data;
  88. let ocrData = [
  89. ];
  90. console.log(data, 'dataocr');
  91. const itemData = formData.value[Index(item.title, formData.value)]
  92. itemData[itemData.value] = fileList.pathDomain
  93. console.log(data, 'dataocr');
  94. if (imageType == "1") {
  95. // 人像面
  96. if (!data.name || !data.idno) {
  97. uni.showModal({
  98. title: "提示",
  99. content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影",
  100. success: function (res) { }
  101. });
  102. return;
  103. }
  104. if (item.title == "经办人证件人像面") {
  105. ocrData = ocrData.concat([
  106. {
  107. title: "经办人姓名",
  108. key: "name"
  109. },
  110. {
  111. title: "经办人证件号码",
  112. key: "idno"
  113. }
  114. ]);
  115. submitQuery.value.agentIdType = 101; //身份证类型
  116. submitQuery.value.agentAddress = data.address; //经办人住址
  117. // registerQuery.agentGender = data.gender == '男' ? 'MALE' : 'FEMALE' //经办人性别
  118. } else {
  119. ocrData = ocrData.concat([
  120. {
  121. title: "姓名",
  122. key: "name"
  123. },
  124. {
  125. title: "证件号码",
  126. key: "idno"
  127. },
  128. {
  129. title: "住址",
  130. key: "address"
  131. }
  132. ]);
  133. submitQuery.value.userIdType = 101; //身份证
  134. registerQuery.gender = data.gender == '男' ? 'MALE' : 'FEMALE' //用户性别
  135. }
  136. } else {
  137. if (!data.enddate) {
  138. uni.showModal({
  139. title: "提示",
  140. content: "很抱歉,我们无法识别您的证件,请按规范上传正反面,确保图片清晰、背景简洁(如白墙或桌面),减少证件反光和阴影",
  141. success: function (res) { }
  142. });
  143. return;
  144. }
  145. if (item.title == "经办人证件国徽面") {
  146. submitQuery.value.agentIdVld = data.enddate; //经办人证件有效期
  147. } else {
  148. submitQuery.value.customerIdVld = data.enddate; //证件有效期
  149. }
  150. }
  151. // 处理数据展示
  152. handleDataList(ocrData, data, formData);
  153. console.log(formData, 'formData');
  154. }).finally(()=>{
  155. uni.hideLoading();
  156. });
  157. }
  158. //图像文件上传
  159. function uploadImgHandle(fileList, item, formData) {
  160. if (
  161. ["人像面", "国徽面", "经办人证件人像面", "经办人证件国徽面"].includes(
  162. item.title
  163. )
  164. ) {
  165. idCardOcr(fileList, item, formData);
  166. } else if (item.title == "营业执照") {
  167. cardImageOcrYY(fileList, item, formData);
  168. } else {
  169. cardFileImageUpdate(fileList, item, formData);
  170. }
  171. }
  172. return {
  173. uploadImgHandle,
  174. submitQuery
  175. };
  176. }