leo-list.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="leo-list">
  3. <template v-if="list.length">
  4. <view class="uni-flex uni-row leo-align-items-center leo-space-between leo-list-item" v-for="(item, index) in list"
  5. :key="index" @tap="navTo(path + item.id)">
  6. <view class="uni-flex uni-row leo-align-items-center">
  7. <view style="width: 100%;">
  8. <view class="text-line-height-1 text-title leo-ellipsis-1">
  9. {{ item.tatle || "暂无数据"}}
  10. </view>
  11. <view class="text-line-height-1 text-date leo-ellipsis-1">
  12. {{item.createTime|time}}
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <template v-else>
  19. <view class="" style="text-align: center;">
  20. 暂无数据
  21. </view>
  22. </template>
  23. </view>
  24. </template>
  25. <script>
  26. import moment from '@/common/moment';
  27. export default {
  28. props: {
  29. list: {
  30. type:Array,
  31. default() {
  32. return []
  33. }
  34. },
  35. borderRadius: {
  36. type: [Number, String],
  37. default: 0
  38. },
  39. path: {
  40. type: String,
  41. default: ''
  42. }
  43. },
  44. filters:{
  45. time(val) {
  46. // 拿到当前时间戳和发布时的时间戳,然后得出时间戳差
  47. var curTime = new Date();
  48. var postTime = new Date(val);
  49. var timeDiff = curTime.getTime() - postTime.getTime();
  50. // 单位换算
  51. var min = 60 * 1000;
  52. var hour = min * 60;
  53. var day = hour * 24;
  54. var week = day * 7;
  55. // 计算发布时间距离当前时间的周、天、时、分
  56. var exceedWeek = Math.floor(timeDiff / week);
  57. var exceedDay = Math.floor(timeDiff / day);
  58. var exceedHour = Math.floor(timeDiff / hour);
  59. var exceedMin = Math.floor(timeDiff / min);
  60. // 最后判断时间差到底是属于哪个区间,然后return
  61. if (exceedWeek > 0) {
  62. if(curTime.getFullYear()==postTime.getFullYear()){
  63. return moment(val).format('MM-DD');
  64. }else{
  65. return moment(val).format('YYYY-MM-DD');
  66. }
  67. } else {
  68. if (exceedDay < 7 && exceedDay > 0) {
  69. return exceedDay + '天前';
  70. } else {
  71. if (exceedHour < 24 && exceedHour > 0) {
  72. return exceedHour + '小时前';
  73. } else {
  74. if(exceedMin<1){
  75. exceedMin=0
  76. }
  77. return exceedMin + '分钟前';
  78. }
  79. }
  80. }
  81. }
  82. },
  83. data() {
  84. return {
  85. }
  86. },
  87. methods: {
  88. // 通用跳转
  89. navTo(route) {
  90. this.$mRouter.push({
  91. route
  92. });
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .leo-list {
  99. .leo-list-item {
  100. padding: 30rpx 0rpx;
  101. border-top: #e4e7ed 2rpx solid;
  102. &:first-child {
  103. border-top: #e4e7ed 2rpx solid;
  104. }
  105. .icon {
  106. display: block;
  107. width: 64rpx;
  108. height: 64rpx;
  109. }
  110. }
  111. }
  112. .uni-flex {
  113. display: flex;
  114. flex-direction: row;
  115. }
  116. .uni-flex-item {
  117. flex: 1;
  118. }
  119. .uni-row {
  120. flex-direction: row;
  121. }
  122. .uni-column {
  123. flex-direction: column;
  124. }
  125. .leo-align-items-center {
  126. align-items: center;
  127. width: 100%;
  128. }
  129. .leo-space-between {
  130. justify-content: space-between;
  131. }
  132. .text-line-height-1 {
  133. line-height: 1.5 !important;
  134. }
  135. .text-title {
  136. font-size:16px !important;
  137. line-height: 1.5;
  138. //width:78%;
  139. //float: left;
  140. //white-space:nowrap;
  141. //text-overflow:ellipsis;
  142. //-o-text-overflow:ellipsis;
  143. //overflow: hidden;
  144. }
  145. .text-date {
  146. font-size: $font-sm !important;
  147. float: right;
  148. //width:20%;
  149. text-align: right;
  150. color: rgba(156,164,169,1);
  151. margin-top: 6rpx;
  152. }
  153. .leo-ellipsis-1 {
  154. display: -webkit-box;
  155. text-overflow: -o-ellipsis-lastline;
  156. overflow: hidden;
  157. text-overflow: ellipsis;
  158. -webkit-line-clamp: 2;
  159. line-clamp: 2;
  160. -webkit-box-orient: vertical;
  161. }
  162. </style>