| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const common_assets = require("../../common/assets.js");
- const api_message = require("../../api/message.js");
- const api_assessment = require("../../api/assessment.js");
- const _sfc_main = {
- __name: "training-detail",
- setup(__props) {
- const pageType = common_vendor.ref("offline");
- const regStatus = common_vendor.ref("consult");
- const liveStatus = common_vendor.ref("");
- const mediaInfo = common_vendor.ref({});
- const isPlaying = common_vendor.ref(false);
- const loading = common_vendor.ref(true);
- const trainingId = common_vendor.ref(null);
- const trainingInfo = common_vendor.ref({
- title: "",
- location: "",
- organizer: "",
- trainingTime: "",
- deadline: "",
- isEnding: false,
- tags: [],
- description: "",
- requirements: "",
- benefits: ""
- });
- const latitude = common_vendor.ref(31.22863);
- const longitude = common_vendor.ref(121.45039);
- const markers = common_vendor.ref([{
- id: 1,
- latitude: 31.22863,
- longitude: 121.45039,
- title: "SOHO东海广场",
- iconPath: "/static/icons/location.svg",
- width: 32,
- height: 32,
- callout: {
- content: "上海静安区SOHO东海广场1209",
- color: "#333333",
- fontSize: 12,
- borderRadius: 8,
- padding: 8,
- bgColor: "#ffffff",
- display: "ALWAYS"
- }
- }]);
- common_vendor.onLoad((options) => {
- if (options.id) {
- trainingId.value = options.id;
- loadTrainingDetail(options.id);
- }
- if (options.type)
- pageType.value = options.type;
- if (options.status)
- liveStatus.value = options.status;
- if (pageType.value === "video") {
- common_vendor.index.setNavigationBarTitle({ title: "视频培训详情" });
- } else if (pageType.value === "live") {
- common_vendor.index.setNavigationBarTitle({ title: "直播培训详情" });
- } else {
- common_vendor.index.setNavigationBarTitle({ title: "培训详情" });
- }
- mediaInfo.value = {
- views: options.views,
- duration: options.duration,
- spectators: options.spectators
- };
- if (options.regSuccess)
- regStatus.value = "enrolled";
- if (options.isFinished)
- regStatus.value = "finished";
- });
- const loadTrainingDetail = async (id) => {
- try {
- loading.value = true;
- const res = await api_assessment.getTrainingDetail(id);
- if (res.code === 200 && res.data) {
- const data = res.data;
- trainingInfo.value = {
- title: data.trainingName || data.title || "培训详情",
- location: data.location || "线上培训",
- organizer: data.organizer || data.organizerName || "平台推荐",
- trainingTime: formatTrainingTime(data.startTime, data.endTime),
- deadline: formatDeadline(data.deadline || data.registrationDeadline),
- isEnding: checkIsEnding(data.deadline || data.registrationDeadline),
- tags: data.tags ? data.tags.split(",").filter((tag) => tag.trim()) : [],
- description: data.description || data.remark || "",
- requirements: data.requirements || "",
- benefits: data.benefits || "",
- price: data.price || "0.00",
- cover: data.coverImage || "/static/images/assess_cover.svg"
- };
- if (data.videoUrl) {
- mediaInfo.value.videoUrl = data.videoUrl;
- }
- if (data.views) {
- mediaInfo.value.views = data.views;
- }
- if (data.duration) {
- mediaInfo.value.duration = data.duration;
- }
- } else {
- common_vendor.index.showToast({ title: "获取培训详情失败", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.__f__("error", "at pages/assessment/training-detail.vue:263", "获取培训详情失败:", err);
- common_vendor.index.showToast({ title: "网络错误,请重试", icon: "none" });
- } finally {
- loading.value = false;
- }
- };
- const formatTrainingTime = (startTime, endTime) => {
- if (!startTime)
- return "";
- const formatDate = (dateStr) => {
- const date = new Date(dateStr);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- return `${year}-${month}-${day}`;
- };
- if (endTime && startTime !== endTime) {
- return `${formatDate(startTime)} 至 ${formatDate(endTime)}`;
- }
- return formatDate(startTime);
- };
- const formatDeadline = (deadline) => {
- if (!deadline)
- return "";
- const date = new Date(deadline);
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, "0");
- const day = String(date.getDate()).padStart(2, "0");
- const hours = String(date.getHours()).padStart(2, "0");
- const minutes = String(date.getMinutes()).padStart(2, "0");
- return `${year}-${month}-${day} ${hours}:${minutes}`;
- };
- const checkIsEnding = (deadline) => {
- if (!deadline)
- return false;
- const now = /* @__PURE__ */ new Date();
- const deadlineDate = new Date(deadline);
- const timeDiff = deadlineDate.getTime() - now.getTime();
- const daysDiff = timeDiff / (1e3 * 3600 * 24);
- return daysDiff > 0 && daysDiff <= 3;
- };
- const playVideo = () => {
- isPlaying.value = true;
- setTimeout(() => {
- const videoContext = common_vendor.index.createVideoContext("myVideo");
- videoContext.play();
- videoContext.requestFullScreen({
- direction: 90
- // 横屏全屏
- });
- }, 300);
- };
- const onFullscreenChange = (e) => {
- if (!e.detail.fullScreen)
- ;
- };
- const handleConsult = async () => {
- var _a;
- try {
- common_vendor.index.showLoading({ title: "正在连接客服..." });
- const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
- const userId = userInfo.studentId || null;
- const userName = userInfo.name || "用户";
- const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.svg";
- const res = await api_message.createOrGetSession({
- sessionType: 1,
- fromUserId: userId,
- fromUserName: userName,
- fromUserAvatar: userAvatar,
- sourceId: "training_" + (((_a = trainingData.value) == null ? void 0 : _a.id) || trainingId.value)
- });
- common_vendor.index.hideLoading();
- if (res.data) {
- const session = res.data;
- const title = encodeURIComponent(trainingInfo.value.title || "");
- const cover = encodeURIComponent(trainingInfo.value.cover || "");
- const price = trainingInfo.value.price || "0.00";
- common_vendor.index.navigateTo({
- url: `/pages/chat/chat?sessionId=${session.sessionId}&sessionNo=${session.sessionNo || ""}&fromUserId=${userId || ""}&userName=${encodeURIComponent(userName)}&type=training&title=${title}&cover=${cover}&trainingId=${trainingId.value || ""}&price=${price}`
- });
- } else {
- common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
- }
- } catch (err) {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/assessment/training-detail.vue:361", "创建会话失败:", err);
- common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
- }
- };
- const watchLive = () => common_vendor.index.showToast({ title: "正在进入直播间...", icon: "loading" });
- const watchReplay = () => {
- pageType.value = "video";
- playVideo();
- };
- return (_ctx, _cache) => {
- return common_vendor.e({
- a: pageType.value === "video" || pageType.value === "live"
- }, pageType.value === "video" || pageType.value === "live" ? common_vendor.e({
- b: isPlaying.value && mediaInfo.value.videoUrl
- }, isPlaying.value && mediaInfo.value.videoUrl ? {
- c: mediaInfo.value.videoUrl,
- d: common_vendor.o(onFullscreenChange)
- } : common_vendor.e({
- e: trainingInfo.value.cover || "/static/images/assess_cover.svg",
- f: pageType.value === "video"
- }, pageType.value === "video" ? {
- g: common_vendor.o(playVideo)
- } : {}, {
- h: common_vendor.t(mediaInfo.value.views || "95万"),
- i: pageType.value === "video"
- }, pageType.value === "video" ? {
- j: common_assets._imports_1$1,
- k: common_vendor.t(mediaInfo.value.duration || "10:28")
- } : {
- l: common_assets._imports_0$2,
- m: common_vendor.t(mediaInfo.value.spectators || "1234567890")
- })) : {}, {
- n: loading.value
- }, loading.value ? {} : {}, {
- o: !loading.value
- }, !loading.value ? common_vendor.e({
- p: common_vendor.t(trainingInfo.value.title || "培训详情"),
- q: common_vendor.n(pageType.value === "video" || pageType.value === "live" ? "video-title" : ""),
- r: pageType.value === "offline"
- }, pageType.value === "offline" ? common_vendor.e({
- s: trainingInfo.value.location
- }, trainingInfo.value.location ? {
- t: common_assets._imports_2$2,
- v: common_vendor.t(trainingInfo.value.location)
- } : {}, {
- w: trainingInfo.value.organizer
- }, trainingInfo.value.organizer ? {
- x: common_assets._imports_0$2,
- y: common_vendor.t(trainingInfo.value.organizer)
- } : {}, {
- z: trainingInfo.value.trainingTime
- }, trainingInfo.value.trainingTime ? {
- A: common_assets._imports_1$1,
- B: common_vendor.t(trainingInfo.value.trainingTime)
- } : {}, {
- C: trainingInfo.value.deadline
- }, trainingInfo.value.deadline ? common_vendor.e({
- D: common_assets._imports_1$1,
- E: common_vendor.t(trainingInfo.value.deadline),
- F: trainingInfo.value.isEnding
- }, trainingInfo.value.isEnding ? {} : {}) : {}) : {
- G: common_vendor.t(trainingInfo.value.lecturer || "待定")
- }) : {}, {
- H: !loading.value
- }, !loading.value ? common_vendor.e({
- I: trainingInfo.value.tags && trainingInfo.value.tags.length > 0
- }, trainingInfo.value.tags && trainingInfo.value.tags.length > 0 ? {
- J: common_vendor.f(trainingInfo.value.tags, (tag, idx, i0) => {
- return {
- a: common_vendor.t(tag),
- b: idx
- };
- })
- } : {}, {
- K: trainingInfo.value.description
- }, trainingInfo.value.description ? {
- L: common_vendor.t(trainingInfo.value.description)
- } : {}, {
- M: trainingInfo.value.requirements
- }, trainingInfo.value.requirements ? {
- N: common_vendor.t(trainingInfo.value.requirements)
- } : {}, {
- O: trainingInfo.value.benefits
- }, trainingInfo.value.benefits ? {
- P: common_vendor.t(trainingInfo.value.benefits)
- } : {}) : {}, {
- Q: pageType.value === "offline"
- }, pageType.value === "offline" ? {} : {}, {
- R: pageType.value === "offline"
- }, pageType.value === "offline" ? {
- S: latitude.value,
- T: longitude.value,
- U: markers.value
- } : {}, {
- V: pageType.value !== "video"
- }, pageType.value !== "video" ? common_vendor.e({
- W: pageType.value === "offline"
- }, pageType.value === "offline" ? common_vendor.e({
- X: regStatus.value === "consult"
- }, regStatus.value === "consult" ? {
- Y: common_vendor.o(handleConsult)
- } : {}, {
- Z: regStatus.value === "enrolled"
- }, regStatus.value === "enrolled" ? {} : {}, {
- aa: regStatus.value === "finished"
- }, regStatus.value === "finished" ? {} : {}) : pageType.value === "live" ? common_vendor.e({
- ac: liveStatus.value === "streaming" || liveStatus.value === "upcoming"
- }, liveStatus.value === "streaming" || liveStatus.value === "upcoming" ? {
- ad: common_vendor.o(watchLive)
- } : liveStatus.value === "not-started" ? {} : liveStatus.value === "finished" ? {
- ag: common_vendor.o(watchReplay)
- } : {
- ah: common_vendor.o(watchLive)
- }, {
- ae: liveStatus.value === "not-started",
- af: liveStatus.value === "finished"
- }) : {}, {
- ab: pageType.value === "live"
- }) : {});
- };
- }
- };
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6baaf426"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/assessment/training-detail.js.map
|