interview_retake.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. isVideoLoading: true,
  36. videoError: false,
  37. videoErrorMsg: "",
  38. videoContext: null
  39. };
  40. },
  41. computed: {
  42. currentStep() {
  43. if (!this.failedItems.length)
  44. return null;
  45. const current = this.failedItems[this.currentIndex];
  46. return {
  47. ...current,
  48. tipText: `${current.name}`,
  49. tipImage: this.gestureOverlays[current.type],
  50. guideVideo: this.guideVideos[current.type]
  51. };
  52. }
  53. },
  54. onLoad(options) {
  55. if (options.failedItems) {
  56. const items = JSON.parse(options.failedItems);
  57. this.failedItems = items.map((item) => ({
  58. name: this.getNameByType(item.type),
  59. type: item.type
  60. }));
  61. }
  62. },
  63. methods: {
  64. getNameByType(type) {
  65. const nameMap = {
  66. left_palm: "展示完整的左手手掌",
  67. left_back: "展示完整的左手手背",
  68. left_fist: "展示完整的左手握拳",
  69. right_palm: "展示完整的右手手掌",
  70. right_back: "展示完整的右手手背",
  71. right_fist: "展示完整的右手握拳"
  72. };
  73. return nameMap[type] || "";
  74. },
  75. takePhoto() {
  76. const camera = common_vendor.index.createCameraContext();
  77. camera.takePhoto({
  78. quality: "high",
  79. success: (res) => {
  80. this.tempImagePath = res.tempImagePath;
  81. this.showCamera = false;
  82. },
  83. fail: (err) => {
  84. common_vendor.index.showToast({
  85. title: "拍照失败",
  86. icon: "none"
  87. });
  88. }
  89. });
  90. },
  91. retakePhoto() {
  92. this.showCamera = true;
  93. this.tempImagePath = "";
  94. },
  95. async confirmPhoto() {
  96. try {
  97. const uploadResult = await this.uploadImage(this.tempImagePath);
  98. this.uploadedImages[this.currentStep.type] = uploadResult.url;
  99. if (this.currentIndex < this.failedItems.length - 1) {
  100. this.currentIndex++;
  101. this.showCamera = true;
  102. this.tempImagePath = "";
  103. } else {
  104. this.completeRetake();
  105. }
  106. } catch (err) {
  107. common_vendor.index.showToast({
  108. title: "上传失败,请重试",
  109. icon: "none"
  110. });
  111. }
  112. },
  113. async uploadImage(tempFilePath) {
  114. const tenant_id = common_vendor.index.getStorageSync("tenant_id") || "1";
  115. const description = `补拍-${this.currentStep.name}`;
  116. return new Promise((resolve, reject) => {
  117. common_vendor.index.uploadFile({
  118. url: `${common_config.apiBaseUrl}/job/upload_posture_photo`,
  119. filePath: tempFilePath,
  120. name: "photo",
  121. formData: {
  122. "application_id": common_vendor.index.getStorageSync("appId"),
  123. "tenant_id": tenant_id,
  124. "description": description
  125. },
  126. success: (uploadRes) => {
  127. try {
  128. const result = typeof uploadRes.data === "string" ? JSON.parse(uploadRes.data) : uploadRes.data;
  129. resolve(result);
  130. } catch (e) {
  131. reject(new Error("解析上传结果失败"));
  132. }
  133. },
  134. fail: reject
  135. });
  136. });
  137. },
  138. completeRetake() {
  139. const pages = getCurrentPages();
  140. const prevPage = pages[pages.length - 2];
  141. if (prevPage && prevPage.$vm) {
  142. prevPage.$vm.updateCheckResults(this.uploadedImages);
  143. }
  144. common_vendor.index.showToast({
  145. title: "补拍完成",
  146. icon: "success",
  147. duration: 1500,
  148. success: () => {
  149. setTimeout(() => {
  150. common_vendor.index.redirectTo({
  151. url: "/pages/success/success?type=retake&message=手部照片补拍完成,请等待系统审核"
  152. });
  153. }, 1500);
  154. }
  155. });
  156. },
  157. handleError(e) {
  158. console.error("相机错误:", e.detail);
  159. common_vendor.index.showToast({
  160. title: "相机启动失败,将使用系统相机",
  161. icon: "none"
  162. });
  163. this.fallbackToChooseImage();
  164. },
  165. fallbackToChooseImage() {
  166. this.showCamera = false;
  167. common_vendor.index.chooseImage({
  168. count: 1,
  169. sourceType: ["camera"],
  170. success: async (res) => {
  171. try {
  172. const uploadResult = await this.uploadImage(res.tempFilePaths[0]);
  173. this.uploadedImages[this.currentStep.type] = uploadResult.data.url;
  174. this.handlePhotoSuccess();
  175. } catch (err) {
  176. this.handlePhotoError();
  177. }
  178. },
  179. fail: () => this.handlePhotoError()
  180. });
  181. },
  182. handlePhotoSuccess() {
  183. if (this.currentIndex < this.failedItems.length - 1) {
  184. this.currentIndex++;
  185. this.showCamera = true;
  186. this.tempImagePath = "";
  187. } else {
  188. this.completeRetake();
  189. }
  190. },
  191. handlePhotoError() {
  192. common_vendor.index.showToast({
  193. title: "拍照失败,请重试",
  194. icon: "none"
  195. });
  196. },
  197. handleVideoError(e) {
  198. console.error("视频加载错误:", e);
  199. this.videoError = true;
  200. this.videoErrorMsg = "视频加载失败,请检查网络";
  201. this.isVideoLoading = false;
  202. if (this.videoContext) {
  203. setTimeout(() => {
  204. this.videoContext.play();
  205. }, 1e3);
  206. }
  207. },
  208. handleVideoLoaded() {
  209. this.isVideoLoading = false;
  210. this.videoError = false;
  211. this.videoErrorMsg = "";
  212. },
  213. initVideoContext() {
  214. if (!this.videoContext) {
  215. this.videoContext = common_vendor.index.createVideoContext("mpVideo", this);
  216. }
  217. },
  218. onShow() {
  219. this.initVideoContext();
  220. }
  221. }
  222. };
  223. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  224. return common_vendor.e({
  225. a: $data.showCamera
  226. }, $data.showCamera ? common_vendor.e({
  227. b: $options.currentStep.tipImage,
  228. c: common_vendor.t($options.currentStep.tipText),
  229. d: $options.currentStep.guideVideo,
  230. e: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  231. f: common_vendor.o((...args) => $options.handleVideoLoaded && $options.handleVideoLoaded(...args)),
  232. g: $data.isVideoLoading
  233. }, $data.isVideoLoading ? {} : {}, {
  234. h: $data.videoError
  235. }, $data.videoError ? {
  236. i: common_vendor.t($data.videoErrorMsg)
  237. } : {}, {
  238. j: common_vendor.s($options.currentStep.type.includes("right_") ? "left:30rpx" : "right:30rpx"),
  239. k: common_vendor.o((...args) => $options.handleError && $options.handleError(...args)),
  240. l: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
  241. }) : {
  242. m: $data.tempImagePath,
  243. n: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
  244. o: common_vendor.o((...args) => $options.confirmPhoto && $options.confirmPhoto(...args))
  245. }, {
  246. p: common_vendor.f($data.failedItems, (item, index, i0) => {
  247. return {
  248. a: common_vendor.t(item.name),
  249. b: index,
  250. c: $data.currentIndex === index ? 1 : "",
  251. d: index < $data.currentIndex ? 1 : ""
  252. };
  253. })
  254. });
  255. }
  256. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  257. wx.createPage(MiniProgramPage);