lesson.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. var renderer = new marked.Renderer();
  2. renderer.code = function(code, language) {
  3. if (language == "mermaid") return '<pre class="mermaid">' + code + "</pre>";
  4. else return "<pre><code>" + code + "</code></pre>";
  5. };
  6. function lesson_show(id) {
  7. $.get(
  8. "../course/lesson_get.php", {
  9. id: id,
  10. },
  11. function(data, status) {
  12. let arrLesson = JSON.parse(data);
  13. let html = "";
  14. for (const lesson of arrLesson) {
  15. html += '<div class="card" style="display:flex;margin:1em;padding:10px;">';
  16. html += '<div style="flex:7;">';
  17. html += '<div class="pd-10">';
  18. html +=
  19. '<div class="title" style="padding-bottom:5px;font-size:200%;font-weight:600;">' +
  20. lesson["title"] +
  21. "</div>";
  22. html += '<div style="">';
  23. let summary = "";
  24. try {
  25. summary = marked(lesson["summary"], { renderer: renderer });
  26. } catch {}
  27. html += '<div class="summary" style="padding-bottom:5px;">' + summary + "</div>";
  28. let live = "";
  29. try {
  30. live = marked(lesson["live"], { renderer: renderer });
  31. } catch {}
  32. html += '<div class="summary" style="padding-bottom:5px;">' + live + "</div>";
  33. let replay = "";
  34. try {
  35. replay = marked(lesson["replay"], { renderer: renderer });
  36. } catch {}
  37. html += '<div class="summary" style="padding-bottom:5px;">' + replay + "</div>";
  38. let attachment = "";
  39. try {
  40. attachment = marked(lesson["attachment"], { renderer: renderer });
  41. } catch {}
  42. html += '<div class="summary" style="padding-bottom:5px;">' + attachment + "</div>";
  43. html += "</div>";
  44. html += "</div>";
  45. html += "</div>";
  46. html += '<div style="flex:3;max-width:15em;">';
  47. let d = new Date();
  48. d.setTime(lesson["date"]);
  49. let strData = d.toLocaleDateString();
  50. let strTime = d.toLocaleTimeString();
  51. html += "<div >" + gLocal.gui.date + ":" + strData + "</div>";
  52. html += "<div >" + gLocal.gui.time + ":" + strTime + "</div>";
  53. let dt = lesson["duration"] / 60;
  54. let sdt = "";
  55. if (dt > 59) {
  56. sdt += Math.floor(dt / 60) + gLocal.gui.h;
  57. }
  58. let m = dt % 60;
  59. if (m > 0) {
  60. sdt += (dt % 60) + gLocal.gui.mins;
  61. }
  62. html += "<div >" + gLocal.gui.duration + ":" + sdt + "</div>";
  63. let now = new Date();
  64. let lesson_time = "";
  65. if (now < lesson["date"]) {
  66. lesson_time = gLocal.gui.not_started;
  67. } else if (now > lesson["date"] && now < lesson["date"] + dt * 1000) {
  68. lesson_time = gLocal.gui.in_progress;
  69. } else {
  70. lesson_time = gLocal.gui.already_over;
  71. }
  72. html += '<div ><span class="lesson_status">' + lesson_time + "</span></div>";
  73. html += "</div>";
  74. html += "</div>";
  75. }
  76. $("#lesson_list").html(html);
  77. mermaid.initialize();
  78. }
  79. );
  80. }
  81. function lesson_load(lesson_id) {
  82. $.get(
  83. "../course/lesson_get.php", {
  84. id: lesson_id,
  85. },
  86. function(data, status) {
  87. let html = "";
  88. let lesson_info = JSON.parse(data);
  89. if (lesson_info) {
  90. //head
  91. html += "<div id='course_info_head' class='course_info_block'>";
  92. html += "<div id='course_info_head_title'>";
  93. html += "<div id='course_title'>" + lesson_info.title + "</div>";
  94. html += "<div id='course_subtitle'>" + lesson_info.subtitle + "</div>";
  95. html += "</div>";
  96. html += "</div>";
  97. //end of head
  98. let d = new Date();
  99. d.setTime(lesson_info.date);
  100. let strData = d.toLocaleDateString();
  101. let strTime = d.toLocaleTimeString();
  102. let dt = lesson_info["duration"] / 60;
  103. let strDuration = "";
  104. if (dt > 59) {
  105. strDuration += Math.floor(dt / 60) + "小时";
  106. }
  107. let m = dt % 60;
  108. if (m > 0) {
  109. strDuration += (dt % 60) + "分钟";
  110. }
  111. html += "<div id='lesson_info_head_2' class='course_info_block'>";
  112. html += "<div class='info_item'>" + "<span>上课时间:<span>" + strData + " " + strTime + "</div>";
  113. html +=
  114. "<div class='info_item'>" + "<span>" + gLocal.gui.duration + ":<span>" + strDuration + "</div>";
  115. html += "<div class='info_item'>" + "<span>" + gLocal.gui.speaker + ":<span>";
  116. html +=
  117. "<a href='../uhome/course.php?userid=" +
  118. lesson_info.teacher +
  119. "'>" +
  120. lesson_info.teacher_info.nickname +
  121. "</a>";
  122. html += "</span>";
  123. //html += "<span>地区:缅甸</span>";
  124. html += "</div>";
  125. html += "</div>";
  126. // end of course_info_head_2
  127. //live
  128. if (lesson_info.live && lesson_info.live.length > 0) {
  129. html += "<div id='course_info_live' class='course_info_block'>";
  130. html += "<h2>" + gLocal.gui.notice_live + "</h2>";
  131. try {
  132. html += marked(lesson_info.live);
  133. } catch (e) {
  134. html += e.message;
  135. }
  136. html += "</div>";
  137. }
  138. //end of live
  139. //replay
  140. if (lesson_info.replay && lesson_info.replay.length > 0) {
  141. html += "<div id='course_info_replay' class='course_info_block'>";
  142. html += "<h2>" + gLocal.gui.record_replay + "</h2>";
  143. try {
  144. html += marked(lesson_info.replay);
  145. } catch (e) {
  146. html += e.message;
  147. }
  148. html += "</div>";
  149. }
  150. //end of replay
  151. //attachment
  152. if (lesson_info.attachment && lesson_info.attachment.length > 0) {
  153. html += "<div id='course_info_attachment' class='course_info_block'>";
  154. html += "<h2>" + gLocal.gui.attachment + "</h2>";
  155. try {
  156. html += "<div class='course_info_content'>";
  157. html += note_init(lesson_info.attachment);
  158. html += "</div>";
  159. } catch (e) {
  160. html += e.message;
  161. }
  162. html += "</div>";
  163. }
  164. //end of attachment
  165. //content
  166. if (lesson_info.content && lesson_info.content.length > 0) {
  167. html += "<div id='course_info_content' class='course_info_block'>";
  168. html += "<h2>" + gLocal.gui.detaile + "</h2>";
  169. try {
  170. html += marked(lesson_info.content);
  171. } catch (e) {
  172. html += e.message;
  173. }
  174. html += "</div>";
  175. }
  176. //end of attachment
  177. $("#lesson_info").html(html);
  178. $("#page_title").text(lesson_info.title);
  179. note_refresh_new();
  180. render_course_info(lesson_info.course_id);
  181. render_lesson_list(lesson_info.course_id, lesson_info.id);
  182. }
  183. }
  184. );
  185. }
  186. function render_course_info(course_id) {
  187. $.get(
  188. "../course/course_get.php", {
  189. id: course_id,
  190. },
  191. function(data, status) {
  192. let html = "";
  193. let course_info = JSON.parse(data);
  194. if (course_info) {
  195. let html = "";
  196. html += "<div id='parent_title'>";
  197. html += "<a href='../course/course.php?id=" + course_info.id + "'>";
  198. html += course_info.title;
  199. html += "</a>";
  200. html += "</div>";
  201. html += "<div id='course_button'>";
  202. html += "<button>关注</button>";
  203. html += "<button>报名</button>";
  204. html += "</div>";
  205. $("#course_info").html(html);
  206. }
  207. }
  208. );
  209. }
  210. function render_lesson_list(course_id, currLesson) {
  211. $.get(
  212. "../course/lesson_list.php", {
  213. id: course_id,
  214. },
  215. function(data, status) {
  216. let arrLesson = JSON.parse(data);
  217. let html = "";
  218. for (const lesson of arrLesson) {
  219. let currlessonStyle = "";
  220. if (lesson.id == currLesson) {
  221. currlessonStyle = " curr_lesson";
  222. } else {
  223. currlessonStyle = " not_curr_lesson";
  224. }
  225. //计算课程是否已经开始
  226. let now = new Date();
  227. let class_lesson_time = "";
  228. let dt = lesson["duration"] / 60;
  229. if (now < lesson["date"]) {
  230. class_lesson_time = "not_started";
  231. } else if (now > lesson["date"] && now < lesson["date"] + dt * 1000) {
  232. class_lesson_time = "in_progress";
  233. } else {
  234. class_lesson_time = "already_over";
  235. }
  236. html += '<div class="lesson_card ' + currlessonStyle + '" >';
  237. let d = new Date();
  238. d.setTime(lesson["date"]);
  239. let strData = d.toLocaleDateString();
  240. let strTime = d.toLocaleTimeString();
  241. html += '<div class="pd-10">';
  242. html += "<div class='datatime " + class_lesson_time + "'>" + strData + " " + strTime + "</div>";
  243. html +=
  244. '<div class="title" ><a href="../course/lesson.php?id=' +
  245. lesson["id"] +
  246. '">' +
  247. lesson["title"] +
  248. "</a></div>";
  249. html += "</div>";
  250. html += "</div>";
  251. }
  252. $("#lesson_list").html(html);
  253. }
  254. );
  255. }
  256. function lesson_get_timeline_settime(start, div) {
  257. let lessonTime;
  258. if (start) {
  259. lessonTime = new Date(parseInt(start));
  260. } else {
  261. lessonTime = new Date();
  262. }
  263. let month = lessonTime.getMonth() + 1;
  264. month = month > 9 ? month : "0" + month;
  265. let d = lessonTime.getDate();
  266. d = d > 9 ? d : "0" + d;
  267. let data = lessonTime.getFullYear() + "-" + month + "-" + d;
  268. let strData = "<input type='date' id='" + div + "_date' value='" + data + "'/>";
  269. let H = lessonTime.getHours();
  270. H = H > 9 ? H : "0" + H;
  271. let M = lessonTime.getMinutes();
  272. M = M > 9 ? M : "0" + M;
  273. let strTime = "<input type='time' id='" + div + "_time' value='" + H + ":" + M + "'/>";
  274. $("#form_" + div).html(strData + strTime);
  275. }
  276. function lesson_get_timeline_submit() {
  277. let start_date = new Date();
  278. let start_data = $("#start_date").val().split("-");
  279. let start_time = $("#start_time").val().split(":");
  280. start_date.setFullYear(start_data[0], parseInt(start_data[1]) - 1, start_data[2]);
  281. start_date.setHours(start_time[0], start_time[1]);
  282. let end_date = new Date();
  283. let end_data = $("#end_date").val().split("-");
  284. let end_time = $("#end_time").val().split(":");
  285. end_date.setFullYear(end_data[0], parseInt(end_data[1]) - 1, end_data[2]);
  286. end_date.setHours(end_time[0], end_time[1], 0, 0);
  287. location.assign("../course/lesson_get_timeline.php?start=" + start_date.getTime() + "&end=" + end_date.getTime());
  288. }
  289. function lesson_get_timeline_json(start, end) {
  290. $.get(
  291. "../ucenter/active_log_get.php", {
  292. start: start,
  293. end: end,
  294. },
  295. function(data) {
  296. $("#timeline_json").val(data);
  297. let json = JSON.parse(data);
  298. let html = "<table>";
  299. for (const row of json) {
  300. html += "<tr>";
  301. let start_date = new Date(parseInt(row.time));
  302. html += "<td>" + start_date.getHours() + ":" + start_date.getMinutes() + "</td>";
  303. html += "<td>" + gLocal.LogType[row.active] + "</td>";
  304. html += "<td>";
  305. switch (row.active) {
  306. case "30":
  307. html += "<a href='../dict/?word=" + row.content + "' target='_blank'>" + row.content + "</a>";
  308. break;
  309. case "11":
  310. break;
  311. case "20":
  312. break;
  313. default:
  314. html += row.content;
  315. break;
  316. }
  317. html += "</td>";
  318. html += "</tr>";
  319. }
  320. html += "</table>";
  321. $("#timeline_table").html(html);
  322. }
  323. );
  324. }