interview_retake.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_config = require("../../common/config.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. failedItems: [],
  8. currentIndex: 0,
  9. showCamera: true,
  10. tempImagePath: "",
  11. uploadedImages: {},
  12. isH5: false,
  13. cameraPosition: "front",
  14. cameraMode: "normal",
  15. cameraContext: null,
  16. cameraInitRetries: 0,
  17. // 添加手势引导图片
  18. gestureOverlays: {
  19. left_palm: "http://data.qicai321.com/minlong/18590378-6792-4a26-be18-ad9f2bcc4159.png",
  20. left_back: "http://data.qicai321.com/minlong/e08cff2b-3b1d-478f-a62b-766b38445a16.png",
  21. left_fist: "http://data.qicai321.com/minlong/d30ccab7-9cfe-4386-bf0e-ac1f0045bd76.png",
  22. right_palm: "http://data.qicai321.com/minlong/8068a698-ac40-4a5d-a737-54dba47a668d.png",
  23. right_back: "http://data.qicai321.com/minlong/f04a1f7e-4f79-49c7-9a02-bbad296672ea.png",
  24. right_fist: "http://data.qicai321.com/minlong/1d9bbc36-2fb8-4489-bff6-c36e7a31bd37.png"
  25. },
  26. // 添加引导视频
  27. guideVideos: {
  28. left_palm: "http://data.qicai321.com/minlong/fd080e3b-67be-4ce7-87a3-58d047cfbbb1.mp4",
  29. left_back: "http://data.qicai321.com/minlong/394a858c-672a-44bd-8206-450913863900.mp4",
  30. left_fist: "http://data.qicai321.com/minlong/37153e68-a8f0-4a93-b677-5e5678379243.mp4",
  31. right_palm: "http://data.qicai321.com/minlong/ebf6e43f-ffdf-49bb-8b00-adeff9ce1b56.mp4",
  32. right_back: "http://data.qicai321.com/minlong/e0ca45e2-af3e-42a0-9dd1-4de545e9c720.mp4",
  33. right_fist: "http://data.qicai321.com/minlong/77028dd6-22bb-41b4-8879-19699e8b1dbb.mp4"
  34. }
  35. };
  36. },
  37. computed: {
  38. currentStep() {
  39. if (!this.failedItems.length)
  40. return null;
  41. const current = this.failedItems[this.currentIndex];
  42. return {
  43. ...current,
  44. tipText: `${current.name}`,
  45. tipImage: this.gestureOverlays[current.type],
  46. guideVideo: this.guideVideos[current.type]
  47. };
  48. }
  49. },
  50. onLoad(options) {
  51. if (options.failedItems) {
  52. const items = JSON.parse(options.failedItems);
  53. this.failedItems = items.map((item) => ({
  54. name: this.getNameByType(item.type),
  55. type: item.type
  56. }));
  57. }
  58. },
  59. methods: {
  60. getNameByType(type) {
  61. const nameMap = {
  62. left_palm: "展示完整的左手手掌",
  63. left_back: "展示完整的左手手背",
  64. left_fist: "展示完整的左手握拳",
  65. right_palm: "展示完整的右手手掌",
  66. right_back: "展示完整的右手手背",
  67. right_fist: "展示完整的右手握拳"
  68. };
  69. return nameMap[type] || "";
  70. },
  71. takePhoto() {
  72. const camera = common_vendor.index.createCameraContext();
  73. camera.takePhoto({
  74. quality: "high",
  75. success: (res) => {
  76. this.tempImagePath = res.tempImagePath;
  77. this.showCamera = false;
  78. },
  79. fail: (err) => {
  80. common_vendor.index.showToast({
  81. title: "拍照失败",
  82. icon: "none"
  83. });
  84. }
  85. });
  86. },
  87. retakePhoto() {
  88. this.showCamera = true;
  89. this.tempImagePath = "";
  90. },
  91. async confirmPhoto() {
  92. try {
  93. const uploadResult = await this.uploadImage(this.tempImagePath);
  94. this.uploadedImages[this.currentStep.type] = uploadResult.url;
  95. if (this.currentIndex < this.failedItems.length - 1) {
  96. this.currentIndex++;
  97. this.showCamera = true;
  98. this.tempImagePath = "";
  99. } else {
  100. this.completeRetake();
  101. }
  102. } catch (err) {
  103. common_vendor.index.showToast({
  104. title: "上传失败,请重试",
  105. icon: "none"
  106. });
  107. }
  108. },
  109. async uploadImage(tempFilePath) {
  110. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  111. const description = `补拍-${this.currentStep.name}`;
  112. return new Promise((resolve, reject) => {
  113. common_vendor.index.uploadFile({
  114. url: `${common_config.apiBaseUrl}/job/upload_posture_photo`,
  115. filePath: tempFilePath,
  116. name: "photo",
  117. formData: {
  118. "application_id": common_vendor.index.getStorageSync("appId"),
  119. "tenant_id": tenant_id,
  120. "description": description
  121. },
  122. success: (uploadRes) => {
  123. try {
  124. const result = typeof uploadRes.data === "string" ? JSON.parse(uploadRes.data) : uploadRes.data;
  125. resolve(result);
  126. } catch (e) {
  127. reject(new Error("解析上传结果失败"));
  128. }
  129. },
  130. fail: reject
  131. });
  132. });
  133. },
  134. completeRetake() {
  135. const pages = getCurrentPages();
  136. const prevPage = pages[pages.length - 2];
  137. if (prevPage && prevPage.$vm) {
  138. prevPage.$vm.updateCheckResults(this.uploadedImages);
  139. }
  140. common_vendor.index.showToast({
  141. title: "补拍完成",
  142. icon: "success",
  143. duration: 1500,
  144. success: () => {
  145. setTimeout(() => {
  146. common_vendor.index.redirectTo({
  147. url: "/pages/success/success?type=retake&message=手部照片补拍完成,请等待系统审核"
  148. });
  149. }, 1500);
  150. }
  151. });
  152. },
  153. handleError(e) {
  154. console.error("相机错误:", e.detail);
  155. common_vendor.index.showToast({
  156. title: "相机启动失败,将使用系统相机",
  157. icon: "none"
  158. });
  159. this.fallbackToChooseImage();
  160. },
  161. fallbackToChooseImage() {
  162. this.showCamera = false;
  163. common_vendor.index.chooseImage({
  164. count: 1,
  165. sourceType: ["camera"],
  166. success: async (res) => {
  167. try {
  168. const uploadResult = await this.uploadImage(res.tempFilePaths[0]);
  169. this.uploadedImages[this.currentStep.type] = uploadResult.data.url;
  170. this.handlePhotoSuccess();
  171. } catch (err) {
  172. this.handlePhotoError();
  173. }
  174. },
  175. fail: () => this.handlePhotoError()
  176. });
  177. },
  178. handlePhotoSuccess() {
  179. if (this.currentIndex < this.failedItems.length - 1) {
  180. this.currentIndex++;
  181. this.showCamera = true;
  182. this.tempImagePath = "";
  183. } else {
  184. this.completeRetake();
  185. }
  186. },
  187. handlePhotoError() {
  188. common_vendor.index.showToast({
  189. title: "拍照失败,请重试",
  190. icon: "none"
  191. });
  192. }
  193. }
  194. };
  195. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  196. return common_vendor.e({
  197. a: $data.showCamera
  198. }, $data.showCamera ? {
  199. b: $options.currentStep.tipImage,
  200. c: common_vendor.t($options.currentStep.tipText),
  201. d: $options.currentStep.guideVideo,
  202. e: common_vendor.s($options.currentStep.type.includes("right_") ? "left:30rpx" : "right:30rpx"),
  203. f: common_vendor.o((...args) => $options.handleError && $options.handleError(...args)),
  204. g: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
  205. } : {
  206. h: $data.tempImagePath,
  207. i: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
  208. j: common_vendor.o((...args) => $options.confirmPhoto && $options.confirmPhoto(...args))
  209. }, {
  210. k: common_vendor.f($data.failedItems, (item, index, i0) => {
  211. return {
  212. a: common_vendor.t(item.name),
  213. b: index,
  214. c: $data.currentIndex === index ? 1 : "",
  215. d: index < $data.currentIndex ? 1 : ""
  216. };
  217. })
  218. });
  219. }
  220. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  221. wx.createPage(MiniProgramPage);