index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <v-container>
  3. <v-text-field
  4. append-outer-icon="mdi-magnify"
  5. @click:append-outer="searchTrigger"
  6. @keyup.enter="searchTrigger"
  7. clearable
  8. v-model="search"
  9. label="Поиск"
  10. ></v-text-field>
  11. <v-data-table
  12. :loading="isLoading"
  13. :headers="headers"
  14. :items="comments"
  15. :page.sync="page"
  16. :items-per-page="100"
  17. hide-default-footer
  18. disable-sort
  19. loading-text="Загрузка комментариев"
  20. no-data-text="Нет данных"
  21. >
  22. <template v-slot:item.created_at="{ item }">
  23. {{ getFormatDate(item.created_at) }}
  24. </template>
  25. <template v-slot:item.user.date_registration="{ item }">
  26. {{ item.user ? getFormatDate(item.user.date_registration) : "" }}
  27. </template>
  28. <template v-slot:item.user.date_last_activity="{ item }">
  29. {{ item.user ? getFormatDate(item.user.date_last_activity) : "" }}
  30. </template>
  31. <template v-slot:item.news.alias="{ item }">
  32. <nuxt-link :to="getFormatLink(item.news)"><span v-html="item.news.title"></span></nuxt-link>
  33. </template>
  34. </v-data-table>
  35. <v-row class="my-5" justify="center">
  36. <v-pagination
  37. v-if="comments.length"
  38. v-model="page"
  39. :total-visible="20"
  40. :length="total"
  41. class="my-5"
  42. >
  43. </v-pagination>
  44. </v-row>
  45. </v-container>
  46. </template>
  47. <script>
  48. export default {
  49. layout: "admin",
  50. data() {
  51. return {
  52. page: 1,
  53. total: 0,
  54. comments: [],
  55. search: "",
  56. isLoading: false,
  57. headers: [
  58. { text: "ID", value: "id" },
  59. { text: "Дата создания", value: "created_at" },
  60. { text: "ID пользователя", value: "user.id" },
  61. { text: "Имя пользователя", value: "user.first_name" },
  62. { text: "Email", value: "user.email" },
  63. { text: "Дата регистрации", value: "user.date_registration" },
  64. { text: "IP регистрации", value: "user.registration_ip_address" },
  65. { text: "Дата последней активности", value: "user.date_last_activity" },
  66. {
  67. text: "IP последней активности",
  68. value: "user.last_activity_ip_address",
  69. },
  70. { text: "Страница", value: "news.alias" },
  71. { text: "Комментарий", value: "message" },
  72. { text: "IP адрес", value: "ip_address" },
  73. { text: "User agent", value: "user_agent" },
  74. ],
  75. };
  76. },
  77. async mounted() {
  78. await this.loadTrigger();
  79. },
  80. watch: {
  81. async page() {
  82. this.comments = [];
  83. window.scrollTo(0, 0);
  84. await this.loadTrigger();
  85. },
  86. },
  87. methods: {
  88. async loadComments() {
  89. return await this.$axios
  90. .$get(`admin/comments/log/page_${this.page}`)
  91. .then((res) => res.data);
  92. },
  93. async searchComments() {
  94. return await this.$axios
  95. .$get(`admin/comments/log/search/${this.search}/page_${this.page}`)
  96. .then((res) => res.data);
  97. },
  98. async loadTrigger() {
  99. this.isLoading = true;
  100. let response;
  101. if (this.search) response = await this.searchComments();
  102. else response = await this.loadComments();
  103. this.total = response.total_pages;
  104. this.comments = response.comments || [];
  105. this.isLoading = false;
  106. },
  107. async searchTrigger() {
  108. this.page = 1;
  109. await this.loadTrigger();
  110. },
  111. getFormatDate(str) {
  112. if(!str) return '';
  113. let date = new Date(str);
  114. return date.toLocaleString("ru-RU");
  115. },
  116. getFormatLink(news) {
  117. return {
  118. name: "news-category-alias",
  119. params: {
  120. category: news.category.alias,
  121. alias: news.alias,
  122. },
  123. };
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. </style>