groupItem.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="content">
  3. <view v-for="(value, index) in list">
  4. <view class="item u-border-bottom" :class="currIndex ===index ? 'bg_view' : ''" hover-class="message-hover-class"
  5. @tap="link(value)">
  6. <img-cache :src="value.avatar || value.imgUrl"></img-cache>
  7. <view class="right title-wrap">
  8. <view class="right_top">
  9. <view class="right_top_name u-line-1">{{ value.chatName }}</view>
  10. <view class="right_top_time ">{{value.lastOperTime || value.lastOpenTime | format}}</view>
  11. </view>
  12. <view class="right_btm ">
  13. <view class="u-line-1">{{value.desc}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. components: {
  23. },
  24. data() {
  25. return {
  26. list: [],
  27. currIndex: -1,
  28. $url:''
  29. };
  30. },
  31. onLoad() {
  32. },
  33. onShow() {
  34. this.query(false);
  35. },
  36. onPullDownRefresh() {
  37. this.query(true)
  38. },
  39. methods: {
  40. link(item,index) {
  41. this.currIndex = index;
  42. this.$u.vuex('chatObj', item);
  43. this.$u.route({url: 'pageC/chat/chat'});
  44. },
  45. query(freshFlag) {
  46. this.$socket.getGroups('', this.userData.user.operId, res => {
  47. this.list = res.response.data;
  48. if(freshFlag){
  49. uni.stopPullDownRefresh();
  50. }
  51. });
  52. }
  53. },
  54. filters: {
  55. format: function (e) {
  56. // 获取js 时间戳
  57. let time = new Date().getTime();
  58. // 去掉 js 时间戳后三位
  59. time = parseInt((time - e) / 1000);
  60. // 存储转换值
  61. let s;
  62. if (time < 60 * 10) {
  63. // 十分钟内
  64. return '刚刚';
  65. } else if (time < 60 * 60 && time >= 60 * 10) {
  66. // 超过十分钟少于1小时
  67. s = Math.floor(time / 60);
  68. return s + '分钟前';
  69. } else if (time < 60 * 60 * 24 && time >= 60 * 60) {
  70. // 超过1小时少于24小时
  71. s = Math.floor(time / 60 / 60);
  72. return s + '小时前';
  73. } else if (time < 60 * 60 * 24 * 3 && time >= 60 * 60 * 24) {
  74. // 超过1天少于3天内
  75. s = Math.floor(time / 60 / 60 / 24);
  76. return s + '天前';
  77. } else {
  78. // 超过3天
  79. var date = new Date(e);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  80. var Y = date.getFullYear() + '-';
  81. var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  82. var D = date.getDate() + ' ';
  83. var h = date.getHours() + ':';
  84. var m = date.getMinutes() + ':';
  85. var ss = date.getSeconds();
  86. return h+m+ss;
  87. }
  88. }
  89. },
  90. };
  91. </script>
  92. <style lang="scss">
  93. .content{
  94. background-color: #fff;
  95. }
  96. .item {
  97. width: 750rpx;
  98. height: 140rpx;
  99. display: flex;
  100. align-items: center;
  101. image {
  102. width: 96rpx;
  103. height: 96rpx;
  104. margin: 20rpx;
  105. border-radius: 12rpx;
  106. flex: 0 0 96rpx;
  107. }
  108. .right {
  109. overflow: hidden;
  110. flex: 1 0;
  111. padding: 20rpx 20rpx 40rpx 0;
  112. &_top {
  113. display: flex;
  114. justify-content: space-between;
  115. &_name {
  116. font-size: 28rpx;
  117. font-weight: 800;
  118. color: $u-main-color;
  119. flex: 0 0 450rpx;
  120. overflow: hidden;
  121. }
  122. &_time {
  123. font-size: 22rpx;
  124. color: $u-light-color;
  125. }
  126. }
  127. &_btm {
  128. display: flex;
  129. justify-content: space-between;
  130. align-items: center;
  131. font-size: 22rpx;
  132. color: $u-tips-color;
  133. padding-top: 10rpx;
  134. }
  135. }
  136. }
  137. .bg_view {
  138. background-color: #fafafa;
  139. }
  140. .slot-wrap {
  141. display: flex;
  142. align-items: center;
  143. padding: 0 30rpx;
  144. }
  145. </style>