index.vue 2.9 KB

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