training-detail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const common_assets = require("../../common/assets.js");
  4. const api_message = require("../../api/message.js");
  5. const api_assessment = require("../../api/assessment.js");
  6. const _sfc_main = {
  7. __name: "training-detail",
  8. setup(__props) {
  9. const pageType = common_vendor.ref("offline");
  10. const regStatus = common_vendor.ref("consult");
  11. const liveStatus = common_vendor.ref("");
  12. const mediaInfo = common_vendor.ref({});
  13. const isPlaying = common_vendor.ref(false);
  14. const loading = common_vendor.ref(true);
  15. const trainingId = common_vendor.ref(null);
  16. const trainingInfo = common_vendor.ref({
  17. title: "",
  18. location: "",
  19. organizer: "",
  20. trainingTime: "",
  21. deadline: "",
  22. isEnding: false,
  23. tags: [],
  24. description: "",
  25. requirements: "",
  26. benefits: ""
  27. });
  28. const latitude = common_vendor.ref(31.22863);
  29. const longitude = common_vendor.ref(121.45039);
  30. const markers = common_vendor.ref([{
  31. id: 1,
  32. latitude: 31.22863,
  33. longitude: 121.45039,
  34. title: "SOHO东海广场",
  35. iconPath: "/static/icons/location.svg",
  36. width: 32,
  37. height: 32,
  38. callout: {
  39. content: "上海静安区SOHO东海广场1209",
  40. color: "#333333",
  41. fontSize: 12,
  42. borderRadius: 8,
  43. padding: 8,
  44. bgColor: "#ffffff",
  45. display: "ALWAYS"
  46. }
  47. }]);
  48. common_vendor.onLoad((options) => {
  49. if (options.id) {
  50. trainingId.value = options.id;
  51. loadTrainingDetail(options.id);
  52. }
  53. if (options.type)
  54. pageType.value = options.type;
  55. if (options.status)
  56. liveStatus.value = options.status;
  57. if (pageType.value === "video") {
  58. common_vendor.index.setNavigationBarTitle({ title: "视频培训详情" });
  59. } else if (pageType.value === "live") {
  60. common_vendor.index.setNavigationBarTitle({ title: "直播培训详情" });
  61. } else {
  62. common_vendor.index.setNavigationBarTitle({ title: "培训详情" });
  63. }
  64. mediaInfo.value = {
  65. views: options.views,
  66. duration: options.duration,
  67. spectators: options.spectators
  68. };
  69. if (options.regSuccess)
  70. regStatus.value = "enrolled";
  71. if (options.isFinished)
  72. regStatus.value = "finished";
  73. });
  74. const loadTrainingDetail = async (id) => {
  75. try {
  76. loading.value = true;
  77. const res = await api_assessment.getTrainingDetail(id);
  78. if (res.code === 200 && res.data) {
  79. const data = res.data;
  80. trainingInfo.value = {
  81. title: data.trainingName || data.title || "培训详情",
  82. location: data.location || "线上培训",
  83. organizer: data.organizer || data.organizerName || "平台推荐",
  84. trainingTime: formatTrainingTime(data.startTime, data.endTime),
  85. deadline: formatDeadline(data.deadline || data.registrationDeadline),
  86. isEnding: checkIsEnding(data.deadline || data.registrationDeadline),
  87. tags: data.tags ? data.tags.split(",").filter((tag) => tag.trim()) : [],
  88. description: data.description || data.remark || "",
  89. requirements: data.requirements || "",
  90. benefits: data.benefits || "",
  91. price: data.price || "0.00",
  92. cover: data.coverImage || "/static/images/assess_cover.svg"
  93. };
  94. if (data.videoUrl) {
  95. mediaInfo.value.videoUrl = data.videoUrl;
  96. }
  97. if (data.views) {
  98. mediaInfo.value.views = data.views;
  99. }
  100. if (data.duration) {
  101. mediaInfo.value.duration = data.duration;
  102. }
  103. } else {
  104. common_vendor.index.showToast({ title: "获取培训详情失败", icon: "none" });
  105. }
  106. } catch (err) {
  107. common_vendor.index.__f__("error", "at pages/assessment/training-detail.vue:263", "获取培训详情失败:", err);
  108. common_vendor.index.showToast({ title: "网络错误,请重试", icon: "none" });
  109. } finally {
  110. loading.value = false;
  111. }
  112. };
  113. const formatTrainingTime = (startTime, endTime) => {
  114. if (!startTime)
  115. return "";
  116. const formatDate = (dateStr) => {
  117. const date = new Date(dateStr);
  118. const year = date.getFullYear();
  119. const month = String(date.getMonth() + 1).padStart(2, "0");
  120. const day = String(date.getDate()).padStart(2, "0");
  121. return `${year}-${month}-${day}`;
  122. };
  123. if (endTime && startTime !== endTime) {
  124. return `${formatDate(startTime)} 至 ${formatDate(endTime)}`;
  125. }
  126. return formatDate(startTime);
  127. };
  128. const formatDeadline = (deadline) => {
  129. if (!deadline)
  130. return "";
  131. const date = new Date(deadline);
  132. const year = date.getFullYear();
  133. const month = String(date.getMonth() + 1).padStart(2, "0");
  134. const day = String(date.getDate()).padStart(2, "0");
  135. const hours = String(date.getHours()).padStart(2, "0");
  136. const minutes = String(date.getMinutes()).padStart(2, "0");
  137. return `${year}-${month}-${day} ${hours}:${minutes}`;
  138. };
  139. const checkIsEnding = (deadline) => {
  140. if (!deadline)
  141. return false;
  142. const now = /* @__PURE__ */ new Date();
  143. const deadlineDate = new Date(deadline);
  144. const timeDiff = deadlineDate.getTime() - now.getTime();
  145. const daysDiff = timeDiff / (1e3 * 3600 * 24);
  146. return daysDiff > 0 && daysDiff <= 3;
  147. };
  148. const playVideo = () => {
  149. isPlaying.value = true;
  150. setTimeout(() => {
  151. const videoContext = common_vendor.index.createVideoContext("myVideo");
  152. videoContext.play();
  153. videoContext.requestFullScreen({
  154. direction: 90
  155. // 横屏全屏
  156. });
  157. }, 300);
  158. };
  159. const onFullscreenChange = (e) => {
  160. if (!e.detail.fullScreen)
  161. ;
  162. };
  163. const handleConsult = async () => {
  164. var _a;
  165. try {
  166. common_vendor.index.showLoading({ title: "正在连接客服..." });
  167. const userInfo = common_vendor.index.getStorageSync("userInfo") || {};
  168. const userId = userInfo.studentId || null;
  169. const userName = userInfo.name || "用户";
  170. const userAvatar = userInfo.avatarUrl || "/static/images/user_avatar.svg";
  171. const res = await api_message.createOrGetSession({
  172. sessionType: 1,
  173. fromUserId: userId,
  174. fromUserName: userName,
  175. fromUserAvatar: userAvatar,
  176. sourceId: "training_" + (((_a = trainingData.value) == null ? void 0 : _a.id) || trainingId.value)
  177. });
  178. common_vendor.index.hideLoading();
  179. if (res.data) {
  180. const session = res.data;
  181. const title = encodeURIComponent(trainingInfo.value.title || "");
  182. const cover = encodeURIComponent(trainingInfo.value.cover || "");
  183. const price = trainingInfo.value.price || "0.00";
  184. common_vendor.index.navigateTo({
  185. 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}`
  186. });
  187. } else {
  188. common_vendor.index.showToast({ title: "创建会话失败", icon: "none" });
  189. }
  190. } catch (err) {
  191. common_vendor.index.hideLoading();
  192. common_vendor.index.__f__("error", "at pages/assessment/training-detail.vue:361", "创建会话失败:", err);
  193. common_vendor.index.showToast({ title: "连接失败,请重试", icon: "none" });
  194. }
  195. };
  196. const watchLive = () => common_vendor.index.showToast({ title: "正在进入直播间...", icon: "loading" });
  197. const watchReplay = () => {
  198. pageType.value = "video";
  199. playVideo();
  200. };
  201. return (_ctx, _cache) => {
  202. return common_vendor.e({
  203. a: pageType.value === "video" || pageType.value === "live"
  204. }, pageType.value === "video" || pageType.value === "live" ? common_vendor.e({
  205. b: isPlaying.value && mediaInfo.value.videoUrl
  206. }, isPlaying.value && mediaInfo.value.videoUrl ? {
  207. c: mediaInfo.value.videoUrl,
  208. d: common_vendor.o(onFullscreenChange)
  209. } : common_vendor.e({
  210. e: trainingInfo.value.cover || "/static/images/assess_cover.svg",
  211. f: pageType.value === "video"
  212. }, pageType.value === "video" ? {
  213. g: common_vendor.o(playVideo)
  214. } : {}, {
  215. h: common_vendor.t(mediaInfo.value.views || "95万"),
  216. i: pageType.value === "video"
  217. }, pageType.value === "video" ? {
  218. j: common_assets._imports_1$1,
  219. k: common_vendor.t(mediaInfo.value.duration || "10:28")
  220. } : {
  221. l: common_assets._imports_0$2,
  222. m: common_vendor.t(mediaInfo.value.spectators || "1234567890")
  223. })) : {}, {
  224. n: loading.value
  225. }, loading.value ? {} : {}, {
  226. o: !loading.value
  227. }, !loading.value ? common_vendor.e({
  228. p: common_vendor.t(trainingInfo.value.title || "培训详情"),
  229. q: common_vendor.n(pageType.value === "video" || pageType.value === "live" ? "video-title" : ""),
  230. r: pageType.value === "offline"
  231. }, pageType.value === "offline" ? common_vendor.e({
  232. s: trainingInfo.value.location
  233. }, trainingInfo.value.location ? {
  234. t: common_assets._imports_2$2,
  235. v: common_vendor.t(trainingInfo.value.location)
  236. } : {}, {
  237. w: trainingInfo.value.organizer
  238. }, trainingInfo.value.organizer ? {
  239. x: common_assets._imports_0$2,
  240. y: common_vendor.t(trainingInfo.value.organizer)
  241. } : {}, {
  242. z: trainingInfo.value.trainingTime
  243. }, trainingInfo.value.trainingTime ? {
  244. A: common_assets._imports_1$1,
  245. B: common_vendor.t(trainingInfo.value.trainingTime)
  246. } : {}, {
  247. C: trainingInfo.value.deadline
  248. }, trainingInfo.value.deadline ? common_vendor.e({
  249. D: common_assets._imports_1$1,
  250. E: common_vendor.t(trainingInfo.value.deadline),
  251. F: trainingInfo.value.isEnding
  252. }, trainingInfo.value.isEnding ? {} : {}) : {}) : {
  253. G: common_vendor.t(trainingInfo.value.lecturer || "待定")
  254. }) : {}, {
  255. H: !loading.value
  256. }, !loading.value ? common_vendor.e({
  257. I: trainingInfo.value.tags && trainingInfo.value.tags.length > 0
  258. }, trainingInfo.value.tags && trainingInfo.value.tags.length > 0 ? {
  259. J: common_vendor.f(trainingInfo.value.tags, (tag, idx, i0) => {
  260. return {
  261. a: common_vendor.t(tag),
  262. b: idx
  263. };
  264. })
  265. } : {}, {
  266. K: trainingInfo.value.description
  267. }, trainingInfo.value.description ? {
  268. L: common_vendor.t(trainingInfo.value.description)
  269. } : {}, {
  270. M: trainingInfo.value.requirements
  271. }, trainingInfo.value.requirements ? {
  272. N: common_vendor.t(trainingInfo.value.requirements)
  273. } : {}, {
  274. O: trainingInfo.value.benefits
  275. }, trainingInfo.value.benefits ? {
  276. P: common_vendor.t(trainingInfo.value.benefits)
  277. } : {}) : {}, {
  278. Q: pageType.value === "offline"
  279. }, pageType.value === "offline" ? {} : {}, {
  280. R: pageType.value === "offline"
  281. }, pageType.value === "offline" ? {
  282. S: latitude.value,
  283. T: longitude.value,
  284. U: markers.value
  285. } : {}, {
  286. V: pageType.value !== "video"
  287. }, pageType.value !== "video" ? common_vendor.e({
  288. W: pageType.value === "offline"
  289. }, pageType.value === "offline" ? common_vendor.e({
  290. X: regStatus.value === "consult"
  291. }, regStatus.value === "consult" ? {
  292. Y: common_vendor.o(handleConsult)
  293. } : {}, {
  294. Z: regStatus.value === "enrolled"
  295. }, regStatus.value === "enrolled" ? {} : {}, {
  296. aa: regStatus.value === "finished"
  297. }, regStatus.value === "finished" ? {} : {}) : pageType.value === "live" ? common_vendor.e({
  298. ac: liveStatus.value === "streaming" || liveStatus.value === "upcoming"
  299. }, liveStatus.value === "streaming" || liveStatus.value === "upcoming" ? {
  300. ad: common_vendor.o(watchLive)
  301. } : liveStatus.value === "not-started" ? {} : liveStatus.value === "finished" ? {
  302. ag: common_vendor.o(watchReplay)
  303. } : {
  304. ah: common_vendor.o(watchLive)
  305. }, {
  306. ae: liveStatus.value === "not-started",
  307. af: liveStatus.value === "finished"
  308. }) : {}, {
  309. ab: pageType.value === "live"
  310. }) : {});
  311. };
  312. }
  313. };
  314. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-6baaf426"]]);
  315. wx.createPage(MiniProgramPage);
  316. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/assessment/training-detail.js.map