index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="search_video_container">
  3. <custom-nav-bar :title="isVideo ? '视频' : '图片'" />
  4. <u-list
  5. v-if="!isEmpty"
  6. @scrolltolower="scrolltolower"
  7. lowerThreshold="100"
  8. class="search_data_container"
  9. height="1"
  10. >
  11. <u-list-item v-for="(item, idx) in getRenderList" :key="idx">
  12. <search-media-row
  13. v-if="item.length > 0"
  14. :isVideo="isVideo"
  15. :source="item"
  16. :idx="idx"
  17. />
  18. </u-list-item>
  19. </u-list>
  20. <u-empty v-else mode="list" />
  21. </view>
  22. </template>
  23. <script>
  24. import IMSDK, { MessageType } from "openim-uniapp-polyfill";
  25. import dayjs from "dayjs";
  26. import CustomNavBar from "../../../components/CustomNavBar/index.vue";
  27. import SearchMediaRow from "./components/SearchMediaRow.vue";
  28. const systemInfo = uni.getSystemInfoSync();
  29. export default {
  30. components: {
  31. CustomNavBar,
  32. SearchMediaRow,
  33. },
  34. data() {
  35. return {
  36. isVideo: false,
  37. searchResult: {
  38. week: [],
  39. month: [],
  40. before: [],
  41. },
  42. loadState: {
  43. loading: false,
  44. hasMore: true,
  45. pageIndex: 1,
  46. },
  47. };
  48. },
  49. computed: {
  50. getRenderList() {
  51. return Object.values(this.searchResult);
  52. },
  53. isEmpty() {
  54. return (
  55. [
  56. ...this.searchResult.week,
  57. ...this.searchResult.month,
  58. ...this.searchResult.before,
  59. ].length === 0
  60. );
  61. },
  62. },
  63. onLoad(options) {
  64. const { isVideo } = options;
  65. console.log(isVideo);
  66. this.isVideo = JSON.parse(isVideo);
  67. this.loadMediaData();
  68. },
  69. methods: {
  70. scrolltolower() {
  71. if (this.loadState.hasMore && !this.loadState.loading) {
  72. this.loadSearchData();
  73. }
  74. },
  75. loadMediaData() {
  76. this.loadState.loading = true;
  77. const options = {
  78. conversationID:
  79. this.$store.getters.storeCurrentConversation.conversationID,
  80. keywordList: [],
  81. keywordListMatchType: 0,
  82. senderUserIDList: [],
  83. messageTypeList: [
  84. this.isVideo ? MessageType.VideoMessage : MessageType.PictureMessage,
  85. ],
  86. searchTimePosition: 0,
  87. searchTimePeriod: 0,
  88. pageIndex: this.loadState.pageIndex,
  89. count: 50,
  90. };
  91. IMSDK.asyncApi(IMSDK.IMMethods.SearchLocalMessages, IMSDK.uuid(), options)
  92. .then(({ data }) => {
  93. const searchData = data.searchResultItems
  94. ? data.searchResultItems[0].messageList
  95. : [];
  96. let weekMessage = [];
  97. let monthMessage = [];
  98. let beforeMessage = [];
  99. searchData.map((message) => {
  100. const time = message.sendTime;
  101. if (time > dayjs().subtract(1, "week")) {
  102. weekMessage.push(message);
  103. } else if (time > dayjs().subtract(1, "month")) {
  104. monthMessage.push(message);
  105. } else {
  106. beforeMessage.push(message);
  107. }
  108. });
  109. this.searchResult = {
  110. week: [...this.searchResult.week, ...weekMessage],
  111. month: [...this.searchResult.month, ...monthMessage],
  112. before: [...this.searchResult.before, ...beforeMessage],
  113. };
  114. console.log(this.searchResult);
  115. this.loadState.pageIndex += 1;
  116. this.loadState.hasMore = searchData.length === 50;
  117. })
  118. .catch((e) => {
  119. console.log(e);
  120. uni.$u.toast("搜索失败");
  121. })
  122. .finally(() => (this.loadState.loading = false));
  123. },
  124. },
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .search_video_container {
  129. @include colBox(false);
  130. height: 100vh;
  131. .search_data_container {
  132. flex: 1;
  133. }
  134. .u-empty {
  135. margin-top: 25vh !important;
  136. }
  137. }
  138. </style>