officialAccount/unpackage/dist/dev/mp-weixin/pages/addjigou/name.js

240 lines
8.3 KiB
JavaScript
Raw Normal View History

2025-06-09 17:33:50 +08:00
"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const request_index = require("../../request/index.js");
2025-06-11 17:33:34 +08:00
const pages_addjigou_api_addjigou = require("./api/addjigou.js");
2025-06-09 17:33:50 +08:00
if (!Array) {
const _easycom_u_modal2 = common_vendor.resolveComponent("u-modal");
_easycom_u_modal2();
}
const _easycom_u_modal = () => "../../uni_modules/vk-uview-ui/components/u-modal/u-modal.js";
if (!Math) {
_easycom_u_modal();
}
const _sfc_main = {
__name: "name",
setup(__props) {
const show = common_vendor.ref(false);
const content = common_vendor.ref("");
const nameArray = ["姓名", "性别", "身份证号码", "民族", "出生日期", "住址", "签发机关", "有效期限"];
const textArray = common_vendor.reactive(["", "", "", "", "", "", "", ""]);
2025-06-11 17:33:34 +08:00
const fontphoto = common_vendor.ref("");
const endphoto = common_vendor.ref("");
common_vendor.ref(0);
2025-06-09 17:33:50 +08:00
const tempImagePath = common_vendor.ref("");
function getMessage() {
common_vendor.index.chooseImage({
count: 1,
sourceType: ["camera"],
success: (chooseRes) => {
tempImagePath.value = chooseRes.tempFilePaths[0];
uploadImage(tempImagePath.value);
},
fail: (err) => {
2025-06-11 17:33:34 +08:00
common_vendor.index.__f__("error", "at pages/addjigou/name.vue:138", "拍照失败:", err);
2025-06-09 17:33:50 +08:00
}
});
}
const headImge = common_vendor.ref("");
const backImge = common_vendor.ref("");
function uploadImage(filePath) {
2025-06-13 13:42:14 +08:00
uping.value = false;
2025-06-09 17:33:50 +08:00
common_vendor.index.showLoading();
common_vendor.index.uploadFile({
url: `${request_index.base_url}/api/ocr/idCard`,
// 替换为你的POST接口地址
filePath,
name: "file",
// 后端接收时的字段名
header: {
"X-Access-Token": common_vendor.index.getStorageSync("token") || ""
},
formData: {},
success: (uploadRes) => {
2025-06-13 13:42:14 +08:00
common_vendor.index.__f__("log", "at pages/addjigou/name.vue:176", "token", common_vendor.index.getStorageSync("token"));
2025-06-09 17:33:50 +08:00
if (!JSON.parse(uploadRes.data).success) {
common_vendor.index.showToast({
title: "识别失败",
icon: "error"
});
common_vendor.index.hideLoading();
return;
}
if (JSON.parse(JSON.parse(uploadRes.data).result.data).data.face) {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.face.data;
textArray[0] = father.name;
textArray[1] = father.sex;
textArray[2] = father.idNumber;
textArray[3] = father.ethnicity;
textArray[4] = father.birthDate;
textArray[5] = father.address;
common_vendor.index.showToast({
title: "识别成功"
});
headImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 0);
2025-06-09 17:33:50 +08:00
common_vendor.index.hideLoading();
} else {
let father = JSON.parse(JSON.parse(uploadRes.data).result.data).data.back.data;
textArray[6] = father.issueAuthority;
textArray[7] = father.validPeriod;
common_vendor.index.showToast({
title: "识别成功"
});
backImge.value = filePath;
2025-06-11 17:33:34 +08:00
savephoto(filePath, 1);
2025-06-09 17:33:50 +08:00
common_vendor.index.hideLoading();
}
},
fail: (err) => {
common_vendor.index.showToast({
title: "上传出错",
icon: "error"
});
common_vendor.index.hideLoading();
}
});
}
2025-06-13 13:42:14 +08:00
const uping = common_vendor.ref(true);
2025-06-11 17:33:34 +08:00
const savephoto = (filePath, type) => {
2025-06-09 17:33:50 +08:00
common_vendor.index.uploadFile({
url: `${request_index.base_url}/sys/common/upload`,
// 替换为你的POST接口地址
filePath,
name: "file",
// 后端接收时的字段名
header: {
"X-Access-Token": common_vendor.index.getStorageSync("token") || ""
},
formData: {
biz: `temp`
},
success: (uploadRes) => {
2025-06-11 17:33:34 +08:00
if (!type) {
fontphoto.value = JSON.parse(uploadRes.data).message;
} else {
endphoto.value = JSON.parse(uploadRes.data).message;
}
2025-06-13 13:42:14 +08:00
uping.value = true;
2025-06-09 17:33:50 +08:00
},
fail: (err) => {
common_vendor.index.showToast({
title: "上传出错",
icon: "error"
});
common_vendor.index.hideLoading();
}
});
};
const openLook = (res) => {
if (res) {
content.value = res;
show.value = true;
}
};
const next = () => {
2025-06-11 17:33:34 +08:00
const allNonEmpty = textArray.every((item) => {
return item !== "";
2025-06-09 17:33:50 +08:00
});
2025-06-13 13:42:14 +08:00
if (!uping.value) {
return;
}
2025-06-11 17:33:34 +08:00
if (allNonEmpty) {
const range = textArray[7];
const [start, end] = range.split("-");
let pushMessage = {
id: common_vendor.index.getStorageSync("specicalid") || "",
tel: common_vendor.index.getStorageSync("tel"),
name: textArray[0],
sex: textArray[1],
idCard: textArray[2],
national: textArray[3],
birthDate: textArray[4],
idCardAddress: textArray[5],
issuingAuthority: textArray[6],
startTime: start,
endTime: end,
cardZmPath: fontphoto.value,
cardFmPath: endphoto.value
};
pages_addjigou_api_addjigou.changemessage(pushMessage).then((res) => {
if (res.success) {
if (res.message == `保存成功!`) {
common_vendor.index.navigateTo({
url: "/pages/addjigou/card"
});
} else {
common_vendor.index.setStorageSync("specicalid", res.result.id);
common_vendor.index.navigateTo({
url: "/pages/addjigou/card"
});
}
} else {
common_vendor.index.showToast({
title: res.message,
icon: "error"
});
}
});
} else {
common_vendor.index.showToast({
title: "请完善信息",
icon: "error"
});
}
2025-06-09 17:33:50 +08:00
};
const goBack = () => {
common_vendor.index.navigateBack();
};
common_vendor.onLoad(() => {
2025-06-13 13:42:14 +08:00
if (common_vendor.index.getStorageSync("baddata")) {
let data = common_vendor.index.getStorageSync("baddata");
textArray[0] = data.name;
textArray[1] = data.sex;
textArray[2] = data.idCard;
textArray[3] = data.national;
textArray[4] = data.birthDate;
textArray[5] = data.idCardAddress;
textArray[6] = data.issuingAuthority;
textArray[7] = `${data.startTime}-${data.endTime}`;
headImge.value = `${request_index.base_url}/sys/common/static/${data.cardZmPath}`;
backImge.value = `${request_index.base_url}/sys/common/static/${data.cardFmPath}`;
fontphoto.value = data.cardZmPath;
endphoto.value = data.cardFmPath;
}
2025-06-09 17:33:50 +08:00
});
return (_ctx, _cache) => {
return {
a: common_vendor.o(($event) => show.value = $event),
b: common_vendor.p({
content: content.value,
modelValue: show.value
}),
c: common_assets._imports_0$6,
d: common_vendor.o(goBack),
2025-06-13 13:42:14 +08:00
e: common_assets._imports_0$4,
2025-06-11 17:33:34 +08:00
f: headImge.value ? headImge.value : `/static/index/IDcard.png`,
g: !headImge.value,
h: common_assets._imports_1$5,
i: common_vendor.o(getMessage),
j: backImge.value ? backImge.value : `/static/index/backIDcard.png`,
k: !backImge.value,
l: common_assets._imports_1$5,
m: common_vendor.o(getMessage),
n: common_vendor.f(nameArray, (item, index, i0) => {
2025-06-09 17:33:50 +08:00
return {
a: common_vendor.t(item),
b: common_vendor.t(textArray[index] ? textArray[index] : "自动获取"),
c: index,
d: common_vendor.o(($event) => openLook(textArray[index]), index)
};
}),
2025-06-11 17:33:34 +08:00
o: common_vendor.o(next)
2025-06-09 17:33:50 +08:00
};
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4363d488"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/addjigou/name.js.map