interview_retake.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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: "https://data.qicai321.com/minlong/18590378-6792-4a26-be18-ad9f2bcc4159.png",
  20. left_back: "https://data.qicai321.com/minlong/e08cff2b-3b1d-478f-a62b-766b38445a16.png",
  21. left_fist: "https://data.qicai321.com/minlong/d30ccab7-9cfe-4386-bf0e-ac1f0045bd76.png",
  22. right_palm: "https://data.qicai321.com/minlong/8068a698-ac40-4a5d-a737-54dba47a668d.png",
  23. right_back: "https://data.qicai321.com/minlong/f04a1f7e-4f79-49c7-9a02-bbad296672ea.png",
  24. right_fist: "https://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. this.navigateToNextPage();
  150. }
  151. });
  152. },
  153. // 根据配置决定跳转到下一个页面
  154. navigateToNextPage() {
  155. let configData = {};
  156. try {
  157. const configStr = common_vendor.index.getStorageSync("configData");
  158. if (configStr && configStr.trim()) {
  159. configData = JSON.parse(configStr);
  160. }
  161. } catch (error) {
  162. console.error("解析configData失败:", error);
  163. configData = {};
  164. }
  165. console.log("interview_success页面获取到的配置数据:", configData);
  166. const questionFormSwitches = (configData == null ? void 0 : configData.question_form_switches) || {};
  167. const hasChoiceQuestions = questionFormSwitches.enable_fill_blank || questionFormSwitches.enable_image_choice || questionFormSwitches.enable_multiple_choice || questionFormSwitches.enable_single_choice;
  168. const hasPostureDetection = configData == null ? void 0 : configData.enable_posture_check;
  169. const hasCandidateQuestions = questionFormSwitches.enable_candidate_questions;
  170. let targetUrl = "/pages/success/success";
  171. let pageName = "success页面";
  172. console.log("interview_success页面配置检查:", {
  173. hasChoiceQuestions,
  174. hasPostureDetection,
  175. hasCandidateQuestions,
  176. questionFormSwitches
  177. });
  178. if (hasCandidateQuestions) {
  179. targetUrl = "/pages/interview-question/interview-question";
  180. pageName = "interview-question页面";
  181. } else {
  182. targetUrl = "/pages/success/success";
  183. pageName = "success页面";
  184. }
  185. console.log("interview_success页面根据配置跳转到:", targetUrl);
  186. common_vendor.index.reLaunch({
  187. url: targetUrl,
  188. success: () => {
  189. console.log(`成功跳转到${pageName}`);
  190. },
  191. fail: (err) => {
  192. console.error(`跳转到${pageName}失败:`, err);
  193. common_vendor.index.navigateTo({
  194. url: targetUrl,
  195. fail: (navigateErr) => {
  196. console.error(`导航到${pageName}也失败:`, navigateErr);
  197. common_vendor.index.redirectTo({
  198. url: targetUrl,
  199. fail: (redirectErr) => {
  200. console.error("所有跳转方式都失败:", redirectErr);
  201. common_vendor.index.reLaunch({
  202. url: "/pages/success/success"
  203. });
  204. }
  205. });
  206. }
  207. });
  208. }
  209. });
  210. },
  211. handleError(e) {
  212. console.error("相机错误:", e.detail);
  213. common_vendor.index.showToast({
  214. title: "相机启动失败,将使用系统相机",
  215. icon: "none"
  216. });
  217. this.fallbackToChooseImage();
  218. },
  219. fallbackToChooseImage() {
  220. this.showCamera = false;
  221. common_vendor.index.chooseImage({
  222. count: 1,
  223. sourceType: ["camera"],
  224. success: async (res) => {
  225. try {
  226. const uploadResult = await this.uploadImage(res.tempFilePaths[0]);
  227. this.uploadedImages[this.currentStep.type] = uploadResult.data.url;
  228. this.handlePhotoSuccess();
  229. } catch (err) {
  230. this.handlePhotoError();
  231. }
  232. },
  233. fail: () => this.handlePhotoError()
  234. });
  235. },
  236. handlePhotoSuccess() {
  237. if (this.currentIndex < this.failedItems.length - 1) {
  238. this.currentIndex++;
  239. this.showCamera = true;
  240. this.tempImagePath = "";
  241. } else {
  242. this.completeRetake();
  243. }
  244. },
  245. handlePhotoError() {
  246. common_vendor.index.showToast({
  247. title: "拍照失败,请重试",
  248. icon: "none"
  249. });
  250. },
  251. handleVideoError(e) {
  252. console.error("视频加载错误:", e);
  253. this.videoError = true;
  254. this.videoErrorMsg = "视频加载失败,请检查网络";
  255. this.isVideoLoading = false;
  256. if (this.videoContext) {
  257. setTimeout(() => {
  258. this.videoContext.play();
  259. }, 1e3);
  260. }
  261. },
  262. handleVideoLoaded() {
  263. this.isVideoLoading = false;
  264. this.videoError = false;
  265. this.videoErrorMsg = "";
  266. },
  267. initVideoContext() {
  268. if (!this.videoContext) {
  269. this.videoContext = common_vendor.index.createVideoContext("mpVideo", this);
  270. }
  271. },
  272. onShow() {
  273. this.initVideoContext();
  274. }
  275. }
  276. };
  277. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  278. return common_vendor.e({
  279. a: $data.showCamera
  280. }, $data.showCamera ? common_vendor.e({
  281. b: $options.currentStep.tipImage,
  282. c: common_vendor.t($options.currentStep.tipText),
  283. d: $options.currentStep.guideVideo,
  284. e: common_vendor.o((...args) => $options.handleVideoError && $options.handleVideoError(...args)),
  285. f: common_vendor.o((...args) => $options.handleVideoLoaded && $options.handleVideoLoaded(...args)),
  286. g: $data.isVideoLoading
  287. }, $data.isVideoLoading ? {} : {}, {
  288. h: $data.videoError
  289. }, $data.videoError ? {
  290. i: common_vendor.t($data.videoErrorMsg)
  291. } : {}, {
  292. j: common_vendor.s($options.currentStep.type.includes("right_") ? "left:30rpx" : "right:30rpx"),
  293. k: common_vendor.o((...args) => $options.handleError && $options.handleError(...args)),
  294. l: common_vendor.o((...args) => $options.takePhoto && $options.takePhoto(...args))
  295. }) : {
  296. m: $data.tempImagePath,
  297. n: common_vendor.o((...args) => $options.retakePhoto && $options.retakePhoto(...args)),
  298. o: common_vendor.o((...args) => $options.confirmPhoto && $options.confirmPhoto(...args))
  299. }, {
  300. p: common_vendor.f($data.failedItems, (item, index, i0) => {
  301. return {
  302. a: common_vendor.t(item.name),
  303. b: index,
  304. c: $data.currentIndex === index ? 1 : "",
  305. d: index < $data.currentIndex ? 1 : ""
  306. };
  307. })
  308. });
  309. }
  310. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  311. wx.createPage(MiniProgramPage);