location_event.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>事件列表</title>
  8. <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.2/css/bootstrap.min.css">
  9. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.5.16/vue.min.js"></script>
  10. <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
  11. <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.min.js"></script>
  12. </head>
  13. <body>
  14. <div id="app">
  15. <table class="table table-hover">
  16. <thead>
  17. <tr>
  18. <th>起始时间</th>
  19. <th>终止时间</th>
  20. <th>事件名</th>
  21. <th>创建时间</th>
  22. <th>操作</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr v-for="event in events" :key="event.id">
  27. <td>{{ convertToBeijingTime(event.start_time) }}</td>
  28. <td>{{ convertToBeijingTime(event.end_time) }}</td>
  29. <td>{{ event.event_name }}</td>
  30. <td>{{ convertToBeijingTime(event.created_at) }}</td>
  31. <td>
  32. <button @click="confirmDelete(event.id)">删除</button>
  33. </td>
  34. </tr>
  35. </tbody>
  36. </table>
  37. <nav aria-label="Page navigation">
  38. <ul class="pagination">
  39. <li class="page-item" :class="{ 'disabled': currentPage === 1 }">
  40. <a class="page-link" href="#" aria-label="Previous" @click="prevPage">
  41. <span aria-hidden="true">«</span>
  42. </a>
  43. </li>
  44. <li class="page-item" v-for="page in totalPages" :key="page" :class="{ 'active': currentPage === page }">
  45. <a class="page-link" href="#" @click="gotoPage(page)">{{ page }}</a>
  46. </li>
  47. <li class="page-item" :class="{ 'disabled': currentPage === totalPages }">
  48. <a class="page-link" href="#" aria-label="Next" @click="nextPage">
  49. <span aria-hidden="true">»</span>
  50. </a>
  51. </li>
  52. </ul>
  53. </nav>
  54. </div>
  55. <script>
  56. function convertToBeijingTime(dateString) {
  57. // 创建 Date 对象,将字符串解析为日期
  58. const date = new Date(dateString);
  59. // 转换为北京时间
  60. const beijingTime = date.toLocaleString('zh-CN', {
  61. timeZone: 'Asia/Shanghai',
  62. year: 'numeric',
  63. month: '2-digit',
  64. day: '2-digit',
  65. hour: '2-digit',
  66. minute: '2-digit',
  67. second: '2-digit'
  68. });
  69. return beijingTime;
  70. }
  71. new Vue({
  72. el: '#app',
  73. data() {
  74. return {
  75. events: [],
  76. currentPage: 1,
  77. totalPages: 0,
  78. pageSize: 10
  79. };
  80. },
  81. mounted() {
  82. this.fetchEvents();
  83. },
  84. methods: {
  85. confirmDelete(id) {
  86. if (confirm('确定要删除吗?')) {
  87. // 发送删除请求
  88. axios.delete(`https://api.tianyunperfect.cn/location/event_delete?id=${id}`)
  89. .then(response => {
  90. this.fetchEvents();
  91. })
  92. }
  93. },
  94. fetchEvents() {
  95. axios.get('https://api.tianyunperfect.cn/location/event_page', {
  96. params: {
  97. page: this.currentPage,
  98. size: this.pageSize
  99. }
  100. })
  101. .then(response => {
  102. this.events = response.data.data.list;
  103. this.totalPages = Math.ceil(response.data.data.total / this.pageSize);
  104. })
  105. .catch(error => {
  106. console.error(error);
  107. });
  108. },
  109. prevPage() {
  110. if (this.currentPage > 1) {
  111. this.currentPage--;
  112. this.fetchEvents();
  113. }
  114. },
  115. nextPage() {
  116. if (this.currentPage < this.totalPages) {
  117. this.currentPage++;
  118. this.fetchEvents();
  119. }
  120. },
  121. gotoPage(page) {
  122. if (page >= 1 && page <= this.totalPages) {
  123. this.currentPage = page;
  124. this.fetchEvents();
  125. }
  126. }
  127. }
  128. });
  129. </script>
  130. </body>
  131. </html>