course.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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>" + gLocal.gui.watch + "</button>";
  22. html += "<button disabled>" + 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. $("img").one("error", function () {
  66. $(this).attr("src", "../course/img/default.jpg");
  67. });
  68. }
  69. }
  70. );
  71. $.get(
  72. "../course/lesson_list.php",
  73. {
  74. id: course_id,
  75. },
  76. function (data, status) {
  77. let arrLesson = JSON.parse(data);
  78. let html = "";
  79. for (const lesson of arrLesson) {
  80. //计算课程是否已经开始
  81. let now = new Date();
  82. let class_lesson_time = "";
  83. let dt = lesson["duration"] / 60;
  84. if (now < lesson["date"]) {
  85. class_lesson_time = "not_started";
  86. } else if (now > lesson["date"] && now < lesson["date"] + dt * 1000) {
  87. class_lesson_time = "in_progress";
  88. } else {
  89. class_lesson_time = "already_over";
  90. }
  91. html += '<div class="lesson_card" >';
  92. let d = new Date();
  93. d.setTime(lesson["date"]);
  94. let strData = d.toLocaleDateString();
  95. let strTime = d.toLocaleTimeString();
  96. html += '<div class="pd-10">';
  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. html += "</div>";
  105. /*
  106. let dt = lesson["duration"] / 60;
  107. let sdt = "";
  108. if (dt > 59) {
  109. sdt += Math.floor(dt / 60) + "小时";
  110. }
  111. let m = dt % 60;
  112. if (m > 0) {
  113. sdt += (dt % 60) + "分钟";
  114. }
  115. html += "<div >" + gLocal.gui.duration + ":" + sdt + "</div>";
  116. html += '<div ><span class="lesson_status">' + lesson_time + "</span></div>";
  117. */
  118. html += "</div>";
  119. }
  120. $("#lesson_list").html(html);
  121. }
  122. );
  123. }