chatItem.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view class="item u-border-bottom" :class="value.isTop? 'bg_view' : ''" hover-class="message-hover-class" @tap="linkTo(value)">
  3. <img-cache :src="value.avatar|| value.imgUrl"></img-cache>
  4. <u-badge v-if="value.unreadNumber" :count="value.unreadNumber" type="error" class="badge" :offset="offset"></u-badge>
  5. <view class="right title-wrap">
  6. <view class="right_top">
  7. <view class="right_top_name u-line-1">{{ value.chatName || value.nickName}}</view>
  8. <view class="right_top_time ">{{value.lastOperTime || value.lastOpenTime | format}}</view>
  9. </view>
  10. <view class="right_btm ">
  11. <view class="u-line-1">{{value.msgType==0?value.content:message[value.msgType]}}</view>
  12. <view class="" v-show="voiceIcon">
  13. <u-icon color="#c4c7cf" v-if="index%2==0" name="bell" size="22"></u-icon>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import ImgCache from '@/components/img-cache/img-cache.vue';
  21. export default {
  22. name: 'u-chatItem',
  23. components:{
  24. ImgCache
  25. },
  26. props: {
  27. value: {
  28. type: Object,
  29. default() {
  30. return {};
  31. }
  32. },
  33. index: {
  34. type: Number,
  35. default: -1
  36. },
  37. voiceIcon:{
  38. type: Boolean,
  39. default () {
  40. return false;
  41. }
  42. }
  43. },
  44. data() {
  45. return {
  46. offset:[10, 620],
  47. message:['文字', '图片', '表情', '语音', '视频',
  48. '签到', '已撤销一条消息', '发红包', '抢红包'],
  49. $url:''
  50. };
  51. },
  52. filters: {
  53. format: function (e) {
  54. // 获取js 时间戳
  55. let time = new Date().getTime();
  56. // 去掉 js 时间戳后三位
  57. time = parseInt((time - e) / 1000);
  58. // 存储转换值
  59. let s;
  60. if (time < 60 * 10) {
  61. // 十分钟内
  62. return '刚刚';
  63. } else if (time < 60 * 60 && time >= 60 * 10) {
  64. // 超过十分钟少于1小时
  65. s = Math.floor(time / 60);
  66. return s + '分钟前';
  67. } else if (time < 60 * 60 * 24 && time >= 60 * 60) {
  68. // 超过1小时少于24小时
  69. s = Math.floor(time / 60 / 60);
  70. return s + '小时前';
  71. } else if (time < 60 * 60 * 24 * 3 && time >= 60 * 60 * 24) {
  72. // 超过1天少于3天内
  73. s = Math.floor(time / 60 / 60 / 24);
  74. return s + '天前';
  75. } else {
  76. // 超过3天
  77. var date = new Date(e);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
  78. var Y = date.getFullYear() + '-';
  79. var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  80. var D = date.getDate() + ' ';
  81. var h = date.getHours() + ':';
  82. var m = date.getMinutes() + ':';
  83. var ss = date.getSeconds();
  84. return h+m+ss;
  85. }
  86. }
  87. },
  88. methods:{
  89. linkTo(item) {
  90. this.$emit('linkTo',item)
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="scss">
  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>