123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_config = require("../../common/config.js");
- const _sfc_main = {
- data() {
- return {
- failedItems: [],
- currentIndex: 0,
- showCamera: true,
- tempImagePath: "",
- uploadedImages: {},
- isH5: false,
- cameraPosition: "front",
- cameraMode: "normal",
- cameraContext: null,
- cameraInitRetries: 0,
- // 添加手势引导图片
- gestureOverlays: {
- left_palm: "http://data.qicai321.com/minlong/18590378-6792-4a26-be18-ad9f2bcc4159.png",
- left_back: "http://data.qicai321.com/minlong/e08cff2b-3b1d-478f-a62b-766b38445a16.png",
- left_fist: "http://data.qicai321.com/minlong/d30ccab7-9cfe-4386-bf0e-ac1f0045bd76.png",
- right_palm: "http://data.qicai321.com/minlong/8068a698-ac40-4a5d-a737-54dba47a668d.png",
- right_back: "http://data.qicai321.com/minlong/f04a1f7e-4f79-49c7-9a02-bbad296672ea.png",
- right_fist: "http://data.qicai321.com/minlong/1d9bbc36-2fb8-4489-bff6-c36e7a31bd37.png"
- },
- // 添加引导视频
- guideVideos: {
- left_palm: "http://data.qicai321.com/minlong/fd080e3b-67be-4ce7-87a3-58d047cfbbb1.mp4",
- left_back: "http://data.qicai321.com/minlong/394a858c-672a-44bd-8206-450913863900.mp4",
- left_fist: "http://data.qicai321.com/minlong/37153e68-a8f0-4a93-b677-5e5678379243.mp4",
- right_palm: "http://data.qicai321.com/minlong/ebf6e43f-ffdf-49bb-8b00-adeff9ce1b56.mp4",
- right_back: "http://data.qicai321.com/minlong/e0ca45e2-af3e-42a0-9dd1-4de545e9c720.mp4",
- right_fist: "http://data.qicai321.com/minlong/77028dd6-22bb-41b4-8879-19699e8b1dbb.mp4"
- },
- isVideoLoading: true,
- videoError: false,
- videoErrorMsg: "",
- videoContext: null
- };
- },
- computed: {
- currentStep() {
- if (!this.failedItems.length)
- return null;
- const current = this.failedItems[this.currentIndex];
- return {
- ...current,
- tipText: `${current.name}`,
- tipImage: this.gestureOverlays[current.type],
- guideVideo: this.guideVideos[current.type]
- };
- }
- },
- onLoad(options) {
- if (options.failedItems) {
- const items = JSON.parse(options.failedItems);
- this.failedItems = items.map((item) => ({
- name: this.getNameByType(item.type),
- type: item.type
- }));
- }
- },
- methods: {
- getNameByType(type) {
- const nameMap = {
- left_palm: "展示完整的左手手掌",
- left_back: "展示完整的左手手背",
- left_fist: "展示完整的左手握拳",
- right_palm: "展示完整的右手手掌",
- right_back: "展示完整的右手手背",
- right_fist: "展示完整的右手握拳"
- };
- return nameMap[type] || "";
- },
- takePhoto() {
- const camera = common_vendor.index.createCameraContext();
- camera.takePhoto({
- quality: "high",
- success: (res) => {
- this.tempImagePath = res.tempImagePath;
- this.showCamera = false;
- },
- fail: (err) => {
- common_vendor.index.showToast({
- title: "拍照失败",
- icon: "none"
- });
- }
- });
- },
- retakePhoto() {
- this.showCamera = true;
- this.tempImagePath = "";
- },
- async confirmPhoto() {
- try {
- const uploadResult = await this.uploadImage(this.tempImagePath);
- this.uploadedImages[this.currentStep.type] = uploadResult.url;
- if (this.currentIndex < this.failedItems.length - 1) {
- this.currentIndex++;
- this.showCamera = true;
- this.tempImagePath = "";
- } else {
- this.completeRetake();
- }
- } catch (err) {
- common_vendor.index.showToast({
- title: "上传失败,请重试",
- icon: "none"
- });
- }
- },
- async uploadImage(tempFilePath) {
- const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
- const description = `补拍-${this.currentStep.name}`;
- return new Promise((resolve, reject) => {
- common_vendor.index.uploadFile({
- url: `${common_config.apiBaseUrl}/job/upload_posture_photo`,
- filePath: tempFilePath,
- name: "photo",
- formData: {
- "application_id": common_vendor.index.getStorageSync("appId"),
- "tenant_id": tenant_id,
- "description": description
- },
- success: (uploadRes) => {
- try {
- const result = typeof uploadRes.data === "string" ? JSON.parse(uploadRes.data) : uploadRes.data;
- resolve(result);
- } catch (e) {
- reject(new Error("解析上传结果失败"));
- }
- },
- fail: reject
- });
- });
- },
- completeRetake() {
- const pages = getCurrentPages();
- const prevPage = pages[pages.length - 2];
- if (prevPage && prevPage.$vm) {
- prevPage.$vm.updateCheckResults(this.uploadedImages);
- }
- common_vendor.index.showToast({
- title: "补拍完成",
- icon: "success",
- duration: 1500,
- success: () => {
- setTimeout(() => {
- common_vendor.index.redirectTo({
- url: "/pages/success/success?type=retake&message=手部照片补拍完成,请等待系统审核"
- });
- }, 1500);
- }
- });
- },
- handleError(e) {
- console.error("相机错误:", e.detail);
- common_vendor.index.showToast({
- title: "相机启动失败,将使用系统相机",
- icon: "none"
- });
- this.fallbackToChooseImage();
- },
- fallbackToChooseImage() {
- this.showCamera = false;
- common_vendor.index.chooseImage({
- count: 1,
- sourceType: ["camera"],
- success: async (res) => {
- try {
- const uploadResult = await this.uploadImage(res.tempFilePaths[0]);
- this.uploadedImages[this.currentStep.type] = uploadResult.data.url;
- this.handlePhotoSuccess();
- } catch (err) {
- this.handlePhotoError();
- }
- },
- fail: () => this.handlePhotoError()
- });
- },
- handlePhotoSuccess() {
- if (this.currentIndex < this.failedItems.length - 1) {
- this.currentIndex++;
- this.showCamera = true;
- this.tempImagePath = "";
- } else {
- this.completeRetake();
- }
- },
- handlePhotoError() {
- common_vendor.index.showToast({
- title: "拍照失败,请重试",
- icon: "none"
- });
- },
- handleVideoError(e) {
- console.error("视频加载错误:", e);
- this.videoError = true;
- this.videoErrorMsg = "视频加载失败,请检查网络";
- this.isVideoLoading = false;
- if (this.videoContext) {
- setTimeout(() => {
- this.videoContext.play();
- }, 1e3);
- }
- },
- handleVideoLoaded() {
- this.isVideoLoading = false;
- this.videoError = false;
- this.videoErrorMsg = "";
- },
- initVideoContext() {
- if (!this.videoContext) {
- this.videoContext = common_vendor.index.createVideoContext("mpVideo", this);
- }
- },
- onShow() {
- this.initVideoContext();
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $data.showCamera
- }, $data.showCamera ? common_vendor.e({
- b: $options.currentStep.tipImage,
- c: common_vendor.t($options.currentStep.tipText),
- d: $options.currentStep.guideVideo,
- e: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
- f: common_vendor.o((...args) => $options.handleVideoLoaded && $options.handleVideoLoaded(...args)),
- g: $data.isVideoLoading
- }, $data.isVideoLoading ? {} : {}, {
- h: $data.videoError
- }, $data.videoError ? {
- i: common_vendor.t($data.videoErrorMsg)
- } : {}, {
- j: common_vendor.s($options.currentStep.type.includes("right_") ? "left:30rpx" : "right:30rpx"),
- k: common_vendor.o((...args) => $options.handleError && $options.handleError(...args)),
- l: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
- }) : {
- m: $data.tempImagePath,
- n: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
- o: common_vendor.o((...args) => $options.confirmPhoto && $options.confirmPhoto(...args))
- }, {
- p: common_vendor.f($data.failedItems, (item, index, i0) => {
- return {
- a: common_vendor.t(item.name),
- b: index,
- c: $data.currentIndex === index ? 1 : "",
- d: index < $data.currentIndex ? 1 : ""
- };
- })
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
|