detail.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. {% extends "base.html" %}
  2. {% load static %}
  3. {% block title %}
  4. 文章详情:{{ article.title }}
  5. {% endblock title %}
  6. {% block content %}
  7. <div class="container">
  8. <div class="row">
  9. <div class="col-3 mt-4 sidebar" id="sidebar">
  10. <div class="sidebar__inner">
  11. <h4><strong>目录</strong></h4>
  12. <hr>
  13. <div>
  14. {{ tor|safe }}
  15. </div>
  16. </div>
  17. </div>
  18. <div class="col-9">
  19. <h1 class="mt-4 mb-4">
  20. {{ article.title }}
  21. </h1>
  22. <div class="col-12 alert alert-success">
  23. 作者: {{ article.author }}
  24. {% if user == article.author %}
  25. · <a href="#" onclick="confirm_delete()">
  26. 删除文章
  27. </a>
  28. · <a href="{% url 'article:article_update' article.id %}">
  29. 编辑文章
  30. </a>
  31. {% endif %}
  32. <div>
  33. 浏览:{{ article.total_views }}
  34. </div>
  35. <form style="display: none"
  36. id="safa_delete"
  37. action="{% url 'article:article_safe_delete' article.id %}"
  38. method="post"
  39. >
  40. {% csrf_token %}
  41. <button type="submit">
  42. 发送
  43. </button>
  44. </form>
  45. </div>
  46. {% if article.avatar %}
  47. <div class="row mt-2">
  48. <img src="{{ article.avatar.url }}"
  49. alt="avatar"
  50. style="max-width: 100%; border-radius: 20px;"
  51. >
  52. </div>
  53. <hr/>
  54. {% endif %}
  55. <div class="col-12">
  56. <p>
  57. {{ article.body|safe }}
  58. </p>
  59. </div>
  60. <hr>
  61. {% if user.is_authenticated %}
  62. <div>
  63. <form action="{% url 'comment:post_comment' article.id %}" method="post">
  64. {% csrf_token %}
  65. <div class="form-group">
  66. <label for="body">
  67. <strong>
  68. 发表评论
  69. </strong>
  70. </label>
  71. <!--<textarea type="text" class="form-control" id="body" name="body" rows="2"></textarea>-->
  72. <div>
  73. {{ comment_form.media }}
  74. {{ comment_form.body }}
  75. </div>
  76. </div>
  77. <button type="submit" class="btn btn-primary">发送</button>
  78. </form>
  79. </div>
  80. <br>
  81. {% else %}
  82. <br>
  83. <h5 class="row justify-content-center">
  84. 请<a href="{% url 'userprofile:login' %}">登录</a>后回复
  85. </h5>
  86. <br>
  87. {% endif %}
  88. {% load mptt_tags %}
  89. <h4>共有{{ comments.count }}条评论</h4>
  90. <div class="row">
  91. <!-- 遍历树形结构 -->
  92. {% recursetree comments %}
  93. <!-- 给 node 取个别名 comment -->
  94. {% with comment=node %}
  95. <div class="{% if comment.reply_to %}
  96. offset-1 col-11
  97. {% else %}
  98. col-12
  99. {% endif %}">
  100. <hr>
  101. <p>
  102. <strong style="color: pink">
  103. {{ comment.user }}
  104. </strong>
  105. {% if comment.reply_to %}
  106. <i class="far fa-arrow-alt-circle-right"
  107. style="color: cornflowerblue;"
  108. ></i>
  109. <strong style="color: pink">
  110. {{ comment.reply_to }}
  111. </strong>
  112. {% endif %}
  113. </p>
  114. <div>{{ comment.body|safe }}</div>
  115. <div>
  116. <span style="color: gray">
  117. {{ comment.created|date:"Y-m-d H:i" }}
  118. </span>
  119. <!-- 加载 modal 的按钮 -->
  120. {% if user.is_authenticated %}
  121. <button type="button"
  122. class="btn btn-light btn-sm text-muted"
  123. onclick="load_modal({{ article.id }}, {{ comment.id }})">
  124. 回复
  125. </button>
  126. {% else %}
  127. <a class="btn btn-light btn-sm text-muted"
  128. href="{% url 'userprofile:login' %}">
  129. 回复
  130. </a>
  131. {% endif %}
  132. </div>
  133. <!-- Modal -->
  134. <div class="modal fade"
  135. id="comment_{{ comment.id }}"
  136. tabindex="-1"
  137. role="dialog"
  138. aria-labelledby="CommentModalCenter"
  139. aria-hidden="true">
  140. <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
  141. <div class="modal-content" style="height: 480px">
  142. <div class="modal-header">
  143. <h5 class="modal-title" id="exampleModalCenterTitle">
  144. 回复 {{ comment.user }}:</h5>
  145. </div>
  146. <div class="modal-body" id="modal_body_{{ comment.id }}"></div>
  147. </div>
  148. </div>
  149. </div>
  150. {% if not comment.is_leaf_node %}
  151. <div class="children">
  152. {{ children }}
  153. </div>
  154. {% endif %}
  155. </div>
  156. {% endwith %}
  157. {% endrecursetree %}
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <script>
  163. function confirm_delete() {
  164. layer.open({
  165. title: "删除文章",
  166. content: "确认删除这篇文章吗?",
  167. yes: function (index, layero) {
  168. $('form#safe_delete button').click();
  169. layer.close(index);
  170. },
  171. })
  172. }
  173. </script>
  174. <script src="{% static 'ckeditor/ckeditor/plugins/prism/lib/prism/prism_patched.min.js' %}"></script>
  175. <!-- 粘性侧边栏样式 -->
  176. <style>
  177. .sidebar {
  178. will-change: min-height;
  179. }
  180. .sidebar__inner {
  181. transform: translate(0, 0);
  182. transform: translate3d(0, 0, 0);
  183. will-change: position, transform;
  184. }
  185. </style>
  186. <link rel="stylesheet" href="{% static 'prism/prism.css' %}">
  187. {% endblock content %}
  188. {% block script %}
  189. <!--二级回复-->
  190. <script>
  191. // 加载 modal
  192. function load_modal(article_id, comment_id) {
  193. let modal_body = '#modal_body_' + comment_id;
  194. let modal_id = '#comment_' + comment_id;
  195. // 加载编辑器
  196. if ($(modal_body).children().length === 0) {
  197. let content = '<iframe src="/comment/post_comment/' +
  198. article_id +
  199. '/' +
  200. comment_id +
  201. '"' +
  202. ' frameborder="0" style="width: 100%; height: 100%;" id="iframe_' +
  203. comment_id +
  204. '"></iframe>';
  205. $(modal_body).append(content);
  206. }
  207. ;
  208. $(modal_id).modal('show');
  209. }
  210. </script>
  211. <!--侧边栏-->
  212. <script>
  213. $(".django-ckeditor-widget").removeAttr('style');
  214. </script>
  215. <script src="{% static 'sticky_sidebar/jquery.sticky-sidebar.min.js' %}"></script>
  216. <script type="text/javascript">
  217. $('#sidebar').stickySidebar({
  218. topSpacing: 20,
  219. bottomSpacing: 20,
  220. });
  221. </script>
  222. {% endblock script %}