List.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="new-list">
  3. <div class="empty" v-if="newList.length == 0">
  4. 暂无数据
  5. </div>
  6. <div class="new-item hand" v-for="item in newList" :key="item.id" @click="navTo('/directories/detail?id='+ item.id)">
  7. <div class="title clamp">
  8. <span class="title-icon"></span>
  9. {{ item.title }}
  10. </div>
  11. <div class="time">{{ item.release_time?item.release_time:item.add_time | time }}</div>
  12. </div>
  13. <el-pagination layout="prev, pager, next" :total="total" background prev-text="上一页" next-text="下一页" @current-change="currentChange" :page-size="15" hide-on-single-page></el-pagination>
  14. </div>
  15. </template>
  16. <script>
  17. import { loadIndexs, splist, loveList, friendList , newsList, openList , regulationList, getDirectoriesList } from '../../request/api.js';
  18. export default {
  19. data() {
  20. return {
  21. newList: [],
  22. total: 0,
  23. page: 1,
  24. limit: 15
  25. };
  26. },
  27. filters: {
  28. time(val) {
  29. let arr = val.split(' ')
  30. let str = arr[0]
  31. str = str.replace(/-/g, '.')
  32. return str
  33. }
  34. },
  35. created() {
  36. this.getList()
  37. },
  38. methods:{
  39. navTo(url) {
  40. this.$router.push(url);
  41. },
  42. currentChange(e) {
  43. this.page = e
  44. this.getList()
  45. },
  46. getList() {
  47. let obj = this
  48. getDirectoriesList({
  49. page: obj.page,
  50. limit: obj.limit
  51. }).then(res => {
  52. obj.newList = res.data.list.sort(this.compare('id'))
  53. obj.total = res.data.count
  54. })
  55. },
  56. compare(attribute) {
  57. return function(obj1, obj2) {
  58. var val1 = obj1[attribute];
  59. var val2 = obj2[attribute];
  60. if (val1 < val2) {
  61. return 1;
  62. } else if (val1 > val2) {
  63. return -1;
  64. } else {
  65. return 0;
  66. }
  67. }
  68. }
  69. }
  70. };
  71. </script>
  72. <style lang="scss" scoped>
  73. .empty {
  74. text-align: center;
  75. color: #999;
  76. height: 400px;
  77. line-height: 400px;
  78. }
  79. .new-list {
  80. // padding: 0px 72px 0 40px;
  81. .new-item {
  82. display: flex;
  83. justify-content: space-between;
  84. font-size: 18px;
  85. font-family: PingFang SC;
  86. font-weight: 500;
  87. color: #666666;
  88. height: 40px;
  89. border-bottom: 1px solid #E5E5E5;
  90. line-height: 40px;
  91. &:hover {
  92. color: red;
  93. .title {
  94. .title-icon {
  95. border-left-color: red;
  96. }
  97. }
  98. }
  99. .title {
  100. width: 800px;
  101. .title-icon {
  102. display: inline-block;
  103. width: 0;
  104. height: 0;
  105. width: 0;
  106. height: 0;
  107. border-top: 6px solid transparent;
  108. border-left: 8px solid #d2d2d2;
  109. border-bottom: 6px solid transparent;
  110. }
  111. }
  112. }
  113. }
  114. /deep/ .el-pagination {
  115. margin-top: 50px;
  116. text-align: center;
  117. }
  118. </style>