| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const api_assessment = require("../../api/assessment.js");
- const _sfc_main = {
- __name: "webview",
- setup(__props) {
- const url = common_vendor.ref("");
- const loading = common_vendor.ref(true);
- const errorMessage = common_vendor.ref("");
- const examList = common_vendor.ref([]);
- const showExamList = common_vendor.ref(false);
- const allFinished = common_vendor.ref(false);
- const assessmentId = common_vendor.ref("");
- const selectExam = (examUrl) => {
- if (!examUrl) {
- common_vendor.index.showToast({ title: "考试链接无效", icon: "none" });
- return;
- }
- common_vendor.index.setStorageSync("temp_exam_url", examUrl);
- common_vendor.index.navigateTo({
- url: `/pages/assessment/quiz?from=kaoshixing&assessmentId=${encodeURIComponent(assessmentId.value || "")}`
- });
- };
- const goToResult = () => {
- if (!assessmentId.value || assessmentId.value === "undefined") {
- common_vendor.index.showToast({ title: "参数错误", icon: "none" });
- return;
- }
- common_vendor.index.navigateTo({
- url: `/pages/assessment/result?id=${assessmentId.value}`
- });
- };
- common_vendor.onShow(() => {
- if (showExamList.value) {
- checkEvaluationStatus();
- }
- });
- const checkEvaluationStatus = async () => {
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const studentId = userInfo.studentId || userInfo.id;
- if (!studentId || !assessmentId.value || assessmentId.value === "undefined")
- return;
- const res = await api_assessment.getEvaluationResult(assessmentId.value, studentId);
- if (res.code === 200 && res.data) {
- allFinished.value = res.data.allFinished || false;
- const abilityResults = res.data.abilityResults || [];
- if (abilityResults.length > 0) {
- examList.value = examList.value.map((exam) => {
- const matched = abilityResults.find(
- (a) => a.name === exam.name || a.abilityName === exam.name
- );
- return {
- ...exam,
- isFinished: matched ? matched.isPass !== void 0 : false
- };
- });
- }
- }
- } catch (error) {
- common_vendor.index.__f__("error", "at pages/common/webview.vue:98", "检查测评状态失败:", error);
- }
- };
- common_vendor.onLoad(async (options) => {
- assessmentId.value = options.assessmentId || "";
- const mode = options.mode || "";
- const fallbackUrl = options.fallbackUrl ? decodeURIComponent(options.fallbackUrl) : "";
- if (options.url && mode !== "kaoshixing") {
- let combinedUrl = decodeURIComponent(options.url);
- const queryParams = [];
- for (let key in options) {
- if (key !== "assessmentId" && key !== "mode" && key !== "url") {
- queryParams.push(`${key}=${options[key]}`);
- }
- }
- if (queryParams.length > 0) {
- combinedUrl += (combinedUrl.indexOf("?") !== -1 ? "&" : "?") + queryParams.join("&");
- }
- url.value = combinedUrl;
- loading.value = false;
- return;
- }
- if (mode !== "kaoshixing") {
- url.value = fallbackUrl;
- if (!url.value)
- errorMessage.value = "缺少测评链接";
- loading.value = false;
- return;
- }
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const studentId = userInfo.studentId || userInfo.id;
- const studentName = userInfo.name || userInfo.nickName || "学员";
- const loginRes = await api_assessment.kaoshixingSilentLogin({
- user_id: String(studentId),
- user_name: studentName,
- department: "学员",
- evaluationId: assessmentId.value
- });
- if (loginRes.code === 200 && loginRes.data) {
- if (loginRes.data.exams && loginRes.data.exams.length > 0) {
- examList.value = loginRes.data.exams;
- showExamList.value = true;
- checkEvaluationStatus();
- } else if (loginRes.data.url) {
- common_vendor.index.setStorageSync("temp_exam_url", loginRes.data.url);
- common_vendor.index.redirectTo({
- url: `/pages/assessment/quiz?from=kaoshixing&assessmentId=${encodeURIComponent(assessmentId.value || "")}`
- });
- return;
- }
- } else {
- throw new Error(loginRes.msg || "考试星登录失败");
- }
- } catch (error) {
- errorMessage.value = error.message || "加载失败";
- } finally {
- loading.value = false;
- }
- });
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: loading.value
- }, loading.value ? {} : errorMessage.value ? {
- c: common_vendor.t(errorMessage.value)
- } : showExamList.value ? common_vendor.e({
- e: common_vendor.f(examList.value, (item, index, i0) => {
- return common_vendor.e({
- a: common_vendor.t(item.name || "专业能力测评"),
- b: item.isFinished
- }, item.isFinished ? {} : {}, {
- c: common_vendor.t(item.isFinished ? "重考" : "开始"),
- d: common_vendor.n(item.isFinished ? "retry" : ""),
- e: index,
- f: common_vendor.o(($event) => selectExam(item.url), index)
- });
- }),
- f: common_vendor.n(allFinished.value ? "" : "disabled"),
- g: !allFinished.value,
- h: common_vendor.o(goToResult),
- i: !allFinished.value
- }, !allFinished.value ? {} : {}) : url.value ? {
- k: url.value
- } : {}, {
- b: errorMessage.value,
- d: showExamList.value,
- j: url.value
- });
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b2eba2b3"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/common/webview.js.map
|