interview_retake.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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/interview-question/interview-question"
  152. //'/pages/success/success?type=retake&message=手部照片补拍完成,请等待系统审核'
  153. });
  154. }, 1500);
  155. }
  156. });
  157. },
  158. handleError(e) {
  159. console.error("相机错误:", e.detail);
  160. common_vendor.index.showToast({
  161. title: "相机启动失败,将使用系统相机",
  162. icon: "none"
  163. });
  164. this.fallbackToChooseImage();
  165. },
  166. fallbackToChooseImage() {
  167. this.showCamera = false;
  168. common_vendor.index.chooseImage({
  169. count: 1,
  170. sourceType: ["camera"],
  171. success: async (res) => {
  172. try {
  173. const uploadResult = await this.uploadImage(res.tempFilePaths[0]);
  174. this.uploadedImages[this.currentStep.type] = uploadResult.data.url;
  175. this.handlePhotoSuccess();
  176. } catch (err) {
  177. this.handlePhotoError();
  178. }
  179. },
  180. fail: () => this.handlePhotoError()
  181. });
  182. },
  183. handlePhotoSuccess() {
  184. if (this.currentIndex < this.failedItems.length - 1) {
  185. this.currentIndex++;
  186. this.showCamera = true;
  187. this.tempImagePath = "";
  188. } else {
  189. this.completeRetake();
  190. }
  191. },
  192. handlePhotoError() {
  193. common_vendor.index.showToast({
  194. title: "拍照失败,请重试",
  195. icon: "none"
  196. });
  197. },
  198. handleVideoError(e) {
  199. console.error("视频加载错误:", e);
  200. this.videoError = true;
  201. this.videoErrorMsg = "视频加载失败,请检查网络";
  202. this.isVideoLoading = false;
  203. if (this.videoContext) {
  204. setTimeout(() => {
  205. this.videoContext.play();
  206. }, 1e3);
  207. }
  208. },
  209. handleVideoLoaded() {
  210. this.isVideoLoading = false;
  211. this.videoError = false;
  212. this.videoErrorMsg = "";
  213. },
  214. initVideoContext() {
  215. if (!this.videoContext) {
  216. this.videoContext = common_vendor.index.createVideoContext("mpVideo", this);
  217. }
  218. },
  219. onShow() {
  220. this.initVideoContext();
  221. }
  222. }
  223. };
  224. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  225. return common_vendor.e({
  226. a: $data.showCamera
  227. }, $data.showCamera ? common_vendor.e({
  228. b: $options.currentStep.tipImage,
  229. c: common_vendor.t($options.currentStep.tipText),
  230. d: $options.currentStep.guideVideo,
  231. e: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  232. f: common_vendor.o((...args) => $options.handleVideoLoaded && $options.handleVideoLoaded(...args)),
  233. g: $data.isVideoLoading
  234. }, $data.isVideoLoading ? {} : {}, {
  235. h: $data.videoError
  236. }, $data.videoError ? {
  237. i: common_vendor.t($data.videoErrorMsg)
  238. } : {}, {
  239. j: common_vendor.s($options.currentStep.type.includes("right_") ? "left:30rpx" : "right:30rpx"),
  240. k: common_vendor.o((...args) => $options.handleError && $options.handleError(...args)),
  241. l: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
  242. }) : {
  243. m: $data.tempImagePath,
  244. n: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
  245. o: common_vendor.o((...args) => $options.confirmPhoto && $options.confirmPhoto(...args))
  246. }, {
  247. p: common_vendor.f($data.failedItems, (item, index, i0) => {
  248. return {
  249. a: common_vendor.t(item.name),
  250. b: index,
  251. c: $data.currentIndex === index ? 1 : "",
  252. d: index < $data.currentIndex ? 1 : ""
  253. };
  254. })
  255. });
  256. }
  257. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  258. wx.createPage(MiniProgramPage);