course.js 4.8 KB

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