webview.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const api_assessment = require("../../api/assessment.js");
  4. const _sfc_main = {
  5. __name: "webview",
  6. setup(__props) {
  7. const url = common_vendor.ref("");
  8. const loading = common_vendor.ref(true);
  9. const errorMessage = common_vendor.ref("");
  10. const examList = common_vendor.ref([]);
  11. const showExamList = common_vendor.ref(false);
  12. const allFinished = common_vendor.ref(false);
  13. const assessmentId = common_vendor.ref("");
  14. const selectExam = (examUrl) => {
  15. if (!examUrl) {
  16. common_vendor.index.showToast({ title: "考试链接无效", icon: "none" });
  17. return;
  18. }
  19. common_vendor.index.setStorageSync("temp_exam_url", examUrl);
  20. common_vendor.index.navigateTo({
  21. url: `/pages/assessment/quiz?from=kaoshixing&assessmentId=${encodeURIComponent(assessmentId.value || "")}`
  22. });
  23. };
  24. const goToResult = () => {
  25. if (!assessmentId.value || assessmentId.value === "undefined") {
  26. common_vendor.index.showToast({ title: "参数错误", icon: "none" });
  27. return;
  28. }
  29. common_vendor.index.navigateTo({
  30. url: `/pages/assessment/result?id=${assessmentId.value}`
  31. });
  32. };
  33. common_vendor.onShow(() => {
  34. if (showExamList.value) {
  35. checkEvaluationStatus();
  36. }
  37. });
  38. const checkEvaluationStatus = async () => {
  39. try {
  40. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  41. const studentId = userInfo.studentId || userInfo.id;
  42. if (!studentId || !assessmentId.value || assessmentId.value === "undefined")
  43. return;
  44. const res = await api_assessment.getEvaluationResult(assessmentId.value, studentId);
  45. if (res.code === 200 && res.data) {
  46. allFinished.value = res.data.allFinished || false;
  47. const abilityResults = res.data.abilityResults || [];
  48. if (abilityResults.length > 0) {
  49. examList.value = examList.value.map((exam) => {
  50. const matched = abilityResults.find(
  51. (a) => a.name === exam.name || a.abilityName === exam.name
  52. );
  53. return {
  54. ...exam,
  55. isFinished: matched ? matched.isPass !== void 0 : false
  56. };
  57. });
  58. }
  59. }
  60. } catch (error) {
  61. common_vendor.index.__f__("error", "at pages/common/webview.vue:98", "检查测评状态失败:", error);
  62. }
  63. };
  64. common_vendor.onLoad(async (options) => {
  65. assessmentId.value = options.assessmentId || "";
  66. const mode = options.mode || "";
  67. const fallbackUrl = options.fallbackUrl ? decodeURIComponent(options.fallbackUrl) : "";
  68. if (options.url && mode !== "kaoshixing") {
  69. let combinedUrl = decodeURIComponent(options.url);
  70. const queryParams = [];
  71. for (let key in options) {
  72. if (key !== "assessmentId" && key !== "mode" && key !== "url") {
  73. queryParams.push(`${key}=${options[key]}`);
  74. }
  75. }
  76. if (queryParams.length > 0) {
  77. combinedUrl += (combinedUrl.indexOf("?") !== -1 ? "&" : "?") + queryParams.join("&");
  78. }
  79. url.value = combinedUrl;
  80. loading.value = false;
  81. return;
  82. }
  83. if (mode !== "kaoshixing") {
  84. url.value = fallbackUrl;
  85. if (!url.value)
  86. errorMessage.value = "缺少测评链接";
  87. loading.value = false;
  88. return;
  89. }
  90. try {
  91. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  92. const studentId = userInfo.studentId || userInfo.id;
  93. const studentName = userInfo.name || userInfo.nickName || "学员";
  94. const loginRes = await api_assessment.kaoshixingSilentLogin({
  95. user_id: String(studentId),
  96. user_name: studentName,
  97. department: "学员",
  98. evaluationId: assessmentId.value
  99. });
  100. if (loginRes.code === 200 && loginRes.data) {
  101. if (loginRes.data.exams && loginRes.data.exams.length > 0) {
  102. examList.value = loginRes.data.exams;
  103. showExamList.value = true;
  104. checkEvaluationStatus();
  105. } else if (loginRes.data.url) {
  106. common_vendor.index.setStorageSync("temp_exam_url", loginRes.data.url);
  107. common_vendor.index.redirectTo({
  108. url: `/pages/assessment/quiz?from=kaoshixing&assessmentId=${encodeURIComponent(assessmentId.value || "")}`
  109. });
  110. return;
  111. }
  112. } else {
  113. throw new Error(loginRes.msg || "考试星登录失败");
  114. }
  115. } catch (error) {
  116. errorMessage.value = error.message || "加载失败";
  117. } finally {
  118. loading.value = false;
  119. }
  120. });
  121. return (_ctx, _cache) => {
  122. return common_vendor.e({
  123. a: loading.value
  124. }, loading.value ? {} : errorMessage.value ? {
  125. c: common_vendor.t(errorMessage.value)
  126. } : showExamList.value ? common_vendor.e({
  127. e: common_vendor.f(examList.value, (item, index, i0) => {
  128. return common_vendor.e({
  129. a: common_vendor.t(item.name || "专业能力测评"),
  130. b: item.isFinished
  131. }, item.isFinished ? {} : {}, {
  132. c: common_vendor.t(item.isFinished ? "重考" : "开始"),
  133. d: common_vendor.n(item.isFinished ? "retry" : ""),
  134. e: index,
  135. f: common_vendor.o(($event) => selectExam(item.url), index)
  136. });
  137. }),
  138. f: common_vendor.n(allFinished.value ? "" : "disabled"),
  139. g: !allFinished.value,
  140. h: common_vendor.o(goToResult),
  141. i: !allFinished.value
  142. }, !allFinished.value ? {} : {}) : url.value ? {
  143. k: url.value
  144. } : {}, {
  145. b: errorMessage.value,
  146. d: showExamList.value,
  147. j: url.value
  148. });
  149. };
  150. }
  151. };
  152. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b2eba2b3"]]);
  153. wx.createPage(MiniProgramPage);
  154. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/common/webview.js.map