record.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view class="page">
  3. <view class="list-footer">
  4. <view class="searchOut">
  5. <uni-search-bar ref="searchBar" placeholder="搜索" bgColor="#F7F7F7" :show="false" @confirm="search"
  6. @input="search">
  7. </uni-search-bar>
  8. </view>
  9. </view>
  10. <scroll-view scroll-y="true" class="chat-list" :style="{'height': maxheight}" @scrolltolower="getDate">
  11. <view v-for="(row,index) in list" class="chat-item">
  12. <view class="u-img">
  13. <image
  14. :src="row.sender.avatar"
  15. :lazy-load="true" style="border-radius: 10px;" :data-id="index" @error="imageError"
  16. class="u-logo"></image>
  17. </view>
  18. <view class="u-content">
  19. <view class="chat-time">
  20. <view class="">
  21. <!-- {{row.msg.user_info.uid == 0 ? '系统': (row.msg.user_info.show_name || row.msg.user_info.name || '')}} -->
  22. {{row.sender.nickname}}
  23. </view>
  24. <view class="">
  25. <!-- {{ timestampFormat(row.msg.time + '') }} -->
  26. {{timestampToTime(row.addtime)}}
  27. </view>
  28. </view>
  29. <view class="chat-content">
  30. <!-- <image v-if="row.type == 'image'" :src="row.content1" mode="widthFix" style="max-width: 80%;"></image>
  31. <view v-if="row.type == 'video'" class="" v-html="row.content">
  32. </view> -->
  33. <rich-text :nodes="row.content"
  34. space="true" />
  35. <!-- <view v-if="row.type == 'text'" class="">
  36. {{row.content}}
  37. </view> -->
  38. </view>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. </view>
  43. </template>
  44. <script>
  45. import http from "../../library/http.js"
  46. export default {
  47. data() {
  48. return {
  49. user: uni.getStorageSync('userInfo'),
  50. // emojiList: emoj_data.emoji_list,
  51. maxheight: '',
  52. list: [],
  53. group_id: '',
  54. chat_msg: '',
  55. page: 1,
  56. limit: 30,
  57. loadingType: 'more',
  58. isgroup: 0,
  59. };
  60. },
  61. computed: {
  62. staticPhoto() {
  63. return _data.staticPhoto();
  64. },
  65. },
  66. onLoad(opt) {
  67. this.group_id = opt.group_id
  68. this.isgroup = opt.isgroup
  69. this.getDate('reload')
  70. },
  71. onShow() {
  72. let _this = this;
  73. },
  74. onReady(res) {
  75. var that = this;
  76. uni.getSystemInfo({
  77. success: resu => {
  78. const query = uni.createSelectorQuery();
  79. query.select('.chat-list').boundingClientRect();
  80. query.exec(function(res) {
  81. that.maxheight = resu.windowHeight - res[0].top + 'px';
  82. console.log(that.maxheight);
  83. });
  84. },
  85. fail: res => {}
  86. });
  87. },
  88. methods: {
  89. timestampToTime(timestamp) {
  90. var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
  91. var Y = date.getFullYear();
  92. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
  93. var D = date.getDate();
  94. var h = date.getHours();
  95. var m = date.getMinutes();
  96. var s = date.getSeconds();
  97. if (D < 10) D = '0' + D;
  98. if (h < 10) h = '0' + h;
  99. if (m < 10) m = '0' + m;
  100. if (s < 10) s = '0' + s;
  101. return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s;
  102. },
  103. imageError(e) {
  104. let index = e.currentTarget.dataset.id;
  105. this.list[index].msg.user_info.face = "/default_photo_path.png";
  106. },
  107. getDate(type) {
  108. let that = this
  109. if(type == 'reload') {
  110. that.list = []
  111. that.page = 1
  112. that.loadingType = 'more'
  113. }
  114. if(that.loadingType == 'loading' || that.loadingType == 'noMore') {
  115. return
  116. }
  117. that.loadingType = 'loading'
  118. http.setWait(false).get('group.php?act=search_msg',{
  119. id: that.group_id,
  120. page: that.page,
  121. limit: that.limit,
  122. key: that.chat_msg,
  123. isgroup: that.isgroup,
  124. userid: that.user.id
  125. }).then(res => {
  126. if(res.data && res.data.length > 0) {
  127. let data = [];
  128. res.data.forEach(item => {
  129. if(item.type != 'time') {
  130. item.content = item.content.split('-qute-')[0]
  131. data.push(item)
  132. }
  133. })
  134. that.list = that.list.concat(data.reverse())
  135. that.page++
  136. that.loadingType = 'more'
  137. }else {
  138. that.loadingType = 'noMore'
  139. }
  140. console.log(that.list);
  141. })
  142. },
  143. search(chat_msg) {
  144. let that = this
  145. that.chat_msg = chat_msg.trim();
  146. this.getDate('reload')
  147. console.log(that.chat_msg,'that.chat_msg');
  148. },
  149. }
  150. }
  151. </script>
  152. <style scoped lang="scss">
  153. page {
  154. height: auto;
  155. min-height: 100%;
  156. }
  157. .chat-list {
  158. background-color: #fff;
  159. }
  160. .u-logo {
  161. width: 75rpx !important;
  162. height: 75rpx !important;
  163. flex-shrink: 0;
  164. }
  165. .chat-item {
  166. display: flex;
  167. .u-img {
  168. // padding: 30rpx;
  169. width: 135rpx;
  170. height: 135rpx;
  171. flex-shrink: 0;
  172. display: flex;
  173. justify-content: center;
  174. align-items: center;
  175. }
  176. .u-content {
  177. flex-grow: 1;
  178. border-bottom: 1px solid #ededed;
  179. padding-right: 30rpx;
  180. padding-left: 15rpx;
  181. .chat-time {
  182. display: flex;
  183. justify-content: space-between;
  184. padding: 10rpx 0rpx;
  185. }
  186. .chat-content {
  187. padding: 10rpx 0rpx;
  188. }
  189. }
  190. }
  191. </style>