index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <div>
  3. <v-row class="mx-auto mt-5 px-4">
  4. <v-btn @click="showModerationComments">Показать комментарии на модерацию</v-btn>
  5. <v-btn @click="showAllComments" class="mx-2"> Показать все комментарии </v-btn>
  6. <v-btn to="/admin/comments/log"> Показать лог комментариев </v-btn>
  7. <v-spacer></v-spacer>
  8. <v-checkbox
  9. max-width="600"
  10. v-model="moderationStatus"
  11. @click="changeStatus"
  12. label="Статус модератора"
  13. ></v-checkbox>
  14. </v-row>
  15. <v-list two-line>
  16. <v-list-item v-for="comment in comments.comments" :key="comment.id">
  17. <v-list-item-content>
  18. <v-row>
  19. <v-col>
  20. {{ comment.user_create_for_admin ? comment.user_create_for_admin.first_name : 'Гость' }}
  21. </v-col>
  22. <v-col cols="2">
  23. {{ convertDate(comment.created_at) }}
  24. </v-col>
  25. <v-col cols="5">
  26. {{ comment.message ? comment.message : '' }}
  27. </v-col>
  28. <v-col cols="2">
  29. <nuxt-link :to="getLink(comment.news_for_admin)" target="_blank" v-html="comment.news_for_admin.title"></nuxt-link>
  30. </v-col>
  31. <v-col>
  32. <nuxt-link :to="getEditLink(comment.news_for_admin)" target="_blank">
  33. Редактировать
  34. </nuxt-link>
  35. </v-col>
  36. </v-row>
  37. </v-list-item-content>
  38. <v-list-item-action class="is-flex">
  39. <v-btn
  40. icon
  41. v-if="comment.need_moderation"
  42. @click="approveComment(comment.id)"
  43. >
  44. <v-icon color="green lighten-1">mdi-check-circle</v-icon>
  45. </v-btn>
  46. <v-btn icon @click="removeComment(comment.id)">
  47. <v-icon color="red darker-1">mdi-delete</v-icon>
  48. <!--удалить-->
  49. </v-btn>
  50. <v-btn icon :to="{name: 'admin-comments-id', params: { id: comment.id, message: comment.message}}">
  51. <v-icon color="green darker-1"> mdi-pencil </v-icon>
  52. <!--изменить-->
  53. </v-btn>
  54. </v-list-item-action>
  55. </v-list-item>
  56. </v-list>
  57. <v-pagination
  58. v-model="counter"
  59. :length="comments.total_pages"
  60. ref="pagination"
  61. @input="loadComments"
  62. :next-icon="'Вперед'"
  63. :prev-icon="'Назад'"
  64. :next-aria-label="'next-text'"
  65. :prev-aria-label="'prev-text'"
  66. :page-aria-label="'page-text'"
  67. :current-page-aria-label="'current-page'"
  68. total-visible="10"
  69. ></v-pagination>
  70. </div>
  71. </template>
  72. <script>
  73. export default {
  74. data() {
  75. return {
  76. moderationStatus: false,
  77. moderationOnly: false,
  78. counter: 1,
  79. comments: [],
  80. moderation_status: ''
  81. };
  82. },
  83. mounted() {
  84. this.$axios
  85. .$get("admin/comments/list/all")
  86. .then((res) => {
  87. this.comments = res.data
  88. return res.data;
  89. });
  90. this.$axios
  91. .$get("comments/premoderation/status")
  92. .then((res) => {
  93. this.moderationStatus = res.data.moderation_status
  94. return res.data.moderation_status;
  95. });
  96. },
  97. layout: "admin",
  98. methods: {
  99. async approveComment(commentId) {
  100. await this.$axios
  101. .$get(
  102. "https://api.amic.ru/api/v1/admin/comments/approve/" +
  103. commentId
  104. )
  105. .then((res) => {
  106. console.log(res);
  107. })
  108. .catch((error) => {
  109. console.log(error);
  110. });
  111. },
  112. async removeComment(commentId) {
  113. await this.$axios
  114. .$get(
  115. "https://api.amic.ru/api/v1/admin/comments/remove/" +
  116. commentId
  117. )
  118. .then((res) => {
  119. console.log(res);
  120. })
  121. .catch((error) => {
  122. console.log(error);
  123. });
  124. },
  125. async changeStatus() {
  126. if (!this.moderationStatus) {
  127. this.$axios
  128. .$get("authorized/admin/comments/premoderation/disable")
  129. .then((res) => {
  130. console.log(res);
  131. });
  132. } else {
  133. this.$axios
  134. .$get("authorized/admin/comments/premoderation/enable")
  135. .then((res) => {
  136. console.log(res);
  137. });
  138. }
  139. },
  140. async showModerationComments() {
  141. this.moderationOnly = true;
  142. const comments = await this.$axios
  143. .$get("admin/comments/list/moderation")
  144. .then((res) => {
  145. this.comments = res.data;
  146. return res.data;
  147. });
  148. return { comments };
  149. },
  150. async showAllComments() {
  151. this.moderationOnly = false;
  152. const comments = await this.$axios
  153. .$get("admin/comments/list/all/page_1")
  154. .then((res) => {
  155. this.comments = res.data;
  156. return res.data;
  157. });
  158. return { comments };
  159. },
  160. async loadComments() {
  161. if (this.moderationOnly) {
  162. await this.$axios
  163. .$get(`admin/comments/list/moderation/page_` + this.counter)
  164. .then((res) => {
  165. this.comments = res.data;
  166. return res.data;
  167. });
  168. return { comments };
  169. } else {
  170. await this.$axios
  171. .$get(`admin/comments/list/all/page_` + this.counter)
  172. .then((res) => {
  173. this.comments = res.data;
  174. return res.data;
  175. });
  176. }
  177. },
  178. getLink(news) {
  179. return {
  180. name: 'news-category-alias',
  181. params: {
  182. category: news.category_for_admin.alias,
  183. alias: news.alias
  184. }
  185. }
  186. },
  187. getEditLink(news) {
  188. return {
  189. name: 'admin-publications-id',
  190. params: {
  191. id: news.id
  192. }
  193. }
  194. },
  195. convertDate(dateTampstamp) {
  196. const date = new Date(dateTampstamp);
  197. const dateString =
  198. date.toLocaleString("ru", {
  199. day: "numeric",
  200. month: "long",
  201. }) +
  202. " " +
  203. date.getFullYear() +
  204. ", " +
  205. ("0" + date.getHours()).slice(-2) +
  206. ":" +
  207. ("0" + date.getMinutes()).slice(-2);
  208. return dateString;
  209. },
  210. },
  211. };
  212. </script>
  213. <style>
  214. </style>