interview_retake.js 11 KB

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