2
0

course.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. function course_load(course_id) {
  2. $.get(
  3. "../course/course_get.php",
  4. {
  5. id: course_id,
  6. },
  7. function (data, status) {
  8. let html = "";
  9. let course_info = JSON.parse(data);
  10. if (course_info) {
  11. //head
  12. html += "<div id='course_info_head' class='course_info_block'>";
  13. html += "<div id='course_info_head_1'>";
  14. html += "<div id='course_info_head_face'>";
  15. html += "<img src='../../tmp/images/course/" + course_info.id + ".jpg' />";
  16. html += "</div>";
  17. html += "<div id='course_info_head_title'>";
  18. html += "<div id='course_title'>" + course_info.title + "</div>";
  19. html += "<div id='course_subtitle'>" + course_info.subtitle + "</div>";
  20. html += "<div id='course_button'>";
  21. html += "<button class='disable'>" + gLocal.gui.watch + "</button>";
  22. html += "<button disabled class='disable'>" + gLocal.gui.sign_up + "</button>";
  23. html += "</div>";
  24. html += "</div>";
  25. html += "</div>";
  26. html += "<div id='course_info_head_2'>";
  27. html += "<span><span>" + gLocal.gui.speaker + ": </span>";
  28. html +=
  29. "<a href='../uhome/course.php?userid=" +
  30. course_info.teacher +
  31. "'>" +
  32. course_info.teacher_info.nickname +
  33. "</a>";
  34. html += "</span>";
  35. //html += "<span>地区:缅甸</span>";
  36. html += "</div>";
  37. // end of course_info_head_2
  38. html += "</div>";
  39. //end of head
  40. //summary
  41. if (course_info.summary.length > 0) {
  42. html += "<div id='course_info_summary' class='course_info_block'>";
  43. html += "<h2>" + gLocal.gui.introduction + "</h2>";
  44. try {
  45. html += marked(course_info.summary);
  46. } catch (e) {
  47. html += e.message;
  48. }
  49. html += "</div>";
  50. }
  51. //end of summary
  52. //attachment
  53. if (course_info.attachment.length > 0) {
  54. html += "<div id='course_info_attachment' class='course_info_block'>";
  55. html += "<h2>" + gLocal.gui.attachment + "</h2>";
  56. try {
  57. html += marked(course_info.attachment);
  58. } catch (e) {
  59. html += e.message;
  60. }
  61. html += "</div>";
  62. }
  63. //end of attachment
  64. $("#course_info").html(html);
  65. $("#page_title").text(course_info.title);
  66. $("img").one("error", function () {
  67. $(this).attr("src", "../course/img/default.jpg");
  68. });
  69. }
  70. }
  71. );
  72. $.get(
  73. "../course/lesson_list.php",
  74. {
  75. id: course_id,
  76. },
  77. function (data, status) {
  78. let arrLesson = JSON.parse(data);
  79. let html = "";
  80. for (const lesson of arrLesson) {
  81. //计算课程是否已经开始
  82. let now = new Date();
  83. let class_lesson_time = "";
  84. let dt = lesson["duration"] / 60;
  85. if (now < lesson["date"]) {
  86. class_lesson_time = "not_started";
  87. } else if (now > lesson["date"] && now < lesson["date"] + dt * 1000) {
  88. class_lesson_time = "in_progress";
  89. } else {
  90. class_lesson_time = "already_over";
  91. }
  92. html += '<div class="lesson_card" >';
  93. let d = new Date();
  94. d.setTime(lesson["date"]);
  95. let strData = d.toLocaleDateString();
  96. let strTime = d.toLocaleTimeString();
  97. html += "<div class='datatime " + class_lesson_time + "'>" + strData + " " + strTime + "</div>";
  98. html +=
  99. '<div class="title" ><a href="../course/lesson.php?id=' +
  100. lesson["id"] +
  101. '" style="color:var(--main-color);">' +
  102. lesson["title"] +
  103. "</a></div>";
  104. /*
  105. let dt = lesson["duration"] / 60;
  106. let sdt = "";
  107. if (dt > 59) {
  108. sdt += Math.floor(dt / 60) + "小时";
  109. }
  110. let m = dt % 60;
  111. if (m > 0) {
  112. sdt += (dt % 60) + "分钟";
  113. }
  114. html += "<div >" + gLocal.gui.duration + ":" + sdt + "</div>";
  115. html += '<div ><span class="lesson_status">' + lesson_time + "</span></div>";
  116. */
  117. html += "</div>";
  118. }
  119. $("#lesson_list").html(html);
  120. }
  121. );
  122. }