search.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="app">
  3. <view id="app-top">
  4. <uni-nav-bar statusBar backgroundColor="#f8f8f8" left-icon="left" @clickLeft="utils.navigateBack()" fixed title="搜索聊天信息" >
  5. </uni-nav-bar>
  6. <view class="search-view fx-h fx-bc fx-ac">
  7. <u--input
  8. placeholder="搜索聊天内容"
  9. prefixIcon="search"
  10. clearable
  11. border="none"
  12. prefixIconStyle="font-size: 22px;color: #909399"
  13. v-model="popKeyword"
  14. @input="tapPopKeyWord"
  15. ></u--input>
  16. </view>
  17. </view>
  18. <scroll-view class="pop-win-scroll" :style="'height:calc(100vh - ' + barheight + 'px)'" scroll-y :scroll-into-view="toView" scroll-with-animation='true' show-scrollbar="false" >
  19. <view class="item fx-r fx-bc" @tap="tapItem(item)" v-for="(item,index) in data">
  20. <image :src="utils.getAvatar(item.img,item.chat_type)" mode="aspectFill"></image>
  21. <view class="info fx-h fx-ac">
  22. <view class="nickname">{{item.name}}</view>
  23. <rich-text class="title" :nodes="getRanValue(item.data)"></rich-text>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <style>
  30. .search-view{background: #fff;margin-top: 1px;padding: 10px;}
  31. .search-view .u-input{width: 100%;}
  32. .pop-win-scroll{height:calc(100% - 60px);margin-top: 1px;}
  33. .pop-win-scroll .item{background: #fff;padding:0 10px;position: relative;}
  34. .pop-win-scroll .item:active{background: #f1f1f1;}
  35. .pop-win-scroll .item image{width: 40px;height: 40px;border-radius: 50%;}
  36. .pop-win-scroll .item .info{width: calc(100% - 70px);padding: 10px 0;margin-left: 10px;font-size: 14px;color:#787878;border-bottom: 1px solid #f1f1f1;}
  37. .pop-win-scroll .item .info .title{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;}
  38. .pop-win-scroll .item .flg{background: #ff5857;width: 20px;height: 20px;border-radius: 50%;font-size: 10px;text-align: center;line-height: 20px;color: #fff;}
  39. .pop-win-scroll .item:last-child .info{border-bottom: 0;}
  40. .pop-win-scroll .letter{padding: 10px;background: #F8F6F6;}
  41. </style>
  42. <script>
  43. import {mapState,mapMutations } from 'vuex';
  44. export default {
  45. computed: mapState(['user','sysData']),
  46. data() {
  47. return {
  48. barheight : 40,
  49. toView : "",
  50. data : [],
  51. popKeyword : "",
  52. groupId : 0
  53. }
  54. },
  55. onLoad(option){
  56. this.groupId = option.groupId || 0;
  57. this.$nextTick(() => {
  58. uni.createSelectorQuery().select("#app-top").boundingClientRect(res=>{
  59. this.barheight = res.height;
  60. }).exec();
  61. });
  62. },
  63. onUnload() {
  64. // uni.$off('groupSendClose');
  65. },
  66. methods: {
  67. /**
  68. * 配置数据
  69. */
  70. getData:function(){
  71. this
  72. .request
  73. .post("chatSearchMsg",{keyword : this.popKeyword,groupId:this.groupId})
  74. .then(res=>{
  75. if(res.code == 200) {
  76. this.data = res.data;
  77. } else {
  78. uni.showModal({title: '系统提示',content:res.msg,showCancel: false});
  79. }
  80. });
  81. },
  82. tapPopKeyWord:function(){
  83. if(this.popKeyword == '') return;
  84. this.getData();
  85. },
  86. /**
  87. * 搜索聊天信息
  88. * @param {Object} item
  89. */
  90. tapItem:function(item){
  91. //聊天分组
  92. if(item.chat_type == 'chat') {
  93. uni.navigateTo({
  94. url:'chat?groupId=' + item.group_id + '&usercode=' + item.f_uid + "&msgId=" + item.msgId + "&nid=" + item.nid
  95. })
  96. }
  97. //聊天分组
  98. if(item.chat_type == 'group_chat') {
  99. uni.navigateTo({
  100. url: 'chatGroup?groupId=' + item.group_id + '&usercode=' + item.f_uid + "&msgId=" + item.msgId + "&nid=" + item.nid
  101. })
  102. }
  103. },
  104. /**
  105. * 遍历字符串
  106. */
  107. getRanValue:function(str) {
  108. let value = str;
  109. if (value.indexOf(this.popKeyword)!==-1) {
  110. let reg = new RegExp(this.popKeyword, 'gi')
  111. return value.replace(reg, `<font style="color:#2fbec0">${this.popKeyword}</font>`)
  112. } else {
  113. return value
  114. }
  115. },
  116. }
  117. }
  118. </script>