|
|
@@ -221,14 +221,38 @@ import { ElMessage } from "element-plus";
|
|
|
import type { FormInstance, FormRules } from "element-plus";
|
|
|
import type { UploadRequestOptions, UploadUserFile } from "element-plus";
|
|
|
import { Plus, InfoFilled } from "@element-plus/icons-vue";
|
|
|
-import { getOcrRequestByBase64 } from "@/api/modules/businessInfo";
|
|
|
+import { getOcrRequestUrl } from "@/api/modules/businessInfo";
|
|
|
import {
|
|
|
- uploadBusinessInfoImageWithPageOcr,
|
|
|
+ uploadBusinessInfoImageWithFinalizeOcr,
|
|
|
filterOutUploadUserFileByUid,
|
|
|
failBusinessInfoUploadCleanup
|
|
|
} from "@/utils/businessInfoImageUpload";
|
|
|
import { localGet, localSet } from "@/utils/index";
|
|
|
|
|
|
+const GEEKER_USER_KEY = "geeker-user";
|
|
|
+
|
|
|
+function buildOcrRequestUrlParams(imageUrls: string, ocrType: string) {
|
|
|
+ const params: {
|
|
|
+ imageUrls: string;
|
|
|
+ ocrType: string;
|
|
|
+ storeId?: string | number;
|
|
|
+ storeUserId?: string | number;
|
|
|
+ } = { imageUrls, ocrType };
|
|
|
+ const geeker = localGet(GEEKER_USER_KEY) as
|
|
|
+ | { userInfo?: { storeId?: string | number | null; id?: string | number | null } }
|
|
|
+ | null
|
|
|
+ | undefined;
|
|
|
+ const storeId = geeker?.userInfo?.storeId ?? localGet("createdId");
|
|
|
+ const storeUserId = geeker?.userInfo?.id;
|
|
|
+ if (storeId !== undefined && storeId !== null && String(storeId).trim() !== "") {
|
|
|
+ params.storeId = storeId;
|
|
|
+ }
|
|
|
+ if (storeUserId !== undefined && storeUserId !== null && String(storeUserId).trim() !== "") {
|
|
|
+ params.storeUserId = storeUserId;
|
|
|
+ }
|
|
|
+ return params;
|
|
|
+}
|
|
|
+
|
|
|
const BUSINESS_DATA_CACHE_KEY = "businessData";
|
|
|
|
|
|
const formRef = ref<FormInstance>();
|
|
|
@@ -252,7 +276,7 @@ function clearBusinessLicenseOcr() {
|
|
|
businessLicenseOcr.legalPerson = "";
|
|
|
}
|
|
|
|
|
|
-/** 从 ocrRequestByBase64 成功响应中取出 creditCode / companyName / legalPerson */
|
|
|
+/** 从 ocrRequestUrl 响应中取出 creditCode / companyName / legalPerson */
|
|
|
function pickBusinessLicenseOcrFields(res: any) {
|
|
|
const raw = res?.data ?? res;
|
|
|
let node: any = raw;
|
|
|
@@ -291,7 +315,7 @@ function splitIdCardValidPeriod(raw: string): { begin: string; end: string } {
|
|
|
return { begin: "", end: "" };
|
|
|
}
|
|
|
|
|
|
-/** 人像面 getOcrRequestByBase64(ID_CARD) 成功响应 */
|
|
|
+/** 人像面 ocrRequestUrl(ID_CARD) 成功响应 */
|
|
|
function pickIdCardPortraitOcrFields(res: any): {
|
|
|
name: string;
|
|
|
idNumber: string;
|
|
|
@@ -659,16 +683,17 @@ function mergeIdCardOcrFromFields(fields: ReturnType<typeof pickIdCardPortraitOc
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function requestIdCardPortraitOcr(file: File) {
|
|
|
- const formData = new FormData();
|
|
|
- formData.append("imageFile", file, file.name || "id-portrait.jpg");
|
|
|
- formData.append("ocrType", "ID_CARD");
|
|
|
+async function requestIdCardPortraitOcrByUrl(imageUrl: string) {
|
|
|
isIdPortraitOcrProcessing.value = true;
|
|
|
try {
|
|
|
- const res: any = await getOcrRequestByBase64(formData);
|
|
|
+ const res: any = await getOcrRequestUrl(buildOcrRequestUrlParams(imageUrl, "ID_CARD"));
|
|
|
if (res?.code === 200 || res?.code === "200") {
|
|
|
const fields = pickIdCardPortraitOcrFields(res);
|
|
|
mergeIdCardOcrFromFields(fields, "portrait");
|
|
|
+ if (!fields.name && !fields.idNumber) {
|
|
|
+ clearIdPortraitOcr();
|
|
|
+ throw new Error("身份证人像面识别未通过,请核对照片清晰度");
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
clearIdPortraitOcr();
|
|
|
@@ -678,14 +703,11 @@ async function requestIdCardPortraitOcr(file: File) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/** 国徽面单独 OCR,合并有效期限(及背面地址等),不清空人像面已识别字段 */
|
|
|
-async function requestIdCardEmblemOcr(file: File) {
|
|
|
- const formData = new FormData();
|
|
|
- formData.append("imageFile", file, file.name || "id-emblem.jpg");
|
|
|
- formData.append("ocrType", "ID_CARD");
|
|
|
+/** 国徽面 ocrRequestUrl,合并有效期限(及背面地址等),不清空人像面已识别字段 */
|
|
|
+async function requestIdCardEmblemOcrByUrl(imageUrl: string) {
|
|
|
isIdPortraitOcrProcessing.value = true;
|
|
|
try {
|
|
|
- const res: any = await getOcrRequestByBase64(formData);
|
|
|
+ const res: any = await getOcrRequestUrl(buildOcrRequestUrlParams(imageUrl, "ID_CARD"));
|
|
|
if (res?.code === 200 || res?.code === "200") {
|
|
|
const fields = pickIdCardPortraitOcrFields(res);
|
|
|
mergeIdCardOcrFromFields(fields, "emblem");
|
|
|
@@ -700,16 +722,17 @@ async function requestIdCardEmblemOcr(file: File) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-async function requestBusinessLicenseOcr(file: File) {
|
|
|
- const formData = new FormData();
|
|
|
- formData.append("imageFile", file, file.name || "license.jpg");
|
|
|
- formData.append("ocrType", "BUSINESS_LICENSE");
|
|
|
- const res: any = await getOcrRequestByBase64(formData);
|
|
|
+async function requestBusinessLicenseOcrByUrl(imageUrl: string) {
|
|
|
+ const res: any = await getOcrRequestUrl(buildOcrRequestUrlParams(imageUrl, "BUSINESS_LICENSE"));
|
|
|
if (res?.code === 200 || res?.code === "200") {
|
|
|
const fields = pickBusinessLicenseOcrFields(res);
|
|
|
businessLicenseOcr.creditCode = fields.creditCode;
|
|
|
businessLicenseOcr.companyName = fields.companyName;
|
|
|
businessLicenseOcr.legalPerson = fields.legalPerson;
|
|
|
+ if (!fields.creditCode && !fields.companyName && !fields.legalPerson) {
|
|
|
+ clearBusinessLicenseOcr();
|
|
|
+ throw new Error("营业执照识别未通过,请核对照片清晰度");
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
clearBusinessLicenseOcr();
|
|
|
@@ -729,9 +752,12 @@ async function handleLicenseUpload(options: UploadRequestOptions) {
|
|
|
|
|
|
uploadFileItem.status = "uploading";
|
|
|
try {
|
|
|
- const { fileUrl, mediaId } = await uploadBusinessInfoImageWithPageOcr(file, requestBusinessLicenseOcr, {
|
|
|
- showUploadOverlay: true
|
|
|
- });
|
|
|
+ const { fileUrl, mediaId } = await uploadBusinessInfoImageWithFinalizeOcr(
|
|
|
+ file,
|
|
|
+ "BUSINESS_LICENSE",
|
|
|
+ requestBusinessLicenseOcrByUrl,
|
|
|
+ { showUploadOverlay: true }
|
|
|
+ );
|
|
|
uploadFileItem.status = "success";
|
|
|
uploadFileItem.url = fileUrl;
|
|
|
uploadFileItem.response = { media_id: mediaId, url: fileUrl };
|
|
|
@@ -786,8 +812,8 @@ async function handleIdCardUpload(options: UploadRequestOptions, side: IdCardSid
|
|
|
|
|
|
uploadFileItem.status = "uploading";
|
|
|
try {
|
|
|
- const runOcr = side === "portrait" ? requestIdCardPortraitOcr : requestIdCardEmblemOcr;
|
|
|
- const { fileUrl, mediaId } = await uploadBusinessInfoImageWithPageOcr(file, runOcr, {
|
|
|
+ const runOcrByUrl = side === "portrait" ? requestIdCardPortraitOcrByUrl : requestIdCardEmblemOcrByUrl;
|
|
|
+ const { fileUrl, mediaId } = await uploadBusinessInfoImageWithFinalizeOcr(file, "ID_CARD", runOcrByUrl, {
|
|
|
showUploadOverlay: true
|
|
|
});
|
|
|
if (side === "portrait") {
|